| Index: chrome/browser/ui/app_list/app_list_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/app_list/app_list_controller_unittest.cc b/chrome/browser/ui/app_list/app_list_controller_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..12022380fe53cb4c03d375fa9f50921c4998a2d7
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/app_list/app_list_controller_unittest.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "apps/pref_names.h"
|
| +#include "apps/prefs.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/prefs/pref_registry_simple.h"
|
| +#include "base/prefs/pref_service.h"
|
| +#include "base/prefs/pref_service_builder.h"
|
| +#include "base/prefs/testing_pref_store.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/app_list/app_list_service.h"
|
| +#include "chrome/browser/ui/app_list/app_list_service_impl.h"
|
| +#include "chrome/browser/ui/app_list/test/fake_keep_alive_service.h"
|
| +#include "chrome/browser/ui/app_list/test/fake_profile.h"
|
| +#include "chrome/browser/ui/app_list/test/fake_profile_store.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +class TestingAppListServiceImpl : public AppListServiceImpl {
|
| + public:
|
| + TestingAppListServiceImpl(PrefService* local_state,
|
| + scoped_ptr<ProfileStore> profile_store,
|
| + scoped_ptr<KeepAliveService> keep_alive_service)
|
| + : AppListServiceImpl(local_state,
|
| + profile_store.Pass(),
|
| + keep_alive_service.Pass()),
|
| + showing_for_profile_(NULL) {
|
| + }
|
| +
|
| + Profile* showing_for_profile() const {
|
| + return showing_for_profile_;
|
| + }
|
| +
|
| + virtual void CreateForProfile(Profile* requested_profile) OVERRIDE {
|
| + }
|
| +
|
| + virtual void ShowForProfile(Profile* requested_profile) OVERRIDE {
|
| + showing_for_profile_ = requested_profile;
|
| + }
|
| +
|
| + virtual void DismissAppList() OVERRIDE {
|
| + showing_for_profile_ = NULL;
|
| + }
|
| +
|
| + virtual bool IsAppListVisible() const OVERRIDE {
|
| + return !!showing_for_profile_;
|
| + }
|
| +
|
| + virtual gfx::NativeWindow GetAppListWindow() OVERRIDE {
|
| + return NULL;
|
| + }
|
| +
|
| + virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE {
|
| + return NULL;
|
| + }
|
| +
|
| + private:
|
| + Profile* showing_for_profile_;
|
| +};
|
| +
|
| +class AppListControllerUnitTest : public testing::Test {
|
| + public:
|
| + virtual void SetUp() OVERRIDE {
|
| + user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd"));
|
| + profile1_.reset(new FakeProfile("p1",
|
| + base::FilePath(FILE_PATH_LITERAL("profile1"))));
|
| + PrefRegistrySimple* pref_registry = new PrefRegistrySimple;
|
| +
|
| + AppListService::RegisterPrefs(pref_registry);
|
| + apps::RegisterPrefs(pref_registry);
|
| +
|
| + PrefServiceBuilder builder;
|
| + builder.WithUserPrefs(new TestingPrefStore);
|
| + local_state_.reset(builder.Create(pref_registry));
|
| +
|
| + keep_alive_service_ = new FakeKeepAliveService;
|
| + profile_store_ = new FakeProfileStore(user_data_dir_);
|
| + service_.reset(new TestingAppListServiceImpl(
|
| + local_state_.get(),
|
| + make_scoped_ptr(profile_store_),
|
| + make_scoped_ptr(keep_alive_service_)));
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + }
|
| +
|
| + base::FilePath user_data_dir_;
|
| + scoped_ptr<PrefService> local_state_;
|
| + FakeProfileStore* profile_store_;
|
| + FakeKeepAliveService* keep_alive_service_;
|
| + scoped_ptr<TestingAppListServiceImpl> service_;
|
| + scoped_ptr<FakeProfile> profile1_;
|
| +};
|
| +
|
| +TEST_F(AppListControllerUnitTest, EnablingStateIsPersisted) {
|
| + EXPECT_FALSE(local_state_->GetBoolean(
|
| + apps::prefs::kAppLauncherHasBeenEnabled));
|
| + service_->EnableAppList(profile1_.get());
|
| + EXPECT_TRUE(local_state_->GetBoolean(
|
| + apps::prefs::kAppLauncherHasBeenEnabled));
|
| + EXPECT_EQ(profile1_->GetPath(),
|
| + local_state_->GetFilePath(prefs::kAppListProfile));
|
| +}
|
| +
|
| +TEST_F(AppListControllerUnitTest, ShowingForProfileLoadsAProfile) {
|
| + service_->EnableAppList(profile1_.get());
|
| + service_->Show();
|
| + EXPECT_EQ(NULL, service_->showing_for_profile());
|
| +
|
| + base::FilePath profile_dir = user_data_dir_.Append(profile1_->GetPath());
|
| + profile_store_->RunCallbackByPath(profile_dir, profile1_.get());
|
| + EXPECT_EQ(profile1_.get(), service_->showing_for_profile());
|
| + EXPECT_TRUE(service_->IsAppListVisible());
|
| +}
|
|
|