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

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

Issue 1231083007: Expose distiller functions to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-content
Patch Set: Move dependencies to correct files Created 5 years, 3 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
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/renderer/dom_automation_controller.h » ('j') | 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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); 156 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
157 *result = reader.ReadToValue(json); 157 *result = reader.ReadToValue(json);
158 if (!*result) { 158 if (!*result) {
159 DLOG(ERROR) << reader.GetErrorMessage(); 159 DLOG(ERROR) << reader.GetErrorMessage();
160 return false; 160 return false;
161 } 161 }
162 162
163 return true; 163 return true;
164 } 164 }
165 165
166 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute.
167 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host,
168 const int world_id,
169 const std::string& original_script,
170 scoped_ptr<base::Value>* result)
171 WARN_UNUSED_RESULT;
172
173 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host,
174 const int world_id,
175 const std::string& original_script,
176 scoped_ptr<base::Value>* result) {
177 std::string script =
178 "window.domAutomationController.setAutomationId(0);" + original_script;
179 DOMOperationObserver dom_op_observer(render_frame_host->GetRenderViewHost());
180 render_frame_host->ExecuteJavaScriptInIsolatedWorld(
181 base::UTF8ToUTF16(script),
182 content::RenderFrameHost::JavaScriptResultCallback(), world_id);
183 std::string json;
184 if (!dom_op_observer.WaitAndGetResponse(&json)) {
185 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver.";
186 return false;
187 }
188
189 // Nothing more to do for callers that ignore the returned JS value.
190 if (!result)
191 return true;
192
193 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
194 *result = reader.ReadToValue(json);
195 if (!*result) {
196 DLOG(ERROR) << reader.GetErrorMessage();
197 return false;
198 }
199
200 return true;
201 }
202
166 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, 203 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type,
167 ui::KeyboardCode key_code, 204 ui::KeyboardCode key_code,
168 int native_key_code, 205 int native_key_code,
169 int modifiers, 206 int modifiers,
170 NativeWebKeyboardEvent* event) { 207 NativeWebKeyboardEvent* event) {
171 event->nativeKeyCode = native_key_code; 208 event->nativeKeyCode = native_key_code;
172 event->windowsKeyCode = key_code; 209 event->windowsKeyCode = key_code;
173 event->setKeyIdentifierFromWindowsKeyCode(); 210 event->setKeyIdentifierFromWindowsKeyCode();
174 event->type = type; 211 event->type = type;
175 event->modifiers = modifiers; 212 event->modifiers = modifiers;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 DCHECK(result); 615 DCHECK(result);
579 scoped_ptr<base::Value> value; 616 scoped_ptr<base::Value> value;
580 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || 617 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) ||
581 !value.get()) { 618 !value.get()) {
582 return false; 619 return false;
583 } 620 }
584 621
585 return value->GetAsBoolean(result); 622 return value->GetAsBoolean(result);
586 } 623 }
587 624
625 bool ExecuteScriptInIsolatedWorldAndExtractBool(
626 const ToRenderFrameHost& adapter,
627 const int world_id,
628 const std::string& script,
629 bool* result) {
630 DCHECK(result);
631 scoped_ptr<base::Value> value;
632 if (!ExecuteScriptInIsolatedWorldHelper(adapter.render_frame_host(), world_id,
633 script, &value) ||
634 !value.get()) {
635 return false;
636 }
637
638 return value->GetAsBoolean(result);
639 }
640
588 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, 641 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter,
589 const std::string& script, 642 const std::string& script,
590 std::string* result) { 643 std::string* result) {
591 DCHECK(result); 644 DCHECK(result);
592 scoped_ptr<base::Value> value; 645 scoped_ptr<base::Value> value;
593 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || 646 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) ||
594 !value.get()) { 647 !value.get()) {
595 return false; 648 return false;
596 } 649 }
597 650
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 void FrameWatcher::WaitFrames(int frames_to_wait) { 1040 void FrameWatcher::WaitFrames(int frames_to_wait) {
988 if (frames_to_wait <= 0) 1041 if (frames_to_wait <= 0)
989 return; 1042 return;
990 base::RunLoop run_loop; 1043 base::RunLoop run_loop;
991 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); 1044 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
992 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); 1045 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait);
993 run_loop.Run(); 1046 run_loop.Run();
994 } 1047 }
995 1048
996 } // namespace content 1049 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/renderer/dom_automation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698