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 4c9a58b95cdbc5dc260dc6ce3d95a9410204c254..cb2c0c40d4b4aeb6e3f50bd2f7d06f8ba60e1db0 100644 |
| --- a/extensions/browser/api_test_utils.cc |
| +++ b/extensions/browser/api_test_utils.cc |
| @@ -11,10 +11,24 @@ |
| #include "content/public/test/test_utils.h" |
| #include "extensions/browser/extension_function.h" |
| #include "extensions/browser/extension_function_dispatcher.h" |
| +#include "extensions/common/extension_builder.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +using extensions::ExtensionFunctionDispatcher; |
| + |
| namespace { |
| +class TestFunctionDispatcherDelegate |
| + : public ExtensionFunctionDispatcher::Delegate { |
| + public: |
| + TestFunctionDispatcherDelegate() {} |
| + virtual ~TestFunctionDispatcherDelegate() {} |
| + |
| + // NULL implementation. |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); |
| +}; |
| + |
| base::Value* ParseJSON(const std::string& data) { |
| return base::JSONReader::Read(data); |
| } |
| @@ -69,6 +83,15 @@ namespace extensions { |
| namespace api_test_utils { |
| +scoped_refptr<Extension> CreateEmptyExtension() { |
|
Yoyo Zhou
2014/08/08 01:28:04
I recently found extensions/common/test_util.h. I
Daniel Nishi
2014/08/08 17:24:08
I think it looks better, too.
Done.
|
| + scoped_refptr<Extension> empty_extension( |
| + ExtensionBuilder() |
| + .SetManifest( |
| + DictionaryBuilder().Set("name", "Test").Set("version", "1.0")) |
| + .Build()); |
| + return empty_extension; |
| +} |
| + |
| base::Value* RunFunctionAndReturnSingleResult( |
| UIThreadExtensionFunction* function, |
| const std::string& args, |
| @@ -98,6 +121,27 @@ base::Value* RunFunctionAndReturnSingleResult( |
| return NULL; |
| } |
| +base::Value* RunDelegatelessFunctionAndReturnSingleResult( |
|
Yoyo Zhou
2014/08/08 01:28:04
I think the default should be with no delegate, si
Daniel Nishi
2014/08/08 17:24:08
Done.
|
| + UIThreadExtensionFunction* function, |
| + const std::string& args, |
| + content::BrowserContext* context) { |
| + return RunDelegatelessFunctionAndReturnSingleResult( |
| + function, args, context, NONE); |
| +} |
| + |
| +base::Value* RunDelegatelessFunctionAndReturnSingleResult( |
| + UIThreadExtensionFunction* function, |
| + const std::string& args, |
| + content::BrowserContext* context, |
| + RunFunctionFlags flags) { |
| + TestFunctionDispatcherDelegate delegate; |
| + scoped_ptr<ExtensionFunctionDispatcher> dispatcher( |
| + new ExtensionFunctionDispatcher(context, &delegate)); |
| + |
| + return RunFunctionAndReturnSingleResult( |
| + function, args, context, dispatcher.Pass(), flags); |
| +} |
| + |
| bool RunFunction(UIThreadExtensionFunction* function, |
| const std::string& args, |
| content::BrowserContext* context, |