| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 | 31 |
| 32 void WebUITestHandler::PreloadJavaScript(const base::string16& js_text, | 32 void WebUITestHandler::PreloadJavaScript(const base::string16& js_text, |
| 33 RenderViewHost* preload_host) { | 33 RenderViewHost* preload_host) { |
| 34 DCHECK(preload_host); | 34 DCHECK(preload_host); |
| 35 preload_host->Send(new ChromeViewMsg_WebUIJavaScript( | 35 preload_host->Send(new ChromeViewMsg_WebUIJavaScript( |
| 36 preload_host->GetRoutingID(), js_text)); | 36 preload_host->GetRoutingID(), js_text)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void WebUITestHandler::RunJavaScript(const base::string16& js_text) { | 39 void WebUITestHandler::RunJavaScript(const base::string16& js_text) { |
| 40 web_ui()->GetWebContents()->GetMainFrame()->ExecuteJavaScript(js_text); | 40 web_ui()->GetWebContents()->GetMainFrame()->ExecuteJavaScriptForTests( |
| 41 js_text); |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool WebUITestHandler::RunJavaScriptTestWithResult( | 44 bool WebUITestHandler::RunJavaScriptTestWithResult( |
| 44 const base::string16& js_text) { | 45 const base::string16& js_text) { |
| 45 test_succeeded_ = false; | 46 test_succeeded_ = false; |
| 46 run_test_succeeded_ = false; | 47 run_test_succeeded_ = false; |
| 47 content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame(); | 48 content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame(); |
| 48 frame->ExecuteJavaScript(js_text, | 49 frame->ExecuteJavaScriptForTests( |
| 49 base::Bind(&WebUITestHandler::JavaScriptComplete, | 50 js_text, base::Bind(&WebUITestHandler::JavaScriptComplete, |
| 50 base::Unretained(this))); | 51 base::Unretained(this))); |
| 51 return WaitForResult(); | 52 return WaitForResult(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void WebUITestHandler::RegisterMessages() { | 55 void WebUITestHandler::RegisterMessages() { |
| 55 web_ui()->RegisterMessageCallback("testResult", | 56 web_ui()->RegisterMessageCallback("testResult", |
| 56 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); | 57 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { | 60 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { |
| 60 // Quit the message loop if |is_waiting_| so waiting process can get result or | 61 // Quit the message loop if |is_waiting_| so waiting process can get result or |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // complete. | 107 // complete. |
| 107 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { | 108 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { |
| 108 content::RunMessageLoop(); | 109 content::RunMessageLoop(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 is_waiting_ = false; | 112 is_waiting_ = false; |
| 112 | 113 |
| 113 // To succeed the test must execute as well as pass the test. | 114 // To succeed the test must execute as well as pass the test. |
| 114 return run_test_succeeded_ && test_succeeded_; | 115 return run_test_succeeded_ && test_succeeded_; |
| 115 } | 116 } |
| OLD | NEW |