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

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

Issue 946543003: PlzNavigate: have renderer-initiated navigations be same-process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 17 matching lines...) Expand all
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents_delegate.h" 29 #include "content/public/browser/web_contents_delegate.h"
30 #include "content/public/browser/web_contents_observer.h" 30 #include "content/public/browser/web_contents_observer.h"
31 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
32 #include "content/public/common/page_state.h" 32 #include "content/public/common/page_state.h"
33 #include "content/public/common/page_type.h" 33 #include "content/public/common/page_type.h"
34 #include "content/public/common/url_constants.h" 34 #include "content/public/common/url_constants.h"
35 #include "content/public/test/mock_render_process_host.h" 35 #include "content/public/test/mock_render_process_host.h"
36 #include "content/public/test/test_notification_tracker.h" 36 #include "content/public/test/test_notification_tracker.h"
37 #include "content/public/test/test_utils.h" 37 #include "content/public/test/test_utils.h"
38 #include "content/test/test_navigation_url_loader.h"
38 #include "content/test/test_render_frame_host.h" 39 #include "content/test/test_render_frame_host.h"
39 #include "content/test/test_render_view_host.h" 40 #include "content/test/test_render_view_host.h"
40 #include "content/test/test_web_contents.h" 41 #include "content/test/test_web_contents.h"
41 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
42 #include "skia/ext/platform_canvas.h" 43 #include "skia/ext/platform_canvas.h"
43 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
44 45
45 using base::Time; 46 using base::Time;
46 47
47 namespace { 48 namespace {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return navigation_request->common_params().url; 239 return navigation_request->common_params().url;
239 } 240 }
240 const IPC::Message* message = 241 const IPC::Message* message =
241 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 242 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
242 CHECK(message); 243 CHECK(message);
243 Tuple<FrameMsg_Navigate_Params> nav_params; 244 Tuple<FrameMsg_Navigate_Params> nav_params;
244 FrameMsg_Navigate::Read(message, &nav_params); 245 FrameMsg_Navigate::Read(message, &nav_params);
245 return get<0>(nav_params).common_params.url; 246 return get<0>(nav_params).common_params.url;
246 } 247 }
247 248
249 void SimulateServerRedirectIfPlzNavigate(TestRenderFrameHost* test_rfh,
clamy 2015/02/23 10:52:34 Please rename that method SimulateServerRedirect a
carlosk 2015/03/04 19:42:40 Change was moved to another CL.
250 const GURL& redirect_url) {
251 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
252 switches::kEnableBrowserSideNavigation)) {
253 return;
254 }
255
256 NavigatorImpl* navigator_impl =
257 static_cast<NavigatorImpl*>(test_rfh->frame_tree_node()->navigator());
258 NavigationRequest* request =
259 navigator_impl->GetNavigationRequestForNodeForTesting(
260 test_rfh->frame_tree_node());
261 CHECK(request);
262
263 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
264 test_rfh->SendBeforeUnloadACK(true);
265
clamy 2015/02/23 10:52:34 CHECK that the request status is STARTED here (the
carlosk 2015/03/04 19:42:40 Change was moved to another CL.
266 TestNavigationURLLoader* loader =
267 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
268 CHECK(loader);
269 loader->SimulateServerRedirect(redirect_url);
270 }
271
248 protected: 272 protected:
249 GURL navigated_url_; 273 GURL navigated_url_;
250 size_t navigation_entry_committed_counter_; 274 size_t navigation_entry_committed_counter_;
251 }; 275 };
252 276
253 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, 277 void RegisterForAllNavNotifications(TestNotificationTracker* tracker,
254 NavigationController* controller) { 278 NavigationController* controller) {
255 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, 279 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED,
256 Source<NavigationController>(controller)); 280 Source<NavigationController>(controller));
257 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, 281 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 NavigationControllerImpl& controller = controller_impl(); 337 NavigationControllerImpl& controller = controller_impl();
314 TestNotificationTracker notifications; 338 TestNotificationTracker notifications;
315 RegisterForAllNavNotifications(&notifications, &controller); 339 RegisterForAllNavNotifications(&notifications, &controller);
316 340
317 const int kNumUrls = 5; 341 const int kNumUrls = 5;
318 std::vector<GURL> urls(kNumUrls); 342 std::vector<GURL> urls(kNumUrls);
319 for (int i = 0; i < kNumUrls; ++i) { 343 for (int i = 0; i < kNumUrls; ++i) {
320 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); 344 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i));
321 } 345 }
322 346
347 main_test_rfh()->RendererRequestIfPlzNavigate(urls[0], true);
carlosk 2015/02/20 19:16:51 For each SendNavigate call the intent might be dif
323 main_test_rfh()->PrepareForCommit(urls[0]); 348 main_test_rfh()->PrepareForCommit(urls[0]);
324 main_test_rfh()->SendNavigate(0, urls[0]); 349 main_test_rfh()->SendNavigate(0, urls[0]);
325 EXPECT_EQ(1U, navigation_entry_committed_counter_); 350 EXPECT_EQ(1U, navigation_entry_committed_counter_);
326 navigation_entry_committed_counter_ = 0; 351 navigation_entry_committed_counter_ = 0;
327 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); 352 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL());
328 EXPECT_FALSE(controller.CanGoBack()); 353 EXPECT_FALSE(controller.CanGoBack());
329 EXPECT_FALSE(controller.CanGoForward()); 354 EXPECT_FALSE(controller.CanGoForward());
330 EXPECT_FALSE(controller.CanGoToOffset(1)); 355 EXPECT_FALSE(controller.CanGoToOffset(1));
331 356
332 for (int i = 1; i <= 4; ++i) { 357 for (int i = 1; i <= 4; ++i) {
358 main_test_rfh()->RendererRequestIfPlzNavigate(urls[i], true);
333 main_test_rfh()->PrepareForCommit(urls[i]); 359 main_test_rfh()->PrepareForCommit(urls[i]);
334 main_test_rfh()->SendNavigate(i, urls[i]); 360 main_test_rfh()->SendNavigate(i, urls[i]);
335 EXPECT_EQ(1U, navigation_entry_committed_counter_); 361 EXPECT_EQ(1U, navigation_entry_committed_counter_);
336 navigation_entry_committed_counter_ = 0; 362 navigation_entry_committed_counter_ = 0;
337 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); 363 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL());
338 EXPECT_TRUE(controller.CanGoToOffset(-i)); 364 EXPECT_TRUE(controller.CanGoToOffset(-i));
339 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); 365 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1)));
340 EXPECT_FALSE(controller.CanGoToOffset(1)); 366 EXPECT_FALSE(controller.CanGoToOffset(1));
341 } 367 }
342 368
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 863
838 // Now make a pending back/forward navigation. The zeroth entry should be 864 // Now make a pending back/forward navigation. The zeroth entry should be
839 // pending. 865 // pending.
840 controller.GoBack(); 866 controller.GoBack();
841 EXPECT_EQ(0U, notifications.size()); 867 EXPECT_EQ(0U, notifications.size());
842 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 868 EXPECT_EQ(0, controller.GetPendingEntryIndex());
843 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 869 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
844 870
845 // Before that commits, do a new navigation. 871 // Before that commits, do a new navigation.
846 const GURL kNewURL("http://foo/see"); 872 const GURL kNewURL("http://foo/see");
873 main_test_rfh()->RendererRequestIfPlzNavigate(kNewURL, true);
847 main_test_rfh()->PrepareForCommit(kNewURL); 874 main_test_rfh()->PrepareForCommit(kNewURL);
848 main_test_rfh()->SendNavigate(3, kNewURL); 875 main_test_rfh()->SendNavigate(3, kNewURL);
849 876
850 // There should no longer be any pending entry, and the third navigation we 877 // There should no longer be any pending entry, and the third navigation we
851 // just made should be committed. 878 // just made should be committed.
852 EXPECT_EQ(1U, navigation_entry_committed_counter_); 879 EXPECT_EQ(1U, navigation_entry_committed_counter_);
853 navigation_entry_committed_counter_ = 0; 880 navigation_entry_committed_counter_ = 0;
854 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 881 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
855 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 882 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
856 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 883 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 controller.GoBack(); 917 controller.GoBack();
891 foo_rfh->SendBeforeUnloadACK(true); 918 foo_rfh->SendBeforeUnloadACK(true);
892 EXPECT_EQ(0U, notifications.size()); 919 EXPECT_EQ(0U, notifications.size());
893 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 920 EXPECT_EQ(0, controller.GetPendingEntryIndex());
894 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 921 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
895 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( 922 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry(
896 controller.GetPendingEntry())->bindings()); 923 controller.GetPendingEntry())->bindings());
897 924
898 // Before that commits, do a new navigation. 925 // Before that commits, do a new navigation.
899 const GURL kNewURL("http://foo/bee"); 926 const GURL kNewURL("http://foo/bee");
927 foo_rfh->RendererRequestIfPlzNavigate(kNewURL, true);
900 foo_rfh->PrepareForCommit(kNewURL); 928 foo_rfh->PrepareForCommit(kNewURL);
901 foo_rfh->SendNavigate(3, kNewURL); 929 foo_rfh->SendNavigate(3, kNewURL);
902 930
903 // There should no longer be any pending entry, and the third navigation we 931 // There should no longer be any pending entry, and the third navigation we
904 // just made should be committed. 932 // just made should be committed.
905 EXPECT_EQ(1U, navigation_entry_committed_counter_); 933 EXPECT_EQ(1U, navigation_entry_committed_counter_);
906 navigation_entry_committed_counter_ = 0; 934 navigation_entry_committed_counter_ = 0;
907 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 935 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
908 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 936 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
909 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 937 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
(...skipping 28 matching lines...) Expand all
938 966
939 // Now make a pending new navigation. 967 // Now make a pending new navigation.
940 const GURL kNewURL("http://foo/see"); 968 const GURL kNewURL("http://foo/see");
941 controller.LoadURL( 969 controller.LoadURL(
942 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 970 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
943 EXPECT_EQ(0U, notifications.size()); 971 EXPECT_EQ(0U, notifications.size());
944 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 972 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
945 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 973 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
946 974
947 // Before that commits, a back navigation from the renderer commits. 975 // Before that commits, a back navigation from the renderer commits.
976 main_test_rfh()->RendererRequestIfPlzNavigate(kExistingURL1, true);
948 main_test_rfh()->PrepareForCommit(kExistingURL1); 977 main_test_rfh()->PrepareForCommit(kExistingURL1);
949 main_test_rfh()->SendNavigate(0, kExistingURL1); 978 main_test_rfh()->SendNavigate(0, kExistingURL1);
950 979
951 // There should no longer be any pending entry, and the back navigation we 980 // There should no longer be any pending entry, and the back navigation we
952 // just made should be committed. 981 // just made should be committed.
953 EXPECT_EQ(1U, navigation_entry_committed_counter_); 982 EXPECT_EQ(1U, navigation_entry_committed_counter_);
954 navigation_entry_committed_counter_ = 0; 983 navigation_entry_committed_counter_ = 0;
955 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 984 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
956 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 985 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
957 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); 986 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL());
(...skipping 20 matching lines...) Expand all
978 controller.LoadURL( 1007 controller.LoadURL(
979 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1008 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
980 EXPECT_EQ(0U, notifications.size()); 1009 EXPECT_EQ(0U, notifications.size());
981 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1010 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
982 EXPECT_TRUE(controller.GetPendingEntry()); 1011 EXPECT_TRUE(controller.GetPendingEntry());
983 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 1012 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
984 EXPECT_EQ(1, delegate->navigation_state_change_count()); 1013 EXPECT_EQ(1, delegate->navigation_state_change_count());
985 1014
986 // Before that commits, a document.write and location.reload can cause the 1015 // Before that commits, a document.write and location.reload can cause the
987 // renderer to send a FrameNavigate with page_id -1. 1016 // renderer to send a FrameNavigate with page_id -1.
1017 main_test_rfh()->RendererRequestIfPlzNavigate(kExistingURL, true);
carlosk 2015/02/20 19:16:51 This one I am really unsure about. From test comme
clamy 2015/02/23 10:52:34 The way blink determines if a request has a user g
carlosk 2015/03/04 19:42:40 Ack. Also with the current cancellation policy a n
988 main_test_rfh()->PrepareForCommit(kExistingURL); 1018 main_test_rfh()->PrepareForCommit(kExistingURL);
989 main_test_rfh()->SendNavigate(-1, kExistingURL); 1019 main_test_rfh()->SendNavigate(-1, kExistingURL);
990 1020
991 // This should clear the pending entry and notify of a navigation state 1021 // This should clear the pending entry and notify of a navigation state
992 // change, so that we do not keep displaying kNewURL. 1022 // change, so that we do not keep displaying kNewURL.
993 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1023 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
994 EXPECT_FALSE(controller.GetPendingEntry()); 1024 EXPECT_FALSE(controller.GetPendingEntry());
995 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 1025 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
996 EXPECT_EQ(2, delegate->navigation_state_change_count()); 1026 EXPECT_EQ(2, delegate->navigation_state_change_count());
997 1027
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 controller.LoadURL( 1272 controller.LoadURL(
1243 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1273 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1244 main_test_rfh()->PrepareForCommit(url1); 1274 main_test_rfh()->PrepareForCommit(url1);
1245 main_test_rfh()->SendNavigate(0, url1); 1275 main_test_rfh()->SendNavigate(0, url1);
1246 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1276 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1247 navigation_entry_committed_counter_ = 0; 1277 navigation_entry_committed_counter_ = 0;
1248 1278
1249 controller.Reload(true); 1279 controller.Reload(true);
1250 EXPECT_EQ(0U, notifications.size()); 1280 EXPECT_EQ(0U, notifications.size());
1251 1281
1282 SimulateServerRedirectIfPlzNavigate(main_test_rfh(), url2);
carlosk 2015/02/20 19:16:51 I guess that "a reload navigation produces a new p
clamy 2015/02/23 10:52:34 Acknowledged.
1252 main_test_rfh()->PrepareForCommit(url2); 1283 main_test_rfh()->PrepareForCommit(url2);
1253 main_test_rfh()->SendNavigate(1, url2); 1284 main_test_rfh()->SendNavigate(1, url2);
1254 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1285 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1255 navigation_entry_committed_counter_ = 0; 1286 navigation_entry_committed_counter_ = 0;
1256 1287
1257 // Now the reload is committed. 1288 // Now the reload is committed.
1258 EXPECT_EQ(controller.GetEntryCount(), 2); 1289 EXPECT_EQ(controller.GetEntryCount(), 2);
1259 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1290 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1260 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1291 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1261 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1292 EXPECT_TRUE(controller.GetLastCommittedEntry());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 TestNotificationTracker notifications; 1333 TestNotificationTracker notifications;
1303 RegisterForAllNavNotifications(&notifications, &controller); 1334 RegisterForAllNavNotifications(&notifications, &controller);
1304 1335
1305 const GURL original_url("http://foo1"); 1336 const GURL original_url("http://foo1");
1306 const GURL final_url("http://foo2"); 1337 const GURL final_url("http://foo2");
1307 1338
1308 // Load up the original URL, but get redirected. 1339 // Load up the original URL, but get redirected.
1309 controller.LoadURL( 1340 controller.LoadURL(
1310 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1341 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1311 EXPECT_EQ(0U, notifications.size()); 1342 EXPECT_EQ(0U, notifications.size());
1343 SimulateServerRedirectIfPlzNavigate(main_test_rfh(), final_url);
1312 main_test_rfh()->PrepareForCommit(final_url); 1344 main_test_rfh()->PrepareForCommit(final_url);
1313 main_test_rfh()->SendNavigateWithOriginalRequestURL( 1345 main_test_rfh()->SendNavigateWithOriginalRequestURL(
1314 0, final_url, original_url); 1346 0, final_url, original_url);
1315 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1347 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1316 navigation_entry_committed_counter_ = 0; 1348 navigation_entry_committed_counter_ = 0;
1317 1349
1318 // The NavigationEntry should save both the original URL and the final 1350 // The NavigationEntry should save both the original URL and the final
1319 // redirected URL. 1351 // redirected URL.
1320 EXPECT_EQ( 1352 EXPECT_EQ(
1321 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); 1353 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL());
(...skipping 13 matching lines...) Expand all
1335 EXPECT_TRUE(controller.GetPendingEntry()); 1367 EXPECT_TRUE(controller.GetPendingEntry());
1336 EXPECT_FALSE(controller.CanGoBack()); 1368 EXPECT_FALSE(controller.CanGoBack());
1337 EXPECT_FALSE(controller.CanGoForward()); 1369 EXPECT_FALSE(controller.CanGoForward());
1338 1370
1339 // Make sure the title has been cleared (will be redrawn just after reload). 1371 // Make sure the title has been cleared (will be redrawn just after reload).
1340 // Avoids a stale cached title when the new page being reloaded has no title. 1372 // Avoids a stale cached title when the new page being reloaded has no title.
1341 // See http://crbug.com/96041. 1373 // See http://crbug.com/96041.
1342 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); 1374 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty());
1343 1375
1344 // Send that the navigation has proceeded; say it got redirected again. 1376 // Send that the navigation has proceeded; say it got redirected again.
1377 SimulateServerRedirectIfPlzNavigate(main_test_rfh(), final_url);
1345 main_test_rfh()->PrepareForCommit(final_url); 1378 main_test_rfh()->PrepareForCommit(final_url);
1346 main_test_rfh()->SendNavigate(0, final_url); 1379 main_test_rfh()->SendNavigate(0, final_url);
1347 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1380 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1348 navigation_entry_committed_counter_ = 0; 1381 navigation_entry_committed_counter_ = 0;
1349 1382
1350 // Now the reload is committed. 1383 // Now the reload is committed.
1351 EXPECT_EQ(controller.GetEntryCount(), 1); 1384 EXPECT_EQ(controller.GetEntryCount(), 1);
1352 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1385 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1353 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1386 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1354 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1387 EXPECT_TRUE(controller.GetLastCommittedEntry());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 1562
1530 // We should now have a pending navigation to go back. 1563 // We should now have a pending navigation to go back.
1531 EXPECT_EQ(controller.GetEntryCount(), 2); 1564 EXPECT_EQ(controller.GetEntryCount(), 2);
1532 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1565 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1533 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1566 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1534 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1567 EXPECT_TRUE(controller.GetLastCommittedEntry());
1535 EXPECT_TRUE(controller.GetPendingEntry()); 1568 EXPECT_TRUE(controller.GetPendingEntry());
1536 EXPECT_FALSE(controller.CanGoBack()); 1569 EXPECT_FALSE(controller.CanGoBack());
1537 EXPECT_TRUE(controller.CanGoForward()); 1570 EXPECT_TRUE(controller.CanGoForward());
1538 1571
1572 SimulateServerRedirectIfPlzNavigate(main_test_rfh(), url3);
carlosk 2015/02/20 19:16:51 Same as previous comment for "a reload navigation
clamy 2015/02/23 10:52:34 Acknowledged.
1539 main_test_rfh()->PrepareForCommit(url3); 1573 main_test_rfh()->PrepareForCommit(url3);
1540 main_test_rfh()->SendNavigate(2, url3); 1574 main_test_rfh()->SendNavigate(2, url3);
1541 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1575 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1542 navigation_entry_committed_counter_ = 0; 1576 navigation_entry_committed_counter_ = 0;
1543 1577
1544 // The back navigation resulted in a completely new navigation. 1578 // The back navigation resulted in a completely new navigation.
1545 // TODO(darin): perhaps this behavior will be confusing to users? 1579 // TODO(darin): perhaps this behavior will be confusing to users?
1546 EXPECT_EQ(controller.GetEntryCount(), 3); 1580 EXPECT_EQ(controller.GetEntryCount(), 3);
1547 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); 1581 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2);
1548 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1582 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1621
1588 // Receives a back message when there is a different renavigation already 1622 // Receives a back message when there is a different renavigation already
1589 // pending. 1623 // pending.
1590 TEST_F(NavigationControllerTest, Back_OtherBackPending) { 1624 TEST_F(NavigationControllerTest, Back_OtherBackPending) {
1591 NavigationControllerImpl& controller = controller_impl(); 1625 NavigationControllerImpl& controller = controller_impl();
1592 const GURL kUrl1("http://foo/1"); 1626 const GURL kUrl1("http://foo/1");
1593 const GURL kUrl2("http://foo/2"); 1627 const GURL kUrl2("http://foo/2");
1594 const GURL kUrl3("http://foo/3"); 1628 const GURL kUrl3("http://foo/3");
1595 1629
1596 // First navigate three places so we have some back history. 1630 // First navigate three places so we have some back history.
1631 main_test_rfh()->RendererRequestIfPlzNavigate(kUrl1, true);
1597 main_test_rfh()->PrepareForCommit(kUrl1); 1632 main_test_rfh()->PrepareForCommit(kUrl1);
1598 main_test_rfh()->SendNavigate(0, kUrl1); 1633 main_test_rfh()->SendNavigate(0, kUrl1);
1634 main_test_rfh()->RendererRequestIfPlzNavigate(kUrl2, true);
1599 main_test_rfh()->PrepareForCommit(kUrl2); 1635 main_test_rfh()->PrepareForCommit(kUrl2);
1600 main_test_rfh()->SendNavigate(1, kUrl2); 1636 main_test_rfh()->SendNavigate(1, kUrl2);
1637 main_test_rfh()->RendererRequestIfPlzNavigate(kUrl3, true);
1601 main_test_rfh()->PrepareForCommit(kUrl3); 1638 main_test_rfh()->PrepareForCommit(kUrl3);
1602 main_test_rfh()->SendNavigate(2, kUrl3); 1639 main_test_rfh()->SendNavigate(2, kUrl3);
1603 1640
1604 // With nothing pending, say we get a navigation to the second entry. 1641 // With nothing pending, say we get a navigation to the second entry.
1642 main_test_rfh()->RendererRequestIfPlzNavigate(kUrl2, true);
1605 main_test_rfh()->PrepareForCommit(kUrl2); 1643 main_test_rfh()->PrepareForCommit(kUrl2);
1606 main_test_rfh()->SendNavigate(1, kUrl2); 1644 main_test_rfh()->SendNavigate(1, kUrl2);
1607 1645
1608 // We know all the entries have the same site instance, so we can just grab 1646 // We know all the entries have the same site instance, so we can just grab
1609 // a random one for looking up other entries. 1647 // a random one for looking up other entries.
1610 SiteInstance* site_instance = 1648 SiteInstance* site_instance =
1611 NavigationEntryImpl::FromNavigationEntry( 1649 NavigationEntryImpl::FromNavigationEntry(
1612 controller.GetLastCommittedEntry())->site_instance(); 1650 controller.GetLastCommittedEntry())->site_instance();
1613 1651
1614 // That second URL should be the last committed and it should have gotten the 1652 // That second URL should be the last committed and it should have gotten the
1615 // new title. 1653 // new title.
1616 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); 1654 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL());
1617 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1655 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1618 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1656 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1619 1657
1620 // Now go forward to the last item again and say it was committed. 1658 // Now go forward to the last item again and say it was committed.
1621 controller.GoForward(); 1659 controller.GoForward();
1622 main_test_rfh()->PrepareForCommit(kUrl3); 1660 main_test_rfh()->PrepareForCommit(kUrl3);
1623 main_test_rfh()->SendNavigate(2, kUrl3); 1661 main_test_rfh()->SendNavigate(2, kUrl3);
1624 1662
1625 // Now start going back one to the second page. It will be pending. 1663 // Now start going back one to the second page. It will be pending.
1626 controller.GoBack(); 1664 controller.GoBack();
1627 EXPECT_EQ(1, controller.GetPendingEntryIndex()); 1665 EXPECT_EQ(1, controller.GetPendingEntryIndex());
1628 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 1666 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
1629 1667
1630 // Not synthesize a totally new back event to the first page. This will not 1668 // Now synthesize a totally new back event to the first page. This will not
1631 // match the pending one. 1669 // match the pending one.
1670 main_test_rfh()->RendererRequestIfPlzNavigate(kUrl1, true);
1632 main_test_rfh()->PrepareForCommit(kUrl1); 1671 main_test_rfh()->PrepareForCommit(kUrl1);
1633 main_test_rfh()->SendNavigate(0, kUrl1); 1672 main_test_rfh()->SendNavigate(0, kUrl1);
1634 1673
1635 // The committed navigation should clear the pending entry. 1674 // The committed navigation should clear the pending entry.
1636 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1675 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1637 1676
1638 // But the navigated entry should be the last committed. 1677 // But the navigated entry should be the last committed.
1639 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1678 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1640 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); 1679 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL());
1641 } 1680 }
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
2617 NavigationControllerImpl& controller = controller_impl(); 2656 NavigationControllerImpl& controller = controller_impl();
2618 // First navigate somewhere normal. 2657 // First navigate somewhere normal.
2619 const GURL url1("http://foo"); 2658 const GURL url1("http://foo");
2620 controller.LoadURL( 2659 controller.LoadURL(
2621 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2660 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2622 main_test_rfh()->PrepareForCommit(url1); 2661 main_test_rfh()->PrepareForCommit(url1);
2623 main_test_rfh()->SendNavigate(0, url1); 2662 main_test_rfh()->SendNavigate(0, url1);
2624 2663
2625 // Now navigate somewhere with an interstitial. 2664 // Now navigate somewhere with an interstitial.
2626 const GURL url2("http://bar"); 2665 const GURL url2("http://bar");
2627 controller.LoadURL( 2666 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
2628 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2667 std::string());
carlosk 2015/02/20 19:16:51 The previous URL value here seemed to not be what
clamy 2015/02/23 10:52:34 Acknowledged.
2629 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2668 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2630 set_page_type(PAGE_TYPE_INTERSTITIAL); 2669 set_page_type(PAGE_TYPE_INTERSTITIAL);
2631 2670
2632 // At this point the interstitial will be displayed and the load will still 2671 // At this point the interstitial will be displayed and the load will still
2633 // be pending. If the user continues, the load will commit. 2672 // be pending. If the user continues, the load will commit.
2634 main_test_rfh()->PrepareForCommit(url2); 2673 main_test_rfh()->PrepareForCommit(url2);
2635 main_test_rfh()->SendNavigate(1, url2); 2674 main_test_rfh()->SendNavigate(1, url2);
2636 2675
2637 // The page should be a normal page again. 2676 // The page should be a normal page again.
2638 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 2677 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 2839
2801 // We should have navigated, transient entry should be gone. 2840 // We should have navigated, transient entry should be gone.
2802 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2841 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2803 EXPECT_EQ(controller.GetEntryCount(), 3); 2842 EXPECT_EQ(controller.GetEntryCount(), 3);
2804 2843
2805 // Add a transient again, then navigate with no pending entry this time. 2844 // Add a transient again, then navigate with no pending entry this time.
2806 transient_entry = new NavigationEntryImpl; 2845 transient_entry = new NavigationEntryImpl;
2807 transient_entry->SetURL(transient_url); 2846 transient_entry->SetURL(transient_url);
2808 controller.SetTransientEntry(transient_entry); 2847 controller.SetTransientEntry(transient_entry);
2809 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2848 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2849 main_test_rfh()->RendererRequestIfPlzNavigate(url3, true);
carlosk 2015/02/20 19:16:51 Again not really sure about these ones in this tes
clamy 2015/02/23 10:52:34 Acknowledged.
2810 main_test_rfh()->PrepareForCommit(url3); 2850 main_test_rfh()->PrepareForCommit(url3);
2811 main_test_rfh()->SendNavigate(3, url3); 2851 main_test_rfh()->SendNavigate(3, url3);
2812 // Transient entry should be gone. 2852 // Transient entry should be gone.
2813 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2853 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2814 EXPECT_EQ(controller.GetEntryCount(), 4); 2854 EXPECT_EQ(controller.GetEntryCount(), 4);
2815 2855
2816 // Initiate a navigation, add a transient then commit navigation. 2856 // Initiate a navigation, add a transient then commit navigation.
2817 controller.LoadURL( 2857 controller.LoadURL(
2818 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2858 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2819 transient_entry = new NavigationEntryImpl; 2859 transient_entry = new NavigationEntryImpl;
2820 transient_entry->SetURL(transient_url); 2860 transient_entry->SetURL(transient_url);
2821 controller.SetTransientEntry(transient_entry); 2861 controller.SetTransientEntry(transient_entry);
2822 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2862 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2823 main_test_rfh()->PrepareForCommit(url4); 2863 main_test_rfh()->PrepareForCommit(url4);
2824 main_test_rfh()->SendNavigate(4, url4); 2864 main_test_rfh()->SendNavigate(4, url4);
2825 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 2865 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2826 EXPECT_EQ(controller.GetEntryCount(), 5); 2866 EXPECT_EQ(controller.GetEntryCount(), 5);
2827 2867
2828 // Add a transient and go back. This should simply remove the transient. 2868 // Add a transient and go back. This should simply remove the transient.
2829 transient_entry = new NavigationEntryImpl; 2869 transient_entry = new NavigationEntryImpl;
2830 transient_entry->SetURL(transient_url); 2870 transient_entry->SetURL(transient_url);
2831 controller.SetTransientEntry(transient_entry); 2871 controller.SetTransientEntry(transient_entry);
2832 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2872 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2833 EXPECT_TRUE(controller.CanGoBack()); 2873 EXPECT_TRUE(controller.CanGoBack());
2834 EXPECT_FALSE(controller.CanGoForward()); 2874 EXPECT_FALSE(controller.CanGoForward());
2835 controller.GoBack(); 2875 controller.GoBack();
2836 // Transient entry should be gone. 2876 // Transient entry should be gone.
2837 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 2877 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2838 EXPECT_EQ(controller.GetEntryCount(), 5); 2878 EXPECT_EQ(controller.GetEntryCount(), 5);
2879
2880 main_test_rfh()->RendererRequestIfPlzNavigate(url3, false);
2839 main_test_rfh()->PrepareForCommit(url3); 2881 main_test_rfh()->PrepareForCommit(url3);
2840 main_test_rfh()->SendNavigate(3, url3); 2882 main_test_rfh()->SendNavigate(3, url3);
2841 2883
2842 // Add a transient and go to an entry before the current one. 2884 // Add a transient and go to an entry before the current one.
2843 transient_entry = new NavigationEntryImpl; 2885 transient_entry = new NavigationEntryImpl;
2844 transient_entry->SetURL(transient_url); 2886 transient_entry->SetURL(transient_url);
2845 controller.SetTransientEntry(transient_entry); 2887 controller.SetTransientEntry(transient_entry);
2846 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2888 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2847 controller.GoToIndex(1); 2889 controller.GoToIndex(1);
2848 // The navigation should have been initiated, transient entry should be gone. 2890 // The navigation should have been initiated, transient entry should be gone.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2924 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2883 main_test_rfh()->PrepareForCommit(url3); 2925 main_test_rfh()->PrepareForCommit(url3);
2884 main_test_rfh()->SendNavigate(3, url3); 2926 main_test_rfh()->SendNavigate(3, url3);
2885 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2927 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2886 2928
2887 // Add a transient and do an in-page navigation, replacing the current entry. 2929 // Add a transient and do an in-page navigation, replacing the current entry.
2888 transient_entry = new NavigationEntryImpl; 2930 transient_entry = new NavigationEntryImpl;
2889 transient_entry->SetURL(transient_url); 2931 transient_entry->SetURL(transient_url);
2890 controller.SetTransientEntry(transient_entry); 2932 controller.SetTransientEntry(transient_entry);
2891 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2933 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2934
2935 main_test_rfh()->RendererRequestIfPlzNavigate(url3_ref, false);
2892 main_test_rfh()->PrepareForCommit(url3_ref); 2936 main_test_rfh()->PrepareForCommit(url3_ref);
2893 main_test_rfh()->SendNavigate(3, url3_ref); 2937 main_test_rfh()->SendNavigate(3, url3_ref);
2894 // Transient entry should be gone. 2938 // Transient entry should be gone.
2895 EXPECT_FALSE(controller.GetTransientEntry()); 2939 EXPECT_FALSE(controller.GetTransientEntry());
2896 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); 2940 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL());
2897 2941
2898 // Ensure the URLs are correct. 2942 // Ensure the URLs are correct.
2899 EXPECT_EQ(controller.GetEntryCount(), 5); 2943 EXPECT_EQ(controller.GetEntryCount(), 5);
2900 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2944 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2901 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); 2945 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1);
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
4589 { 4633 {
4590 LoadCommittedDetails details; 4634 LoadCommittedDetails details;
4591 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4635 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4592 EXPECT_EQ(PAGE_TYPE_ERROR, 4636 EXPECT_EQ(PAGE_TYPE_ERROR,
4593 controller_impl().GetLastCommittedEntry()->GetPageType()); 4637 controller_impl().GetLastCommittedEntry()->GetPageType());
4594 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4638 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4595 } 4639 }
4596 } 4640 }
4597 4641
4598 } // namespace content 4642 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_delegate.h » ('j') | content/browser/frame_host/navigator_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698