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

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

Issue 12313067: Prevent bindings escalation on an existing NavigationEntry (attempt 3). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 EXPECT_EQ(controller.GetEntryCount(), 1); 293 EXPECT_EQ(controller.GetEntryCount(), 1);
294 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 294 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
295 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 295 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
296 EXPECT_TRUE(controller.GetLastCommittedEntry()); 296 EXPECT_TRUE(controller.GetLastCommittedEntry());
297 EXPECT_FALSE(controller.GetPendingEntry()); 297 EXPECT_FALSE(controller.GetPendingEntry());
298 ASSERT_TRUE(controller.GetActiveEntry()); 298 ASSERT_TRUE(controller.GetActiveEntry());
299 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); 299 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry());
300 EXPECT_FALSE(controller.CanGoBack()); 300 EXPECT_FALSE(controller.CanGoBack());
301 EXPECT_FALSE(controller.CanGoForward()); 301 EXPECT_FALSE(controller.CanGoForward());
302 EXPECT_EQ(contents()->GetMaxPageID(), 0); 302 EXPECT_EQ(contents()->GetMaxPageID(), 0);
303 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
304 controller.GetLastCommittedEntry())->bindings());
303 305
304 // The timestamp should have been set. 306 // The timestamp should have been set.
305 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); 307 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null());
306 308
307 // Load another... 309 // Load another...
308 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 310 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
309 311
310 // The load should now be pending. 312 // The load should now be pending.
311 EXPECT_EQ(controller.GetEntryCount(), 1); 313 EXPECT_EQ(controller.GetEntryCount(), 1);
312 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 314 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 860 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
859 EXPECT_EQ(1, delegate->navigation_state_change_count()); 861 EXPECT_EQ(1, delegate->navigation_state_change_count());
860 862
861 // There should be no visible entry (resulting in about:blank in the 863 // There should be no visible entry (resulting in about:blank in the
862 // omnibox), ensuring no spoof is possible. 864 // omnibox), ensuring no spoof is possible.
863 EXPECT_FALSE(controller.GetVisibleEntry()); 865 EXPECT_FALSE(controller.GetVisibleEntry());
864 866
865 contents()->SetDelegate(NULL); 867 contents()->SetDelegate(NULL);
866 } 868 }
867 869
870 // Ensure that NavigationEntries track which bindings their RenderViewHost had
871 // at the time they committed. http://crbug.com/173672.
872 TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
873 NavigationControllerImpl& controller = controller_impl();
874 TestNotificationTracker notifications;
875 RegisterForAllNavNotifications(&notifications, &controller);
876
877 const GURL url1("http://foo1");
878 const GURL url2("http://foo2");
879
880 // Navigate to a first, unprivileged URL.
881 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
882 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings,
883 NavigationEntryImpl::FromNavigationEntry(
884 controller.GetPendingEntry())->bindings());
885
886 // Commit.
887 TestRenderViewHost* orig_rvh = static_cast<TestRenderViewHost*>(test_rvh());
888 orig_rvh->SendNavigate(0, url1);
889 EXPECT_EQ(controller.GetEntryCount(), 1);
890 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
891 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
892 controller.GetLastCommittedEntry())->bindings());
893
894 // Navigate to a second URL, simulate the beforeunload ack for the cross-site
895 // transition, and set bindings on the pending RenderViewHost to simulate a
896 // privileged url.
897 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
898 orig_rvh->SendShouldCloseACK(true);
899 contents()->GetPendingRenderViewHost()->AllowBindings(1);
900 static_cast<TestRenderViewHost*>(
901 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2);
902
903 // The second load should be committed, and bindings should be remembered.
904 EXPECT_EQ(controller.GetEntryCount(), 2);
905 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
906 EXPECT_TRUE(controller.CanGoBack());
907 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry(
908 controller.GetLastCommittedEntry())->bindings());
909
910 // Going back, the first entry should still appear unprivileged.
911 controller.GoBack();
912 orig_rvh->SendNavigate(0, url1);
913 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
914 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
915 controller.GetLastCommittedEntry())->bindings());
916 }
917
868 TEST_F(NavigationControllerTest, Reload) { 918 TEST_F(NavigationControllerTest, Reload) {
869 NavigationControllerImpl& controller = controller_impl(); 919 NavigationControllerImpl& controller = controller_impl();
870 TestNotificationTracker notifications; 920 TestNotificationTracker notifications;
871 RegisterForAllNavNotifications(&notifications, &controller); 921 RegisterForAllNavNotifications(&notifications, &controller);
872 922
873 const GURL url1("http://foo1"); 923 const GURL url1("http://foo1");
874 924
875 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 925 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
876 EXPECT_EQ(0U, notifications.size()); 926 EXPECT_EQ(0U, notifications.size());
877 test_rvh()->SendNavigate(0, url1); 927 test_rvh()->SendNavigate(0, url1);
(...skipping 2404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 PAGE_TRANSITION_LINK); 3332 PAGE_TRANSITION_LINK);
3283 session_helper_.AssertNavigationEquals(nav, 3333 session_helper_.AssertNavigationEquals(nav,
3284 windows_[0]->tabs[0]->navigations[0]); 3334 windows_[0]->tabs[0]->navigations[0]);
3285 nav.set_url(url2); 3335 nav.set_url(url2);
3286 session_helper_.AssertNavigationEquals(nav, 3336 session_helper_.AssertNavigationEquals(nav,
3287 windows_[0]->tabs[0]->navigations[1]); 3337 windows_[0]->tabs[0]->navigations[1]);
3288 } 3338 }
3289 */ 3339 */
3290 3340
3291 } // namespace content 3341 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.cc ('k') | content/browser/web_contents/navigation_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698