Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 1738233002: Disallow was_within_same_page = true for a cross-process navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 9 #include <utility>
10 10
(...skipping 3577 matching lines...) Expand 10 before | Expand all | Expand 10 after
3588 // If the renderer claims it performed an in-page navigation from 3588 // If the renderer claims it performed an in-page navigation from
3589 // about:blank, trust the renderer. 3589 // about:blank, trust the renderer.
3590 // This can happen when an iframe is created and populated via 3590 // This can happen when an iframe is created and populated via
3591 // document.write(), then tries to perform a fragment navigation. 3591 // document.write(), then tries to perform a fragment navigation.
3592 // TODO(japhet): We should only trust the renderer if the about:blank 3592 // TODO(japhet): We should only trust the renderer if the about:blank
3593 // was the first document in the given frame, but we don't have enough 3593 // was the first document in the given frame, but we don't have enough
3594 // information to identify that case currently. 3594 // information to identify that case currently.
3595 const GURL blank_url(url::kAboutBlankURL); 3595 const GURL blank_url(url::kAboutBlankURL);
3596 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); 3596 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url);
3597 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, 3597 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true,
3598 main_test_rfh())); 3598 main_test_rfh(), false));
3599 3599
3600 // Navigate to URL with no refs. 3600 // Navigate to URL with no refs.
3601 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); 3601 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url);
3602 3602
3603 // Reloading the page is not an in-page navigation. 3603 // Reloading the page is not an in-page navigation.
3604 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh())); 3604 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh(),
3605 false));
3605 const GURL other_url("http://www.google.com/add.html"); 3606 const GURL other_url("http://www.google.com/add.html");
3606 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3607 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3607 main_test_rfh())); 3608 main_test_rfh(), false));
3608 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); 3609 const GURL url_with_ref("http://www.google.com/home.html#my_ref");
3609 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, 3610 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
3610 main_test_rfh())); 3611 main_test_rfh(), false));
3611 3612
3612 // Navigate to URL with refs. 3613 // Navigate to URL with refs.
3613 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url_with_ref); 3614 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url_with_ref);
3614 3615
3615 // Reloading the page is not an in-page navigation. 3616 // Reloading the page is not an in-page navigation.
3616 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, 3617 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false,
3617 main_test_rfh())); 3618 main_test_rfh(), false));
3618 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, 3619 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false,
3619 main_test_rfh())); 3620 main_test_rfh(), false));
3620 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3621 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3621 main_test_rfh())); 3622 main_test_rfh(), false));
3622 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 3623 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
3623 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, 3624 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true,
3624 main_test_rfh())); 3625 main_test_rfh(), false));
3625 3626
3626 // Going to the same url again will be considered in-page 3627 // Going to the same url again will be considered in-page
3627 // if the renderer says it is even if the navigation type isn't IN_PAGE. 3628 // if the renderer says it is even if the navigation type isn't IN_PAGE.
3628 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, 3629 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
3629 main_test_rfh())); 3630 main_test_rfh(), false));
3630 3631
3631 // Going back to the non ref url will be considered in-page if the navigation 3632 // Going back to the non ref url will be considered in-page if the navigation
3632 // type is IN_PAGE. 3633 // type is IN_PAGE.
3633 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, 3634 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true,
3634 main_test_rfh())); 3635 main_test_rfh(), false));
3635 3636
3636 // If the renderer says this is a same-origin in-page navigation, believe it. 3637 // If the renderer says this is a same-origin in-page navigation, believe it.
3637 // This is the pushState/replaceState case. 3638 // This is the pushState/replaceState case.
3638 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, 3639 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true,
3639 main_test_rfh())); 3640 main_test_rfh(), false));
3640 3641
3641 // Don't believe the renderer if it claims a cross-origin navigation is 3642 // Don't believe the renderer if it claims a cross-origin navigation is
3642 // in-page. 3643 // in-page.
3643 const GURL different_origin_url("http://www.example.com"); 3644 const GURL different_origin_url("http://www.example.com");
3644 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); 3645 MockRenderProcessHost* rph = main_test_rfh()->GetProcess();
3645 EXPECT_EQ(0, rph->bad_msg_count()); 3646 EXPECT_EQ(0, rph->bad_msg_count());
3646 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3647 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3647 main_test_rfh())); 3648 main_test_rfh(), false));
3648 EXPECT_EQ(1, rph->bad_msg_count()); 3649 EXPECT_EQ(1, rph->bad_msg_count());
3649 } 3650 }
3650 3651
3651 // Tests that IsInPageNavigation behaves properly with the 3652 // Tests that IsInPageNavigation behaves properly with the
3652 // allow_universal_access_from_file_urls flag. 3653 // allow_universal_access_from_file_urls flag.
3653 TEST_F(NavigationControllerTest, IsInPageNavigationWithUniversalFileAccess) { 3654 TEST_F(NavigationControllerTest, IsInPageNavigationWithUniversalFileAccess) {
3654 NavigationControllerImpl& controller = controller_impl(); 3655 NavigationControllerImpl& controller = controller_impl();
3655 3656
3656 // Test allow_universal_access_from_file_urls flag. 3657 // Test allow_universal_access_from_file_urls flag.
3657 const GURL different_origin_url("http://www.example.com"); 3658 const GURL different_origin_url("http://www.example.com");
3658 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); 3659 MockRenderProcessHost* rph = main_test_rfh()->GetProcess();
3659 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); 3660 WebPreferences prefs = test_rvh()->GetWebkitPreferences();
3660 prefs.allow_universal_access_from_file_urls = true; 3661 prefs.allow_universal_access_from_file_urls = true;
3661 test_rvh()->UpdateWebkitPreferences(prefs); 3662 test_rvh()->UpdateWebkitPreferences(prefs);
3662 prefs = test_rvh()->GetWebkitPreferences(); 3663 prefs = test_rvh()->GetWebkitPreferences();
3663 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); 3664 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls);
3664 3665
3665 // Allow in page navigation to be cross-origin if existing URL is file scheme. 3666 // Allow in page navigation to be cross-origin if existing URL is file scheme.
3666 const GURL file_url("file:///foo/index.html"); 3667 const GURL file_url("file:///foo/index.html");
3667 const url::Origin file_origin(file_url); 3668 const url::Origin file_origin(file_url);
3668 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, file_url); 3669 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, file_url);
3669 EXPECT_TRUE(file_origin.IsSameOriginWith( 3670 EXPECT_TRUE(file_origin.IsSameOriginWith(
3670 main_test_rfh()->frame_tree_node()->current_origin())); 3671 main_test_rfh()->frame_tree_node()->current_origin()));
3671 EXPECT_EQ(0, rph->bad_msg_count()); 3672 EXPECT_EQ(0, rph->bad_msg_count());
3672 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, 3673 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true,
3673 main_test_rfh())); 3674 main_test_rfh(), false));
3674 EXPECT_EQ(0, rph->bad_msg_count()); 3675 EXPECT_EQ(0, rph->bad_msg_count());
3675 3676
3676 // Doing a replaceState to a cross-origin URL is thus allowed. 3677 // Doing a replaceState to a cross-origin URL is thus allowed.
3677 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3678 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3678 params.page_id = 1; 3679 params.page_id = 1;
3679 params.nav_entry_id = 1; 3680 params.nav_entry_id = 1;
3680 params.did_create_new_entry = false; 3681 params.did_create_new_entry = false;
3681 params.url = different_origin_url; 3682 params.url = different_origin_url;
3682 params.origin = file_origin; 3683 params.origin = file_origin;
3683 params.transition = ui::PAGE_TRANSITION_LINK; 3684 params.transition = ui::PAGE_TRANSITION_LINK;
3684 params.gesture = NavigationGestureUser; 3685 params.gesture = NavigationGestureUser;
3685 params.page_state = PageState::CreateFromURL(different_origin_url); 3686 params.page_state = PageState::CreateFromURL(different_origin_url);
3686 params.was_within_same_page = true; 3687 params.was_within_same_page = true;
3687 params.is_post = false; 3688 params.is_post = false;
3688 params.post_id = -1; 3689 params.post_id = -1;
3689 main_test_rfh()->SendRendererInitiatedNavigationRequest(different_origin_url, 3690 main_test_rfh()->SendRendererInitiatedNavigationRequest(different_origin_url,
3690 false); 3691 false);
3691 main_test_rfh()->PrepareForCommit(); 3692 main_test_rfh()->PrepareForCommit();
3692 contents()->GetMainFrame()->SendNavigateWithParams(&params); 3693 contents()->GetMainFrame()->SendNavigateWithParams(&params);
3693 3694
3694 // At this point, we should still consider the current origin to be file://, 3695 // At this point, we should still consider the current origin to be file://,
3695 // so that a file URL would still be in-page. See https://crbug.com/553418. 3696 // so that a file URL would still be in-page. See https://crbug.com/553418.
3696 EXPECT_TRUE(file_origin.IsSameOriginWith( 3697 EXPECT_TRUE(file_origin.IsSameOriginWith(
3697 main_test_rfh()->frame_tree_node()->current_origin())); 3698 main_test_rfh()->frame_tree_node()->current_origin()));
3698 EXPECT_TRUE( 3699 EXPECT_TRUE(
3699 controller.IsURLInPageNavigation(file_url, true, main_test_rfh())); 3700 controller.IsURLInPageNavigation(file_url, true, main_test_rfh(), false));
3700 EXPECT_EQ(0, rph->bad_msg_count()); 3701 EXPECT_EQ(0, rph->bad_msg_count());
3701 3702
3702 // Don't honor allow_universal_access_from_file_urls if actual URL is 3703 // Don't honor allow_universal_access_from_file_urls if actual URL is
3703 // not file scheme. 3704 // not file scheme.
3704 const GURL url("http://www.google.com/home.html"); 3705 const GURL url("http://www.google.com/home.html");
3705 main_test_rfh()->NavigateAndCommitRendererInitiated(2, true, url); 3706 main_test_rfh()->NavigateAndCommitRendererInitiated(2, true, url);
3706 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3707 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3707 main_test_rfh())); 3708 main_test_rfh(), false));
3708 EXPECT_EQ(1, rph->bad_msg_count()); 3709 EXPECT_EQ(1, rph->bad_msg_count());
3709 } 3710 }
3710 3711
3711 // Some pages can have subframes with the same base URL (minus the reference) as 3712 // Some pages can have subframes with the same base URL (minus the reference) as
3712 // the main page. Even though this is hard, it can happen, and we don't want 3713 // the main page. Even though this is hard, it can happen, and we don't want
3713 // these subframe navigations to affect the toplevel document. They should 3714 // these subframe navigations to affect the toplevel document. They should
3714 // instead be ignored. http://crbug.com/5585 3715 // instead be ignored. http://crbug.com/5585
3715 TEST_F(NavigationControllerTest, SameSubframe) { 3716 TEST_F(NavigationControllerTest, SameSubframe) {
3716 NavigationControllerImpl& controller = controller_impl(); 3717 NavigationControllerImpl& controller = controller_impl();
3717 // Navigate the main frame. 3718 // Navigate the main frame.
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
5123 EXPECT_EQ(default_ssl_status.connection_status, 5124 EXPECT_EQ(default_ssl_status.connection_status,
5124 details.ssl_status.connection_status); 5125 details.ssl_status.connection_status);
5125 EXPECT_EQ(default_ssl_status.content_status, 5126 EXPECT_EQ(default_ssl_status.content_status,
5126 details.ssl_status.content_status); 5127 details.ssl_status.content_status);
5127 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size()); 5128 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size());
5128 5129
5129 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); 5130 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count());
5130 } 5131 }
5131 5132
5132 } // namespace content 5133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698