1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
7 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
9 #include "chrome/browser/sync/test/integration/themes_helper.h"
10
11 using sync_integration_test_util::AwaitCommitActivityCompletion;
12 using themes_helper::GetCustomTheme;
13 using themes_helper::GetThemeID;
14 using themes_helper::HasOrWillHaveCustomTheme;
15 using themes_helper::ThemeIsPendingInstall;
16 using themes_helper::UseCustomTheme;
17 using themes_helper::UseDefaultTheme;
18 using themes_helper::UseSystemTheme;
19 using themes_helper::UsingCustomTheme;
20 using themes_helper::UsingDefaultTheme;
21 using themes_helper::UsingSystemTheme;
22
23 class TwoClientThemesSyncTest : public SyncTest {
24 public:
TwoClientThemesSyncTest()25 TwoClientThemesSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientThemesSyncTest()26 virtual ~TwoClientThemesSyncTest() {}
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(TwoClientThemesSyncTest);
30 };
31
32 class LegacyTwoClientThemesSyncTest : public SyncTest {
33 public:
LegacyTwoClientThemesSyncTest()34 LegacyTwoClientThemesSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {}
~LegacyTwoClientThemesSyncTest()35 virtual ~LegacyTwoClientThemesSyncTest() {}
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(LegacyTwoClientThemesSyncTest);
39 };
40
41 // TODO(akalin): Add tests for model association (i.e., tests that
42 // start with SetupClients(), change the theme state, then call
43 // SetupSync()).
44
45 // TCM ID - 3667311.
IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest,CustomTheme)46 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomTheme) {
47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
48
49 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
50 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
51 ASSERT_FALSE(UsingCustomTheme(verifier()));
52
53 UseCustomTheme(GetProfile(0), 0);
54 UseCustomTheme(verifier(), 0);
55 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
56 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
57
58 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
59
60 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
61 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
62 // TODO(akalin): Add functions to simulate when a pending extension
63 // is installed as well as when a pending extension fails to
64 // install.
65 ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
66 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
67 }
68
69 // TCM ID - 3599303.
70 // TODO(sync): Fails on Chrome OS. See http://crbug.com/84575.
71 // TODO(erg): Fails on linux_aura. See http://crbug.com/304554
72 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest,DISABLED_NativeTheme)73 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_NativeTheme) {
74 #else
75 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeTheme) {
76 #endif // OS_CHROMEOS
77 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
78
79 UseCustomTheme(GetProfile(0), 0);
80 UseCustomTheme(GetProfile(1), 0);
81 UseCustomTheme(verifier(), 0);
82
83 ASSERT_TRUE(AwaitQuiescence());
84
85 UseSystemTheme(GetProfile(0));
86 UseSystemTheme(verifier());
87 ASSERT_TRUE(UsingSystemTheme(GetProfile(0)));
88 ASSERT_TRUE(UsingSystemTheme(verifier()));
89
90 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
91
92 ASSERT_TRUE(UsingSystemTheme(GetProfile(0)));
93 ASSERT_TRUE(UsingSystemTheme(GetProfile(1)));
94 ASSERT_TRUE(UsingSystemTheme(verifier()));
95 }
96
97 // TCM ID - 7247455.
98 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DefaultTheme) {
99 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
100
101 UseCustomTheme(GetProfile(0), 0);
102 UseCustomTheme(GetProfile(1), 0);
103 UseCustomTheme(verifier(), 0);
104
105 ASSERT_TRUE(AwaitQuiescence());
106
107 UseDefaultTheme(GetProfile(0));
108 UseDefaultTheme(verifier());
109 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
110 ASSERT_TRUE(UsingDefaultTheme(verifier()));
111
112 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
113
114 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
115 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
116 ASSERT_TRUE(UsingDefaultTheme(verifier()));
117 }
118
119 // TCM ID - 7292065.
120 // TODO(sync): Fails on Chrome OS. See http://crbug.com/84575.
121 // TODO(erg): Fails on linux_aura. See http://crbug.com/304554
122 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
123 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_NativeDefaultRace) {
124 #else
125 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeDefaultRace) {
126 #endif // OS_CHROMEOS
127 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
128
129 UseSystemTheme(GetProfile(0));
130 UseDefaultTheme(GetProfile(1));
131 ASSERT_TRUE(UsingSystemTheme(GetProfile(0)));
132 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
133
134 ASSERT_TRUE(AwaitQuiescence());
135
136 // TODO(akalin): Add function that compares two profiles to see if
137 // they're at the same state.
138
139 ASSERT_EQ(UsingSystemTheme(GetProfile(0)),
140 UsingSystemTheme(GetProfile(1)));
141 ASSERT_EQ(UsingDefaultTheme(GetProfile(0)),
142 UsingDefaultTheme(GetProfile(1)));
143 }
144
145 // TCM ID - 7294077.
146 // TODO(sync): Fails on Chrome OS. See http://crbug.com/84575.
147 #if defined(OS_CHROMEOS)
148 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_CustomNativeRace) {
149 #else
150 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomNativeRace) {
151 #endif // OS_CHROMEOS
152 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
153
154 UseCustomTheme(GetProfile(0), 0);
155 UseSystemTheme(GetProfile(1));
156 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
157 ASSERT_TRUE(UsingSystemTheme(GetProfile(1)));
158
159 ASSERT_TRUE(AwaitQuiescence());
160
161 // TODO(akalin): Add function to wait for pending extensions to be
162 // installed.
163
164 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
165 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
166 }
167
168 // TCM ID - 7307225.
169 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomDefaultRace) {
170 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
171
172 UseCustomTheme(GetProfile(0), 0);
173 UseDefaultTheme(GetProfile(1));
174 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
175 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
176
177 ASSERT_TRUE(AwaitQuiescence());
178
179 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
180 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
181 }
182
183 // TCM ID - 7264758.
184 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomCustomRace) {
185 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
186
187 // TODO(akalin): Generalize this to n clients.
188
189 UseCustomTheme(GetProfile(0), 0);
190 UseCustomTheme(GetProfile(1), 1);
191 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
192 ASSERT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(1)));
193
194 ASSERT_TRUE(AwaitQuiescence());
195
196 bool using_theme_0 =
197 (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) &&
198 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0));
199 bool using_theme_1 =
200 HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) &&
201 (GetThemeID(GetProfile(1)) == GetCustomTheme(1));
202
203 // Equivalent to using_theme_0 xor using_theme_1.
204 ASSERT_NE(using_theme_0, using_theme_1);
205 }
206
207 // TCM ID - 3723272.
208 IN_PROC_BROWSER_TEST_F(LegacyTwoClientThemesSyncTest, DisableThemes) {
209 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
210
211 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
212 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
213 ASSERT_FALSE(UsingCustomTheme(verifier()));
214
215 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::THEMES));
216 UseCustomTheme(GetProfile(0), 0);
217 UseCustomTheme(verifier(), 0);
218 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
219
220 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
221 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
222 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
223
224 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::THEMES));
225 ASSERT_TRUE(AwaitQuiescence());
226
227 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
228 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
229 ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
230 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
231 }
232
233 // TCM ID - 3687288.
234 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DisableSync) {
235 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
236
237 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
238 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
239 ASSERT_FALSE(UsingCustomTheme(verifier()));
240
241 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
242 UseCustomTheme(GetProfile(0), 0);
243 UseCustomTheme(verifier(), 0);
244 ASSERT_TRUE(
245 AwaitCommitActivityCompletion(GetSyncService((0))));
246
247 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
248 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
249 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
250
251 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
252 ASSERT_TRUE(AwaitQuiescence());
253
254 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
255 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
256 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
257 ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
258 }
259