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

Unified Diff: chrome/browser/ui/webui/web_ui_test_handler.cc

Issue 7146024: Use ExecuteJavascriptInWebFrameNotifyResult to return results even in error condition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sorted includes. Created 9 years, 6 months 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/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..eb30ea7f33dbafb8397f7f84276b20da7fad2957 100644
--- a/chrome/browser/ui/webui/web_ui_test_handler.cc
+++ b/chrome/browser/ui/webui/web_ui_test_handler.cc
@@ -8,39 +8,41 @@
#include "base/values.h"
#include "chrome/test/ui_test_utils.h"
#include "content/browser/renderer_host/render_view_host.h"
+#include "content/common/notification_details.h"
+#include "content/common/notification_registrar.h"
bool WebUITestHandler::RunJavascript(const std::string& js_test,
bool is_test) {
Paweł Hajdan Jr. 2011/06/15 08:18:21 nit: Please align this line.
Sheridan Rawlins 2011/06/15 15:41:14 Done.
- web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
- string16(), UTF8ToUTF16(js_test));
-
- if (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;
- if (is_waiting_)
- MessageLoopForUI::current()->Quit();
-}
-
-void WebUITestHandler::HandleFail(const ListValue* args) {
- 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));
+void WebUITestHandler::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // Always quit the message loop so Waiting process can get result or error.
+ MessageLoopForUI::current()->Quit();
+
+ Value* value = Details<std::pair<int, Value*> >(details)->second;
+ ListValue* list_value;
+ ASSERT_TRUE(value->GetAsList(&list_value));
+ ASSERT_TRUE(list_value->GetBoolean(0, &test_succeeded_));
+ if (!test_succeeded_) {
+ std::string message;
+ ASSERT_TRUE(list_value->GetString(1, &message));
+ LOG(ERROR) << message;
+ }
}
bool WebUITestHandler::WaitForResult() {

Powered by Google App Engine
This is Rietveld 408576698