Chromium Code Reviews| Index: chrome/browser/extensions/extension_service_test_base.cc |
| diff --git a/chrome/browser/extensions/extension_service_test_base.cc b/chrome/browser/extensions/extension_service_test_base.cc |
| index 7e8052c0f67ee1ae0ba863f9f33e04243021c4d0..c28d09da857d4b815a52661595dd1f8e209d4763 100644 |
| --- a/chrome/browser/extensions/extension_service_test_base.cc |
| +++ b/chrome/browser/extensions/extension_service_test_base.cc |
| @@ -8,6 +8,8 @@ |
| #include "base/files/file_util.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/path_service.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "chrome/browser/extensions/component_loader.h" |
| #include "chrome/browser/extensions/extension_error_reporter.h" |
| @@ -187,6 +189,93 @@ void ExtensionServiceTestBase::ResetThreadBundle(int options) { |
| thread_bundle_.reset(new content::TestBrowserThreadBundle(options)); |
| } |
| +size_t ExtensionServiceTestBase::GetPrefKeyCount() { |
| + const base::DictionaryValue* dict = |
| + profile()->GetPrefs()->GetDictionary("extensions.settings"); |
| + if (!dict) { |
| + ADD_FAILURE(); |
| + return 0; |
| + } |
| + return dict->size(); |
| +} |
| + |
| +void ExtensionServiceTestBase::ValidatePrefKeyCount(size_t count) { |
| + EXPECT_EQ(count, GetPrefKeyCount()); |
| +} |
| + |
| +testing::AssertionResult ExtensionServiceTestBase::ValidateBooleanPref( |
| + const std::string& extension_id, |
| + const std::string& pref_path, |
| + bool expected_val) { |
| + std::string msg = base::StringPrintf("while checking: %s %s == %s", |
| + extension_id.c_str(), pref_path.c_str(), |
| + expected_val ? "true" : "false"); |
| + |
| + PrefService* prefs = profile()->GetPrefs(); |
| + const base::DictionaryValue* dict = |
| + prefs->GetDictionary("extensions.settings"); |
| + if (!dict) { |
| + return testing::AssertionFailure() |
| + << "extension.settings does not exist " << msg; |
| + } |
| + |
| + const base::DictionaryValue* pref = NULL; |
| + if (!dict->GetDictionary(extension_id, &pref)) { |
| + return testing::AssertionFailure() |
| + << "extension pref does not exist " << msg; |
| + } |
| + |
| + bool val; |
|
Devlin
2015/10/28 16:15:22
nitty nit: initialize val.
Marc Treib
2015/10/29 13:27:57
Done.
|
| + if (!pref->GetBoolean(pref_path, &val)) { |
| + return testing::AssertionFailure() |
| + << pref_path << " pref not found " << msg; |
| + } |
| + |
| + return expected_val == val |
| + ? testing::AssertionSuccess() |
| + : testing::AssertionFailure() << "base::Value is incorrect " << msg; |
| +} |
| + |
| +void ExtensionServiceTestBase::ValidateIntegerPref( |
| + const std::string& extension_id, |
| + const std::string& pref_path, |
| + int expected_val) { |
| + std::string msg = base::StringPrintf("while checking: %s %s == %s", |
| + extension_id.c_str(), pref_path.c_str(), |
| + base::IntToString(expected_val).c_str()); |
| + |
| + PrefService* prefs = profile()->GetPrefs(); |
| + const base::DictionaryValue* dict = |
| + prefs->GetDictionary("extensions.settings"); |
| + ASSERT_TRUE(dict != NULL) << msg; |
| + const base::DictionaryValue* pref = NULL; |
| + ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| + EXPECT_TRUE(pref != NULL) << msg; |
| + int val; |
| + ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; |
| + EXPECT_EQ(expected_val, val) << msg; |
| +} |
| + |
| +void ExtensionServiceTestBase::ValidateStringPref( |
| + const std::string& extension_id, |
| + const std::string& pref_path, |
| + const std::string& expected_val) { |
| + std::string msg = base::StringPrintf("while checking: %s.manifest.%s == %s", |
| + extension_id.c_str(), pref_path.c_str(), |
| + expected_val.c_str()); |
| + |
| + const base::DictionaryValue* dict = |
| + profile()->GetPrefs()->GetDictionary("extensions.settings"); |
| + ASSERT_TRUE(dict != NULL) << msg; |
| + const base::DictionaryValue* pref = NULL; |
| + std::string manifest_path = extension_id + ".manifest"; |
| + ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
| + EXPECT_TRUE(pref != NULL) << msg; |
| + std::string val; |
| + ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| + EXPECT_EQ(expected_val, val) << msg; |
| +} |
| + |
| void ExtensionServiceTestBase::SetUp() { |
| ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| } |