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 "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 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 | 1054 |
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(¬ifications, &controller); | 1063 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1064 std::vector<GURL> url_chain; |
1063 | 1065 |
1064 const GURL url1("http://foo1"); | 1066 const GURL url1("http://foo1"); |
1065 const GURL url2("http://foo2"); | 1067 const GURL url2("http://foo2"); |
1066 | 1068 |
1067 // Navigate to a first, unprivileged URL. | 1069 // Navigate to a first, unprivileged URL. |
1068 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1070 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1069 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1071 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
1070 NavigationEntryImpl::FromNavigationEntry( | 1072 NavigationEntryImpl::FromNavigationEntry( |
1071 controller.GetPendingEntry())->bindings()); | 1073 controller.GetPendingEntry())->bindings()); |
1072 | 1074 |
1073 // Commit. | 1075 // Commit. |
1074 TestRenderViewHost* orig_rvh = static_cast<TestRenderViewHost*>(test_rvh()); | 1076 TestRenderViewHost* orig_rvh = static_cast<TestRenderViewHost*>(test_rvh()); |
1075 orig_rvh->SendNavigate(0, url1); | 1077 orig_rvh->SendNavigate(0, url1); |
1076 EXPECT_EQ(controller.GetEntryCount(), 1); | 1078 EXPECT_EQ(controller.GetEntryCount(), 1); |
1077 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1079 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1078 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1080 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
1079 controller.GetLastCommittedEntry())->bindings()); | 1081 controller.GetLastCommittedEntry())->bindings()); |
1080 | 1082 |
1081 // Manually increase the number of active views in the SiteInstance | 1083 // Manually increase the number of active views in the SiteInstance |
1082 // that orig_rvh belongs to, to prevent it from being destroyed when | 1084 // 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 | 1085 // it gets swapped out, so that we can reuse orig_rvh when the |
1084 // controller goes back. | 1086 // controller goes back. |
1085 static_cast<SiteInstanceImpl*>(orig_rvh->GetSiteInstance())-> | 1087 static_cast<SiteInstanceImpl*>(orig_rvh->GetSiteInstance())-> |
1086 increment_active_view_count(); | 1088 increment_active_view_count(); |
1087 | 1089 |
1088 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1090 // 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 | 1091 // transition, run the unload handler, and set bindings on the pending |
1090 // privileged url. | 1092 // RenderViewHost to simulate a privileged url. |
1091 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1093 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1092 orig_rvh->SendBeforeUnloadACK(true); | 1094 orig_rvh->SendBeforeUnloadACK(true); |
1093 contents()->GetPendingRenderViewHost()->AllowBindings(1); | 1095 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( |
1094 static_cast<TestRenderViewHost*>( | 1096 contents()->GetRenderManagerForTesting()->pending_frame_host(), |
1095 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); | 1097 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), |
1096 orig_rvh->OnSwappedOut(false); | 1098 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); |
| 1099 TestRenderViewHost* new_rvh = |
| 1100 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
| 1101 new_rvh->AllowBindings(1); |
| 1102 new_rvh->SendNavigate(1, url2); |
1097 | 1103 |
1098 // The second load should be committed, and bindings should be remembered. | 1104 // The second load should be committed, and bindings should be remembered. |
1099 EXPECT_EQ(controller.GetEntryCount(), 2); | 1105 EXPECT_EQ(controller.GetEntryCount(), 2); |
1100 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1106 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1101 EXPECT_TRUE(controller.CanGoBack()); | 1107 EXPECT_TRUE(controller.CanGoBack()); |
1102 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( | 1108 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( |
1103 controller.GetLastCommittedEntry())->bindings()); | 1109 controller.GetLastCommittedEntry())->bindings()); |
1104 | 1110 |
1105 // Going back, the first entry should still appear unprivileged. | 1111 // Going back, the first entry should still appear unprivileged. |
1106 controller.GoBack(); | 1112 controller.GoBack(); |
| 1113 new_rvh->SendBeforeUnloadACK(true); |
| 1114 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( |
| 1115 contents()->GetRenderManagerForTesting()->pending_frame_host(), |
| 1116 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), |
| 1117 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); |
1107 orig_rvh->SendNavigate(0, url1); | 1118 orig_rvh->SendNavigate(0, url1); |
1108 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1119 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1109 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1120 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
1110 controller.GetLastCommittedEntry())->bindings()); | 1121 controller.GetLastCommittedEntry())->bindings()); |
1111 } | 1122 } |
1112 | 1123 |
1113 TEST_F(NavigationControllerTest, Reload) { | 1124 TEST_F(NavigationControllerTest, Reload) { |
1114 NavigationControllerImpl& controller = controller_impl(); | 1125 NavigationControllerImpl& controller = controller_impl(); |
1115 TestNotificationTracker notifications; | 1126 TestNotificationTracker notifications; |
1116 RegisterForAllNavNotifications(¬ifications, &controller); | 1127 RegisterForAllNavNotifications(¬ifications, &controller); |
(...skipping 2911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4028 EXPECT_EQ(1, controller.GetEntryCount()); | 4039 EXPECT_EQ(1, controller.GetEntryCount()); |
4029 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4040 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4030 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4041 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4031 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4042 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4032 EXPECT_FALSE(controller.CanGoBack()); | 4043 EXPECT_FALSE(controller.CanGoBack()); |
4033 EXPECT_FALSE(controller.CanGoForward()); | 4044 EXPECT_FALSE(controller.CanGoForward()); |
4034 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4045 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
4035 } | 4046 } |
4036 | 4047 |
4037 } // namespace content | 4048 } // namespace content |
OLD | NEW |