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

Unified Diff: extensions/browser/api_test_utils.cc

Issue 779083002: Move system.display tests to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Less duplicated code Created 6 years 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
« no previous file with comments | « extensions/browser/api_test_utils.h ('k') | extensions/shell/app_shell.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api_test_utils.cc
diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc
index 23c0efeaa1832f27c9ed75be78afbe74f255bb01..8d215a5fc29d961dfabbea9790e13310844f1dee 100644
--- a/extensions/browser/api_test_utils.cc
+++ b/extensions/browser/api_test_utils.cc
@@ -7,6 +7,7 @@
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
+#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_context.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_function.h"
@@ -83,6 +84,57 @@ namespace extensions {
namespace api_test_utils {
+base::DictionaryValue* ParseDictionary(const std::string& data) {
+ base::Value* result = ParseJSON(data);
+ base::DictionaryValue* dict = NULL;
+ result->GetAsDictionary(&dict);
+ return dict;
+}
+
+bool GetBoolean(const base::DictionaryValue* val, const std::string& key) {
+ bool result = false;
+ if (!val->GetBoolean(key, &result))
+ ADD_FAILURE() << key << " does not exist or is not a boolean.";
+ return result;
+}
+
+int GetInteger(const base::DictionaryValue* val, const std::string& key) {
+ int result = 0;
+ if (!val->GetInteger(key, &result))
+ ADD_FAILURE() << key << " does not exist or is not an integer.";
+ return result;
+}
+
+std::string GetString(const base::DictionaryValue* val,
+ const std::string& key) {
+ std::string result;
+ if (!val->GetString(key, &result))
+ ADD_FAILURE() << key << " does not exist or is not a string.";
+ return result;
+}
+
+scoped_refptr<Extension> CreateExtension(
+ Manifest::Location location,
+ base::DictionaryValue* test_extension_value,
+ const std::string& id_input) {
+ std::string error;
+ const base::FilePath test_extension_path;
+ std::string id;
+ if (!id_input.empty())
+ id = crx_file::id_util::GenerateId(id_input);
+ scoped_refptr<Extension> extension(
+ Extension::Create(test_extension_path, location, *test_extension_value,
+ Extension::NO_FLAGS, id, &error));
+ EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error;
+ return extension;
+}
+
+scoped_refptr<Extension> CreateExtension(
+ base::DictionaryValue* test_extension_value) {
+ return CreateExtension(Manifest::INTERNAL, test_extension_value,
+ std::string());
+}
+
base::Value* RunFunctionWithDelegateAndReturnSingleResult(
UIThreadExtensionFunction* function,
const std::string& args,
« no previous file with comments | « extensions/browser/api_test_utils.h ('k') | extensions/shell/app_shell.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698