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 "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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); | 155 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
156 *result = reader.ReadToValue(json); | 156 *result = reader.ReadToValue(json); |
157 if (!*result) { | 157 if (!*result) { |
158 DLOG(ERROR) << reader.GetErrorMessage(); | 158 DLOG(ERROR) << reader.GetErrorMessage(); |
159 return false; | 159 return false; |
160 } | 160 } |
161 | 161 |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
| 165 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
| 166 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
| 167 const int world_id, |
| 168 const std::string& original_script, |
| 169 scoped_ptr<base::Value>* result) |
| 170 WARN_UNUSED_RESULT; |
| 171 |
| 172 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
| 173 const int world_id, |
| 174 const std::string& original_script, |
| 175 scoped_ptr<base::Value>* result) { |
| 176 std::string script = |
| 177 "window.domAutomationController.setAutomationId(0);" + original_script; |
| 178 DOMOperationObserver dom_op_observer(render_frame_host->GetRenderViewHost()); |
| 179 render_frame_host->ExecuteJavaScriptInIsolatedWorld( |
| 180 base::UTF8ToUTF16(script), |
| 181 content::RenderFrameHost::JavaScriptResultCallback(), world_id); |
| 182 std::string json; |
| 183 if (!dom_op_observer.WaitAndGetResponse(&json)) { |
| 184 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; |
| 185 return false; |
| 186 } |
| 187 |
| 188 // Nothing more to do for callers that ignore the returned JS value. |
| 189 if (!result) |
| 190 return true; |
| 191 |
| 192 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
| 193 *result = reader.ReadToValue(json); |
| 194 if (!*result) { |
| 195 DLOG(ERROR) << reader.GetErrorMessage(); |
| 196 return false; |
| 197 } |
| 198 |
| 199 return true; |
| 200 } |
| 201 |
165 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, | 202 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, |
166 ui::KeyboardCode key_code, | 203 ui::KeyboardCode key_code, |
167 int native_key_code, | 204 int native_key_code, |
168 int modifiers, | 205 int modifiers, |
169 NativeWebKeyboardEvent* event) { | 206 NativeWebKeyboardEvent* event) { |
170 event->nativeKeyCode = native_key_code; | 207 event->nativeKeyCode = native_key_code; |
171 event->windowsKeyCode = key_code; | 208 event->windowsKeyCode = key_code; |
172 event->setKeyIdentifierFromWindowsKeyCode(); | 209 event->setKeyIdentifierFromWindowsKeyCode(); |
173 event->type = type; | 210 event->type = type; |
174 event->modifiers = modifiers; | 211 event->modifiers = modifiers; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 DCHECK(result); | 614 DCHECK(result); |
578 scoped_ptr<base::Value> value; | 615 scoped_ptr<base::Value> value; |
579 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 616 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
580 !value.get()) { | 617 !value.get()) { |
581 return false; | 618 return false; |
582 } | 619 } |
583 | 620 |
584 return value->GetAsBoolean(result); | 621 return value->GetAsBoolean(result); |
585 } | 622 } |
586 | 623 |
| 624 bool ExecuteScriptInIsolatedWorldAndExtractBool( |
| 625 const ToRenderFrameHost& adapter, |
| 626 const int world_id, |
| 627 const std::string& script, |
| 628 bool* result) { |
| 629 DCHECK(result); |
| 630 scoped_ptr<base::Value> value; |
| 631 if (!ExecuteScriptInIsolatedWorldHelper(adapter.render_frame_host(), world_id, |
| 632 script, &value) || |
| 633 !value.get()) { |
| 634 return false; |
| 635 } |
| 636 |
| 637 return value->GetAsBoolean(result); |
| 638 } |
| 639 |
587 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, | 640 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
588 const std::string& script, | 641 const std::string& script, |
589 std::string* result) { | 642 std::string* result) { |
590 DCHECK(result); | 643 DCHECK(result); |
591 scoped_ptr<base::Value> value; | 644 scoped_ptr<base::Value> value; |
592 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 645 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
593 !value.get()) { | 646 !value.get()) { |
594 return false; | 647 return false; |
595 } | 648 } |
596 | 649 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 void RenderFrameDeletedObserver::WaitUntilDeleted() { | 1092 void RenderFrameDeletedObserver::WaitUntilDeleted() { |
1040 if (deleted_) | 1093 if (deleted_) |
1041 return; | 1094 return; |
1042 | 1095 |
1043 runner_.reset(new base::RunLoop()); | 1096 runner_.reset(new base::RunLoop()); |
1044 runner_->Run(); | 1097 runner_->Run(); |
1045 runner_.reset(); | 1098 runner_.reset(); |
1046 } | 1099 } |
1047 | 1100 |
1048 } // namespace content | 1101 } // namespace content |
OLD | NEW |