two_client_themes_sync_test.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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_test.h"
8#include "chrome/browser/sync/test/integration/themes_helper.h"
9
10using themes_helper::GetCustomTheme;
11using themes_helper::GetThemeID;
12using themes_helper::HasOrWillHaveCustomTheme;
13using themes_helper::ThemeIsPendingInstall;
14using themes_helper::UseCustomTheme;
15using themes_helper::UseDefaultTheme;
16using themes_helper::UseNativeTheme;
17using themes_helper::UsingCustomTheme;
18using themes_helper::UsingDefaultTheme;
19using themes_helper::UsingNativeTheme;
20
21class 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.
35IN_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// TODO(erg): Fails on linux_aura. See http://crbug.com/304554
61#if defined(OS_CHROMEOS) || defined(OS_LINUX)
62IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_NativeTheme) {
63#else
64IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeTheme) {
65#endif  // OS_CHROMEOS
66  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
67
68  UseCustomTheme(GetProfile(0), 0);
69  UseCustomTheme(GetProfile(1), 0);
70  UseCustomTheme(verifier(), 0);
71
72  ASSERT_TRUE(AwaitQuiescence());
73
74  UseNativeTheme(GetProfile(0));
75  UseNativeTheme(verifier());
76  ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
77  ASSERT_TRUE(UsingNativeTheme(verifier()));
78
79  ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
80
81  ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
82  ASSERT_TRUE(UsingNativeTheme(GetProfile(1)));
83  ASSERT_TRUE(UsingNativeTheme(verifier()));
84}
85
86// TCM ID - 7247455.
87IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DefaultTheme) {
88  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
89
90  UseCustomTheme(GetProfile(0), 0);
91  UseCustomTheme(GetProfile(1), 0);
92  UseCustomTheme(verifier(), 0);
93
94  ASSERT_TRUE(AwaitQuiescence());
95
96  UseDefaultTheme(GetProfile(0));
97  UseDefaultTheme(verifier());
98  ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
99  ASSERT_TRUE(UsingDefaultTheme(verifier()));
100
101  ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
102
103  ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
104  ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
105  ASSERT_TRUE(UsingDefaultTheme(verifier()));
106}
107
108// TCM ID - 7292065.
109// TODO(sync): Fails on Chrome OS. See http://crbug.com/84575.
110// TODO(erg): Fails on linux_aura. See http://crbug.com/304554
111#if defined(OS_CHROMEOS) || defined(OS_LINUX)
112IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_NativeDefaultRace) {
113#else
114IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, NativeDefaultRace) {
115#endif  // OS_CHROMEOS
116  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117
118  UseNativeTheme(GetProfile(0));
119  UseDefaultTheme(GetProfile(1));
120  ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
121  ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
122
123  ASSERT_TRUE(AwaitQuiescence());
124
125  // TODO(akalin): Add function that compares two profiles to see if
126  // they're at the same state.
127
128  ASSERT_EQ(UsingNativeTheme(GetProfile(0)),
129            UsingNativeTheme(GetProfile(1)));
130  ASSERT_EQ(UsingDefaultTheme(GetProfile(0)),
131            UsingDefaultTheme(GetProfile(1)));
132}
133
134// TCM ID - 7294077.
135// TODO(sync): Fails on Chrome OS. See http://crbug.com/84575.
136#if defined(OS_CHROMEOS)
137IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DISABLED_CustomNativeRace) {
138#else
139IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomNativeRace) {
140#endif  // OS_CHROMEOS
141  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
142
143  UseCustomTheme(GetProfile(0), 0);
144  UseNativeTheme(GetProfile(1));
145  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
146  ASSERT_TRUE(UsingNativeTheme(GetProfile(1)));
147
148  ASSERT_TRUE(AwaitQuiescence());
149
150  // TODO(akalin): Add function to wait for pending extensions to be
151  // installed.
152
153  ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
154            HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
155}
156
157// TCM ID - 7307225.
158IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomDefaultRace) {
159  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
160
161  UseCustomTheme(GetProfile(0), 0);
162  UseDefaultTheme(GetProfile(1));
163  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
164  ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
165
166  ASSERT_TRUE(AwaitQuiescence());
167
168  ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
169            HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
170}
171
172// TCM ID - 7264758.
173IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomCustomRace) {
174  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
175
176  // TODO(akalin): Generalize this to n clients.
177
178  UseCustomTheme(GetProfile(0), 0);
179  UseCustomTheme(GetProfile(1), 1);
180  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
181  ASSERT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(1)));
182
183  ASSERT_TRUE(AwaitQuiescence());
184
185  bool using_theme_0 =
186      (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) &&
187      HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0));
188  bool using_theme_1 =
189      HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) &&
190      (GetThemeID(GetProfile(1)) == GetCustomTheme(1));
191
192  // Equivalent to using_theme_0 xor using_theme_1.
193  ASSERT_NE(using_theme_0, using_theme_1);
194}
195
196// TCM ID - 3723272.
197IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DisableThemes) {
198  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
199
200  ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
201  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
202  ASSERT_FALSE(UsingCustomTheme(verifier()));
203
204  ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::THEMES));
205  UseCustomTheme(GetProfile(0), 0);
206  UseCustomTheme(verifier(), 0);
207  ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
208
209  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
210  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
211  ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
212
213  ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::THEMES));
214  ASSERT_TRUE(AwaitQuiescence());
215
216  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
217  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
218  ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
219  ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
220}
221
222// TCM ID - 3687288.
223IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DisableSync) {
224  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
225
226  ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
227  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
228  ASSERT_FALSE(UsingCustomTheme(verifier()));
229
230  ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
231  UseCustomTheme(GetProfile(0), 0);
232  UseCustomTheme(verifier(), 0);
233  ASSERT_TRUE(
234      GetClient(0)->AwaitCommitActivityCompletion());
235
236  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
237  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
238  ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
239
240  ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
241  ASSERT_TRUE(AwaitQuiescence());
242
243  ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
244  ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
245  ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
246  ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
247}
248