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

Unified Diff: chrome/browser/extensions/extension_function_test_utils.cc

Issue 8588067: Refactor to allow same code to test both sync and async functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix dependencies. Created 9 years, 1 month 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
Index: chrome/browser/extensions/extension_function_test_utils.cc
diff --git a/chrome/browser/extensions/extension_function_test_utils.cc b/chrome/browser/extensions/extension_function_test_utils.cc
index e68bf5efdbce7e3f0e6fa062cfbe78ddfa0541c1..99538077849d50df18d55913a63527c233696be1 100644
--- a/chrome/browser/extensions/extension_function_test_utils.cc
+++ b/chrome/browser/extensions/extension_function_test_utils.cc
@@ -142,28 +142,10 @@ base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function,
return function->GetResultValue()->DeepCopy();
}
-void RunFunction(UIThreadExtensionFunction* function,
- const std::string& args,
- Browser* browser,
- RunFunctionFlags flags) {
- scoped_ptr<base::ListValue> parsed_args(ParseList(args));
- ASSERT_TRUE(parsed_args.get()) <<
- "Could not parse extension function arguments: " << args;
- function->SetArgs(parsed_args.get());
-
- TestFunctionDispatcherDelegate dispatcher_delegate(browser);
- ExtensionFunctionDispatcher dispatcher(
- browser->profile(), &dispatcher_delegate);
- function->set_dispatcher(dispatcher.AsWeakPtr());
-
- function->set_profile(browser->profile());
- function->set_include_incognito(flags & INCLUDE_INCOGNITO);
- function->Run();
-}
-
// This helps us be able to wait until an AsyncExtensionFunction calls
// SendResponse.
-class SendResponseDelegate : public AsyncExtensionFunction::DelegateForTests {
+class SendResponseDelegate
+ : public UIThreadExtensionFunction::DelegateForTests {
public:
SendResponseDelegate() : should_post_quit_(false) {}
@@ -182,7 +164,8 @@ class SendResponseDelegate : public AsyncExtensionFunction::DelegateForTests {
return *response_.get();
}
- virtual void OnSendResponse(AsyncExtensionFunction* function, bool success) {
+ virtual void OnSendResponse(UIThreadExtensionFunction* function,
+ bool success) {
ASSERT_FALSE(HasResponse());
response_.reset(new bool);
*response_ = success;
@@ -196,13 +179,25 @@ class SendResponseDelegate : public AsyncExtensionFunction::DelegateForTests {
bool should_post_quit_;
};
-bool RunAsyncFunction(AsyncExtensionFunction* function,
- const std::string& args,
- Browser* browser,
- RunFunctionFlags flags) {
+bool RunFunction(UIThreadExtensionFunction* function,
+ const std::string& args,
+ Browser* browser,
+ RunFunctionFlags flags) {
SendResponseDelegate response_delegate;
function->set_test_delegate(&response_delegate);
- RunFunction(function, args, browser, flags);
+ scoped_ptr<base::ListValue> parsed_args(ParseList(args));
+ EXPECT_TRUE(parsed_args.get()) <<
+ "Could not parse extension function arguments: " << args;
+ function->SetArgs(parsed_args.get());
+
+ TestFunctionDispatcherDelegate dispatcher_delegate(browser);
+ ExtensionFunctionDispatcher dispatcher(
+ browser->profile(), &dispatcher_delegate);
+ function->set_dispatcher(dispatcher.AsWeakPtr());
+
+ function->set_profile(browser->profile());
+ function->set_include_incognito(flags & INCLUDE_INCOGNITO);
+ function->Run();
// If the RunImpl of |function| didn't already call SendResponse, run the
// message loop until they do.

Powered by Google App Engine
This is Rietveld 408576698