Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/browser/web_contents/web_contents_view.h" | 9 #include "content/browser/web_contents/web_contents_view.h" |
| 10 #include "content/common/frame_messages.h" | |
| 10 #include "content/public/browser/load_notification_details.h" | 11 #include "content/public/browser/load_notification_details.h" |
| 11 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
| 13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" | 17 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/common/content_paths.h" | 19 #include "content/public/common/content_paths.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 20 #include "content/public/test/content_browser_test.h" | 21 #include "content/public/test/content_browser_test.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 23 #include "content/public/test/test_navigation_observer.h" | |
| 22 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 23 #include "content/shell/browser/shell.h" | 25 #include "content/shell/browser/shell.h" |
| 24 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
| 25 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 void ResizeWebContentsView(Shell* shell, const gfx::Size& size, | 31 void ResizeWebContentsView(Shell* shell, const gfx::Size& size, |
| 30 bool set_start_page) { | 32 bool set_start_page) { |
| 31 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents | 33 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 ADD_FAILURE() << "Progress values should be in order: " | 531 ADD_FAILURE() << "Progress values should be in order: " |
| 530 << ::testing::PrintToString(progresses); | 532 << ::testing::PrintToString(progresses); |
| 531 } | 533 } |
| 532 | 534 |
| 533 // ... and the last one should be 1.0, meaning complete. | 535 // ... and the last one should be 1.0, meaning complete. |
| 534 ASSERT_GE(progresses.size(), 1U) | 536 ASSERT_GE(progresses.size(), 1U) |
| 535 << "There should be at least one progress update"; | 537 << "There should be at least one progress update"; |
| 536 EXPECT_EQ(1.0, *progresses.rbegin()); | 538 EXPECT_EQ(1.0, *progresses.rbegin()); |
| 537 } | 539 } |
| 538 | 540 |
| 541 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgressWithFrames) { | |
|
Charlie Reis
2014/12/19 19:47:48
I added this to complement the LoadProgress test a
| |
| 542 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 543 scoped_ptr<LoadProgressDelegateAndObserver> delegate( | |
| 544 new LoadProgressDelegateAndObserver(shell())); | |
| 545 | |
| 546 NavigateToURL(shell(), | |
| 547 embedded_test_server()->GetURL("/frame_tree/top.html")); | |
| 548 | |
| 549 const std::vector<double>& progresses = delegate->progresses; | |
| 550 // All updates should be in order ... | |
| 551 if (std::adjacent_find(progresses.begin(), | |
| 552 progresses.end(), | |
| 553 std::greater<double>()) != progresses.end()) { | |
| 554 ADD_FAILURE() << "Progress values should be in order: " | |
| 555 << ::testing::PrintToString(progresses); | |
| 556 } | |
| 557 | |
| 558 // ... and the last one should be 1.0, meaning complete. | |
| 559 ASSERT_GE(progresses.size(), 1U) | |
| 560 << "There should be at least one progress update"; | |
| 561 EXPECT_EQ(1.0, *progresses.rbegin()); | |
| 562 } | |
| 563 | |
| 564 // Ensure that a new navigation that interrupts a pending one will still fire | |
| 565 // a DidStopLoading. See http://crbug.com/429399. | |
| 566 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 567 LoadProgressAfterInterruptedNav) { | |
| 568 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 569 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 570 | |
| 571 // Start at a real page. | |
| 572 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); | |
| 573 | |
| 574 // Simulate a navigation that has not completed. | |
| 575 scoped_ptr<LoadProgressDelegateAndObserver> delegate( | |
| 576 new LoadProgressDelegateAndObserver(shell())); | |
| 577 RenderFrameHost* main_frame = shell()->web_contents()->GetMainFrame(); | |
| 578 FrameHostMsg_DidStartLoading start_msg(main_frame->GetRoutingID(), true); | |
| 579 static_cast<WebContentsImpl*>(shell()->web_contents())->OnMessageReceived( | |
| 580 main_frame, start_msg); | |
| 581 EXPECT_TRUE(delegate->did_start_loading); | |
| 582 EXPECT_FALSE(delegate->did_stop_loading); | |
| 583 | |
| 584 // Also simulate a DidChangeLoadProgress, but not a DidStopLoading. | |
| 585 FrameHostMsg_DidChangeLoadProgress progress_msg(main_frame->GetRoutingID(), | |
| 586 1.0); | |
| 587 static_cast<WebContentsImpl*>(shell()->web_contents())->OnMessageReceived( | |
| 588 main_frame, progress_msg); | |
| 589 EXPECT_TRUE(delegate->did_start_loading); | |
| 590 EXPECT_FALSE(delegate->did_stop_loading); | |
| 591 | |
| 592 // Now interrupt with a new cross-process navigation. | |
| 593 TestNavigationObserver tab_observer(shell()->web_contents(), 1); | |
| 594 GURL url(embedded_test_server()->GetURL("foo.com", "/title2.html")); | |
| 595 shell()->LoadURL(url); | |
| 596 tab_observer.Wait(); | |
| 597 EXPECT_EQ(url, shell()->web_contents()->GetLastCommittedURL()); | |
| 598 | |
| 599 // We should have gotten to DidStopLoading. | |
| 600 EXPECT_TRUE(delegate->did_stop_loading); | |
| 601 } | |
| 602 | |
| 539 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { | 603 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { |
| 540 FirstVisuallyNonEmptyPaintObserver(Shell* shell) | 604 FirstVisuallyNonEmptyPaintObserver(Shell* shell) |
| 541 : WebContentsObserver(shell->web_contents()), | 605 : WebContentsObserver(shell->web_contents()), |
| 542 did_fist_visually_non_empty_paint_(false) {} | 606 did_fist_visually_non_empty_paint_(false) {} |
| 543 | 607 |
| 544 void DidFirstVisuallyNonEmptyPaint() override { | 608 void DidFirstVisuallyNonEmptyPaint() override { |
| 545 did_fist_visually_non_empty_paint_ = true; | 609 did_fist_visually_non_empty_paint_ = true; |
| 546 on_did_first_visually_non_empty_paint_.Run(); | 610 on_did_first_visually_non_empty_paint_.Run(); |
| 547 } | 611 } |
| 548 | 612 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 572 new FirstVisuallyNonEmptyPaintObserver(shell())); | 636 new FirstVisuallyNonEmptyPaintObserver(shell())); |
| 573 | 637 |
| 574 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); | 638 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 575 | 639 |
| 576 observer->WaitForDidFirstVisuallyNonEmptyPaint(); | 640 observer->WaitForDidFirstVisuallyNonEmptyPaint(); |
| 577 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_); | 641 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_); |
| 578 } | 642 } |
| 579 | 643 |
| 580 } // namespace content | 644 } // namespace content |
| 581 | 645 |
| OLD | NEW |