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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 } | 306 } |
307 | 307 |
308 } // namespace | 308 } // namespace |
309 | 309 |
310 bool NavigateIframeToURL(WebContents* web_contents, | 310 bool NavigateIframeToURL(WebContents* web_contents, |
311 std::string iframe_id, | 311 std::string iframe_id, |
312 const GURL& url) { | 312 const GURL& url) { |
313 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe | 313 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
314 // navigations generate extra DidStartLoading and DidStopLoading messages. | 314 // navigations generate extra DidStartLoading and DidStopLoading messages. |
315 // Until we replace swappedout:// with frame proxies, we need to listen for | 315 // Until we replace swappedout:// with frame proxies, we need to listen for |
316 // something else. For now, we trigger NEW_SUBFRAME navigations and listen | 316 // something else. See https://crbug.com/436250. |
Charlie Reis
2015/12/11 22:15:29
I've started reviewing this CL, but I'm wondering
robwu
2015/12/16 09:28:34
Your patch works, so I have reduced the patch to a
| |
317 // for commit. See https://crbug.com/436250. | |
318 std::string script = base::StringPrintf( | 317 std::string script = base::StringPrintf( |
319 "setTimeout(\"" | 318 "var frame = document.getElementById('%s'), timer;" |
320 "var iframes = document.getElementById('%s');iframes.src='%s';" | 319 "frame.onload = frame.onerror = function(event) {" |
321 "\",0)", | 320 // This timer is ugly, but it is a general way to deal with the issue |
321 // mentioned above. Assume that the load really finished when we don't | |
322 // receive any notifications for some arbitrarily chosen time. | |
323 " clearTimeout(timer);" | |
324 " timer = setTimeout(function() {" | |
325 " domAutomationController.send(event.type === 'load');" | |
326 " }, 500);" | |
327 "};" | |
328 "frame.src = '%s';", | |
322 iframe_id.c_str(), url.spec().c_str()); | 329 iframe_id.c_str(), url.spec().c_str()); |
323 WindowedNotificationObserver load_observer( | 330 bool is_loaded = false; |
324 NOTIFICATION_NAV_ENTRY_COMMITTED, | 331 bool result = ExecuteScriptAndExtractBool(web_contents, script, &is_loaded); |
325 Source<NavigationController>(&web_contents->GetController())); | 332 return result && is_loaded; |
326 bool result = ExecuteScript(web_contents, script); | |
327 load_observer.Wait(); | |
328 return result; | |
329 } | 333 } |
330 | 334 |
331 GURL GetFileUrlWithQuery(const base::FilePath& path, | 335 GURL GetFileUrlWithQuery(const base::FilePath& path, |
332 const std::string& query_string) { | 336 const std::string& query_string) { |
333 GURL url = net::FilePathToFileURL(path); | 337 GURL url = net::FilePathToFileURL(path); |
334 if (!query_string.empty()) { | 338 if (!query_string.empty()) { |
335 GURL::Replacements replacements; | 339 GURL::Replacements replacements; |
336 replacements.SetQueryStr(query_string); | 340 replacements.SetQueryStr(query_string); |
337 return url.ReplaceComponents(replacements); | 341 return url.ReplaceComponents(replacements); |
338 } | 342 } |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 void FrameWatcher::WaitFrames(int frames_to_wait) { | 1099 void FrameWatcher::WaitFrames(int frames_to_wait) { |
1096 if (frames_to_wait <= 0) | 1100 if (frames_to_wait <= 0) |
1097 return; | 1101 return; |
1098 base::RunLoop run_loop; | 1102 base::RunLoop run_loop; |
1099 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1103 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1100 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); | 1104 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); |
1101 run_loop.Run(); | 1105 run_loop.Run(); |
1102 } | 1106 } |
1103 | 1107 |
1104 } // namespace content | 1108 } // namespace content |
OLD | NEW |