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()->ExecuteJavaScriptForTests( | 40 web_ui()->GetWebContents()->GetMainFrame()->ExecuteJavaScript(js_text); |
41 js_text); | |
42 } | 41 } |
43 | 42 |
44 bool WebUITestHandler::RunJavaScriptTestWithResult( | 43 bool WebUITestHandler::RunJavaScriptTestWithResult( |
45 const base::string16& js_text) { | 44 const base::string16& js_text) { |
46 test_succeeded_ = false; | 45 test_succeeded_ = false; |
47 run_test_succeeded_ = false; | 46 run_test_succeeded_ = false; |
48 content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame(); | 47 content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame(); |
49 frame->ExecuteJavaScriptForTests( | 48 frame->ExecuteJavaScript(js_text, |
50 js_text, base::Bind(&WebUITestHandler::JavaScriptComplete, | 49 base::Bind(&WebUITestHandler::JavaScriptComplete, |
51 base::Unretained(this))); | 50 base::Unretained(this))); |
52 return WaitForResult(); | 51 return WaitForResult(); |
53 } | 52 } |
54 | 53 |
55 void WebUITestHandler::RegisterMessages() { | 54 void WebUITestHandler::RegisterMessages() { |
56 web_ui()->RegisterMessageCallback("testResult", | 55 web_ui()->RegisterMessageCallback("testResult", |
57 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); | 56 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); |
58 } | 57 } |
59 | 58 |
60 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { | 59 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { |
61 // Quit the message loop if |is_waiting_| so waiting process can get result or | 60 // 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... |
107 // complete. | 106 // complete. |
108 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { | 107 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { |
109 content::RunMessageLoop(); | 108 content::RunMessageLoop(); |
110 } | 109 } |
111 | 110 |
112 is_waiting_ = false; | 111 is_waiting_ = false; |
113 | 112 |
114 // To succeed the test must execute as well as pass the test. | 113 // To succeed the test must execute as well as pass the test. |
115 return run_test_succeeded_ && test_succeeded_; | 114 return run_test_succeeded_ && test_succeeded_; |
116 } | 115 } |
OLD | NEW |