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

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: Clean up Created 5 years, 4 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 "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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 void RenderFrameDeletedObserver::WaitUntilDeleted() { 1102 void RenderFrameDeletedObserver::WaitUntilDeleted() {
1050 if (deleted_) 1103 if (deleted_)
1051 return; 1104 return;
1052 1105
1053 runner_.reset(new base::RunLoop()); 1106 runner_.reset(new base::RunLoop());
1054 runner_->Run(); 1107 runner_->Run();
1055 runner_.reset(); 1108 runner_.reset();
1056 } 1109 }
1057 1110
1058 } // namespace content 1111 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698