OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_service_test_base.h" | 5 #include "chrome/browser/extensions/extension_service_test_base.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/stringprintf.h" | |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "chrome/browser/extensions/component_loader.h" | 14 #include "chrome/browser/extensions/component_loader.h" |
13 #include "chrome/browser/extensions/extension_error_reporter.h" | 15 #include "chrome/browser/extensions/extension_error_reporter.h" |
14 #include "chrome/browser/extensions/extension_garbage_collector_factory.h" | 16 #include "chrome/browser/extensions/extension_garbage_collector_factory.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
17 #include "chrome/browser/extensions/updater/extension_updater.h" | 19 #include "chrome/browser/extensions/updater/extension_updater.h" |
18 #include "chrome/browser/prefs/browser_prefs.h" | 20 #include "chrome/browser/prefs/browser_prefs.h" |
19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 InitializeExtensionService(params); | 182 InitializeExtensionService(params); |
181 service_->updater()->Start(); | 183 service_->updater()->Start(); |
182 } | 184 } |
183 | 185 |
184 void ExtensionServiceTestBase::ResetThreadBundle(int options) { | 186 void ExtensionServiceTestBase::ResetThreadBundle(int options) { |
185 did_reset_thread_bundle_ = true; | 187 did_reset_thread_bundle_ = true; |
186 thread_bundle_.reset(); | 188 thread_bundle_.reset(); |
187 thread_bundle_.reset(new content::TestBrowserThreadBundle(options)); | 189 thread_bundle_.reset(new content::TestBrowserThreadBundle(options)); |
188 } | 190 } |
189 | 191 |
192 size_t ExtensionServiceTestBase::GetPrefKeyCount() { | |
193 const base::DictionaryValue* dict = | |
194 profile()->GetPrefs()->GetDictionary("extensions.settings"); | |
195 if (!dict) { | |
196 ADD_FAILURE(); | |
197 return 0; | |
198 } | |
199 return dict->size(); | |
200 } | |
201 | |
202 void ExtensionServiceTestBase::ValidatePrefKeyCount(size_t count) { | |
203 EXPECT_EQ(count, GetPrefKeyCount()); | |
204 } | |
205 | |
206 testing::AssertionResult ExtensionServiceTestBase::ValidateBooleanPref( | |
207 const std::string& extension_id, | |
208 const std::string& pref_path, | |
209 bool expected_val) { | |
210 std::string msg = base::StringPrintf("while checking: %s %s == %s", | |
211 extension_id.c_str(), pref_path.c_str(), | |
212 expected_val ? "true" : "false"); | |
213 | |
214 PrefService* prefs = profile()->GetPrefs(); | |
215 const base::DictionaryValue* dict = | |
216 prefs->GetDictionary("extensions.settings"); | |
217 if (!dict) { | |
218 return testing::AssertionFailure() | |
219 << "extension.settings does not exist " << msg; | |
220 } | |
221 | |
222 const base::DictionaryValue* pref = NULL; | |
223 if (!dict->GetDictionary(extension_id, &pref)) { | |
224 return testing::AssertionFailure() | |
225 << "extension pref does not exist " << msg; | |
226 } | |
227 | |
228 bool val; | |
Devlin
2015/10/28 16:15:22
nitty nit: initialize val.
Marc Treib
2015/10/29 13:27:57
Done.
| |
229 if (!pref->GetBoolean(pref_path, &val)) { | |
230 return testing::AssertionFailure() | |
231 << pref_path << " pref not found " << msg; | |
232 } | |
233 | |
234 return expected_val == val | |
235 ? testing::AssertionSuccess() | |
236 : testing::AssertionFailure() << "base::Value is incorrect " << msg; | |
237 } | |
238 | |
239 void ExtensionServiceTestBase::ValidateIntegerPref( | |
240 const std::string& extension_id, | |
241 const std::string& pref_path, | |
242 int expected_val) { | |
243 std::string msg = base::StringPrintf("while checking: %s %s == %s", | |
244 extension_id.c_str(), pref_path.c_str(), | |
245 base::IntToString(expected_val).c_str()); | |
246 | |
247 PrefService* prefs = profile()->GetPrefs(); | |
248 const base::DictionaryValue* dict = | |
249 prefs->GetDictionary("extensions.settings"); | |
250 ASSERT_TRUE(dict != NULL) << msg; | |
251 const base::DictionaryValue* pref = NULL; | |
252 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | |
253 EXPECT_TRUE(pref != NULL) << msg; | |
254 int val; | |
255 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; | |
256 EXPECT_EQ(expected_val, val) << msg; | |
257 } | |
258 | |
259 void ExtensionServiceTestBase::ValidateStringPref( | |
260 const std::string& extension_id, | |
261 const std::string& pref_path, | |
262 const std::string& expected_val) { | |
263 std::string msg = base::StringPrintf("while checking: %s.manifest.%s == %s", | |
264 extension_id.c_str(), pref_path.c_str(), | |
265 expected_val.c_str()); | |
266 | |
267 const base::DictionaryValue* dict = | |
268 profile()->GetPrefs()->GetDictionary("extensions.settings"); | |
269 ASSERT_TRUE(dict != NULL) << msg; | |
270 const base::DictionaryValue* pref = NULL; | |
271 std::string manifest_path = extension_id + ".manifest"; | |
272 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; | |
273 EXPECT_TRUE(pref != NULL) << msg; | |
274 std::string val; | |
275 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; | |
276 EXPECT_EQ(expected_val, val) << msg; | |
277 } | |
278 | |
190 void ExtensionServiceTestBase::SetUp() { | 279 void ExtensionServiceTestBase::SetUp() { |
191 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 280 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
192 } | 281 } |
193 | 282 |
194 void ExtensionServiceTestBase::SetUpTestCase() { | 283 void ExtensionServiceTestBase::SetUpTestCase() { |
195 // Safe to call multiple times. | 284 // Safe to call multiple times. |
196 ExtensionErrorReporter::Init(false); // no noisy errors. | 285 ExtensionErrorReporter::Init(false); // no noisy errors. |
197 } | 286 } |
198 | 287 |
199 // These are declared in the .cc so that all inheritors don't need to know | 288 // These are declared in the .cc so that all inheritors don't need to know |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 // interfere with the tests. Those tests that need an external provider | 320 // interfere with the tests. Those tests that need an external provider |
232 // will register one specifically. | 321 // will register one specifically. |
233 service_->ClearProvidersForTesting(); | 322 service_->ClearProvidersForTesting(); |
234 | 323 |
235 #if defined(OS_CHROMEOS) | 324 #if defined(OS_CHROMEOS) |
236 InstallLimiter::Get(profile_.get())->DisableForTest(); | 325 InstallLimiter::Get(profile_.get())->DisableForTest(); |
237 #endif | 326 #endif |
238 } | 327 } |
239 | 328 |
240 } // namespace extensions | 329 } // namespace extensions |
OLD | NEW |