OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/app_list/app_list_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_service.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/browser/ui/app_list/app_list_service_impl.h" | 15 #include "chrome/browser/ui/app_list/app_list_service_impl.h" |
16 #include "chrome/browser/ui/app_list/test/fake_profile.h" | 16 #include "chrome/browser/ui/app_list/test/fake_profile.h" |
17 #include "chrome/browser/ui/app_list/test/fake_profile_store.h" | 17 #include "chrome/browser/ui/app_list/test/fake_profile_store.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "components/prefs/pref_registry_simple.h" | 20 #include "components/prefs/pref_registry_simple.h" |
21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
22 #include "components/prefs/pref_service_factory.h" | 22 #include "components/prefs/pref_service_factory.h" |
23 #include "components/prefs/testing_pref_store.h" | 23 #include "components/prefs/testing_pref_store.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/app_list/app_list_switches.h" | 25 #include "ui/app_list/app_list_switches.h" |
26 | 26 |
27 class TestingAppListServiceImpl : public AppListServiceImpl { | 27 class TestingAppListServiceImpl : public AppListServiceImpl { |
28 public: | 28 public: |
29 TestingAppListServiceImpl(const base::CommandLine& command_line, | 29 TestingAppListServiceImpl(const base::CommandLine& command_line, |
30 PrefService* local_state, | 30 PrefService* local_state, |
31 scoped_ptr<ProfileStore> profile_store) | 31 std::unique_ptr<ProfileStore> profile_store) |
32 : AppListServiceImpl(command_line, local_state, std::move(profile_store)), | 32 : AppListServiceImpl(command_line, local_state, std::move(profile_store)), |
33 showing_for_profile_(NULL), | 33 showing_for_profile_(NULL), |
34 destroy_app_list_call_count_(0) {} | 34 destroy_app_list_call_count_(0) {} |
35 | 35 |
36 Profile* showing_for_profile() const { | 36 Profile* showing_for_profile() const { |
37 return showing_for_profile_; | 37 return showing_for_profile_; |
38 } | 38 } |
39 | 39 |
40 int destroy_app_list_call_count() const { | 40 int destroy_app_list_call_count() const { |
41 return destroy_app_list_call_count_; | 41 return destroy_app_list_call_count_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 AppListService::RegisterPrefs(pref_registry); | 100 AppListService::RegisterPrefs(pref_registry); |
101 profiles::RegisterPrefs(pref_registry); | 101 profiles::RegisterPrefs(pref_registry); |
102 | 102 |
103 PrefServiceFactory factory; | 103 PrefServiceFactory factory; |
104 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); | 104 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); |
105 local_state_ = factory.Create(pref_registry); | 105 local_state_ = factory.Create(pref_registry); |
106 | 106 |
107 profile_store_ = new FakeProfileStore(user_data_dir_, local_state_.get()); | 107 profile_store_ = new FakeProfileStore(user_data_dir_, local_state_.get()); |
108 service_.reset(new TestingAppListServiceImpl( | 108 service_.reset(new TestingAppListServiceImpl( |
109 command_line, | 109 command_line, local_state_.get(), |
110 local_state_.get(), | 110 std::unique_ptr<ProfileStore>(profile_store_))); |
111 scoped_ptr<ProfileStore>(profile_store_))); | |
112 } | 111 } |
113 | 112 |
114 void EnableAppList() { | 113 void EnableAppList() { |
115 service_->EnableAppList(profile1_.get(), | 114 service_->EnableAppList(profile1_.get(), |
116 AppListService::ENABLE_VIA_COMMAND_LINE); | 115 AppListService::ENABLE_VIA_COMMAND_LINE); |
117 } | 116 } |
118 | 117 |
119 base::FilePath user_data_dir_; | 118 base::FilePath user_data_dir_; |
120 scoped_ptr<PrefService> local_state_; | 119 std::unique_ptr<PrefService> local_state_; |
121 FakeProfileStore* profile_store_; | 120 FakeProfileStore* profile_store_; |
122 scoped_ptr<TestingAppListServiceImpl> service_; | 121 std::unique_ptr<TestingAppListServiceImpl> service_; |
123 scoped_ptr<FakeProfile> profile1_; | 122 std::unique_ptr<FakeProfile> profile1_; |
124 scoped_ptr<FakeProfile> profile2_; | 123 std::unique_ptr<FakeProfile> profile2_; |
125 | 124 |
126 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); | 125 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); |
127 }; | 126 }; |
128 | 127 |
129 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { | 128 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { |
130 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); | 129 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); |
131 EnableAppList(); | 130 EnableAppList(); |
132 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); | 131 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); |
133 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( | 132 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( |
134 local_state_->GetFilePath(prefs::kAppListProfile))); | 133 local_state_->GetFilePath(prefs::kAppListProfile))); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, | 269 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, |
271 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 270 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
272 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); | 271 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); |
273 | 272 |
274 // An auto-show here should update the enable method to prevent recording it | 273 // An auto-show here should update the enable method to prevent recording it |
275 // as ENABLE_FOR_APP_INSTALL. | 274 // as ENABLE_FOR_APP_INSTALL. |
276 service_->ShowForAppInstall(profile1_.get(), "", false); | 275 service_->ShowForAppInstall(profile1_.get(), "", false); |
277 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, | 276 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, |
278 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 277 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
279 } | 278 } |
OLD | NEW |