diff options
author | thiago.santos <thiago.santos@intel.com> | 2014-12-22 18:00:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-23 02:01:30 +0000 |
commit | 5c855a28156ed8f4d3f191ea7a1f9ee3dc777ee7 (patch) | |
tree | fda19fc7dc29a3f568a8822c168db674bbb6d83c /extensions/browser/api_test_utils.cc | |
parent | 00742d0a34d5aae0f59baedc1173702f22d2aeae (diff) | |
download | chromium_src-5c855a28156ed8f4d3f191ea7a1f9ee3dc777ee7.zip chromium_src-5c855a28156ed8f4d3f191ea7a1f9ee3dc777ee7.tar.gz chromium_src-5c855a28156ed8f4d3f191ea7a1f9ee3dc777ee7.tar.bz2 |
Move system.display tests to extensions/
Also copy a few helper functions from extension_function_test_utils.h to
api_test_utils.h so we don't need to depend on chrome/. These helper
functions are needed by tests other than the display test and will help with
the migration.
BUG=392842
Review URL: https://codereview.chromium.org/779083002
Cr-Commit-Position: refs/heads/master@{#309514}
Diffstat (limited to 'extensions/browser/api_test_utils.cc')
-rw-r--r-- | extensions/browser/api_test_utils.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc index 23c0efe..8d215a5 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, |