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

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

Issue 196133032: Add test for filtering of IPC messages when RenderFrameHost is swapped out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix NavigationControllerTest.LoadURL_WithBindings Created 6 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 | Annotate | Revision Log
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/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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/frame_host/cross_site_transferring_request.h"
14 #include "content/browser/frame_host/navigation_controller_impl.h" 15 #include "content/browser/frame_host/navigation_controller_impl.h"
15 #include "content/browser/frame_host/navigation_entry_impl.h" 16 #include "content/browser/frame_host/navigation_entry_impl.h"
16 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
17 #include "content/browser/frame_host/navigator.h" 18 #include "content/browser/frame_host/navigator.h"
18 #include "content/browser/site_instance_impl.h" 19 #include "content/browser/site_instance_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 20 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/common/frame_messages.h" 21 #include "content/common/frame_messages.h"
21 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
22 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 contents()->SetDelegate(NULL); 1055 contents()->SetDelegate(NULL);
1055 } 1056 }
1056 1057
1057 // Ensure that NavigationEntries track which bindings their RenderViewHost had 1058 // Ensure that NavigationEntries track which bindings their RenderViewHost had
1058 // at the time they committed. http://crbug.com/173672. 1059 // at the time they committed. http://crbug.com/173672.
1059 TEST_F(NavigationControllerTest, LoadURL_WithBindings) { 1060 TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
1060 NavigationControllerImpl& controller = controller_impl(); 1061 NavigationControllerImpl& controller = controller_impl();
1061 TestNotificationTracker notifications; 1062 TestNotificationTracker notifications;
1062 RegisterForAllNavNotifications(&notifications, &controller); 1063 RegisterForAllNavNotifications(&notifications, &controller);
1063 1064
1065 std::vector<GURL> url_chain;
1066 url_chain.push_back(GURL());
Charlie Reis 2014/03/25 23:51:35 I think we can just pass an empty vector, since th
1067
1064 const GURL url1("http://foo1"); 1068 const GURL url1("http://foo1");
1065 const GURL url2("http://foo2"); 1069 const GURL url2("http://foo2");
1066 1070
1067 // Navigate to a first, unprivileged URL. 1071 // Navigate to a first, unprivileged URL.
1068 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1072 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1069 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, 1073 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings,
1070 NavigationEntryImpl::FromNavigationEntry( 1074 NavigationEntryImpl::FromNavigationEntry(
1071 controller.GetPendingEntry())->bindings()); 1075 controller.GetPendingEntry())->bindings());
1072 1076
1073 // Commit. 1077 // Commit.
1074 TestRenderViewHost* orig_rvh = static_cast<TestRenderViewHost*>(test_rvh()); 1078 TestRenderViewHost* orig_rvh = static_cast<TestRenderViewHost*>(test_rvh());
1075 orig_rvh->SendNavigate(0, url1); 1079 orig_rvh->SendNavigate(0, url1);
1076 EXPECT_EQ(controller.GetEntryCount(), 1); 1080 EXPECT_EQ(controller.GetEntryCount(), 1);
1077 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1081 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1078 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 1082 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
1079 controller.GetLastCommittedEntry())->bindings()); 1083 controller.GetLastCommittedEntry())->bindings());
1080 1084
1081 // Manually increase the number of active views in the SiteInstance 1085 // Manually increase the number of active views in the SiteInstance
1082 // that orig_rvh belongs to, to prevent it from being destroyed when 1086 // that orig_rvh belongs to, to prevent it from being destroyed when
1083 // it gets swapped out, so that we can reuse orig_rvh when the 1087 // it gets swapped out, so that we can reuse orig_rvh when the
1084 // controller goes back. 1088 // controller goes back.
1085 static_cast<SiteInstanceImpl*>(orig_rvh->GetSiteInstance())-> 1089 static_cast<SiteInstanceImpl*>(orig_rvh->GetSiteInstance())->
1086 increment_active_view_count(); 1090 increment_active_view_count();
1087 1091
1088 // Navigate to a second URL, simulate the beforeunload ack for the cross-site 1092 // Navigate to a second URL, simulate the beforeunload ack for the cross-site
1089 // transition, and set bindings on the pending RenderViewHost to simulate a 1093 // transition, the running of unload handler, and set bindings on the pending
Charlie Reis 2014/03/25 23:51:35 nit: run the unload handler (Each phrase in the l
1090 // privileged url. 1094 // RenderViewHost to simulate a privileged url.
1091 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1095 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1092 orig_rvh->SendBeforeUnloadACK(true); 1096 orig_rvh->SendBeforeUnloadACK(true);
1093 contents()->GetPendingRenderViewHost()->AllowBindings(1); 1097 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(
1094 static_cast<TestRenderViewHost*>( 1098 contents()->GetRenderManagerForTesting()->pending_frame_host(),
1095 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); 1099 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(),
1096 orig_rvh->OnSwappedOut(false); 1100 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false);
1101 TestRenderViewHost* new_rvh =
1102 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost());
1103 new_rvh->AllowBindings(1);
1104 new_rvh->SendNavigate(1, url2);
1097 1105
1098 // The second load should be committed, and bindings should be remembered. 1106 // The second load should be committed, and bindings should be remembered.
1099 EXPECT_EQ(controller.GetEntryCount(), 2); 1107 EXPECT_EQ(controller.GetEntryCount(), 2);
1100 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1108 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1101 EXPECT_TRUE(controller.CanGoBack()); 1109 EXPECT_TRUE(controller.CanGoBack());
1102 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( 1110 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry(
1103 controller.GetLastCommittedEntry())->bindings()); 1111 controller.GetLastCommittedEntry())->bindings());
1104 1112
1105 // Going back, the first entry should still appear unprivileged. 1113 // Going back, the first entry should still appear unprivileged.
1106 controller.GoBack(); 1114 controller.GoBack();
1115 new_rvh->SendBeforeUnloadACK(true);
1116 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(
1117 contents()->GetRenderManagerForTesting()->pending_frame_host(),
1118 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(),
1119 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false);
1107 orig_rvh->SendNavigate(0, url1); 1120 orig_rvh->SendNavigate(0, url1);
1108 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1121 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1109 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 1122 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
1110 controller.GetLastCommittedEntry())->bindings()); 1123 controller.GetLastCommittedEntry())->bindings());
1111 } 1124 }
1112 1125
1113 TEST_F(NavigationControllerTest, Reload) { 1126 TEST_F(NavigationControllerTest, Reload) {
1114 NavigationControllerImpl& controller = controller_impl(); 1127 NavigationControllerImpl& controller = controller_impl();
1115 TestNotificationTracker notifications; 1128 TestNotificationTracker notifications;
1116 RegisterForAllNavNotifications(&notifications, &controller); 1129 RegisterForAllNavNotifications(&notifications, &controller);
(...skipping 2911 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 EXPECT_EQ(1, controller.GetEntryCount()); 4041 EXPECT_EQ(1, controller.GetEntryCount());
4029 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4042 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4030 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4043 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4031 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4044 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4032 EXPECT_FALSE(controller.CanGoBack()); 4045 EXPECT_FALSE(controller.CanGoBack());
4033 EXPECT_FALSE(controller.CanGoForward()); 4046 EXPECT_FALSE(controller.CanGoForward());
4034 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4047 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4035 } 4048 }
4036 4049
4037 } // namespace content 4050 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698