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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 2688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2699 main_test_rfh()->PrepareForCommit(); | 2699 main_test_rfh()->PrepareForCommit(); |
2700 main_test_rfh()->SendNavigateWithParams(&back_params); | 2700 main_test_rfh()->SendNavigateWithParams(&back_params); |
2701 controller.GoForward(); | 2701 controller.GoForward(); |
2702 main_test_rfh()->PrepareForCommit(); | 2702 main_test_rfh()->PrepareForCommit(); |
2703 main_test_rfh()->SendNavigateWithParams(&forward_params); | 2703 main_test_rfh()->SendNavigateWithParams(&forward_params); |
2704 EXPECT_EQ(forward_params.url, | 2704 EXPECT_EQ(forward_params.url, |
2705 controller.GetVisibleEntry()->GetURL()); | 2705 controller.GetVisibleEntry()->GetURL()); |
2706 | 2706 |
2707 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 2707 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
2708 const GURL url3("http://bar"); | 2708 const GURL url3("http://bar"); |
2709 params.page_id = 2; | 2709 FrameHostMsg_DidCommitProvisionalLoad_Params bar_params; |
2710 params.nav_entry_id = 0; | 2710 bar_params.page_id = 2; |
2711 params.did_create_new_entry = true; | 2711 bar_params.nav_entry_id = 0; |
2712 params.url = url3; | 2712 bar_params.did_create_new_entry = true; |
| 2713 bar_params.url = url3; |
| 2714 bar_params.transition = ui::PAGE_TRANSITION_LINK; |
| 2715 bar_params.should_update_history = false; |
| 2716 bar_params.gesture = NavigationGestureUser; |
| 2717 bar_params.method = "GET"; |
| 2718 bar_params.page_state = PageState::CreateFromURL(url3); |
| 2719 bar_params.was_within_same_page = false; |
2713 navigation_entry_committed_counter_ = 0; | 2720 navigation_entry_committed_counter_ = 0; |
2714 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); | 2721 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); |
2715 main_test_rfh()->PrepareForCommit(); | 2722 main_test_rfh()->PrepareForCommit(); |
2716 main_test_rfh()->SendNavigateWithParams(¶ms); | 2723 main_test_rfh()->SendNavigateWithParams(&bar_params); |
2717 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2724 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2718 navigation_entry_committed_counter_ = 0; | 2725 navigation_entry_committed_counter_ = 0; |
2719 EXPECT_FALSE(observer.details().is_in_page); | 2726 EXPECT_FALSE(observer.details().is_in_page); |
2720 EXPECT_EQ(3, controller.GetEntryCount()); | 2727 EXPECT_EQ(3, controller.GetEntryCount()); |
2721 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2728 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2722 } | 2729 } |
2723 | 2730 |
2724 TEST_F(NavigationControllerTest, InPage_Replace) { | 2731 TEST_F(NavigationControllerTest, InPage_Replace) { |
2725 NavigationControllerImpl& controller = controller_impl(); | 2732 NavigationControllerImpl& controller = controller_impl(); |
2726 TestNotificationTracker notifications; | 2733 TestNotificationTracker notifications; |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3753 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3760 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3754 EXPECT_FALSE(controller.IsInitialNavigation()); | 3761 EXPECT_FALSE(controller.IsInitialNavigation()); |
3755 EXPECT_TRUE(controller.GetVisibleEntry()); | 3762 EXPECT_TRUE(controller.GetVisibleEntry()); |
3756 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3763 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3757 | 3764 |
3758 notifications.Reset(); | 3765 notifications.Reset(); |
3759 } | 3766 } |
3760 | 3767 |
3761 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3768 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3762 // regression for bug 1126349. | 3769 // regression for bug 1126349. |
3763 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3770 TEST_F(NavigationControllerTest, IsInPageNavigationFromAboutBlank) { |
3764 NavigationControllerImpl& controller = controller_impl(); | 3771 NavigationControllerImpl& controller = controller_impl(); |
3765 const GURL url("http://www.google.com/home.html"); | 3772 const GURL google_url("http://www.google.com/home.html"); |
| 3773 const url::Origin google_origin(google_url); |
| 3774 |
| 3775 const GURL foo_url("http://www.foo.com"); |
| 3776 const url::Origin foo_origin(foo_url); |
3766 | 3777 |
3767 // If the renderer claims it performed an in-page navigation from | 3778 // If the renderer claims it performed an in-page navigation from |
3768 // about:blank, trust the renderer. | 3779 // about:blank, trust the renderer. |
3769 // This can happen when an iframe is created and populated via | 3780 // This can happen when an iframe is created and populated via |
3770 // document.write(), then tries to perform a fragment navigation. | 3781 // document.write(), then tries to perform a fragment navigation. |
3771 // TODO(japhet): We should only trust the renderer if the about:blank | 3782 // TODO(japhet): We should only trust the renderer if the about:blank |
3772 // was the first document in the given frame, but we don't have enough | 3783 // was the first document in the given frame, but we don't have enough |
3773 // information to identify that case currently. | 3784 // information to identify that case currently. |
3774 // TODO(creis): Update this to verify that the origin of the about:blank page | 3785 // TODO(creis): Update this to verify that the origin of the about:blank page |
3775 // matches if the URL doesn't look same-origin. | 3786 // matches if the URL doesn't look same-origin. |
| 3787 |
| 3788 // Navigate to about:blank, with an empty/unique origin. |
3776 const GURL blank_url(url::kAboutBlankURL); | 3789 const GURL blank_url(url::kAboutBlankURL); |
3777 const url::Origin blank_origin; | |
3778 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); | 3790 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); |
3779 EXPECT_TRUE(controller.IsURLInPageNavigation(url, url::Origin(url), true, | 3791 |
| 3792 // A web URL cannot be in-page if the url::origin doesn't match. |
| 3793 MockRenderProcessHost* process = main_test_rfh()->GetProcess(); |
| 3794 int expected_bad_messages = 0; |
| 3795 EXPECT_EQ(expected_bad_messages, process->bad_msg_count()); |
| 3796 EXPECT_FALSE(controller.IsURLInPageNavigation( |
| 3797 google_url, google_origin, true, main_test_rfh())); |
| 3798 EXPECT_EQ(++expected_bad_messages, process->bad_msg_count()); |
| 3799 |
| 3800 // A web URL can in-page with about:blank if the url::Origin matches. |
| 3801 main_test_rfh()->frame_tree_node()->SetCurrentOrigin(google_origin, false); |
| 3802 EXPECT_TRUE(controller.IsURLInPageNavigation(google_url, google_origin, true, |
3780 main_test_rfh())); | 3803 main_test_rfh())); |
| 3804 EXPECT_EQ(expected_bad_messages, process->bad_msg_count()); |
| 3805 |
| 3806 // A different web URL cannot be in-page with about:blank. |
| 3807 EXPECT_FALSE(controller.IsURLInPageNavigation( |
| 3808 foo_url, foo_origin, true, main_test_rfh())); |
| 3809 EXPECT_EQ(++expected_bad_messages, process->bad_msg_count()); |
| 3810 } |
| 3811 |
| 3812 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
| 3813 NavigationControllerImpl& controller = controller_impl(); |
| 3814 const GURL url("http://www.google.com/home.html"); |
3781 | 3815 |
3782 // Navigate to URL with no refs. | 3816 // Navigate to URL with no refs. |
3783 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); | 3817 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); |
3784 | 3818 |
3785 // Reloading the page is not an in-page navigation. | 3819 // Respect what the renderer says when the origin doesn't change. |
3786 EXPECT_FALSE(controller.IsURLInPageNavigation(url, url::Origin(url), false, | 3820 EXPECT_FALSE(controller.IsURLInPageNavigation(url, url::Origin(url), false, |
3787 main_test_rfh())); | 3821 main_test_rfh())); |
3788 const GURL other_url("http://www.google.com/add.html"); | 3822 const GURL other_url("http://www.google.com/add.html"); |
3789 EXPECT_FALSE(controller.IsURLInPageNavigation( | 3823 EXPECT_FALSE(controller.IsURLInPageNavigation( |
3790 other_url, url::Origin(other_url), false, main_test_rfh())); | 3824 other_url, url::Origin(other_url), false, main_test_rfh())); |
3791 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3825 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3792 EXPECT_TRUE(controller.IsURLInPageNavigation( | 3826 EXPECT_TRUE(controller.IsURLInPageNavigation( |
3793 url_with_ref, url::Origin(url_with_ref), true, main_test_rfh())); | 3827 url_with_ref, url::Origin(url_with_ref), true, main_test_rfh())); |
3794 | 3828 |
3795 // Navigate to URL with refs. | 3829 // Navigate to URL with refs. |
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5335 observer.details().ssl_status.num_unknown_scts); | 5369 observer.details().ssl_status.num_unknown_scts); |
5336 EXPECT_EQ(default_ssl_status.num_invalid_scts, | 5370 EXPECT_EQ(default_ssl_status.num_invalid_scts, |
5337 observer.details().ssl_status.num_invalid_scts); | 5371 observer.details().ssl_status.num_invalid_scts); |
5338 EXPECT_EQ(default_ssl_status.num_valid_scts, | 5372 EXPECT_EQ(default_ssl_status.num_valid_scts, |
5339 observer.details().ssl_status.num_valid_scts); | 5373 observer.details().ssl_status.num_valid_scts); |
5340 | 5374 |
5341 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); | 5375 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); |
5342 } | 5376 } |
5343 | 5377 |
5344 } // namespace content | 5378 } // namespace content |
OLD | NEW |