diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-23 06:52:41 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-23 06:52:41 +0000 |
commit | e49e1014287407cd8aefc5a49a9c466d633841eb (patch) | |
tree | ad2017bcac3cce09ee4e92c73d7e17a6f2a54fc9 /chrome/browser/extensions/extension_function_test_utils.cc | |
parent | 1063d5e16bb34210d25ffaaa640484f7212fac03 (diff) | |
download | chromium_src-e49e1014287407cd8aefc5a49a9c466d633841eb.zip chromium_src-e49e1014287407cd8aefc5a49a9c466d633841eb.tar.gz chromium_src-e49e1014287407cd8aefc5a49a9c466d633841eb.tar.bz2 |
Move DnsApiTest.DnsResolveIPLiteral and DnsApiTest.DnsResolveHostname to app_shell_browsertests.
This results in a significant speedup; tests run in <500ms instead of >2s because the lengthy browser_tests startup is avoided.
This clones some aspects of extension_function_test_utils into extensions/browser/api_test_utils.cc. Later CLs will clean up the redundancy.
BUG=388893
Review URL: https://codereview.chromium.org/394103004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_function_test_utils.cc')
-rw-r--r-- | chrome/browser/extensions/extension_function_test_utils.cc | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/chrome/browser/extensions/extension_function_test_utils.cc b/chrome/browser/extensions/extension_function_test_utils.cc index 94951ca..d3990c3 100644 --- a/chrome/browser/extensions/extension_function_test_utils.cc +++ b/chrome/browser/extensions/extension_function_test_utils.cc @@ -13,6 +13,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/test/base/ui_test_utils.h" +#include "extensions/browser/api_test_utils.h" #include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function_dispatcher.h" #include "extensions/common/extension.h" @@ -55,20 +56,18 @@ base::Value* ParseJSON(const std::string& data) { } base::ListValue* ParseList(const std::string& data) { - scoped_ptr<base::Value> result(ParseJSON(data)); - if (result.get() && result->IsType(base::Value::TYPE_LIST)) - return static_cast<base::ListValue*>(result.release()); - else - return NULL; + base::Value* result = ParseJSON(data); + base::ListValue* list = NULL; + result->GetAsList(&list); + return list; } base::DictionaryValue* ParseDictionary( const std::string& data) { - scoped_ptr<base::Value> result(ParseJSON(data)); - if (result.get() && result->IsType(base::Value::TYPE_DICTIONARY)) - return static_cast<base::DictionaryValue*>(result.release()); - else - return NULL; + base::Value* result = ParseJSON(data); + base::DictionaryValue* dict = NULL; + result->GetAsDictionary(&dict); + return dict; } bool GetBoolean(base::DictionaryValue* val, const std::string& key) { @@ -243,31 +242,18 @@ bool RunFunction(UIThreadExtensionFunction* function, const std::string& args, Browser* browser, RunFunctionFlags flags) { - SendResponseDelegate response_delegate; - function->set_test_delegate(&response_delegate); - 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); - extensions::ExtensionFunctionDispatcher dispatcher(browser->profile(), - &dispatcher_delegate); - function->set_dispatcher(dispatcher.AsWeakPtr()); - - function->set_browser_context(browser->profile()); - function->set_include_incognito(flags & INCLUDE_INCOGNITO); - function->Run()->Execute(); - - // If the RunAsync of |function| didn't already call SendResponse, run the - // message loop until they do. - if (!response_delegate.HasResponse()) { - response_delegate.set_should_post_quit(true); - content::RunMessageLoop(); - } - - EXPECT_TRUE(response_delegate.HasResponse()); - return response_delegate.GetResponse(); + scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher( + new extensions::ExtensionFunctionDispatcher(browser->profile(), + &dispatcher_delegate)); + // TODO(yoz): The cast is a hack; these flags should be defined in + // only one place. See crbug.com/394840. + return extensions::api_test_utils::RunFunction( + function, + args, + browser->profile(), + dispatcher.Pass(), + static_cast<extensions::api_test_utils::RunFunctionFlags>(flags)); } } // namespace extension_function_test_utils |