Chromium Code Reviews| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/browser/web_contents/web_contents_screenshot_manager.h" | 27 #include "content/browser/web_contents/web_contents_screenshot_manager.h" |
| 28 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 29 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
| 31 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_view_host_observer.h" | 33 #include "content/public/browser/render_view_host_observer.h" |
| 34 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
| 35 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 36 #include "content/public/common/page_state.h" | 36 #include "content/public/common/page_state.h" |
| 37 #include "content/public/common/url_constants.h" | |
| 37 #include "content/public/test/mock_render_process_host.h" | 38 #include "content/public/test/mock_render_process_host.h" |
| 38 #include "content/public/test/test_notification_tracker.h" | 39 #include "content/public/test/test_notification_tracker.h" |
| 39 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
| 40 #include "content/test/test_web_contents.h" | 41 #include "content/test/test_web_contents.h" |
| 41 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
| 42 #include "skia/ext/platform_canvas.h" | 43 #include "skia/ext/platform_canvas.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 45 |
| 45 using base::Time; | 46 using base::Time; |
| 46 | 47 |
| (...skipping 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 ASSERT_EQ(controller.GetEntryCount(), 1); | 2605 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2605 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2606 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2606 | 2607 |
| 2607 // Load of |transient_url| completes. | 2608 // Load of |transient_url| completes. |
| 2608 test_rvh()->SendNavigate(1, transient_url); | 2609 test_rvh()->SendNavigate(1, transient_url); |
| 2609 ASSERT_EQ(controller.GetEntryCount(), 2); | 2610 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2610 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2611 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2611 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2612 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2612 } | 2613 } |
| 2613 | 2614 |
| 2615 // Ensure that renderer initiated pending entries get replaced, so that we | |
| 2616 // don't show a stale virtual URL when a navigation commits. | |
| 2617 // See http://crbug.com/266922. | |
| 2618 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | |
| 2619 NavigationControllerImpl& controller = controller_impl(); | |
| 2620 | |
| 2621 const GURL url1("nonexistent:12121"); | |
| 2622 const GURL url1_fixed("http://nonexistent:12121/"); | |
| 2623 const GURL url2("http://foo"); | |
| 2624 | |
| 2625 // We create pending entries for renderer-initiated navigations so that we | |
| 2626 // can show them in new tabs when it is safe. | |
| 2627 contents()->DidStartProvisionalLoadForFrame( | |
| 2628 test_rvh(), 1, -1, true, url1); | |
| 2629 | |
| 2630 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing | |
| 2631 // the virtual URL to differ from the URL. | |
| 2632 controller.GetPendingEntry()->SetURL(url1_fixed); | |
| 2633 controller.GetPendingEntry()->SetVirtualURL(url1); | |
| 2634 | |
| 2635 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); | |
| 2636 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); | |
| 2637 EXPECT_TRUE( | |
| 2638 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
| 2639 is_renderer_initiated()); | |
| 2640 | |
| 2641 // If the user clicks another link, we should replace the pending entry. | |
| 2642 contents()->DidStartProvisionalLoadForFrame( | |
| 2643 test_rvh(), 1, -1, true, url2); | |
| 2644 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | |
| 2645 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | |
| 2646 | |
| 2647 // Once it commits, the URL and virtual URL should reflect the actual page. | |
| 2648 test_rvh()->SendNavigate(0, url2); | |
| 2649 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | |
| 2650 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | |
| 2651 | |
| 2652 // We should not replace the pending entry for an error URL. | |
|
Charlie Reis
2013/08/07 21:34:58
Added a test for the error page here.
| |
| 2653 contents()->DidStartProvisionalLoadForFrame( | |
| 2654 test_rvh(), 1, -1, true, url1); | |
| 2655 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | |
| 2656 contents()->DidStartProvisionalLoadForFrame( | |
| 2657 test_rvh(), 1, -1, true, GURL(kUnreachableWebDataURL)); | |
| 2658 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | |
| 2659 } | |
| 2660 | |
| 2614 // Tests that the URLs for renderer-initiated navigations are not displayed to | 2661 // Tests that the URLs for renderer-initiated navigations are not displayed to |
| 2615 // the user until the navigation commits, to prevent URL spoof attacks. | 2662 // the user until the navigation commits, to prevent URL spoof attacks. |
| 2616 // See http://crbug.com/99016. | 2663 // See http://crbug.com/99016. |
| 2617 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2664 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 2618 NavigationControllerImpl& controller = controller_impl(); | 2665 NavigationControllerImpl& controller = controller_impl(); |
| 2619 TestNotificationTracker notifications; | 2666 TestNotificationTracker notifications; |
| 2620 RegisterForAllNavNotifications(¬ifications, &controller); | 2667 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2621 | 2668 |
| 2622 const GURL url0("http://foo/0"); | 2669 const GURL url0("http://foo/0"); |
| 2623 const GURL url1("http://foo/1"); | 2670 const GURL url1("http://foo/1"); |
| (...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3896 PAGE_TRANSITION_LINK); | 3943 PAGE_TRANSITION_LINK); |
| 3897 session_helper_.AssertNavigationEquals(nav, | 3944 session_helper_.AssertNavigationEquals(nav, |
| 3898 windows_[0]->tabs[0]->navigations[0]); | 3945 windows_[0]->tabs[0]->navigations[0]); |
| 3899 nav.set_url(url2); | 3946 nav.set_url(url2); |
| 3900 session_helper_.AssertNavigationEquals(nav, | 3947 session_helper_.AssertNavigationEquals(nav, |
| 3901 windows_[0]->tabs[0]->navigations[1]); | 3948 windows_[0]->tabs[0]->navigations[1]); |
| 3902 } | 3949 } |
| 3903 */ | 3950 */ |
| 3904 | 3951 |
| 3905 } // namespace content | 3952 } // namespace content |
| OLD | NEW |