15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/command_line.h"
7e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "chrome/browser/sync/profile_sync_service.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/sync/test/integration/apps_helper.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/sync/test/integration/sync_app_list_helper.h"
10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/sync/test/integration/sync_test.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/app_list_switches.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochusing sync_integration_test_util::AwaitCommitActivityCompletion;
17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace {
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const size_t kNumDefaultApps = 2;
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AllProfilesHaveSameAppListAsVerifier() {
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return SyncAppListHelper::GetInstance()->
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      AllProfilesHaveSameAppListAsVerifier();
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SingleClientAppListSyncTest : public SyncTest {
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SingleClientAppListSyncTest() : SyncTest(SINGLE_CLIENT) {}
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~SingleClientAppListSyncTest() {}
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // SyncTest
36c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
37c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    SyncTest::SetUpCommandLine(command_line);
38c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    command_line->AppendSwitch(app_list::switches::kEnableSyncAppList);
39c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  }
40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool SetupClients() OVERRIDE {
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (!SyncTest::SetupClients())
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return false;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Init SyncAppListHelper to ensure that the extension system is initialized
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // for each Profile.
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SyncAppListHelper::GetInstance();
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SingleClientAppListSyncTest);
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListEmpty) {
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SetupSync());
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SingleClientAppListSyncTest, AppListSomeApps) {
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SetupSync());
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const size_t kNumApps = 5;
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (int i = 0; i < static_cast<int>(kNumApps); ++i) {
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    apps_helper::InstallApp(GetProfile(0), i);
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    apps_helper::InstallApp(verifier(), i);
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  app_list::AppListSyncableService* service =
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      app_list::AppListSyncableServiceFactory::GetForProfile(verifier());
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(kNumApps + kNumDefaultApps, service->GetNumSyncItemsForTest());
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
74e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(AllProfilesHaveSameAppListAsVerifier());
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
78