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