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