Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_apps_sync_test.cc
blob8b9e9a96d0acc66ef67721b1e8c2a7ac41ccabf5
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/extensions/extension_service.h"
7 #include "chrome/browser/extensions/launch_util.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/test/integration/apps_helper.h"
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
11 #include "chrome/browser/sync/test/integration/sync_app_helper.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "chrome/common/extensions/extension_constants.h"
14 #include "extensions/browser/app_sorting.h"
15 #include "sync/api/string_ordinal.h"
17 using apps_helper::AllProfilesHaveSameAppsAsVerifier;
18 using apps_helper::CopyNTPOrdinals;
19 using apps_helper::DisableApp;
20 using apps_helper::EnableApp;
21 using apps_helper::FixNTPOrdinalCollisions;
22 using apps_helper::GetAppLaunchOrdinalForApp;
23 using apps_helper::HasSameAppsAsVerifier;
24 using apps_helper::IncognitoDisableApp;
25 using apps_helper::IncognitoEnableApp;
26 using apps_helper::InstallApp;
27 using apps_helper::InstallAppsPendingForSync;
28 using apps_helper::InstallPlatformApp;
29 using apps_helper::SetAppLaunchOrdinalForApp;
30 using apps_helper::SetPageOrdinalForApp;
31 using apps_helper::UninstallApp;
33 class TwoClientAppsSyncTest : public SyncTest {
34 public:
35 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {}
37 virtual ~TwoClientAppsSyncTest() {}
39 private:
40 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest);
43 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithNoApps) {
44 ASSERT_TRUE(SetupSync());
46 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
49 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithSameApps) {
50 ASSERT_TRUE(SetupClients());
52 const int kNumApps = 5;
53 for (int i = 0; i < kNumApps; ++i) {
54 InstallApp(GetProfile(0), i);
55 InstallApp(GetProfile(1), i);
56 InstallApp(verifier(), i);
59 ASSERT_TRUE(SetupSync());
61 ASSERT_TRUE(AwaitQuiescence());
63 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
66 // Install some apps on both clients, some on only one client, some on only the
67 // other, and sync. Both clients should end up with all apps, and the app and
68 // page ordinals should be identical.
69 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithDifferentApps) {
70 ASSERT_TRUE(SetupClients());
72 int i = 0;
74 const int kNumCommonApps = 5;
75 for (int j = 0; j < kNumCommonApps; ++i, ++j) {
76 InstallApp(GetProfile(0), i);
77 InstallApp(GetProfile(1), i);
78 InstallApp(verifier(), i);
81 const int kNumProfile0Apps = 10;
82 for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
83 InstallApp(GetProfile(0), i);
84 InstallApp(verifier(), i);
85 CopyNTPOrdinals(GetProfile(0), verifier(), i);
88 const int kNumProfile1Apps = 10;
89 for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
90 InstallApp(GetProfile(1), i);
91 InstallApp(verifier(), i);
92 CopyNTPOrdinals(GetProfile(1), verifier(), i);
95 const int kNumPlatformApps = 5;
96 for (int j = 0; j < kNumPlatformApps; ++i, ++j) {
97 InstallPlatformApp(GetProfile(1), i);
98 InstallPlatformApp(verifier(), i);
99 CopyNTPOrdinals(GetProfile(1), verifier(), i);
102 FixNTPOrdinalCollisions(verifier());
104 ASSERT_TRUE(SetupSync());
106 ASSERT_TRUE(AwaitQuiescence());
108 InstallAppsPendingForSync(GetProfile(0));
109 InstallAppsPendingForSync(GetProfile(1));
111 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
114 // Install some apps on both clients, then sync. Then install some apps on only
115 // one client, some on only the other, and then sync again. Both clients should
116 // end up with all apps, and the app and page ordinals should be identical.
117 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, InstallDifferentApps) {
118 ASSERT_TRUE(SetupClients());
120 int i = 0;
122 const int kNumCommonApps = 5;
123 for (int j = 0; j < kNumCommonApps; ++i, ++j) {
124 InstallApp(GetProfile(0), i);
125 InstallApp(GetProfile(1), i);
126 InstallApp(verifier(), i);
129 ASSERT_TRUE(SetupSync());
131 ASSERT_TRUE(AwaitQuiescence());
133 const int kNumProfile0Apps = 10;
134 for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
135 InstallApp(GetProfile(0), i);
136 InstallApp(verifier(), i);
137 CopyNTPOrdinals(GetProfile(0), verifier(), i);
140 const int kNumProfile1Apps = 10;
141 for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
142 InstallApp(GetProfile(1), i);
143 InstallApp(verifier(), i);
144 CopyNTPOrdinals(GetProfile(1), verifier(), i);
147 FixNTPOrdinalCollisions(verifier());
149 ASSERT_TRUE(AwaitQuiescence());
151 InstallAppsPendingForSync(GetProfile(0));
152 InstallAppsPendingForSync(GetProfile(1));
154 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
157 // TCM ID - 3711279.
158 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Add) {
159 ASSERT_TRUE(SetupSync());
160 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
162 InstallApp(GetProfile(0), 0);
163 InstallApp(verifier(), 0);
164 ASSERT_TRUE(AwaitQuiescence());
166 InstallAppsPendingForSync(GetProfile(0));
167 InstallAppsPendingForSync(GetProfile(1));
168 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
171 // TCM ID - 3706267.
172 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Uninstall) {
173 ASSERT_TRUE(SetupSync());
174 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
176 InstallApp(GetProfile(0), 0);
177 InstallApp(verifier(), 0);
178 ASSERT_TRUE(AwaitQuiescence());
180 InstallAppsPendingForSync(GetProfile(0));
181 InstallAppsPendingForSync(GetProfile(1));
182 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
184 UninstallApp(GetProfile(0), 0);
185 UninstallApp(verifier(), 0);
186 ASSERT_TRUE(AwaitQuiescence());
187 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
190 // Install an app on one client, then sync. Then uninstall the app on the first
191 // client and sync again. Now install a new app on the first client and sync.
192 // Both client should only have the second app, with identical app and page
193 // ordinals.
194 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UninstallThenInstall) {
195 ASSERT_TRUE(SetupSync());
196 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
198 InstallApp(GetProfile(0), 0);
199 InstallApp(verifier(), 0);
200 ASSERT_TRUE(AwaitQuiescence());
202 InstallAppsPendingForSync(GetProfile(0));
203 InstallAppsPendingForSync(GetProfile(1));
204 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
206 UninstallApp(GetProfile(0), 0);
207 UninstallApp(verifier(), 0);
208 ASSERT_TRUE(AwaitQuiescence());
209 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
211 InstallApp(GetProfile(0), 1);
212 InstallApp(verifier(), 1);
213 ASSERT_TRUE(AwaitQuiescence());
214 InstallAppsPendingForSync(GetProfile(0));
215 InstallAppsPendingForSync(GetProfile(1));
216 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
219 // TCM ID - 3699295.
220 // Flaky: http://crbug.com/226055
221 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DISABLED_Merge) {
222 ASSERT_TRUE(SetupSync());
223 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
225 InstallApp(GetProfile(0), 0);
226 InstallApp(GetProfile(1), 0);
227 ASSERT_TRUE(AwaitQuiescence());
229 UninstallApp(GetProfile(0), 0);
230 InstallApp(GetProfile(0), 1);
231 InstallApp(verifier(), 1);
233 InstallApp(GetProfile(0), 2);
234 InstallApp(GetProfile(1), 2);
235 InstallApp(verifier(), 2);
237 InstallApp(GetProfile(1), 3);
238 InstallApp(verifier(), 3);
240 ASSERT_TRUE(AwaitQuiescence());
241 InstallAppsPendingForSync(GetProfile(0));
242 InstallAppsPendingForSync(GetProfile(1));
243 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
246 // TCM ID - 7723126.
247 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateEnableDisableApp) {
248 ASSERT_TRUE(SetupSync());
249 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
251 InstallApp(GetProfile(0), 0);
252 InstallApp(GetProfile(1), 0);
253 InstallApp(verifier(), 0);
254 ASSERT_TRUE(AwaitQuiescence());
255 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
257 DisableApp(GetProfile(0), 0);
258 DisableApp(verifier(), 0);
259 ASSERT_TRUE(HasSameAppsAsVerifier(0));
260 ASSERT_FALSE(HasSameAppsAsVerifier(1));
262 ASSERT_TRUE(AwaitQuiescence());
263 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
265 EnableApp(GetProfile(1), 0);
266 EnableApp(verifier(), 0);
267 ASSERT_TRUE(HasSameAppsAsVerifier(1));
268 ASSERT_FALSE(HasSameAppsAsVerifier(0));
270 ASSERT_TRUE(AwaitQuiescence());
271 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
274 // TCM ID - 7706637.
275 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateIncognitoEnableDisable) {
276 ASSERT_TRUE(SetupSync());
277 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
279 InstallApp(GetProfile(0), 0);
280 InstallApp(GetProfile(1), 0);
281 InstallApp(verifier(), 0);
282 ASSERT_TRUE(AwaitQuiescence());
283 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
285 IncognitoEnableApp(GetProfile(0), 0);
286 IncognitoEnableApp(verifier(), 0);
287 ASSERT_TRUE(HasSameAppsAsVerifier(0));
288 ASSERT_FALSE(HasSameAppsAsVerifier(1));
290 ASSERT_TRUE(AwaitQuiescence());
291 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
293 IncognitoDisableApp(GetProfile(1), 0);
294 IncognitoDisableApp(verifier(), 0);
295 ASSERT_TRUE(HasSameAppsAsVerifier(1));
296 ASSERT_FALSE(HasSameAppsAsVerifier(0));
298 ASSERT_TRUE(AwaitQuiescence());
299 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
302 // TCM ID - 3718276.
303 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableApps) {
304 ASSERT_TRUE(SetupSync());
305 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
307 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::APPS));
308 InstallApp(GetProfile(0), 0);
309 InstallApp(verifier(), 0);
310 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
311 ASSERT_TRUE(HasSameAppsAsVerifier(0));
312 ASSERT_FALSE(HasSameAppsAsVerifier(1));
314 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::APPS));
315 ASSERT_TRUE(AwaitQuiescence());
317 InstallAppsPendingForSync(GetProfile(0));
318 InstallAppsPendingForSync(GetProfile(1));
319 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
322 // Disable sync for the second client and then install an app on the first
323 // client, then enable sync on the second client. Both clients should have the
324 // same app with identical app and page ordinals.
325 // TCM ID - 3720303.
326 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableSync) {
327 ASSERT_TRUE(SetupSync());
328 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
330 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
331 InstallApp(GetProfile(0), 0);
332 InstallApp(verifier(), 0);
333 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
334 ASSERT_TRUE(HasSameAppsAsVerifier(0));
335 ASSERT_FALSE(HasSameAppsAsVerifier(1));
337 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
338 ASSERT_TRUE(AwaitQuiescence());
340 InstallAppsPendingForSync(GetProfile(0));
341 InstallAppsPendingForSync(GetProfile(1));
342 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
345 // Install the same app on both clients, then sync. Change the page ordinal on
346 // one client and sync. Both clients should have the updated page ordinal for
347 // the app.
348 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdatePageOrdinal) {
349 ASSERT_TRUE(SetupSync());
350 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
352 syncer::StringOrdinal initial_page =
353 syncer::StringOrdinal::CreateInitialOrdinal();
354 InstallApp(GetProfile(0), 0);
355 InstallApp(GetProfile(1), 0);
356 InstallApp(verifier(), 0);
357 ASSERT_TRUE(AwaitQuiescence());
358 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
360 syncer::StringOrdinal second_page = initial_page.CreateAfter();
361 SetPageOrdinalForApp(GetProfile(0), 0, second_page);
362 SetPageOrdinalForApp(verifier(), 0, second_page);
363 ASSERT_TRUE(AwaitQuiescence());
364 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
367 // Install the same app on both clients, then sync. Change the app launch
368 // ordinal on one client and sync. Both clients should have the updated app
369 // launch ordinal for the app.
370 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateAppLaunchOrdinal) {
371 ASSERT_TRUE(SetupSync());
372 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
374 InstallApp(GetProfile(0), 0);
375 InstallApp(GetProfile(1), 0);
376 InstallApp(verifier(), 0);
377 ASSERT_TRUE(AwaitQuiescence());
378 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
380 syncer::StringOrdinal initial_position =
381 GetAppLaunchOrdinalForApp(GetProfile(0), 0);
383 syncer::StringOrdinal second_position = initial_position.CreateAfter();
384 SetAppLaunchOrdinalForApp(GetProfile(0), 0, second_position);
385 SetAppLaunchOrdinalForApp(verifier(), 0, second_position);
386 ASSERT_TRUE(AwaitQuiescence());
387 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
390 // Adjust the CWS location within a page on the first client and sync. Adjust
391 // which page the CWS appears on and sync. Both clients should have the same
392 // page and app launch ordinal values for the CWS.
393 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateCWSOrdinals) {
394 ASSERT_TRUE(SetupSync());
395 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
397 // Change the app launch ordinal.
398 syncer::StringOrdinal cws_app_launch_ordinal =
399 GetProfile(0)->GetExtensionService()->
400 extension_prefs()->app_sorting()->GetAppLaunchOrdinal(
401 extension_misc::kWebStoreAppId);
402 GetProfile(0)->GetExtensionService()->extension_prefs()->app_sorting()->
403 SetAppLaunchOrdinal(
404 extension_misc::kWebStoreAppId, cws_app_launch_ordinal.CreateAfter());
405 verifier()->GetExtensionService()->extension_prefs()->app_sorting()->
406 SetAppLaunchOrdinal(
407 extension_misc::kWebStoreAppId, cws_app_launch_ordinal.CreateAfter());
408 ASSERT_TRUE(AwaitQuiescence());
409 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
411 // Change the page ordinal.
412 syncer::StringOrdinal cws_page_ordinal =
413 GetProfile(1)->GetExtensionService()->
414 extension_prefs()->app_sorting()->GetPageOrdinal(
415 extension_misc::kWebStoreAppId);
416 GetProfile(1)->GetExtensionService()->extension_prefs()->
417 app_sorting()->SetPageOrdinal(extension_misc::kWebStoreAppId,
418 cws_page_ordinal.CreateAfter());
419 verifier()->GetExtensionService()->extension_prefs()->
420 app_sorting()->SetPageOrdinal(extension_misc::kWebStoreAppId,
421 cws_page_ordinal.CreateAfter());
422 ASSERT_TRUE(AwaitQuiescence());
423 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
426 // Adjust the launch type on the first client and sync. Both clients should
427 // have the same launch type values for the CWS.
428 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) {
429 ASSERT_TRUE(SetupSync());
430 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
432 // Change the launch type to window.
433 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
434 extension_misc::kWebStoreAppId,
435 extensions::LAUNCH_TYPE_WINDOW);
436 extensions::SetLaunchType(verifier()->GetExtensionService(),
437 extension_misc::kWebStoreAppId,
438 extensions::LAUNCH_TYPE_WINDOW);
439 ASSERT_TRUE(AwaitQuiescence());
440 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
442 // Change the launch type to regular tab.
443 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
444 extension_misc::kWebStoreAppId,
445 extensions::LAUNCH_TYPE_REGULAR);
446 ASSERT_FALSE(HasSameAppsAsVerifier(1));
447 extensions::SetLaunchType(verifier()->GetExtensionService(),
448 extension_misc::kWebStoreAppId,
449 extensions::LAUNCH_TYPE_REGULAR);
450 ASSERT_TRUE(AwaitQuiescence());
451 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
454 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) {
455 ASSERT_TRUE(SetupSync());
456 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
458 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
459 extension_misc::kWebStoreAppId,
460 extensions::LAUNCH_TYPE_REGULAR);
461 extensions::SetLaunchType(verifier()->GetExtensionService(),
462 extension_misc::kWebStoreAppId,
463 extensions::LAUNCH_TYPE_REGULAR);
464 ASSERT_TRUE(AwaitQuiescence());
465 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
467 const extensions::Extension* extension =
468 GetProfile(1)->GetExtensionService()->
469 GetInstalledExtension(extension_misc::kWebStoreAppId);
470 ASSERT_TRUE(extension);
472 ExtensionSyncService* extension_sync_service =
473 ExtensionSyncService::Get(GetProfile(1));
475 extensions::AppSyncData original_data(
476 extension_sync_service->GetAppSyncData(*extension));
478 // Create an invalid launch type and ensure it doesn't get down-synced. This
479 // simulates the case of a future launch type being added which old versions
480 // don't yet understand.
481 extensions::AppSyncData invalid_launch_type_data(
482 *extension,
483 original_data.extension_sync_data().enabled(),
484 original_data.extension_sync_data().incognito_enabled(),
485 original_data.app_launch_ordinal(),
486 original_data.page_ordinal(),
487 extensions::NUM_LAUNCH_TYPES);
488 extension_sync_service->ProcessAppSyncData(invalid_launch_type_data);
490 // The launch type should remain the same.
491 ASSERT_TRUE(AwaitQuiescence());
492 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
495 // TODO(akalin): Add tests exercising:
496 // - Offline installation/uninstallation behavior
497 // - App-specific properties