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

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

Issue 1457053004: Fix in-page logic for allow_universal_access_from_files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes from review Created 5 years, 1 month 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 3587 matching lines...) Expand 10 before | Expand all | Expand 10 after
3598 // Going back to the non ref url will be considered in-page if the navigation 3598 // Going back to the non ref url will be considered in-page if the navigation
3599 // type is IN_PAGE. 3599 // type is IN_PAGE.
3600 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, 3600 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true,
3601 main_test_rfh())); 3601 main_test_rfh()));
3602 3602
3603 // If the renderer says this is a same-origin in-page navigation, believe it. 3603 // If the renderer says this is a same-origin in-page navigation, believe it.
3604 // This is the pushState/replaceState case. 3604 // This is the pushState/replaceState case.
3605 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, 3605 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true,
3606 main_test_rfh())); 3606 main_test_rfh()));
3607 3607
3608 // Don't believe the renderer if it claims a cross-origin navigation is
3609 // in-page.
3610 const GURL different_origin_url("http://www.example.com");
3611 MockRenderProcessHost* rph = main_test_rfh()->GetProcess();
3612 EXPECT_EQ(0, rph->bad_msg_count());
3613 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3614 main_test_rfh()));
3615 EXPECT_EQ(1, rph->bad_msg_count());
3616 }
3617
3618 // Tests that IsInPageNavigation behaves properly with the
3619 // allow_universal_access_from_file_urls flag.
3620 TEST_F(NavigationControllerTest, IsInPageNavigationWithUniversalFileAccess) {
3621 NavigationControllerImpl& controller = controller_impl();
3622
3608 // Test allow_universal_access_from_file_urls flag. 3623 // Test allow_universal_access_from_file_urls flag.
3609 const GURL different_origin_url("http://www.example.com"); 3624 const GURL different_origin_url("http://www.example.com");
3610 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); 3625 MockRenderProcessHost* rph = main_test_rfh()->GetProcess();
3611 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); 3626 WebPreferences prefs = test_rvh()->GetWebkitPreferences();
3612 prefs.allow_universal_access_from_file_urls = true; 3627 prefs.allow_universal_access_from_file_urls = true;
3613 test_rvh()->UpdateWebkitPreferences(prefs); 3628 test_rvh()->UpdateWebkitPreferences(prefs);
3614 prefs = test_rvh()->GetWebkitPreferences(); 3629 prefs = test_rvh()->GetWebkitPreferences();
3615 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); 3630 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls);
3616 // Allow in page navigation if existing URL is file scheme. 3631
3632 // Allow in page navigation to be cross-origin if existing URL is file scheme.
3617 const GURL file_url("file:///foo/index.html"); 3633 const GURL file_url("file:///foo/index.html");
3618 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, file_url); 3634 const url::Origin file_origin(file_url);
3635 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, file_url);
3636 EXPECT_TRUE(file_origin.IsSameOriginWith(
3637 main_test_rfh()->frame_tree_node()->current_origin()));
3619 EXPECT_EQ(0, rph->bad_msg_count()); 3638 EXPECT_EQ(0, rph->bad_msg_count());
3620 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, 3639 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true,
3621 main_test_rfh())); 3640 main_test_rfh()));
3622 EXPECT_EQ(0, rph->bad_msg_count()); 3641 EXPECT_EQ(0, rph->bad_msg_count());
3623 // Don't honor allow_universal_access_from_file_urls if existing URL is 3642
3643 // Doing a replaceState to a cross-origin URL is thus allowed.
3644 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3645 params.page_id = 1;
3646 params.nav_entry_id = 1;
3647 params.did_create_new_entry = false;
3648 params.url = different_origin_url;
3649 params.origin = file_origin;
3650 params.transition = ui::PAGE_TRANSITION_LINK;
3651 params.gesture = NavigationGestureUser;
3652 params.page_state = PageState::CreateFromURL(different_origin_url);
3653 params.was_within_same_page = true;
3654 params.is_post = false;
3655 params.post_id = -1;
3656 main_test_rfh()->SendRendererInitiatedNavigationRequest(different_origin_url,
3657 false);
3658 main_test_rfh()->PrepareForCommit();
3659 contents()->GetMainFrame()->SendNavigateWithParams(&params);
3660
3661 // At this point, we should still consider the current origin to be file://,
3662 // so that a file URL would still be in-page. See https://crbug.com/553418.
3663 EXPECT_TRUE(file_origin.IsSameOriginWith(
3664 main_test_rfh()->frame_tree_node()->current_origin()));
3665 EXPECT_TRUE(
3666 controller.IsURLInPageNavigation(file_url, true, main_test_rfh()));
3667 EXPECT_EQ(0, rph->bad_msg_count());
3668
3669 // Don't honor allow_universal_access_from_file_urls if actual URL is
3624 // not file scheme. 3670 // not file scheme.
3625 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); 3671 const GURL url("http://www.google.com/home.html");
3672 main_test_rfh()->NavigateAndCommitRendererInitiated(2, true, url);
3626 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3673 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3627 main_test_rfh())); 3674 main_test_rfh()));
3628 EXPECT_EQ(1, rph->bad_msg_count()); 3675 EXPECT_EQ(1, rph->bad_msg_count());
3629
3630 // Remove allow_universal_access_from_file_urls flag.
3631 prefs.allow_universal_access_from_file_urls = false;
3632 test_rvh()->UpdateWebkitPreferences(prefs);
3633 prefs = test_rvh()->GetWebkitPreferences();
3634 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls);
3635
3636 // Don't believe the renderer if it claims a cross-origin navigation is
3637 // in-page.
3638 EXPECT_EQ(1, rph->bad_msg_count());
3639 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3640 main_test_rfh()));
3641 EXPECT_EQ(2, rph->bad_msg_count());
3642 } 3676 }
3643 3677
3644 // Some pages can have subframes with the same base URL (minus the reference) as 3678 // Some pages can have subframes with the same base URL (minus the reference) as
3645 // the main page. Even though this is hard, it can happen, and we don't want 3679 // the main page. Even though this is hard, it can happen, and we don't want
3646 // these subframe navigations to affect the toplevel document. They should 3680 // these subframe navigations to affect the toplevel document. They should
3647 // instead be ignored. http://crbug.com/5585 3681 // instead be ignored. http://crbug.com/5585
3648 TEST_F(NavigationControllerTest, SameSubframe) { 3682 TEST_F(NavigationControllerTest, SameSubframe) {
3649 NavigationControllerImpl& controller = controller_impl(); 3683 NavigationControllerImpl& controller = controller_impl();
3650 // Navigate the main frame. 3684 // Navigate the main frame.
3651 const GURL url("http://www.google.com/"); 3685 const GURL url("http://www.google.com/");
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
5056 EXPECT_EQ(default_ssl_status.connection_status, 5090 EXPECT_EQ(default_ssl_status.connection_status,
5057 details.ssl_status.connection_status); 5091 details.ssl_status.connection_status);
5058 EXPECT_EQ(default_ssl_status.content_status, 5092 EXPECT_EQ(default_ssl_status.content_status,
5059 details.ssl_status.content_status); 5093 details.ssl_status.content_status);
5060 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size()); 5094 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size());
5061 5095
5062 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); 5096 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count());
5063 } 5097 }
5064 5098
5065 } // namespace content 5099 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/test/test_render_frame_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698