Commit 11d61a11 authored by avi@chromium.org's avatar avi@chromium.org

Switch WebUITestHandler to use ExecuteJavascriptInWebFrameCallbackResult.

BUG=168169
TEST=should all pass


Review URL: https://chromiumcodereview.appspot.com/11801014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175426 0039d316-1c4b-4281-b951-d872f2087c98
parent f535b50b
...@@ -517,7 +517,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { ...@@ -517,7 +517,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) {
AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js")));
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("DISABLED_BogusFunctionName"), EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("DISABLED_BogusFunctionName"),
"WebUITestHandler::Observe"); "WebUITestHandler::JavaScriptComplete");
} }
// Test that bogus javascript fails fast - no timeout waiting for result. // Test that bogus javascript fails fast - no timeout waiting for result.
...@@ -525,7 +525,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestRuntimeErrorFailsFast) { ...@@ -525,7 +525,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestRuntimeErrorFailsFast) {
AddLibrary(FilePath(FILE_PATH_LITERAL("runtime_error.js"))); AddLibrary(FilePath(FILE_PATH_LITERAL("runtime_error.js")));
ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL));
EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("TestRuntimeErrorFailsFast"), EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("TestRuntimeErrorFailsFast"),
"WebUITestHandler::Observe"); "WebUITestHandler::JavaScriptComplete");
} }
// Test that bogus javascript fails async test fast as well - no timeout waiting // Test that bogus javascript fails async test fast as well - no timeout waiting
...@@ -535,7 +535,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsAsyncFast) { ...@@ -535,7 +535,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsAsyncFast) {
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
RunJavascriptAsyncTestNoReturn("DISABLED_BogusFunctionName"), RunJavascriptAsyncTestNoReturn("DISABLED_BogusFunctionName"),
"WebUITestHandler::Observe"); "WebUITestHandler::JavaScriptComplete");
} }
// Tests that the async framework works. // Tests that the async framework works.
......
...@@ -44,11 +44,11 @@ bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) { ...@@ -44,11 +44,11 @@ bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) {
test_succeeded_ = false; test_succeeded_ = false;
run_test_succeeded_ = false; run_test_succeeded_ = false;
RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
content::NotificationRegistrar notification_registrar; rvh->ExecuteJavascriptInWebFrameCallbackResult(
notification_registrar.Add( string16(), // frame_xpath
this, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, js_text,
content::Source<RenderViewHost>(rvh)); base::Bind(&WebUITestHandler::JavaScriptComplete,
rvh->ExecuteJavascriptInWebFrameNotifyResult(string16(), js_text); base::Unretained(this)));
return WaitForResult(); return WaitForResult();
} }
...@@ -77,24 +77,19 @@ void WebUITestHandler::HandleTestResult(const ListValue* test_result) { ...@@ -77,24 +77,19 @@ void WebUITestHandler::HandleTestResult(const ListValue* test_result) {
} }
} }
void WebUITestHandler::Observe(int type, void WebUITestHandler::JavaScriptComplete(const base::Value* result) {
const content::NotificationSource& source,
const content::NotificationDetails& details) {
// Quit the message loop if |is_waiting_| so waiting process can get result or // Quit the message loop if |is_waiting_| so waiting process can get result or
// error. To ensure this gets done, do this before ASSERT* calls. // error. To ensure this gets done, do this before ASSERT* calls.
if (is_waiting_) if (is_waiting_)
MessageLoopForUI::current()->Quit(); MessageLoopForUI::current()->Quit();
ASSERT_EQ(content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, type); SCOPED_TRACE("WebUITestHandler::JavaScriptComplete");
SCOPED_TRACE("WebUITestHandler::Observe");
EXPECT_FALSE(run_test_done_); EXPECT_FALSE(run_test_done_);
run_test_done_ = true; run_test_done_ = true;
run_test_succeeded_ = false; run_test_succeeded_ = false;
Value* value = content::Details<std::pair<int, Value*> >(details)->second; ASSERT_TRUE(result->GetAsBoolean(&run_test_succeeded_));
ASSERT_TRUE(value->GetAsBoolean(&run_test_succeeded_));
} }
bool WebUITestHandler::WaitForResult() { bool WebUITestHandler::WaitForResult() {
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/string16.h" #include "base/string16.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
namespace base { namespace base {
class ListValue; class ListValue;
class Value;
} }
namespace content { namespace content {
...@@ -19,8 +19,7 @@ class RenderViewHost; ...@@ -19,8 +19,7 @@ class RenderViewHost;
} }
// This class registers test framework specific handlers on WebUI objects. // This class registers test framework specific handlers on WebUI objects.
class WebUITestHandler : public content::WebUIMessageHandler, class WebUITestHandler : public content::WebUIMessageHandler {
public content::NotificationObserver {
public: public:
WebUITestHandler(); WebUITestHandler();
...@@ -44,10 +43,8 @@ class WebUITestHandler : public content::WebUIMessageHandler, ...@@ -44,10 +43,8 @@ class WebUITestHandler : public content::WebUIMessageHandler,
// Receives testResult messages. // Receives testResult messages.
void HandleTestResult(const base::ListValue* test_result); void HandleTestResult(const base::ListValue* test_result);
// From content::NotificationObserver. // Gets the callback that Javascript execution is complete.
virtual void Observe(int type, void JavaScriptComplete(const base::Value* result);
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Runs a message loop until test finishes. Returns the result of the // Runs a message loop until test finishes. Returns the result of the
// test. // test.
......
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