b8e86ad09fe95de25a09852d9179450541feb4e1
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / two_client_app_list_sync_test.cc
1 // Copyright 2013 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 "base/command_line.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/test/integration/apps_helper.h"
11 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
12 #include "chrome/browser/sync/test/integration/sync_app_list_helper.h"
13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
14 #include "chrome/browser/sync/test/integration/sync_test.h"
15 #include "chrome/browser/ui/app_list/app_list_prefs.h"
16 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
17 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/test/test_utils.h"
20 #include "extensions/browser/extension_prefs.h"
21 #include "extensions/browser/extension_system.h"
22 #include "ui/app_list/app_list_item.h"
23 #include "ui/app_list/app_list_model.h"
24 #include "ui/app_list/app_list_switches.h"
25
26 using apps_helper::DisableApp;
27 using apps_helper::EnableApp;
28 using apps_helper::HasSameAppsAsVerifier;
29 using apps_helper::IncognitoDisableApp;
30 using apps_helper::IncognitoEnableApp;
31 using apps_helper::InstallApp;
32 using apps_helper::InstallAppsPendingForSync;
33 using apps_helper::UninstallApp;
34 using sync_integration_test_util::AwaitCommitActivityCompletion;
35
36 namespace {
37
38 const size_t kNumDefaultApps = 2;
39
40 bool AllProfilesHaveSameAppListAsVerifier() {
41   return SyncAppListHelper::GetInstance()->
42       AllProfilesHaveSameAppListAsVerifier();
43 }
44
45 const app_list::AppListSyncableService::SyncItem* GetSyncItem(
46     Profile* profile,
47     const std::string& app_id) {
48   app_list::AppListSyncableService* service =
49       app_list::AppListSyncableServiceFactory::GetForProfile(profile);
50   return service->GetSyncItem(app_id);
51 }
52
53 // Checks that the synced changes are mirrored in AppListPrefs.
54 void CheckAppInfoInPrefs(Profile* profile,
55                          const std::vector<std::string>& expected_ids) {
56   app_list::AppListSyncableService* service =
57       app_list::AppListSyncableServiceFactory::GetForProfile(profile);
58
59   app_list::AppListPrefs::AppListInfoMap infos;
60
61   app_list::AppListPrefs::Get(profile)->GetAllAppListInfos(&infos);
62   EXPECT_EQ(expected_ids.size(), infos.size());
63
64   for (auto id : expected_ids) {
65     app_list::AppListItem* item =
66         service->model()->top_level_item_list()->FindItem(id);
67     ASSERT_TRUE(item);
68     // Ensure local prefs matches the model data.
69     scoped_ptr<app_list::AppListPrefs::AppListInfo> info =
70         app_list::AppListPrefs::Get(profile)->GetAppListInfo(id);
71     ASSERT_TRUE(info);
72     EXPECT_EQ(item->name(), info->name);
73     EXPECT_TRUE(item->position().Equals(info->position));
74     EXPECT_EQ(item->folder_id(), info->parent_id);
75   }
76 }
77
78 }  // namespace
79
80 class TwoClientAppListSyncTest : public SyncTest {
81  public:
82   TwoClientAppListSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {}
83
84   ~TwoClientAppListSyncTest() override {}
85
86   // SyncTest
87   void SetUpCommandLine(CommandLine* command_line) override {
88     SyncTest::SetUpCommandLine(command_line);
89     command_line->AppendSwitch(app_list::switches::kEnableSyncAppList);
90   }
91
92   bool SetupClients() override {
93     if (!SyncTest::SetupClients())
94       return false;
95
96     // Init SyncAppListHelper to ensure that the extension system is initialized
97     // for each Profile.
98     SyncAppListHelper::GetInstance();
99     return true;
100   }
101
102   bool SetupSync() override {
103     if (!SyncTest::SetupSync())
104       return false;
105     WaitForExtensionServicesToLoad();
106     return true;
107   }
108
109  private:
110   void WaitForExtensionServicesToLoad() {
111     for (int i = 0; i < num_clients(); ++i)
112       WaitForExtensionsServiceToLoadForProfile(GetProfile(i));
113     WaitForExtensionsServiceToLoadForProfile(verifier());
114   }
115
116   void WaitForExtensionsServiceToLoadForProfile(Profile* profile) {
117     ExtensionService* extension_service =
118         extensions::ExtensionSystem::Get(profile)->extension_service();
119     if (extension_service && extension_service->is_ready())
120       return;
121     content::WindowedNotificationObserver extensions_loaded_observer(
122         extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
123         content::NotificationService::AllSources());
124     extensions_loaded_observer.Wait();
125   }
126
127   DISALLOW_COPY_AND_ASSIGN(TwoClientAppListSyncTest);
128 };
129
130 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, StartWithNoApps) {
131   ASSERT_TRUE(SetupSync());
132
133   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
134 }
135
136 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, StartWithSameApps) {
137   ASSERT_TRUE(SetupClients());
138
139   const int kNumApps = 5;
140   for (int i = 0; i < kNumApps; ++i) {
141     InstallApp(GetProfile(0), i);
142     InstallApp(GetProfile(1), i);
143     InstallApp(verifier(), i);
144   }
145
146   ASSERT_TRUE(SetupSync());
147
148   ASSERT_TRUE(AwaitQuiescence());
149
150   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
151 }
152
153 // Install some apps on both clients, some on only one client, some on only the
154 // other, and sync.  Both clients should end up with all apps, and the app and
155 // page ordinals should be identical.
156 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, StartWithDifferentApps) {
157   ASSERT_TRUE(SetupClients());
158
159   int i = 0;
160
161   const int kNumCommonApps = 5;
162   for (int j = 0; j < kNumCommonApps; ++i, ++j) {
163     InstallApp(GetProfile(0), i);
164     InstallApp(GetProfile(1), i);
165     InstallApp(verifier(), i);
166   }
167
168   const int kNumProfile0Apps = 10;
169   for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
170     std::string id = InstallApp(GetProfile(0), i);
171     InstallApp(verifier(), i);
172     SyncAppListHelper::GetInstance()->CopyOrdinalsToVerifier(GetProfile(0), id);
173   }
174
175   const int kNumProfile1Apps = 10;
176   for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
177     std::string id = InstallApp(GetProfile(1), i);
178     InstallApp(verifier(), i);
179     SyncAppListHelper::GetInstance()->CopyOrdinalsToVerifier(GetProfile(1), id);
180   }
181
182   ASSERT_TRUE(SetupSync());
183
184   ASSERT_TRUE(AwaitQuiescence());
185
186   InstallAppsPendingForSync(GetProfile(0));
187   InstallAppsPendingForSync(GetProfile(1));
188
189   // Verify the app lists, but ignore absolute position values, checking only
190   // relative positions (see note in app_list_syncable_service.h).
191   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
192 }
193
194 // Install some apps on both clients, then sync.  Then install some apps on only
195 // one client, some on only the other, and then sync again.  Both clients should
196 // end up with all apps, and the app and page ordinals should be identical.
197 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, InstallDifferentApps) {
198   ASSERT_TRUE(SetupClients());
199
200   int i = 0;
201
202   const int kNumCommonApps = 5;
203   for (int j = 0; j < kNumCommonApps; ++i, ++j) {
204     InstallApp(GetProfile(0), i);
205     InstallApp(GetProfile(1), i);
206     InstallApp(verifier(), i);
207   }
208
209   ASSERT_TRUE(SetupSync());
210
211   ASSERT_TRUE(AwaitQuiescence());
212
213   const int kNumProfile0Apps = 10;
214   for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
215     std::string id = InstallApp(GetProfile(0), i);
216     InstallApp(verifier(), i);
217     SyncAppListHelper::GetInstance()->CopyOrdinalsToVerifier(GetProfile(0), id);
218   }
219
220   const int kNumProfile1Apps = 10;
221   for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
222     std::string id = InstallApp(GetProfile(1), i);
223     InstallApp(verifier(), i);
224     SyncAppListHelper::GetInstance()->CopyOrdinalsToVerifier(GetProfile(1), id);
225   }
226
227   ASSERT_TRUE(AwaitQuiescence());
228
229   InstallAppsPendingForSync(GetProfile(0));
230   InstallAppsPendingForSync(GetProfile(1));
231
232   // Verify the app lists, but ignore absolute position values, checking only
233   // relative positions (see note in app_list_syncable_service.h).
234   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
235 }
236
237 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, Install) {
238   ASSERT_TRUE(SetupSync());
239   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
240
241   InstallApp(GetProfile(0), 0);
242   InstallApp(verifier(), 0);
243   ASSERT_TRUE(AwaitQuiescence());
244
245   InstallAppsPendingForSync(GetProfile(0));
246   InstallAppsPendingForSync(GetProfile(1));
247   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
248 }
249
250 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, Uninstall) {
251   ASSERT_TRUE(SetupSync());
252   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
253
254   InstallApp(GetProfile(0), 0);
255   InstallApp(verifier(), 0);
256   ASSERT_TRUE(AwaitQuiescence());
257
258   InstallAppsPendingForSync(GetProfile(0));
259   InstallAppsPendingForSync(GetProfile(1));
260   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
261
262   UninstallApp(GetProfile(0), 0);
263   UninstallApp(verifier(), 0);
264   ASSERT_TRUE(AwaitQuiescence());
265   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
266 }
267
268 // Install an app on one client, then sync. Then uninstall the app on the first
269 // client and sync again. Now install a new app on the first client and sync.
270 // Both client should only have the second app, with identical app and page
271 // ordinals.
272 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, UninstallThenInstall) {
273   ASSERT_TRUE(SetupSync());
274   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
275
276   InstallApp(GetProfile(0), 0);
277   InstallApp(verifier(), 0);
278   ASSERT_TRUE(AwaitQuiescence());
279
280   InstallAppsPendingForSync(GetProfile(0));
281   InstallAppsPendingForSync(GetProfile(1));
282   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
283
284   UninstallApp(GetProfile(0), 0);
285   UninstallApp(verifier(), 0);
286   ASSERT_TRUE(AwaitQuiescence());
287   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
288
289   InstallApp(GetProfile(0), 1);
290   InstallApp(verifier(), 1);
291   ASSERT_TRUE(AwaitQuiescence());
292   InstallAppsPendingForSync(GetProfile(0));
293   InstallAppsPendingForSync(GetProfile(1));
294   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
295 }
296
297 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, Merge) {
298   ASSERT_TRUE(SetupSync());
299   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
300
301   InstallApp(GetProfile(0), 0);
302   InstallApp(GetProfile(1), 0);
303   ASSERT_TRUE(AwaitQuiescence());
304
305   UninstallApp(GetProfile(0), 0);
306   InstallApp(GetProfile(0), 1);
307   InstallApp(verifier(), 1);
308
309   InstallApp(GetProfile(0), 2);
310   InstallApp(GetProfile(1), 2);
311   InstallApp(verifier(), 2);
312
313   InstallApp(GetProfile(1), 3);
314   InstallApp(verifier(), 3);
315
316   ASSERT_TRUE(AwaitQuiescence());
317   InstallAppsPendingForSync(GetProfile(0));
318   InstallAppsPendingForSync(GetProfile(1));
319   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
320 }
321
322 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, UpdateEnableDisableApp) {
323   ASSERT_TRUE(SetupSync());
324   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
325
326   InstallApp(GetProfile(0), 0);
327   InstallApp(GetProfile(1), 0);
328   InstallApp(verifier(), 0);
329   ASSERT_TRUE(AwaitQuiescence());
330   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
331
332   DisableApp(GetProfile(0), 0);
333   DisableApp(verifier(), 0);
334   ASSERT_TRUE(HasSameAppsAsVerifier(0));
335   ASSERT_FALSE(HasSameAppsAsVerifier(1));
336
337   ASSERT_TRUE(AwaitQuiescence());
338   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
339
340   EnableApp(GetProfile(1), 0);
341   EnableApp(verifier(), 0);
342   ASSERT_TRUE(HasSameAppsAsVerifier(1));
343   ASSERT_FALSE(HasSameAppsAsVerifier(0));
344
345   ASSERT_TRUE(AwaitQuiescence());
346   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
347 }
348
349 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, UpdateIncognitoEnableDisable) {
350   ASSERT_TRUE(SetupSync());
351   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
352
353   InstallApp(GetProfile(0), 0);
354   InstallApp(GetProfile(1), 0);
355   InstallApp(verifier(), 0);
356   ASSERT_TRUE(AwaitQuiescence());
357   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
358
359   IncognitoEnableApp(GetProfile(0), 0);
360   IncognitoEnableApp(verifier(), 0);
361   ASSERT_TRUE(HasSameAppsAsVerifier(0));
362   ASSERT_FALSE(HasSameAppsAsVerifier(1));
363
364   ASSERT_TRUE(AwaitQuiescence());
365   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
366
367   IncognitoDisableApp(GetProfile(1), 0);
368   IncognitoDisableApp(verifier(), 0);
369   ASSERT_TRUE(HasSameAppsAsVerifier(1));
370   ASSERT_FALSE(HasSameAppsAsVerifier(0));
371
372   ASSERT_TRUE(AwaitQuiescence());
373   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
374 }
375
376 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, DisableApps) {
377   ASSERT_TRUE(SetupSync());
378   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
379
380   ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::APP_LIST));
381   InstallApp(GetProfile(0), 0);
382   InstallApp(verifier(), 0);
383   ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
384   ASSERT_TRUE(HasSameAppsAsVerifier(0));
385   ASSERT_FALSE(HasSameAppsAsVerifier(1));
386
387   ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::APP_LIST));
388   ASSERT_TRUE(AwaitQuiescence());
389
390   InstallAppsPendingForSync(GetProfile(0));
391   InstallAppsPendingForSync(GetProfile(1));
392   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
393 }
394
395 // Disable sync for the second client and then install an app on the first
396 // client, then enable sync on the second client. Both clients should have the
397 // same app with identical app and page ordinals.
398 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, DisableSync) {
399   ASSERT_TRUE(SetupSync());
400   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
401
402   ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
403   InstallApp(GetProfile(0), 0);
404   InstallApp(verifier(), 0);
405   ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
406   ASSERT_TRUE(HasSameAppsAsVerifier(0));
407   ASSERT_FALSE(HasSameAppsAsVerifier(1));
408
409   ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
410   ASSERT_TRUE(AwaitQuiescence());
411
412   InstallAppsPendingForSync(GetProfile(0));
413   InstallAppsPendingForSync(GetProfile(1));
414   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
415 }
416
417 // Install some apps on both clients, then sync. Move an app on one client
418 // and sync. Both clients should have the updated position for the app.
419 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, Move) {
420   ASSERT_TRUE(SetupSync());
421   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
422
423   std::vector<std::string> app_ids;
424   // AppListPrefs should be empty since it only begins observing the model after
425   // sync starts.
426   CheckAppInfoInPrefs(GetProfile(1), app_ids);
427
428   const int kNumApps = 5;
429   for (int i = 0; i < kNumApps; ++i) {
430     app_ids.push_back(InstallApp(GetProfile(0), i));
431     InstallApp(GetProfile(1), i);
432     InstallApp(verifier(), i);
433   }
434   ASSERT_TRUE(AwaitQuiescence());
435   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
436
437   // AppListPrefs should contain the newly installed apps.
438   CheckAppInfoInPrefs(GetProfile(1), app_ids);
439
440   size_t first = kNumDefaultApps;
441   SyncAppListHelper::GetInstance()->MoveApp(
442       GetProfile(0), first + 1, first + 2);
443   SyncAppListHelper::GetInstance()->MoveApp(
444       verifier(), first + 1, first + 2);
445
446   ASSERT_TRUE(AwaitQuiescence());
447   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
448
449   // AppListPrefs should reflect the apps being moved in the model.
450   CheckAppInfoInPrefs(GetProfile(1), app_ids);
451 }
452
453 // Install a Default App on both clients, then sync. Remove the app on one
454 // client and sync. Ensure that the app is removed on the other client and
455 // that a REMOVE_DEFAULT_APP entry exists.
456 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncTest, RemoveDefault) {
457   ASSERT_TRUE(SetupClients());
458   ASSERT_TRUE(SetupSync());
459
460   // Install a non-default app.
461   InstallApp(GetProfile(0), 0);
462   InstallApp(GetProfile(1), 0);
463   InstallApp(verifier(), 0);
464
465   // Install a default app in Profile 0 only.
466   const int default_app_index = 1;
467   std::string default_app_id = InstallApp(GetProfile(0), default_app_index);
468   InstallApp(verifier(), default_app_index);
469   SyncAppListHelper::GetInstance()->CopyOrdinalsToVerifier(
470       GetProfile(0), default_app_id);
471
472   ASSERT_TRUE(AwaitQuiescence());
473   InstallAppsPendingForSync(GetProfile(0));
474   InstallAppsPendingForSync(GetProfile(1));
475   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
476
477   // Flag Default app in Profile 1.
478   extensions::ExtensionPrefs::Get(GetProfile(1))
479       ->UpdateExtensionPref(default_app_id,
480                             "was_installed_by_default",
481                             new base::FundamentalValue(true));
482
483   // Remove the default app in Profile 0 and verifier, ensure it was removed
484   // in Profile 1.
485   UninstallApp(GetProfile(0), default_app_index);
486   UninstallApp(verifier(), default_app_index);
487   ASSERT_TRUE(AwaitQuiescence());
488   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
489
490   // Ensure that a REMOVE_DEFAULT_APP SyncItem entry exists in Profile 1.
491   const app_list::AppListSyncableService::SyncItem* sync_item =
492       GetSyncItem(GetProfile(1), default_app_id);
493   ASSERT_TRUE(sync_item);
494   ASSERT_EQ(sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP,
495             sync_item->item_type);
496
497   // Re-Install the same app in Profile 0.
498   std::string app_id2 = InstallApp(GetProfile(0), default_app_index);
499   EXPECT_EQ(default_app_id, app_id2);
500   InstallApp(verifier(), default_app_index);
501   sync_item = GetSyncItem(GetProfile(0), app_id2);
502   EXPECT_EQ(sync_pb::AppListSpecifics::TYPE_APP, sync_item->item_type);
503
504   ASSERT_TRUE(AwaitQuiescence());
505   InstallAppsPendingForSync(GetProfile(0));
506   InstallAppsPendingForSync(GetProfile(1));
507   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
508
509   // Ensure that the REMOVE_DEFAULT_APP SyncItem entry in Profile 1 is replaced
510   // with an APP entry after an install.
511   sync_item = GetSyncItem(GetProfile(1), app_id2);
512   ASSERT_TRUE(sync_item);
513   EXPECT_EQ(sync_pb::AppListSpecifics::TYPE_APP, sync_item->item_type);
514 }
515
516 #if !defined(OS_MACOSX)
517
518 class TwoClientAppListSyncFolderTest : public TwoClientAppListSyncTest {
519  public:
520   TwoClientAppListSyncFolderTest() {}
521   ~TwoClientAppListSyncFolderTest() override {}
522
523   void SetUpCommandLine(CommandLine* command_line) override {
524     TwoClientAppListSyncTest::SetUpCommandLine(command_line);
525   }
526
527   bool SetupClients() override {
528     bool res = TwoClientAppListSyncTest::SetupClients();
529     app_list::AppListSyncableService* verifier_service =
530         app_list::AppListSyncableServiceFactory::GetForProfile(verifier());
531     verifier_service->model()->SetFoldersEnabled(true);
532     return res;
533   }
534
535  private:
536   DISALLOW_COPY_AND_ASSIGN(TwoClientAppListSyncFolderTest);
537 };
538
539 // Install some apps on both clients, then sync. Move an app on one client
540 // to a folder and sync. The app lists, including folders, should match.
541 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncFolderTest, MoveToFolder) {
542   ASSERT_TRUE(SetupSync());
543   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
544
545   const int kNumApps = 5;
546   for (int i = 0; i < kNumApps; ++i) {
547     InstallApp(GetProfile(0), i);
548     InstallApp(GetProfile(1), i);
549     InstallApp(verifier(), i);
550   }
551   ASSERT_TRUE(AwaitQuiescence());
552   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
553
554   size_t index = 2u;
555   std::string folder_id = "Folder 0";
556   SyncAppListHelper::GetInstance()->MoveAppToFolder(
557       GetProfile(0), index, folder_id);
558   SyncAppListHelper::GetInstance()->MoveAppToFolder(
559       verifier(), index, folder_id);
560
561   ASSERT_TRUE(AwaitQuiescence());
562   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
563 }
564
565 IN_PROC_BROWSER_TEST_F(TwoClientAppListSyncFolderTest, FolderAddRemove) {
566   ASSERT_TRUE(SetupSync());
567   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
568
569   const int kNumApps = 10;
570   for (int i = 0; i < kNumApps; ++i) {
571     InstallApp(GetProfile(0), i);
572     InstallApp(GetProfile(1), i);
573     InstallApp(verifier(), i);
574   }
575   ASSERT_TRUE(AwaitQuiescence());
576   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
577
578   // Move a few apps to a folder.
579   const size_t kNumAppsToMove = 3;
580   std::string folder_id = "Folder 0";
581   // The folder will be created at the end of the list; always move the
582   // first non default item in the list.
583   size_t item_index = kNumDefaultApps;
584   for (size_t i = 0; i < kNumAppsToMove; ++i) {
585     SyncAppListHelper::GetInstance()->MoveAppToFolder(
586         GetProfile(0), item_index, folder_id);
587     SyncAppListHelper::GetInstance()->MoveAppToFolder(
588         verifier(), item_index, folder_id);
589   }
590   ASSERT_TRUE(AwaitQuiescence());
591   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
592
593   // Remove one app from the folder.
594   SyncAppListHelper::GetInstance()->MoveAppFromFolder(
595       GetProfile(0), 0, folder_id);
596   SyncAppListHelper::GetInstance()->MoveAppFromFolder(
597       verifier(), 0, folder_id);
598
599   ASSERT_TRUE(AwaitQuiescence());
600   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
601
602   // Remove remaining apps from the folder (deletes folder).
603   for (size_t i = 1; i < kNumAppsToMove; ++i) {
604     SyncAppListHelper::GetInstance()->MoveAppFromFolder(
605         GetProfile(0), 0, folder_id);
606     SyncAppListHelper::GetInstance()->MoveAppFromFolder(
607         verifier(), 0, folder_id);
608   }
609
610   ASSERT_TRUE(AwaitQuiescence());
611   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
612
613   // Move apps back to a (new) folder.
614   for (size_t i = 0; i < kNumAppsToMove; ++i) {
615     SyncAppListHelper::GetInstance()->MoveAppToFolder(
616         GetProfile(0), item_index, folder_id);
617     SyncAppListHelper::GetInstance()->MoveAppToFolder(
618         verifier(), item_index, folder_id);
619   }
620
621   ASSERT_TRUE(AwaitQuiescence());
622   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
623 }
624
625 #endif  // !defined(OS_MACOSX)