Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Side by Side Diff: chrome/browser/ui/app_list/app_list_controller_unittest.cc

Issue 24707002: Add unit tests for AppListServiceImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add IsManaged() check Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 "apps/pref_names.h"
6 #include "apps/prefs.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/pref_service_builder.h"
12 #include "base/prefs/testing_pref_store.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/app_list/app_list_service.h"
15 #include "chrome/browser/ui/app_list/app_list_service_impl.h"
16 #include "chrome/browser/ui/app_list/test/fake_keep_alive_service.h"
17 #include "chrome/browser/ui/app_list/test/fake_profile.h"
18 #include "chrome/browser/ui/app_list/test/fake_profile_store.h"
19 #include "chrome/common/pref_names.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 class TestingAppListServiceImpl : public AppListServiceImpl {
benwells 2013/09/26 06:55:29 Shouldn't this file be called app_list_service_uni
koz (OOO until 15th September) 2013/09/26 22:12:47 Er, yes. Yes it should. Renamed.
23 public:
24 TestingAppListServiceImpl(PrefService* local_state,
25 scoped_ptr<ProfileStore> profile_store,
26 scoped_ptr<KeepAliveService> keep_alive_service)
27 : AppListServiceImpl(local_state,
28 profile_store.Pass(),
29 keep_alive_service.Pass()),
30 showing_for_profile_(NULL) {
31 }
32
33 Profile* showing_for_profile() const {
34 return showing_for_profile_;
35 }
36
37 virtual void CreateForProfile(Profile* requested_profile) OVERRIDE {
38 }
39
40 virtual void ShowForProfile(Profile* requested_profile) OVERRIDE {
41 showing_for_profile_ = requested_profile;
42 }
43
44 virtual void DismissAppList() OVERRIDE {
45 showing_for_profile_ = NULL;
46 }
47
48 virtual bool IsAppListVisible() const OVERRIDE {
49 return !!showing_for_profile_;
50 }
51
52 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE {
53 return NULL;
54 }
55
56 virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE {
57 return NULL;
58 }
59
60 private:
61 Profile* showing_for_profile_;
62 };
63
64 class AppListControllerUnitTest : public testing::Test {
65 public:
66 virtual void SetUp() OVERRIDE {
67 user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd"));
68 profile1_.reset(new FakeProfile("p1",
69 base::FilePath(FILE_PATH_LITERAL("profile1"))));
70 PrefRegistrySimple* pref_registry = new PrefRegistrySimple;
71
72 AppListService::RegisterPrefs(pref_registry);
73 apps::RegisterPrefs(pref_registry);
74
75 PrefServiceBuilder builder;
76 builder.WithUserPrefs(new TestingPrefStore);
77 local_state_.reset(builder.Create(pref_registry));
78
79 keep_alive_service_ = new FakeKeepAliveService;
80 profile_store_ = new FakeProfileStore(user_data_dir_);
81 service_.reset(new TestingAppListServiceImpl(
82 local_state_.get(),
83 make_scoped_ptr(profile_store_),
84 make_scoped_ptr(keep_alive_service_)));
85 }
86
87 virtual void TearDown() OVERRIDE {
benwells 2013/09/26 06:55:29 Is this empty override here for a reason? If so, s
koz (OOO until 15th September) 2013/09/26 22:12:47 Done.
88 }
89
90 base::FilePath user_data_dir_;
91 scoped_ptr<PrefService> local_state_;
92 FakeProfileStore* profile_store_;
93 FakeKeepAliveService* keep_alive_service_;
94 scoped_ptr<TestingAppListServiceImpl> service_;
95 scoped_ptr<FakeProfile> profile1_;
96 };
97
98 TEST_F(AppListControllerUnitTest, EnablingStateIsPersisted) {
benwells 2013/09/26 06:55:29 It seems like we could do a lot more testing. E.g.
koz (OOO until 15th September) 2013/09/26 22:12:47 Done.
99 EXPECT_FALSE(local_state_->GetBoolean(
100 apps::prefs::kAppLauncherHasBeenEnabled));
101 service_->EnableAppList(profile1_.get());
102 EXPECT_TRUE(local_state_->GetBoolean(
103 apps::prefs::kAppLauncherHasBeenEnabled));
104 EXPECT_EQ(profile1_->GetPath(),
105 local_state_->GetFilePath(prefs::kAppListProfile));
106 }
107
108 TEST_F(AppListControllerUnitTest, ShowingForProfileLoadsAProfile) {
109 service_->EnableAppList(profile1_.get());
110 service_->Show();
111 EXPECT_EQ(NULL, service_->showing_for_profile());
112
113 base::FilePath profile_dir = user_data_dir_.Append(profile1_->GetPath());
114 profile_store_->RunCallbackByPath(profile_dir, profile1_.get());
115 EXPECT_EQ(profile1_.get(), service_->showing_for_profile());
116 EXPECT_TRUE(service_->IsAppListVisible());
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698