single_client_app_list_sync_test.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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
16using sync_integration_test_util::AwaitCommitActivityCompletion;
17
18namespace {
19
20const size_t kNumDefaultApps = 2;
21
22bool AllProfilesHaveSameAppListAsVerifier() {
23  return SyncAppListHelper::GetInstance()->
24      AllProfilesHaveSameAppListAsVerifier();
25}
26
27}  // namespace
28
29class SingleClientAppListSyncTest : public SyncTest {
30 public:
31  SingleClientAppListSyncTest() : SyncTest(SINGLE_CLIENT) {}
32
33  virtual ~SingleClientAppListSyncTest() {}
34
35  // SyncTest
36  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
37    SyncTest::SetUpCommandLine(command_line);
38    command_line->AppendSwitch(app_list::switches::kEnableSyncAppList);
39  }
40
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
55IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListEmpty) {
56  ASSERT_TRUE(SetupSync());
57
58  ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
59}
60
61IN_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