Chromium Code Reviews| 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..3bc0d99f49cfd70a6564ba5a79cfa78c66c09ba2 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" |
| @@ -77,12 +78,63 @@ class SendResponseDelegate |
| bool should_post_quit_; |
| }; |
| +scoped_refptr<extensions::Extension> CreateExtension( |
|
James Cook
2014/12/19 18:07:03
Can you move this out of the anonymous namespace a
tmpsantos
2014/12/23 02:09:38
Acknowledged.
|
| + extensions::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<extensions::Extension> extension(extensions::Extension::Create( |
| + test_extension_path, location, *test_extension_value, |
| + extensions::Extension::NO_FLAGS, id, &error)); |
| + EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error; |
| + return extension; |
| +} |
| + |
| } // namespace |
| namespace extensions { |
| namespace api_test_utils { |
| +base::DictionaryValue* ParseDictionary(const std::string& data) { |
|
James Cook
2014/12/19 18:07:03
Likewise, can the extension_function_utils.cc vers
tmpsantos
2014/12/23 02:09:38
Acknowledged.
|
| + 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( |
| + base::DictionaryValue* test_extension_value) { |
| + return ::CreateExtension(Manifest::INTERNAL, test_extension_value, |
| + std::string()); |
| +} |
| + |
| base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| UIThreadExtensionFunction* function, |
| const std::string& args, |