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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 void DidDetachInterstitialPage() override { detach_callback_.Run(); } | 130 void DidDetachInterstitialPage() override { detach_callback_.Run(); } |
131 | 131 |
132 private: | 132 private: |
133 base::Closure attach_callback_; | 133 base::Closure attach_callback_; |
134 base::Closure detach_callback_; | 134 base::Closure detach_callback_; |
135 | 135 |
136 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); | 136 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
137 }; | 137 }; |
138 | 138 |
139 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. | 139 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
140 bool ExecuteScriptHelper( | 140 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, |
141 RenderFrameHost* render_frame_host, | 141 const std::string& original_script, |
142 const std::string& original_script, | 142 std::unique_ptr<base::Value>* result) |
143 scoped_ptr<base::Value>* result) WARN_UNUSED_RESULT; | 143 WARN_UNUSED_RESULT; |
144 | 144 |
145 // Executes the passed |original_script| in the frame specified by | 145 // Executes the passed |original_script| in the frame specified by |
146 // |render_frame_host|. If |result| is not NULL, stores the value that the | 146 // |render_frame_host|. If |result| is not NULL, stores the value that the |
147 // evaluation of the script in |result|. Returns true on success. | 147 // evaluation of the script in |result|. Returns true on success. |
148 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, | 148 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, |
149 const std::string& original_script, | 149 const std::string& original_script, |
150 scoped_ptr<base::Value>* result) { | 150 std::unique_ptr<base::Value>* result) { |
151 // TODO(jcampan): we should make the domAutomationController not require an | 151 // TODO(jcampan): we should make the domAutomationController not require an |
152 // automation id. | 152 // automation id. |
153 std::string script = | 153 std::string script = |
154 "window.domAutomationController.setAutomationId(0);" + original_script; | 154 "window.domAutomationController.setAutomationId(0);" + original_script; |
155 DOMOperationObserver dom_op_observer(render_frame_host); | 155 DOMOperationObserver dom_op_observer(render_frame_host); |
156 render_frame_host->ExecuteJavaScriptWithUserGestureForTests( | 156 render_frame_host->ExecuteJavaScriptWithUserGestureForTests( |
157 base::UTF8ToUTF16(script)); | 157 base::UTF8ToUTF16(script)); |
158 std::string json; | 158 std::string json; |
159 if (!dom_op_observer.WaitAndGetResponse(&json)) { | 159 if (!dom_op_observer.WaitAndGetResponse(&json)) { |
160 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; | 160 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; |
(...skipping 11 matching lines...) Expand all Loading... |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
175 return true; | 175 return true; |
176 } | 176 } |
177 | 177 |
178 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. | 178 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
179 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, | 179 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
180 const int world_id, | 180 const int world_id, |
181 const std::string& original_script, | 181 const std::string& original_script, |
182 scoped_ptr<base::Value>* result) | 182 std::unique_ptr<base::Value>* result) |
183 WARN_UNUSED_RESULT; | 183 WARN_UNUSED_RESULT; |
184 | 184 |
185 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, | 185 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
186 const int world_id, | 186 const int world_id, |
187 const std::string& original_script, | 187 const std::string& original_script, |
188 scoped_ptr<base::Value>* result) { | 188 std::unique_ptr<base::Value>* result) { |
189 std::string script = | 189 std::string script = |
190 "window.domAutomationController.setAutomationId(0);" + original_script; | 190 "window.domAutomationController.setAutomationId(0);" + original_script; |
191 DOMOperationObserver dom_op_observer(render_frame_host); | 191 DOMOperationObserver dom_op_observer(render_frame_host); |
192 render_frame_host->ExecuteJavaScriptInIsolatedWorld( | 192 render_frame_host->ExecuteJavaScriptInIsolatedWorld( |
193 base::UTF8ToUTF16(script), | 193 base::UTF8ToUTF16(script), |
194 content::RenderFrameHost::JavaScriptResultCallback(), world_id); | 194 content::RenderFrameHost::JavaScriptResultCallback(), world_id); |
195 std::string json; | 195 std::string json; |
196 if (!dom_op_observer.WaitAndGetResponse(&json)) { | 196 if (!dom_op_observer.WaitAndGetResponse(&json)) { |
197 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; | 197 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; |
198 return false; | 198 return false; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 net::URLRequestContextGetter* context_getter, | 278 net::URLRequestContextGetter* context_getter, |
279 base::WaitableEvent* event, | 279 base::WaitableEvent* event, |
280 bool* result) { | 280 bool* result) { |
281 net::CookieStore* cookie_store = | 281 net::CookieStore* cookie_store = |
282 context_getter->GetURLRequestContext()->cookie_store(); | 282 context_getter->GetURLRequestContext()->cookie_store(); |
283 cookie_store->SetCookieWithOptionsAsync( | 283 cookie_store->SetCookieWithOptionsAsync( |
284 url, value, net::CookieOptions(), | 284 url, value, net::CookieOptions(), |
285 base::Bind(&SetCookieCallback, result, event)); | 285 base::Bind(&SetCookieCallback, result, event)); |
286 } | 286 } |
287 | 287 |
288 scoped_ptr<net::test_server::HttpResponse> CrossSiteRedirectResponseHandler( | 288 std::unique_ptr<net::test_server::HttpResponse> |
289 const GURL& server_base_url, | 289 CrossSiteRedirectResponseHandler(const GURL& server_base_url, |
290 const net::test_server::HttpRequest& request) { | 290 const net::test_server::HttpRequest& request) { |
291 std::string prefix("/cross-site/"); | 291 std::string prefix("/cross-site/"); |
292 if (!base::StartsWith(request.relative_url, prefix, | 292 if (!base::StartsWith(request.relative_url, prefix, |
293 base::CompareCase::SENSITIVE)) | 293 base::CompareCase::SENSITIVE)) |
294 return scoped_ptr<net::test_server::HttpResponse>(); | 294 return std::unique_ptr<net::test_server::HttpResponse>(); |
295 | 295 |
296 std::string params = request.relative_url.substr(prefix.length()); | 296 std::string params = request.relative_url.substr(prefix.length()); |
297 | 297 |
298 // A hostname to redirect to must be included in the URL, therefore at least | 298 // A hostname to redirect to must be included in the URL, therefore at least |
299 // one '/' character is expected. | 299 // one '/' character is expected. |
300 size_t slash = params.find('/'); | 300 size_t slash = params.find('/'); |
301 if (slash == std::string::npos) | 301 if (slash == std::string::npos) |
302 return scoped_ptr<net::test_server::HttpResponse>(); | 302 return std::unique_ptr<net::test_server::HttpResponse>(); |
303 | 303 |
304 // Replace the host of the URL with the one passed in the URL. | 304 // Replace the host of the URL with the one passed in the URL. |
305 GURL::Replacements replace_host; | 305 GURL::Replacements replace_host; |
306 replace_host.SetHostStr(base::StringPiece(params).substr(0, slash)); | 306 replace_host.SetHostStr(base::StringPiece(params).substr(0, slash)); |
307 GURL redirect_server = server_base_url.ReplaceComponents(replace_host); | 307 GURL redirect_server = server_base_url.ReplaceComponents(replace_host); |
308 | 308 |
309 // Append the real part of the path to the new URL. | 309 // Append the real part of the path to the new URL. |
310 std::string path = params.substr(slash + 1); | 310 std::string path = params.substr(slash + 1); |
311 GURL redirect_target(redirect_server.Resolve(path)); | 311 GURL redirect_target(redirect_server.Resolve(path)); |
312 DCHECK(redirect_target.is_valid()); | 312 DCHECK(redirect_target.is_valid()); |
313 | 313 |
314 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 314 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
315 new net::test_server::BasicHttpResponse); | 315 new net::test_server::BasicHttpResponse); |
316 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); | 316 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); |
317 http_response->AddCustomHeader("Location", redirect_target.spec()); | 317 http_response->AddCustomHeader("Location", redirect_target.spec()); |
318 return std::move(http_response); | 318 return std::move(http_response); |
319 } | 319 } |
320 | 320 |
321 } // namespace | 321 } // namespace |
322 | 322 |
323 bool NavigateIframeToURL(WebContents* web_contents, | 323 bool NavigateIframeToURL(WebContents* web_contents, |
324 std::string iframe_id, | 324 std::string iframe_id, |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 bool ExecuteScript(const ToRenderFrameHost& adapter, | 656 bool ExecuteScript(const ToRenderFrameHost& adapter, |
657 const std::string& script) { | 657 const std::string& script) { |
658 std::string new_script = | 658 std::string new_script = |
659 script + ";window.domAutomationController.send(0);"; | 659 script + ";window.domAutomationController.send(0);"; |
660 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, NULL); | 660 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, NULL); |
661 } | 661 } |
662 | 662 |
663 bool ExecuteScriptAndExtractInt(const ToRenderFrameHost& adapter, | 663 bool ExecuteScriptAndExtractInt(const ToRenderFrameHost& adapter, |
664 const std::string& script, int* result) { | 664 const std::string& script, int* result) { |
665 DCHECK(result); | 665 DCHECK(result); |
666 scoped_ptr<base::Value> value; | 666 std::unique_ptr<base::Value> value; |
667 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 667 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
668 !value.get()) { | 668 !value.get()) { |
669 return false; | 669 return false; |
670 } | 670 } |
671 | 671 |
672 return value->GetAsInteger(result); | 672 return value->GetAsInteger(result); |
673 } | 673 } |
674 | 674 |
675 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, | 675 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, |
676 const std::string& script, bool* result) { | 676 const std::string& script, bool* result) { |
677 DCHECK(result); | 677 DCHECK(result); |
678 scoped_ptr<base::Value> value; | 678 std::unique_ptr<base::Value> value; |
679 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 679 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
680 !value.get()) { | 680 !value.get()) { |
681 return false; | 681 return false; |
682 } | 682 } |
683 | 683 |
684 return value->GetAsBoolean(result); | 684 return value->GetAsBoolean(result); |
685 } | 685 } |
686 | 686 |
687 bool ExecuteScriptInIsolatedWorldAndExtractBool( | 687 bool ExecuteScriptInIsolatedWorldAndExtractBool( |
688 const ToRenderFrameHost& adapter, | 688 const ToRenderFrameHost& adapter, |
689 const int world_id, | 689 const int world_id, |
690 const std::string& script, | 690 const std::string& script, |
691 bool* result) { | 691 bool* result) { |
692 DCHECK(result); | 692 DCHECK(result); |
693 scoped_ptr<base::Value> value; | 693 std::unique_ptr<base::Value> value; |
694 if (!ExecuteScriptInIsolatedWorldHelper(adapter.render_frame_host(), world_id, | 694 if (!ExecuteScriptInIsolatedWorldHelper(adapter.render_frame_host(), world_id, |
695 script, &value) || | 695 script, &value) || |
696 !value.get()) { | 696 !value.get()) { |
697 return false; | 697 return false; |
698 } | 698 } |
699 | 699 |
700 return value->GetAsBoolean(result); | 700 return value->GetAsBoolean(result); |
701 } | 701 } |
702 | 702 |
703 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, | 703 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
704 const std::string& script, | 704 const std::string& script, |
705 std::string* result) { | 705 std::string* result) { |
706 DCHECK(result); | 706 DCHECK(result); |
707 scoped_ptr<base::Value> value; | 707 std::unique_ptr<base::Value> value; |
708 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 708 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
709 !value.get()) { | 709 !value.get()) { |
710 return false; | 710 return false; |
711 } | 711 } |
712 | 712 |
713 return value->GetAsString(result); | 713 return value->GetAsString(result); |
714 } | 714 } |
715 | 715 |
716 namespace { | 716 namespace { |
717 void AddToSetIfFrameMatchesPredicate( | 717 void AddToSetIfFrameMatchesPredicate( |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 last_metadata_ = metadata; | 1106 last_metadata_ = metadata; |
1107 if (frames_to_wait_ == 0) | 1107 if (frames_to_wait_ == 0) |
1108 quit_.Run(); | 1108 quit_.Run(); |
1109 } | 1109 } |
1110 | 1110 |
1111 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { | 1111 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { |
1112 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { | 1112 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { |
1113 ViewHostMsg_SwapCompositorFrame::Param param; | 1113 ViewHostMsg_SwapCompositorFrame::Param param; |
1114 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1114 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
1115 return false; | 1115 return false; |
1116 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 1116 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
1117 base::get<1>(param).AssignTo(frame.get()); | 1117 base::get<1>(param).AssignTo(frame.get()); |
1118 | 1118 |
1119 BrowserThread::PostTask( | 1119 BrowserThread::PostTask( |
1120 BrowserThread::UI, FROM_HERE, | 1120 BrowserThread::UI, FROM_HERE, |
1121 base::Bind(&FrameWatcher::ReceivedFrameSwap, this, frame->metadata)); | 1121 base::Bind(&FrameWatcher::ReceivedFrameSwap, this, frame->metadata)); |
1122 } | 1122 } |
1123 return false; | 1123 return false; |
1124 } | 1124 } |
1125 | 1125 |
1126 void FrameWatcher::AttachTo(WebContents* web_contents) { | 1126 void FrameWatcher::AttachTo(WebContents* web_contents) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 // static | 1232 // static |
1233 TextInputStateTestExport TextInputStateTestExport::FromWebContents( | 1233 TextInputStateTestExport TextInputStateTestExport::FromWebContents( |
1234 WebContents* web_contents) { | 1234 WebContents* web_contents) { |
1235 const TextInputState* state = | 1235 const TextInputState* state = |
1236 static_cast<WebContentsImpl*>(web_contents)->GetTextInputState(); | 1236 static_cast<WebContentsImpl*>(web_contents)->GetTextInputState(); |
1237 | 1237 |
1238 return TextInputStateTestExport(state->type, state->value); | 1238 return TextInputStateTestExport(state->type, state->value); |
1239 } | 1239 } |
1240 | 1240 |
1241 } // namespace content | 1241 } // namespace content |
OLD | NEW |