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

Side by Side Diff: chrome/browser/ui/webui/web_ui_test_handler.cc

Issue 1257603003: Revert of Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698