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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | |
203 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, | 166 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, |
204 ui::KeyboardCode key_code, | 167 ui::KeyboardCode key_code, |
205 int native_key_code, | 168 int native_key_code, |
206 int modifiers, | 169 int modifiers, |
207 NativeWebKeyboardEvent* event) { | 170 NativeWebKeyboardEvent* event) { |
208 event->nativeKeyCode = native_key_code; | 171 event->nativeKeyCode = native_key_code; |
209 event->windowsKeyCode = key_code; | 172 event->windowsKeyCode = key_code; |
210 event->setKeyIdentifierFromWindowsKeyCode(); | 173 event->setKeyIdentifierFromWindowsKeyCode(); |
211 event->type = type; | 174 event->type = type; |
212 event->modifiers = modifiers; | 175 event->modifiers = modifiers; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 574 } |
612 | 575 |
613 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, | 576 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, |
614 const std::string& script, bool* result) { | 577 const std::string& script, bool* result) { |
615 DCHECK(result); | 578 DCHECK(result); |
616 scoped_ptr<base::Value> value; | 579 scoped_ptr<base::Value> value; |
617 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 580 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
618 !value.get()) { | 581 !value.get()) { |
619 return false; | 582 return false; |
620 } | 583 } |
621 | |
622 return value->GetAsBoolean(result); | |
623 } | |
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 | 584 |
638 return value->GetAsBoolean(result); | 585 return value->GetAsBoolean(result); |
639 } | 586 } |
640 | 587 |
641 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, | 588 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
642 const std::string& script, | 589 const std::string& script, |
643 std::string* result) { | 590 std::string* result) { |
644 DCHECK(result); | 591 DCHECK(result); |
645 scoped_ptr<base::Value> value; | 592 scoped_ptr<base::Value> value; |
646 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 593 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 void FrameWatcher::WaitFrames(int frames_to_wait) { | 987 void FrameWatcher::WaitFrames(int frames_to_wait) { |
1041 if (frames_to_wait <= 0) | 988 if (frames_to_wait <= 0) |
1042 return; | 989 return; |
1043 base::RunLoop run_loop; | 990 base::RunLoop run_loop; |
1044 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 991 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1045 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); | 992 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); |
1046 run_loop.Run(); | 993 run_loop.Run(); |
1047 } | 994 } |
1048 | 995 |
1049 } // namespace content | 996 } // namespace content |
OLD | NEW |