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

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 11734018: Revert 174880 due to compilation error in pdf_browsertest.cc (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1374/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "net/cookies/cookie_store.h" 27 #include "net/cookies/cookie_store.h"
28 #include "net/test/python_utils.h" 28 #include "net/test/python_utils.h"
29 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_context_getter.h" 30 #include "net/url_request/url_request_context_getter.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 static const int kDefaultWsPort = 8880; 33 static const int kDefaultWsPort = 8880;
34 34
35 namespace content { 35 namespace content {
36
36 namespace { 37 namespace {
37 38
38 class DOMOperationObserver : public NotificationObserver, 39 class DOMOperationObserver : public NotificationObserver,
39 public WebContentsObserver { 40 public WebContentsObserver {
40 public: 41 public:
41 explicit DOMOperationObserver(RenderViewHost* render_view_host) 42 explicit DOMOperationObserver(RenderViewHost* render_view_host)
42 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), 43 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)),
43 did_respond_(false) { 44 did_respond_(false) {
44 registrar_.Add(this, NOTIFICATION_DOM_OPERATION_RESPONSE, 45 registrar_.Add(this, NOTIFICATION_DOM_OPERATION_RESPONSE,
45 Source<RenderViewHost>(render_view_host)); 46 Source<RenderViewHost>(render_view_host));
(...skipping 25 matching lines...) Expand all
71 NotificationRegistrar registrar_; 72 NotificationRegistrar registrar_;
72 std::string response_; 73 std::string response_;
73 bool did_respond_; 74 bool did_respond_;
74 scoped_refptr<MessageLoopRunner> message_loop_runner_; 75 scoped_refptr<MessageLoopRunner> message_loop_runner_;
75 76
76 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); 77 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
77 }; 78 };
78 79
79 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. 80 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute.
80 bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host, 81 bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host,
81 const std::string& frame_xpath, 82 const std::wstring& frame_xpath,
82 const std::string& original_script, 83 const std::wstring& original_script,
83 scoped_ptr<Value>* result) WARN_UNUSED_RESULT; 84 scoped_ptr<Value>* result) WARN_UNUSED_RESULT;
84 85
85 // Executes the passed |original_script| in the frame pointed to by 86 // Executes the passed |original_script| in the frame pointed to by
86 // |frame_xpath|. If |result| is not NULL, stores the value that the evaluation 87 // |frame_xpath|. If |result| is not NULL, stores the value that the evaluation
87 // of the script in |result|. Returns true on success. 88 // of the script in |result|. Returns true on success.
88 bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host, 89 bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host,
89 const std::string& frame_xpath, 90 const std::wstring& frame_xpath,
90 const std::string& original_script, 91 const std::wstring& original_script,
91 scoped_ptr<Value>* result) { 92 scoped_ptr<Value>* result) {
92 // TODO(jcampan): we should make the domAutomationController not require an 93 // TODO(jcampan): we should make the domAutomationController not require an
93 // automation id. 94 // automation id.
94 std::string script = 95 std::wstring script = L"window.domAutomationController.setAutomationId(0);" +
95 "window.domAutomationController.setAutomationId(0);" + original_script; 96 original_script;
96 DOMOperationObserver dom_op_observer(render_view_host); 97 DOMOperationObserver dom_op_observer(render_view_host);
97 render_view_host->ExecuteJavascriptInWebFrame(UTF8ToUTF16(frame_xpath), 98 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(frame_xpath),
98 UTF8ToUTF16(script)); 99 WideToUTF16Hack(script));
99 std::string json; 100 std::string json;
100 if (!dom_op_observer.WaitAndGetResponse(&json)) { 101 if (!dom_op_observer.WaitAndGetResponse(&json)) {
101 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; 102 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver.";
102 return false; 103 return false;
103 } 104 }
104 105
105 // Nothing more to do for callers that ignore the returned JS value. 106 // Nothing more to do for callers that ignore the returned JS value.
106 if (!result) 107 if (!result)
107 return true; 108 return true;
108 109
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); 274 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
274 275
275 NativeWebKeyboardEvent event_up; 276 NativeWebKeyboardEvent event_up;
276 BuildSimpleWebKeyEvent( 277 BuildSimpleWebKeyEvent(
277 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, 278 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command,
278 &event_up); 279 &event_up);
279 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); 280 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
280 } 281 }
281 282
282 bool ExecuteJavaScript(RenderViewHost* render_view_host, 283 bool ExecuteJavaScript(RenderViewHost* render_view_host,
283 const std::string& frame_xpath, 284 const std::wstring& frame_xpath,
284 const std::string& original_script) { 285 const std::wstring& original_script) {
285 std::string script = 286 std::wstring script =
286 original_script + ";window.domAutomationController.send(0);"; 287 original_script + L";window.domAutomationController.send(0);";
287 return ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, NULL); 288 return ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, NULL);
288 } 289 }
289 290
290 bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host, 291 bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host,
291 const std::string& frame_xpath, 292 const std::wstring& frame_xpath,
292 const std::string& script, 293 const std::wstring& script,
293 int* result) { 294 int* result) {
294 DCHECK(result); 295 DCHECK(result);
295 scoped_ptr<Value> value; 296 scoped_ptr<Value> value;
296 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) || 297 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) ||
297 !value.get()) 298 !value.get())
298 return false; 299 return false;
299 300
300 return value->GetAsInteger(result); 301 return value->GetAsInteger(result);
301 } 302 }
302 303
303 bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host, 304 bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host,
304 const std::string& frame_xpath, 305 const std::wstring& frame_xpath,
305 const std::string& script, 306 const std::wstring& script,
306 bool* result) { 307 bool* result) {
307 DCHECK(result); 308 DCHECK(result);
308 scoped_ptr<Value> value; 309 scoped_ptr<Value> value;
309 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) || 310 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) ||
310 !value.get()) 311 !value.get())
311 return false; 312 return false;
312 313
313 return value->GetAsBoolean(result); 314 return value->GetAsBoolean(result);
314 } 315 }
315 316
316 bool ExecuteJavaScriptAndExtractString(RenderViewHost* render_view_host, 317 bool ExecuteJavaScriptAndExtractString(RenderViewHost* render_view_host,
317 const std::string& frame_xpath, 318 const std::wstring& frame_xpath,
318 const std::string& script, 319 const std::wstring& script,
319 std::string* result) { 320 std::string* result) {
320 DCHECK(result); 321 DCHECK(result);
321 scoped_ptr<Value> value; 322 scoped_ptr<Value> value;
322 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) || 323 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) ||
323 !value.get()) 324 !value.get())
324 return false; 325 return false;
325 326
326 return value->GetAsString(result); 327 return value->GetAsString(result);
327 } 328 }
328 329
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 456 }
456 // The queue should not be empty, unless we were quit because of a timeout. 457 // The queue should not be empty, unless we were quit because of a timeout.
457 if (message_queue_.empty()) 458 if (message_queue_.empty())
458 return false; 459 return false;
459 if (message) 460 if (message)
460 *message = message_queue_.front(); 461 *message = message_queue_.front();
461 return true; 462 return true;
462 } 463 }
463 464
464 } // namespace content 465 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698