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..3afa97b92e9864790ab7e84fb177162840c7468d 100644 |
--- a/chrome/browser/extensions/extension_service_test_base.cc |
+++ b/chrome/browser/extensions/extension_service_test_base.cc |
@@ -8,6 +8,7 @@ |
#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/thread_task_runner_handle.h" |
#include "chrome/browser/extensions/component_loader.h" |
#include "chrome/browser/extensions/extension_error_reporter.h" |
@@ -187,6 +188,102 @@ 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 = "while checking: "; |
Devlin
2015/10/20 17:42:15
base::StringPrintf is a beautiful thing. :) (here
Marc Treib
2015/10/21 12:51:53
You really are a fan of that function, aren't you
|
+ msg += extension_id; |
+ msg += " "; |
+ msg += pref_path; |
+ msg += " == "; |
+ msg += 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; |
+ 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 = " while checking: "; |
+ msg += extension_id; |
+ msg += " "; |
+ msg += pref_path; |
+ msg += " == "; |
+ msg += base::IntToString(expected_val); |
+ |
+ 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 = " while checking: "; |
+ msg += extension_id; |
+ msg += ".manifest."; |
+ msg += pref_path; |
+ msg += " == "; |
+ msg += expected_val; |
+ |
+ 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(); |
} |