Index: chrome/browser/ui/webui/web_ui_test_handler.cc |
diff --git a/chrome/browser/ui/webui/web_ui_test_handler.cc b/chrome/browser/ui/webui/web_ui_test_handler.cc |
index 29eb98c9d3e361247c2f26a39685aa2ba3486a2b..8c93b4d3442193cc2fccd9dc3fcd914c67d52981 100644 |
--- a/chrome/browser/ui/webui/web_ui_test_handler.cc |
+++ b/chrome/browser/ui/webui/web_ui_test_handler.cc |
@@ -8,39 +8,49 @@ |
#include "base/values.h" |
#include "chrome/test/ui_test_utils.h" |
#include "content/browser/renderer_host/render_view_host.h" |
- |
-bool WebUITestHandler::RunJavascript(const std::string& js_test, |
- bool is_test) { |
- web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
- string16(), UTF8ToUTF16(js_test)); |
- |
- if (is_test) |
+#include "content/common/notification_details.h" |
+#include "content/common/notification_registrar.h" |
+ |
+bool WebUITestHandler::RunJavascript(const std::string& js_test, bool is_test) { |
+ if (is_test) { |
+ NotificationRegistrar notification_registrar; |
+ notification_registrar.Add( |
+ this, NotificationType::EXECUTE_JAVASCRIPT_RESULT, |
+ Source<RenderViewHost>(web_ui_->GetRenderViewHost())); |
+ web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrameNotifyResult( |
+ string16(), UTF8ToUTF16(js_test)); |
return WaitForResult(); |
- else |
+ } else { |
+ web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
+ string16(), UTF8ToUTF16(js_test)); |
return true; |
+ } |
} |
-void WebUITestHandler::HandlePass(const ListValue* args) { |
- test_succeeded_ = true; |
+void WebUITestHandler::Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ // Quit the message loop if we were waiting so Waiting process can get result |
+ // or error. |
if (is_waiting_) |
MessageLoopForUI::current()->Quit(); |
-} |
-void WebUITestHandler::HandleFail(const ListValue* args) { |
+ // Default to failing, and bail early on errors. This allows the |
+ // RunJavascriptTest to return failure without causing gtest to fail on this |
+ // test (so we can pass the test for the failing case). |
test_succeeded_ = false; |
- if (is_waiting_) |
- MessageLoopForUI::current()->Quit(); |
- |
- std::string message; |
- ASSERT_TRUE(args->GetString(0, &message)); |
- LOG(ERROR) << message; |
-} |
- |
-void WebUITestHandler::RegisterMessages() { |
- web_ui_->RegisterMessageCallback("Pass", |
- NewCallback(this, &WebUITestHandler::HandlePass)); |
- web_ui_->RegisterMessageCallback("Fail", |
- NewCallback(this, &WebUITestHandler::HandleFail)); |
+ Value* value = Details<std::pair<int, Value*> >(details)->second; |
+ ListValue* list_value; |
+ if (!value->GetAsList(&list_value)) |
+ return; |
+ if (!list_value->GetBoolean(0, &test_succeeded_)) |
+ return; |
+ if (!test_succeeded_) { |
+ std::string message; |
+ if (!list_value->GetString(1, &message)) |
+ return; |
+ LOG(ERROR) << message; |
+ } |
} |
bool WebUITestHandler::WaitForResult() { |