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