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 <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 35 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
36 #include "content/browser/renderer_host/render_widget_host_impl.h" | 36 #include "content/browser/renderer_host/render_widget_host_impl.h" |
37 #include "content/browser/web_contents/web_contents_impl.h" | 37 #include "content/browser/web_contents/web_contents_impl.h" |
38 #include "content/browser/web_contents/web_contents_view.h" | 38 #include "content/browser/web_contents/web_contents_view.h" |
39 #include "content/common/input/synthetic_web_input_event_builders.h" | 39 #include "content/common/input/synthetic_web_input_event_builders.h" |
40 #include "content/common/input_messages.h" | 40 #include "content/common/input_messages.h" |
41 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
42 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
43 #include "content/public/browser/histogram_fetcher.h" | 43 #include "content/public/browser/histogram_fetcher.h" |
44 #include "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
| 45 #include "content/public/browser/navigation_handle.h" |
| 46 #include "content/public/browser/navigation_throttle.h" |
45 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/notification_types.h" | 48 #include "content/public/browser/notification_types.h" |
47 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
48 #include "content/public/browser/render_process_host.h" | 50 #include "content/public/browser/render_process_host.h" |
49 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
50 #include "content/public/browser/storage_partition.h" | 52 #include "content/public/browser/storage_partition.h" |
51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
52 #include "content/public/test/test_navigation_observer.h" | 54 #include "content/public/test/test_navigation_observer.h" |
53 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
54 #include "content/test/accessibility_browser_test_utils.h" | 56 #include "content/test/accessibility_browser_test_utils.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 GURL redirect_target(redirect_server.Resolve(path)); | 340 GURL redirect_target(redirect_server.Resolve(path)); |
339 DCHECK(redirect_target.is_valid()); | 341 DCHECK(redirect_target.is_valid()); |
340 | 342 |
341 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( | 343 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
342 new net::test_server::BasicHttpResponse); | 344 new net::test_server::BasicHttpResponse); |
343 http_response->set_code(http_status_code); | 345 http_response->set_code(http_status_code); |
344 http_response->AddCustomHeader("Location", redirect_target.spec()); | 346 http_response->AddCustomHeader("Location", redirect_target.spec()); |
345 return std::move(http_response); | 347 return std::move(http_response); |
346 } | 348 } |
347 | 349 |
| 350 // Helper class used by the TestNavigationManager to pause navigations. |
| 351 class TestNavigationManagerThrottle : public NavigationThrottle { |
| 352 public: |
| 353 TestNavigationManagerThrottle(NavigationHandle* handle, |
| 354 base::Closure on_will_start_request_closure) |
| 355 : NavigationThrottle(handle), |
| 356 on_will_start_request_closure_(on_will_start_request_closure) {} |
| 357 ~TestNavigationManagerThrottle() override {} |
| 358 |
| 359 private: |
| 360 // NavigationThrottle implementation. |
| 361 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
| 362 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 363 on_will_start_request_closure_); |
| 364 return NavigationThrottle::DEFER; |
| 365 } |
| 366 |
| 367 base::Closure on_will_start_request_closure_; |
| 368 }; |
| 369 |
348 } // namespace | 370 } // namespace |
349 | 371 |
350 bool NavigateIframeToURL(WebContents* web_contents, | 372 bool NavigateIframeToURL(WebContents* web_contents, |
351 std::string iframe_id, | 373 std::string iframe_id, |
352 const GURL& url) { | 374 const GURL& url) { |
353 std::string script = base::StringPrintf( | 375 std::string script = base::StringPrintf( |
354 "setTimeout(\"" | 376 "setTimeout(\"" |
355 "var iframes = document.getElementById('%s');iframes.src='%s';" | 377 "var iframes = document.getElementById('%s');iframes.src='%s';" |
356 "\",0)", | 378 "\",0)", |
357 iframe_id.c_str(), url.spec().c_str()); | 379 iframe_id.c_str(), url.spec().c_str()); |
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 uint32_t InputMsgWatcher::WaitForAck() { | 1427 uint32_t InputMsgWatcher::WaitForAck() { |
1406 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1428 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1407 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) | 1429 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
1408 return ack_result_; | 1430 return ack_result_; |
1409 base::RunLoop run_loop; | 1431 base::RunLoop run_loop; |
1410 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1432 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1411 run_loop.Run(); | 1433 run_loop.Run(); |
1412 return ack_result_; | 1434 return ack_result_; |
1413 } | 1435 } |
1414 | 1436 |
| 1437 TestNavigationManager::TestNavigationManager(int filtering_frame_tree_node_id, |
| 1438 WebContents* web_contents, |
| 1439 const GURL& url) |
| 1440 : WebContentsObserver(web_contents), |
| 1441 filtering_frame_tree_node_id_(filtering_frame_tree_node_id), |
| 1442 url_(url), |
| 1443 navigation_paused_(false), |
| 1444 handle_(nullptr), |
| 1445 handled_navigation_(false), |
| 1446 weak_factory_(this) {} |
| 1447 |
| 1448 TestNavigationManager::TestNavigationManager(WebContents* web_contents, |
| 1449 const GURL& url) |
| 1450 : TestNavigationManager(FrameTreeNode::kFrameTreeNodeInvalidId, |
| 1451 web_contents, |
| 1452 url) {} |
| 1453 |
| 1454 TestNavigationManager::~TestNavigationManager() { |
| 1455 ResumeNavigation(); |
| 1456 } |
| 1457 |
| 1458 void TestNavigationManager::WaitForWillStartRequest() { |
| 1459 DCHECK(!did_finish_loop_runner_); |
| 1460 if (!handle_ && handled_navigation_) |
| 1461 return; |
| 1462 if (navigation_paused_) |
| 1463 return; |
| 1464 will_start_loop_runner_ = new MessageLoopRunner(); |
| 1465 will_start_loop_runner_->Run(); |
| 1466 will_start_loop_runner_ = nullptr; |
| 1467 } |
| 1468 |
| 1469 void TestNavigationManager::WaitForNavigationFinished() { |
| 1470 DCHECK(!will_start_loop_runner_); |
| 1471 if (!handle_ && handled_navigation_) |
| 1472 return; |
| 1473 // Ensure the navigation is resumed if the manager paused it previously. |
| 1474 if (navigation_paused_) |
| 1475 ResumeNavigation(); |
| 1476 did_finish_loop_runner_ = new MessageLoopRunner(); |
| 1477 did_finish_loop_runner_->Run(); |
| 1478 did_finish_loop_runner_ = nullptr; |
| 1479 } |
| 1480 |
| 1481 void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) { |
| 1482 if (handle_ || handle->GetURL() != url_) |
| 1483 return; |
| 1484 if (handled_navigation_) |
| 1485 return; |
| 1486 |
| 1487 if (filtering_frame_tree_node_id_ != FrameTreeNode::kFrameTreeNodeInvalidId && |
| 1488 handle->GetFrameTreeNodeId() != filtering_frame_tree_node_id_) { |
| 1489 return; |
| 1490 } |
| 1491 |
| 1492 handle_ = handle; |
| 1493 std::unique_ptr<NavigationThrottle> throttle( |
| 1494 new TestNavigationManagerThrottle( |
| 1495 handle_, base::Bind(&TestNavigationManager::OnWillStartRequest, |
| 1496 weak_factory_.GetWeakPtr()))); |
| 1497 handle_->RegisterThrottleForTesting(std::move(throttle)); |
| 1498 } |
| 1499 |
| 1500 void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) { |
| 1501 if (handle != handle_) |
| 1502 return; |
| 1503 handle_ = nullptr; |
| 1504 handled_navigation_ = true; |
| 1505 navigation_paused_ = false; |
| 1506 if (did_finish_loop_runner_) |
| 1507 did_finish_loop_runner_->Quit(); |
| 1508 } |
| 1509 |
| 1510 void TestNavigationManager::OnWillStartRequest() { |
| 1511 navigation_paused_ = true; |
| 1512 if (will_start_loop_runner_) |
| 1513 will_start_loop_runner_->Quit(); |
| 1514 |
| 1515 // If waiting for the navigation to finish, resume the navigation. |
| 1516 if (did_finish_loop_runner_) |
| 1517 ResumeNavigation(); |
| 1518 } |
| 1519 |
| 1520 void TestNavigationManager::ResumeNavigation() { |
| 1521 if (!navigation_paused_ || !handle_) |
| 1522 return; |
| 1523 navigation_paused_ = false; |
| 1524 handle_->Resume(); |
| 1525 } |
| 1526 |
1415 } // namespace content | 1527 } // namespace content |
OLD | NEW |