Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5549)

Unified Diff: chrome/browser/extensions/extension_service_test_base.cc

Issue 1411773002: Move Sync-specific tests from ExtensionServiceTest into new file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@su_ext_reenable
Patch Set: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
}

Powered by Google App Engine
This is Rietveld 408576698