Commit fc672e14 authored by ckehoe@chromium.org's avatar ckehoe@chromium.org

Adding support for args as ListValues in extension_function_test_utils.

Review URL: https://codereview.chromium.org/473363003

Cr-Commit-Position: refs/heads/master@{#290130}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290130 0039d316-1c4b-4281-b951-d872f2087c98
parent 8bde78e4
...@@ -242,6 +242,16 @@ bool RunFunction(UIThreadExtensionFunction* function, ...@@ -242,6 +242,16 @@ bool RunFunction(UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
Browser* browser, Browser* browser,
RunFunctionFlags flags) { RunFunctionFlags flags) {
scoped_ptr<base::ListValue> parsed_args(ParseList(args));
EXPECT_TRUE(parsed_args.get())
<< "Could not parse extension function arguments: " << args;
return RunFunction(function, parsed_args.Pass(), browser, flags);
}
bool RunFunction(UIThreadExtensionFunction* function,
scoped_ptr<base::ListValue> args,
Browser* browser,
RunFunctionFlags flags) {
TestFunctionDispatcherDelegate dispatcher_delegate(browser); TestFunctionDispatcherDelegate dispatcher_delegate(browser);
scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher( scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher(
new extensions::ExtensionFunctionDispatcher(browser->profile(), new extensions::ExtensionFunctionDispatcher(browser->profile(),
...@@ -250,7 +260,7 @@ bool RunFunction(UIThreadExtensionFunction* function, ...@@ -250,7 +260,7 @@ bool RunFunction(UIThreadExtensionFunction* function,
// only one place. See crbug.com/394840. // only one place. See crbug.com/394840.
return extensions::api_test_utils::RunFunction( return extensions::api_test_utils::RunFunction(
function, function,
args, args.Pass(),
browser->profile(), browser->profile(),
dispatcher.Pass(), dispatcher.Pass(),
static_cast<extensions::api_test_utils::RunFunctionFlags>(flags)); static_cast<extensions::api_test_utils::RunFunctionFlags>(flags));
......
...@@ -23,6 +23,8 @@ namespace extensions { ...@@ -23,6 +23,8 @@ namespace extensions {
class Extension; class Extension;
} }
// TODO(ckehoe): Accept args as scoped_ptr<base::Value>,
// and migrate existing users to the new API.
namespace extension_function_test_utils { namespace extension_function_test_utils {
// Parse JSON and return as the specified type, or NULL if the JSON is invalid // Parse JSON and return as the specified type, or NULL if the JSON is invalid
...@@ -119,6 +121,10 @@ bool RunFunction(UIThreadExtensionFunction* function, ...@@ -119,6 +121,10 @@ bool RunFunction(UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
Browser* browser, Browser* browser,
RunFunctionFlags flags); RunFunctionFlags flags);
bool RunFunction(UIThreadExtensionFunction* function,
scoped_ptr<base::ListValue> args,
Browser* browser,
RunFunctionFlags flags);
} // namespace extension_function_test_utils } // namespace extension_function_test_utils
......
...@@ -137,12 +137,21 @@ bool RunFunction(UIThreadExtensionFunction* function, ...@@ -137,12 +137,21 @@ bool RunFunction(UIThreadExtensionFunction* function,
content::BrowserContext* context, content::BrowserContext* context,
scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags) { RunFunctionFlags flags) {
SendResponseDelegate response_delegate;
function->set_test_delegate(&response_delegate);
scoped_ptr<base::ListValue> parsed_args(ParseList(args)); scoped_ptr<base::ListValue> parsed_args(ParseList(args));
EXPECT_TRUE(parsed_args.get()) EXPECT_TRUE(parsed_args.get())
<< "Could not parse extension function arguments: " << args; << "Could not parse extension function arguments: " << args;
function->SetArgs(parsed_args.get()); return RunFunction(
function, parsed_args.Pass(), context, dispatcher.Pass(), flags);
}
bool RunFunction(UIThreadExtensionFunction* function,
scoped_ptr<base::ListValue> args,
content::BrowserContext* context,
scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags) {
SendResponseDelegate response_delegate;
function->set_test_delegate(&response_delegate);
function->SetArgs(args.get());
CHECK(dispatcher); CHECK(dispatcher);
function->set_dispatcher(dispatcher->AsWeakPtr()); function->set_dispatcher(dispatcher->AsWeakPtr());
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
class UIThreadExtensionFunction; class UIThreadExtensionFunction;
namespace base { namespace base {
class ListValue;
class Value; class Value;
} }
...@@ -24,6 +25,9 @@ class ExtensionFunctionDispatcher; ...@@ -24,6 +25,9 @@ class ExtensionFunctionDispatcher;
// TODO(yoz): crbug.com/394840: Remove duplicate functionality in // TODO(yoz): crbug.com/394840: Remove duplicate functionality in
// chrome/browser/extensions/extension_function_test_utils.h. // chrome/browser/extensions/extension_function_test_utils.h.
//
// TODO(ckehoe): Accept args as scoped_ptr<base::Value>,
// and migrate existing users to the new API.
namespace api_test_utils { namespace api_test_utils {
enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 };
...@@ -70,6 +74,11 @@ bool RunFunction(UIThreadExtensionFunction* function, ...@@ -70,6 +74,11 @@ bool RunFunction(UIThreadExtensionFunction* function,
content::BrowserContext* context, content::BrowserContext* context,
scoped_ptr<ExtensionFunctionDispatcher> dispatcher, scoped_ptr<ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags); RunFunctionFlags flags);
bool RunFunction(UIThreadExtensionFunction* function,
scoped_ptr<base::ListValue> args,
content::BrowserContext* context,
scoped_ptr<ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags);
} // namespace function_test_utils } // namespace function_test_utils
} // namespace extensions } // namespace extensions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment