| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | 5 #include "chrome/browser/ui/webui/web_ui_test_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | |
| 15 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 | 18 |
| 19 WebUITestHandler::WebUITestHandler() | 19 WebUITestHandler::WebUITestHandler() |
| 20 : test_done_(false), | 20 : test_done_(false), |
| 21 test_succeeded_(false), | 21 test_succeeded_(false), |
| 22 run_test_done_(false), | 22 run_test_done_(false), |
| 23 run_test_succeeded_(false), | 23 run_test_succeeded_(false), |
| 24 is_waiting_(false) { | 24 is_waiting_(false) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 void WebUITestHandler::PreloadJavaScript(const string16& js_text, | 27 void WebUITestHandler::PreloadJavaScript(const string16& js_text, |
| 28 RenderViewHost* preload_host) { | 28 RenderViewHost* preload_host) { |
| 29 DCHECK(preload_host); | 29 DCHECK(preload_host); |
| 30 preload_host->Send(new ChromeViewMsg_WebUIJavaScript( | 30 preload_host->Send(new ChromeViewMsg_WebUIJavaScript( |
| 31 preload_host->routing_id(), string16(), js_text, 0, | 31 preload_host->routing_id(), string16(), js_text, 0, |
| 32 false)); | 32 false)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void WebUITestHandler::RunJavaScript(const string16& js_text) { | 35 void WebUITestHandler::RunJavaScript(const string16& js_text) { |
| 36 web_ui()->tab_contents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame( | 36 web_ui()->web_contents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
| 37 string16(), js_text); | 37 string16(), js_text); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) { | 40 bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) { |
| 41 test_succeeded_ = false; | 41 test_succeeded_ = false; |
| 42 run_test_succeeded_ = false; | 42 run_test_succeeded_ = false; |
| 43 RenderViewHost* rvh = web_ui()->tab_contents()->GetRenderViewHost(); | 43 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost(); |
| 44 content::NotificationRegistrar notification_registrar; | 44 content::NotificationRegistrar notification_registrar; |
| 45 notification_registrar.Add( | 45 notification_registrar.Add( |
| 46 this, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 46 this, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
| 47 content::Source<RenderViewHost>(rvh)); | 47 content::Source<RenderViewHost>(rvh)); |
| 48 rvh->ExecuteJavascriptInWebFrameNotifyResult(string16(), js_text); | 48 rvh->ExecuteJavascriptInWebFrameNotifyResult(string16(), js_text); |
| 49 return WaitForResult(); | 49 return WaitForResult(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void WebUITestHandler::RegisterMessages() { | 52 void WebUITestHandler::RegisterMessages() { |
| 53 web_ui()->RegisterMessageCallback("testResult", | 53 web_ui()->RegisterMessageCallback("testResult", |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // complete. | 109 // complete. |
| 110 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { | 110 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { |
| 111 ui_test_utils::RunMessageLoop(); | 111 ui_test_utils::RunMessageLoop(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 is_waiting_ = false; | 114 is_waiting_ = false; |
| 115 | 115 |
| 116 // To succeed the test must execute as well as pass the test. | 116 // To succeed the test must execute as well as pass the test. |
| 117 return run_test_succeeded_ && test_succeeded_; | 117 return run_test_succeeded_ && test_succeeded_; |
| 118 } | 118 } |
| OLD | NEW |