Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_extensions_sync_test.cc
blob4a423b58f9d4f83074ab97534af65a0ff931fcce
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/test/integration/extensions_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
10 using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier;
11 using extensions_helper::DisableExtension;
12 using extensions_helper::EnableExtension;
13 using extensions_helper::HasSameExtensionsAsVerifier;
14 using extensions_helper::IncognitoDisableExtension;
15 using extensions_helper::IncognitoEnableExtension;
16 using extensions_helper::InstallExtension;
17 using extensions_helper::InstallExtensionsPendingForSync;
18 using extensions_helper::UninstallExtension;
20 class TwoClientExtensionsSyncTest : public SyncTest {
21 public:
22 TwoClientExtensionsSyncTest() : SyncTest(TWO_CLIENT) {}
24 virtual ~TwoClientExtensionsSyncTest() {}
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionsSyncTest);
30 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, StartWithNoExtensions) {
31 ASSERT_TRUE(SetupSync());
33 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
36 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, StartWithSameExtensions) {
37 ASSERT_TRUE(SetupClients());
39 const int kNumExtensions = 5;
40 for (int i = 0; i < kNumExtensions; ++i) {
41 InstallExtension(GetProfile(0), i);
42 InstallExtension(GetProfile(1), i);
43 InstallExtension(verifier(), i);
46 ASSERT_TRUE(SetupSync());
48 ASSERT_TRUE(AwaitQuiescence());
50 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
53 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
54 StartWithDifferentExtensions) {
55 ASSERT_TRUE(SetupClients());
57 int i = 0;
59 const int kNumCommonExtensions = 5;
60 for (int j = 0; j < kNumCommonExtensions; ++i, ++j) {
61 InstallExtension(GetProfile(0), i);
62 InstallExtension(GetProfile(1), i);
63 InstallExtension(verifier(), i);
66 const int kNumProfile0Extensions = 10;
67 for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) {
68 InstallExtension(GetProfile(0), i);
69 InstallExtension(verifier(), i);
72 const int kNumProfile1Extensions = 10;
73 for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) {
74 InstallExtension(GetProfile(1), i);
75 InstallExtension(verifier(), i);
78 ASSERT_TRUE(SetupSync());
80 ASSERT_TRUE(AwaitQuiescence());
82 InstallExtensionsPendingForSync(GetProfile(0));
83 InstallExtensionsPendingForSync(GetProfile(1));
85 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
88 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
89 InstallDifferentExtensions) {
90 ASSERT_TRUE(SetupClients());
92 int i = 0;
94 const int kNumCommonExtensions = 5;
95 for (int j = 0; j < kNumCommonExtensions; ++i, ++j) {
96 InstallExtension(GetProfile(0), i);
97 InstallExtension(GetProfile(1), i);
98 InstallExtension(verifier(), i);
101 ASSERT_TRUE(SetupSync());
103 ASSERT_TRUE(AwaitQuiescence());
105 const int kNumProfile0Extensions = 10;
106 for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) {
107 InstallExtension(GetProfile(0), i);
108 InstallExtension(verifier(), i);
111 const int kNumProfile1Extensions = 10;
112 for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) {
113 InstallExtension(GetProfile(1), i);
114 InstallExtension(verifier(), i);
117 ASSERT_TRUE(AwaitQuiescence());
119 InstallExtensionsPendingForSync(GetProfile(0));
120 InstallExtensionsPendingForSync(GetProfile(1));
122 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
125 // TCM ID - 3637311.
126 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, Add) {
127 ASSERT_TRUE(SetupSync());
128 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
130 InstallExtension(GetProfile(0), 0);
131 InstallExtension(verifier(), 0);
132 ASSERT_TRUE(AwaitQuiescence());
134 InstallExtensionsPendingForSync(GetProfile(0));
135 InstallExtensionsPendingForSync(GetProfile(1));
136 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
139 // TCM ID - 3724281.
140 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, Uninstall) {
141 ASSERT_TRUE(SetupSync());
142 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
144 InstallExtension(GetProfile(0), 0);
145 InstallExtension(verifier(), 0);
146 ASSERT_TRUE(AwaitQuiescence());
148 InstallExtensionsPendingForSync(GetProfile(0));
149 InstallExtensionsPendingForSync(GetProfile(1));
150 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
152 UninstallExtension(GetProfile(0), 0);
153 UninstallExtension(verifier(), 0);
154 ASSERT_TRUE(AwaitQuiescence());
155 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
158 // TCM ID - 3635304.
159 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, Merge) {
160 ASSERT_TRUE(SetupSync());
161 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
163 InstallExtension(GetProfile(0), 0);
164 InstallExtension(GetProfile(1), 0);
165 ASSERT_TRUE(AwaitQuiescence());
167 UninstallExtension(GetProfile(0), 0);
168 InstallExtension(GetProfile(0), 1);
169 InstallExtension(verifier(), 1);
171 InstallExtension(GetProfile(0), 2);
172 InstallExtension(GetProfile(1), 2);
173 InstallExtension(verifier(), 2);
175 InstallExtension(GetProfile(1), 3);
176 InstallExtension(verifier(), 3);
178 ASSERT_TRUE(AwaitQuiescence());
179 InstallExtensionsPendingForSync(GetProfile(0));
180 InstallExtensionsPendingForSync(GetProfile(1));
181 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
184 // TCM ID - 3605300.
185 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
186 UpdateEnableDisableExtension) {
187 ASSERT_TRUE(SetupSync());
188 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
190 InstallExtension(GetProfile(0), 0);
191 InstallExtension(GetProfile(1), 0);
192 InstallExtension(verifier(), 0);
193 ASSERT_TRUE(AwaitQuiescence());
194 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
196 DisableExtension(GetProfile(0), 0);
197 DisableExtension(verifier(), 0);
198 ASSERT_TRUE(HasSameExtensionsAsVerifier(0));
199 ASSERT_FALSE(HasSameExtensionsAsVerifier(1));
201 ASSERT_TRUE(AwaitQuiescence());
202 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
204 EnableExtension(GetProfile(1), 0);
205 EnableExtension(verifier(), 0);
206 ASSERT_TRUE(HasSameExtensionsAsVerifier(1));
207 ASSERT_FALSE(HasSameExtensionsAsVerifier(0));
209 ASSERT_TRUE(AwaitQuiescence());
210 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
213 // TCM ID - 3728322.
214 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
215 UpdateIncognitoEnableDisable) {
216 ASSERT_TRUE(SetupSync());
217 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
219 InstallExtension(GetProfile(0), 0);
220 InstallExtension(GetProfile(1), 0);
221 InstallExtension(verifier(), 0);
222 ASSERT_TRUE(AwaitQuiescence());
223 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
225 IncognitoEnableExtension(GetProfile(0), 0);
226 IncognitoEnableExtension(verifier(), 0);
227 ASSERT_TRUE(HasSameExtensionsAsVerifier(0));
228 ASSERT_FALSE(HasSameExtensionsAsVerifier(1));
230 ASSERT_TRUE(AwaitQuiescence());
231 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
233 IncognitoDisableExtension(GetProfile(1), 0);
234 IncognitoDisableExtension(verifier(), 0);
235 ASSERT_TRUE(HasSameExtensionsAsVerifier(1));
236 ASSERT_FALSE(HasSameExtensionsAsVerifier(0));
238 ASSERT_TRUE(AwaitQuiescence());
239 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
242 // TCM ID - 3732278.
243 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, DisableExtensions) {
244 ASSERT_TRUE(SetupSync());
245 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
247 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::EXTENSIONS));
248 InstallExtension(GetProfile(0), 1);
249 InstallExtension(verifier(), 1);
250 ASSERT_TRUE(
251 GetClient(0)->AwaitFullSyncCompletion());
252 ASSERT_FALSE(AllProfilesHaveSameExtensionsAsVerifier());
254 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::EXTENSIONS));
255 ASSERT_TRUE(AwaitQuiescence());
256 InstallExtensionsPendingForSync(GetProfile(0));
257 InstallExtensionsPendingForSync(GetProfile(1));
258 InstallExtensionsPendingForSync(verifier());
259 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
262 // TCM ID - 3606290.
263 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, DisableSync) {
264 ASSERT_TRUE(SetupSync());
265 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
267 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
268 InstallExtension(GetProfile(0), 0);
269 InstallExtension(verifier(), 0);
270 ASSERT_TRUE(
271 GetClient(0)->AwaitFullSyncCompletion());
272 ASSERT_TRUE(HasSameExtensionsAsVerifier(0));
273 ASSERT_FALSE(HasSameExtensionsAsVerifier(1));
275 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
276 ASSERT_TRUE(AwaitQuiescence());
277 InstallExtensionsPendingForSync(GetProfile(0));
278 InstallExtensionsPendingForSync(GetProfile(1));
279 InstallExtensionsPendingForSync(verifier());
280 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
283 // Regression test for bug 104399: ensure that an extension installed prior to
284 // setting up sync, when uninstalled, is also uninstalled from sync.
285 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
286 UninstallPreinstalledExtensions) {
287 ASSERT_TRUE(SetupClients());
288 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
290 InstallExtension(GetProfile(0), 0);
291 InstallExtension(verifier(), 0);
293 ASSERT_TRUE(SetupSync());
295 InstallExtensionsPendingForSync(GetProfile(0));
296 InstallExtensionsPendingForSync(GetProfile(1));
297 ASSERT_TRUE(AwaitQuiescence());
298 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
300 UninstallExtension(GetProfile(0), 0);
301 UninstallExtension(verifier(), 0);
303 ASSERT_TRUE(AwaitQuiescence());
304 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
307 // TODO(akalin): Add tests exercising:
308 // - Offline installation/uninstallation behavior