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.
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"
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;
21 class TwoClientThemesSyncTest : public SyncTest {
23 TwoClientThemesSyncTest() : SyncTest(TWO_CLIENT) {}
24 virtual ~TwoClientThemesSyncTest() {}
27 DISALLOW_COPY_AND_ASSIGN(TwoClientThemesSyncTest);
30 // TODO(akalin): Add tests for model association (i.e., tests that
31 // start with SetupClients(), change the theme state, then call
35 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomTheme) {
36 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
38 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
39 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
40 ASSERT_FALSE(UsingCustomTheme(verifier()));
42 UseCustomTheme(GetProfile(0), 0);
43 UseCustomTheme(verifier(), 0);
44 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
45 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
47 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
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
54 ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
55 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
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) {
63 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeTheme) {
65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
67 UseCustomTheme(GetProfile(0), 0);
68 UseCustomTheme(GetProfile(1), 0);
69 UseCustomTheme(verifier(), 0);
71 ASSERT_TRUE(AwaitQuiescence());
73 UseNativeTheme(GetProfile(0));
74 UseNativeTheme(verifier());
75 ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
76 ASSERT_TRUE(UsingNativeTheme(verifier()));
78 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
80 ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
81 ASSERT_TRUE(UsingNativeTheme(GetProfile(1)));
82 ASSERT_TRUE(UsingNativeTheme(verifier()));
86 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DefaultTheme) {
87 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
89 UseCustomTheme(GetProfile(0), 0);
90 UseCustomTheme(GetProfile(1), 0);
91 UseCustomTheme(verifier(), 0);
93 ASSERT_TRUE(AwaitQuiescence());
95 UseDefaultTheme(GetProfile(0));
96 UseDefaultTheme(verifier());
97 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
98 ASSERT_TRUE(UsingDefaultTheme(verifier()));
100 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
102 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
103 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
104 ASSERT_TRUE(UsingDefaultTheme(verifier()));
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) {
112 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeDefaultRace) {
113 #endif // OS_CHROMEOS
114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
116 UseNativeTheme(GetProfile(0));
117 UseDefaultTheme(GetProfile(1));
118 ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
119 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
121 ASSERT_TRUE(AwaitQuiescence());
123 // TODO(akalin): Add function that compares two profiles to see if
124 // they're at the same state.
126 ASSERT_EQ(UsingNativeTheme(GetProfile(0)),
127 UsingNativeTheme(GetProfile(1)));
128 ASSERT_EQ(UsingDefaultTheme(GetProfile(0)),
129 UsingDefaultTheme(GetProfile(1)));
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) {
137 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomNativeRace) {
138 #endif // OS_CHROMEOS
139 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
141 UseCustomTheme(GetProfile(0), 0);
142 UseNativeTheme(GetProfile(1));
143 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
144 ASSERT_TRUE(UsingNativeTheme(GetProfile(1)));
146 ASSERT_TRUE(AwaitQuiescence());
148 // TODO(akalin): Add function to wait for pending extensions to be
151 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
152 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
156 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomDefaultRace) {
157 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
159 UseCustomTheme(GetProfile(0), 0);
160 UseDefaultTheme(GetProfile(1));
161 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
162 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
164 ASSERT_TRUE(AwaitQuiescence());
166 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
167 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
171 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomCustomRace) {
172 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
174 // TODO(akalin): Generalize this to n clients.
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)));
181 ASSERT_TRUE(AwaitQuiescence());
184 (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) &&
185 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0));
187 HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) &&
188 (GetThemeID(GetProfile(1)) == GetCustomTheme(1));
190 // Equivalent to using_theme_0 xor using_theme_1.
191 ASSERT_NE(using_theme_0, using_theme_1);
195 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DisableThemes) {
196 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
198 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
199 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
200 ASSERT_FALSE(UsingCustomTheme(verifier()));
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."));
207 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
208 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
209 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
211 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::THEMES));
212 ASSERT_TRUE(AwaitQuiescence());
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()));
221 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DisableSync) {
222 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
224 ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
225 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
226 ASSERT_FALSE(UsingCustomTheme(verifier()));
228 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
229 UseCustomTheme(GetProfile(0), 0);
230 UseCustomTheme(verifier(), 0);
232 GetClient(0)->AwaitFullSyncCompletion("Installed a custom theme."));
234 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
235 ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
236 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
238 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
239 ASSERT_TRUE(AwaitQuiescence());
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)));