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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/pref_service_factory.h" | 10 #include "base/prefs/pref_service_factory.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 public: | 79 public: |
80 AppListServiceUnitTest() {} | 80 AppListServiceUnitTest() {} |
81 | 81 |
82 void SetUp() override { | 82 void SetUp() override { |
83 SetupWithCommandLine(base::CommandLine(base::CommandLine::NO_PROGRAM)); | 83 SetupWithCommandLine(base::CommandLine(base::CommandLine::NO_PROGRAM)); |
84 } | 84 } |
85 | 85 |
86 protected: | 86 protected: |
87 void SetupWithCommandLine(const base::CommandLine& command_line) { | 87 void SetupWithCommandLine(const base::CommandLine& command_line) { |
88 user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd")); | 88 user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd")); |
89 initial_profile_ = "ip"; | |
90 profile1_.reset( | 89 profile1_.reset( |
91 new FakeProfile("p1", user_data_dir_.AppendASCII("profile1"))); | 90 new FakeProfile("p1", user_data_dir_.AppendASCII("profile1"))); |
92 profile2_.reset( | 91 profile2_.reset( |
93 new FakeProfile("p2", user_data_dir_.AppendASCII("profile2"))); | 92 new FakeProfile("p2", user_data_dir_.AppendASCII("profile2"))); |
94 PrefRegistrySimple* pref_registry = new PrefRegistrySimple; | 93 PrefRegistrySimple* pref_registry = new PrefRegistrySimple; |
95 | 94 |
96 AppListService::RegisterPrefs(pref_registry); | 95 AppListService::RegisterPrefs(pref_registry); |
97 profiles::RegisterPrefs(pref_registry); | 96 profiles::RegisterPrefs(pref_registry); |
98 | 97 |
99 base::PrefServiceFactory factory; | 98 base::PrefServiceFactory factory; |
100 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); | 99 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); |
101 local_state_ = factory.Create(pref_registry).Pass(); | 100 local_state_ = factory.Create(pref_registry).Pass(); |
102 | 101 |
103 profile_store_ = new FakeProfileStore(user_data_dir_, initial_profile_); | 102 profile_store_ = new FakeProfileStore(user_data_dir_, local_state_.get()); |
104 service_.reset(new TestingAppListServiceImpl( | 103 service_.reset(new TestingAppListServiceImpl( |
105 command_line, | 104 command_line, |
106 local_state_.get(), | 105 local_state_.get(), |
107 scoped_ptr<ProfileStore>(profile_store_))); | 106 scoped_ptr<ProfileStore>(profile_store_))); |
108 } | 107 } |
109 | 108 |
110 void EnableAppList() { | 109 void EnableAppList() { |
111 service_->EnableAppList(profile1_.get(), | 110 service_->EnableAppList(profile1_.get(), |
112 AppListService::ENABLE_VIA_COMMAND_LINE); | 111 AppListService::ENABLE_VIA_COMMAND_LINE); |
113 } | 112 } |
114 | 113 |
115 base::FilePath user_data_dir_; | 114 base::FilePath user_data_dir_; |
116 std::string initial_profile_; | |
117 scoped_ptr<PrefService> local_state_; | 115 scoped_ptr<PrefService> local_state_; |
118 FakeProfileStore* profile_store_; | 116 FakeProfileStore* profile_store_; |
119 scoped_ptr<TestingAppListServiceImpl> service_; | 117 scoped_ptr<TestingAppListServiceImpl> service_; |
120 scoped_ptr<FakeProfile> profile1_; | 118 scoped_ptr<FakeProfile> profile1_; |
121 scoped_ptr<FakeProfile> profile2_; | 119 scoped_ptr<FakeProfile> profile2_; |
122 | 120 |
123 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); | 121 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); |
124 }; | 122 }; |
125 | 123 |
126 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { | 124 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { |
127 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); | 125 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); |
128 EnableAppList(); | 126 EnableAppList(); |
129 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); | 127 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); |
130 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( | 128 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( |
131 local_state_->GetFilePath(prefs::kAppListProfile))); | 129 local_state_->GetFilePath(prefs::kAppListProfile))); |
132 } | 130 } |
133 | 131 |
134 TEST_F(AppListServiceUnitTest, ShowingForProfileLoadsAProfile) { | 132 TEST_F(AppListServiceUnitTest, ShowingForProfileLoadsAProfile) { |
135 profile_store_->LoadProfile(profile1_.get()); | 133 profile_store_->LoadProfile(profile1_.get()); |
136 EnableAppList(); | 134 EnableAppList(); |
137 service_->Show(); | 135 service_->Show(); |
138 EXPECT_EQ(profile1_.get(), service_->showing_for_profile()); | 136 EXPECT_EQ(profile1_.get(), service_->showing_for_profile()); |
139 EXPECT_TRUE(service_->IsAppListVisible()); | 137 EXPECT_TRUE(service_->IsAppListVisible()); |
140 } | 138 } |
141 | 139 |
142 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { | 140 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { |
143 EnableAppList(); | 141 EnableAppList(); |
144 profile_store_->RemoveProfile(profile1_.get()); | 142 profile_store_->RemoveProfile(profile1_.get()); |
| 143 |
| 144 // kAppListProfile should have been cleared, and therefore GetProfilePath |
| 145 // should return the initial profile. |
| 146 EXPECT_EQ("", local_state_->GetString(prefs::kAppListProfile)); |
145 base::FilePath initial_profile_path = | 147 base::FilePath initial_profile_path = |
146 user_data_dir_.AppendASCII(initial_profile_); | 148 user_data_dir_.AppendASCII(chrome::kInitialProfile); |
147 EXPECT_EQ(initial_profile_path, | 149 EXPECT_EQ(initial_profile_path, |
148 service_->GetProfilePath(profile_store_->GetUserDataDir())); | 150 service_->GetProfilePath(profile_store_->GetUserDataDir())); |
149 } | 151 } |
150 | 152 |
151 TEST_F(AppListServiceUnitTest, | 153 TEST_F(AppListServiceUnitTest, |
152 RemovedProfileResetsToLastUsedProfileIfExists) { | 154 RemovedProfileResetsToLastUsedProfileIfExists) { |
153 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); | 155 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); |
154 EnableAppList(); | 156 EnableAppList(); |
155 profile_store_->RemoveProfile(profile1_.get()); | 157 profile_store_->RemoveProfile(profile1_.get()); |
156 | 158 |
| 159 // kAppListProfile should have been set to kProfileLastUsed. |
| 160 EXPECT_EQ("last-used", local_state_->GetString(prefs::kAppListProfile)); |
157 base::FilePath last_used_profile_path = | 161 base::FilePath last_used_profile_path = |
158 user_data_dir_.AppendASCII("last-used"); | 162 user_data_dir_.AppendASCII("last-used"); |
159 EXPECT_EQ(last_used_profile_path, | 163 EXPECT_EQ(last_used_profile_path, |
160 service_->GetProfilePath(profile_store_->GetUserDataDir())); | 164 service_->GetProfilePath(profile_store_->GetUserDataDir())); |
161 | 165 |
162 // For this test, the AppListViewDelegate is not created because the | 166 // For this test, the AppListViewDelegate is not created because the |
163 // app list is never shown, so there is nothing to destroy. | 167 // app list is never shown, so there is nothing to destroy. |
164 EXPECT_EQ(0, service_->destroy_app_list_call_count()); | 168 EXPECT_EQ(0, service_->destroy_app_list_call_count()); |
165 } | 169 } |
166 | 170 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, | 240 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, |
237 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 241 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
238 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); | 242 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); |
239 | 243 |
240 // An auto-show here should update the enable method to prevent recording it | 244 // An auto-show here should update the enable method to prevent recording it |
241 // as ENABLE_FOR_APP_INSTALL. | 245 // as ENABLE_FOR_APP_INSTALL. |
242 service_->ShowForAppInstall(profile1_.get(), "", false); | 246 service_->ShowForAppInstall(profile1_.get(), "", false); |
243 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, | 247 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, |
244 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 248 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
245 } | 249 } |
OLD | NEW |