• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/test/integration/apps_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_app_list_helper.h"
10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
13 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
14 #include "ui/app_list/app_list_switches.h"
15 
16 using sync_integration_test_util::AwaitCommitActivityCompletion;
17 
18 namespace {
19 
20 const size_t kNumDefaultApps = 2;
21 
AllProfilesHaveSameAppListAsVerifier()22 bool AllProfilesHaveSameAppListAsVerifier() {
23   return SyncAppListHelper::GetInstance()->
24       AllProfilesHaveSameAppListAsVerifier();
25 }
26 
27 }  // namespace
28 
29 class SingleClientAppListSyncTest : public SyncTest {
30  public:
SingleClientAppListSyncTest()31   SingleClientAppListSyncTest() : SyncTest(SINGLE_CLIENT) {}
32 
~SingleClientAppListSyncTest()33   virtual ~SingleClientAppListSyncTest() {}
34 
35   // SyncTest
SetUpCommandLine(CommandLine * command_line)36   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
37     SyncTest::SetUpCommandLine(command_line);
38     command_line->AppendSwitch(app_list::switches::kEnableSyncAppList);
39   }
40 
SetupClients()41   virtual bool SetupClients() OVERRIDE {
42     if (!SyncTest::SetupClients())
43       return false;
44 
45     // Init SyncAppListHelper to ensure that the extension system is initialized
46     // for each Profile.
47     SyncAppListHelper::GetInstance();
48     return true;
49   }
50 
51  private:
52   DISALLOW_COPY_AND_ASSIGN(SingleClientAppListSyncTest);
53 };
54 
IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest,AppListEmpty)55 IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListEmpty) {
56   ASSERT_TRUE(SetupSync());
57 
58   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
59 }
60 
IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest,AppListSomeApps)61 IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListSomeApps) {
62   ASSERT_TRUE(SetupSync());
63 
64   const size_t kNumApps = 5;
65   for (int i = 0; i < static_cast<int>(kNumApps); ++i) {
66     apps_helper::InstallApp(GetProfile(0), i);
67     apps_helper::InstallApp(verifier(), i);
68   }
69 
70   app_list::AppListSyncableService* service =
71       app_list::AppListSyncableServiceFactory::GetForProfile(verifier());
72   ASSERT_EQ(kNumApps + kNumDefaultApps, service->GetNumSyncItemsForTest());
73 
74   ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
75   ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
76 
77 }
78