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