single_client_app_list_sync_test.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 bool SetupClients() OVERRIDE {
35    if (!SyncTest::SetupClients())
36      return false;
37
38    // Init SyncAppListHelper to ensure that the extension system is initialized
39    // for each Profile.
40    SyncAppListHelper::GetInstance();
41    return true;
42  }
43
44 private:
45  DISALLOW_COPY_AND_ASSIGN(SingleClientAppListSyncTest);
46};
47
48IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListEmpty) {
49  ASSERT_TRUE(SetupSync());
50
51  ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
52}
53
54IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListSomeApps) {
55  ASSERT_TRUE(SetupSync());
56
57  const size_t kNumApps = 5;
58  for (int i = 0; i < static_cast<int>(kNumApps); ++i) {
59    apps_helper::InstallApp(GetProfile(0), i);
60    apps_helper::InstallApp(verifier(), i);
61  }
62
63  app_list::AppListSyncableService* service =
64      app_list::AppListSyncableServiceFactory::GetForProfile(verifier());
65  ASSERT_EQ(kNumApps + kNumDefaultApps, service->GetNumSyncItemsForTest());
66
67  ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
68  ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
69
70}
71