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

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

Issue 1048463004: PlzNavigate: track pending commits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved state tracking to RFH Created 5 years, 8 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 NavigationControllerImpl& controller = controller_impl(); 702 NavigationControllerImpl& controller = controller_impl();
703 TestNotificationTracker notifications; 703 TestNotificationTracker notifications;
704 RegisterForAllNavNotifications(&notifications, &controller); 704 RegisterForAllNavNotifications(&notifications, &controller);
705 705
706 const GURL url1("http://foo1"); 706 const GURL url1("http://foo1");
707 const GURL url2("http://foo2"); 707 const GURL url2("http://foo2");
708 708
709 controller.LoadURL( 709 controller.LoadURL(
710 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 710 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
711 EXPECT_EQ(0U, notifications.size()); 711 EXPECT_EQ(0U, notifications.size());
712 main_test_rfh()->PrepareForCommit();
712 main_test_rfh()->SendNavigate(0, url1); 713 main_test_rfh()->SendNavigate(0, url1);
713 EXPECT_EQ(1U, navigation_entry_committed_counter_); 714 EXPECT_EQ(1U, navigation_entry_committed_counter_);
714 navigation_entry_committed_counter_ = 0; 715 navigation_entry_committed_counter_ = 0;
715 716
716 ASSERT_TRUE(controller.GetVisibleEntry()); 717 ASSERT_TRUE(controller.GetVisibleEntry());
717 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); 718 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
718 EXPECT_FALSE(timestamp.is_null()); 719 EXPECT_FALSE(timestamp.is_null());
719 720
720 controller.LoadURL( 721 controller.LoadURL(
721 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 722 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
(...skipping 18 matching lines...) Expand all
740 // navigates from the web page, and here we test that there is no pending entry. 741 // navigates from the web page, and here we test that there is no pending entry.
741 TEST_F(NavigationControllerTest, LoadURL_NoPending) { 742 TEST_F(NavigationControllerTest, LoadURL_NoPending) {
742 NavigationControllerImpl& controller = controller_impl(); 743 NavigationControllerImpl& controller = controller_impl();
743 TestNotificationTracker notifications; 744 TestNotificationTracker notifications;
744 RegisterForAllNavNotifications(&notifications, &controller); 745 RegisterForAllNavNotifications(&notifications, &controller);
745 746
746 // First make an existing committed entry. 747 // First make an existing committed entry.
747 const GURL kExistingURL1("http://eh"); 748 const GURL kExistingURL1("http://eh");
748 controller.LoadURL( 749 controller.LoadURL(
749 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 750 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
751 main_test_rfh()->PrepareForCommit();
750 main_test_rfh()->SendNavigate(0, kExistingURL1); 752 main_test_rfh()->SendNavigate(0, kExistingURL1);
carlosk 2015/04/08 16:35:20 For these cases (here and elsewhere) where a compl
clamy 2015/04/10 14:40:15 Well, I won't do it in this patch which is already
751 EXPECT_EQ(1U, navigation_entry_committed_counter_); 753 EXPECT_EQ(1U, navigation_entry_committed_counter_);
752 navigation_entry_committed_counter_ = 0; 754 navigation_entry_committed_counter_ = 0;
753 755
754 // Do a new navigation without making a pending one. 756 // Do a new navigation without making a pending one.
755 const GURL kNewURL("http://see"); 757 const GURL kNewURL("http://see");
756 main_test_rfh()->SendNavigate(99, kNewURL); 758 main_test_rfh()->NavigateAndCommitRendererInitiated(99, kNewURL);
757 759
758 // There should no longer be any pending entry, and the third navigation we 760 // There should no longer be any pending entry, and the third navigation we
759 // just made should be committed. 761 // just made should be committed.
760 EXPECT_EQ(1U, navigation_entry_committed_counter_); 762 EXPECT_EQ(1U, navigation_entry_committed_counter_);
761 navigation_entry_committed_counter_ = 0; 763 navigation_entry_committed_counter_ = 0;
762 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 764 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
763 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 765 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
764 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 766 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
765 } 767 }
766 768
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 // redirect and abort. See http://crbug.com/83031. 1057 // redirect and abort. See http://crbug.com/83031.
1056 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { 1058 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
1057 NavigationControllerImpl& controller = controller_impl(); 1059 NavigationControllerImpl& controller = controller_impl();
1058 TestNotificationTracker notifications; 1060 TestNotificationTracker notifications;
1059 RegisterForAllNavNotifications(&notifications, &controller); 1061 RegisterForAllNavNotifications(&notifications, &controller);
1060 1062
1061 // First make an existing committed entry. 1063 // First make an existing committed entry.
1062 const GURL kExistingURL("http://foo/eh"); 1064 const GURL kExistingURL("http://foo/eh");
1063 controller.LoadURL(kExistingURL, content::Referrer(), 1065 controller.LoadURL(kExistingURL, content::Referrer(),
1064 ui::PAGE_TRANSITION_TYPED, std::string()); 1066 ui::PAGE_TRANSITION_TYPED, std::string());
1067 main_test_rfh()->PrepareForCommit();
1065 main_test_rfh()->SendNavigate(1, kExistingURL); 1068 main_test_rfh()->SendNavigate(1, kExistingURL);
1066 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1069 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1067 navigation_entry_committed_counter_ = 0; 1070 navigation_entry_committed_counter_ = 0;
1068 1071
1069 // Set a WebContentsDelegate to listen for state changes. 1072 // Set a WebContentsDelegate to listen for state changes.
1070 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 1073 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
1071 EXPECT_FALSE(contents()->GetDelegate()); 1074 EXPECT_FALSE(contents()->GetDelegate());
1072 contents()->SetDelegate(delegate.get()); 1075 contents()->SetDelegate(delegate.get());
1073 1076
1074 // Now make a pending new navigation, initiated by the renderer. 1077 // Now make a pending new navigation, initiated by the renderer.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 1266
1264 // This test ensures that when a guest renderer reloads, the reload goes through 1267 // This test ensures that when a guest renderer reloads, the reload goes through
1265 // without ending up in the "we have a wrong process for the URL" branch in 1268 // without ending up in the "we have a wrong process for the URL" branch in
1266 // NavigationControllerImpl::ReloadInternal. 1269 // NavigationControllerImpl::ReloadInternal.
1267 TEST_F(NavigationControllerTest, ReloadWithGuest) { 1270 TEST_F(NavigationControllerTest, ReloadWithGuest) {
1268 NavigationControllerImpl& controller = controller_impl(); 1271 NavigationControllerImpl& controller = controller_impl();
1269 1272
1270 const GURL url1("http://foo1"); 1273 const GURL url1("http://foo1");
1271 controller.LoadURL( 1274 controller.LoadURL(
1272 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1275 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1276 main_test_rfh()->PrepareForCommit();
1273 main_test_rfh()->SendNavigate(0, url1); 1277 main_test_rfh()->SendNavigate(0, url1);
1274 ASSERT_TRUE(controller.GetVisibleEntry()); 1278 ASSERT_TRUE(controller.GetVisibleEntry());
1275 1279
1276 // Make the entry believe its RenderProcessHost is a guest. 1280 // Make the entry believe its RenderProcessHost is a guest.
1277 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); 1281 NavigationEntryImpl* entry1 = controller.GetVisibleEntry();
1278 reinterpret_cast<MockRenderProcessHost*>( 1282 reinterpret_cast<MockRenderProcessHost*>(
1279 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); 1283 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true);
1280 1284
1281 // And reload. 1285 // And reload.
1282 controller.Reload(true); 1286 controller.Reload(true);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 // Test that certain non-persisted NavigationEntryImpl values get reset after 1361 // Test that certain non-persisted NavigationEntryImpl values get reset after
1358 // commit. 1362 // commit.
1359 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { 1363 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) {
1360 NavigationControllerImpl& controller = controller_impl(); 1364 NavigationControllerImpl& controller = controller_impl();
1361 1365
1362 // The value of "should replace entry" will be tested, but it's an error to 1366 // The value of "should replace entry" will be tested, but it's an error to
1363 // specify it when there are no entries. Create a simple entry to be replaced. 1367 // specify it when there are no entries. Create a simple entry to be replaced.
1364 const GURL url0("http://foo/0"); 1368 const GURL url0("http://foo/0");
1365 controller.LoadURL( 1369 controller.LoadURL(
1366 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1370 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1371 main_test_rfh()->PrepareForCommit();
1367 main_test_rfh()->SendNavigate(0, url0); 1372 main_test_rfh()->SendNavigate(0, url0);
1368 1373
1369 // Set up the pending entry. 1374 // Set up the pending entry.
1370 const GURL url1("http://foo/1"); 1375 const GURL url1("http://foo/1");
1371 controller.LoadURL( 1376 controller.LoadURL(
1372 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1377 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1373 1378
1374 // Set up some sample values. 1379 // Set up some sample values.
1375 const unsigned char* raw_data = 1380 const unsigned char* raw_data =
1376 reinterpret_cast<const unsigned char*>("post\n\n\0data"); 1381 reinterpret_cast<const unsigned char*>("post\n\n\0data");
(...skipping 10 matching lines...) Expand all
1387 pending_entry->set_transferred_global_request_id(transfer_id); 1392 pending_entry->set_transferred_global_request_id(transfer_id);
1388 pending_entry->set_should_replace_entry(true); 1393 pending_entry->set_should_replace_entry(true);
1389 pending_entry->set_should_clear_history_list(true); 1394 pending_entry->set_should_clear_history_list(true);
1390 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); 1395 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData());
1391 EXPECT_TRUE(pending_entry->is_renderer_initiated()); 1396 EXPECT_TRUE(pending_entry->is_renderer_initiated());
1392 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); 1397 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id());
1393 EXPECT_TRUE(pending_entry->should_replace_entry()); 1398 EXPECT_TRUE(pending_entry->should_replace_entry());
1394 EXPECT_TRUE(pending_entry->should_clear_history_list()); 1399 EXPECT_TRUE(pending_entry->should_clear_history_list());
1395 1400
1396 // Fake a commit response. 1401 // Fake a commit response.
1402 main_test_rfh()->PrepareForCommit();
1397 main_test_rfh()->SendNavigate(1, url1); 1403 main_test_rfh()->SendNavigate(1, url1);
1398 1404
1399 // Certain values that are only used for pending entries get reset after 1405 // Certain values that are only used for pending entries get reset after
1400 // commit. 1406 // commit.
1401 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); 1407 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry();
1402 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); 1408 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData());
1403 EXPECT_FALSE(committed_entry->is_renderer_initiated()); 1409 EXPECT_FALSE(committed_entry->is_renderer_initiated());
1404 EXPECT_EQ(GlobalRequestID(-1, -1), 1410 EXPECT_EQ(GlobalRequestID(-1, -1),
1405 committed_entry->transferred_global_request_id()); 1411 committed_entry->transferred_global_request_id());
1406 EXPECT_FALSE(committed_entry->should_replace_entry()); 1412 EXPECT_FALSE(committed_entry->should_replace_entry());
1407 EXPECT_FALSE(committed_entry->should_clear_history_list()); 1413 EXPECT_FALSE(committed_entry->should_clear_history_list());
1408 } 1414 }
1409 1415
1410 // Test that Redirects are preserved after a commit. 1416 // Test that Redirects are preserved after a commit.
1411 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { 1417 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) {
1412 NavigationControllerImpl& controller = controller_impl(); 1418 NavigationControllerImpl& controller = controller_impl();
1413 const GURL url1("http://foo1"); 1419 const GURL url1("http://foo1");
1420 const GURL url2("http://foo2");
1414 controller.LoadURL( 1421 controller.LoadURL(
1415 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1422 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1416 1423
1417 // Set up some redirect values. 1424 // Set up some redirect values.
1418 std::vector<GURL> redirects; 1425 std::vector<GURL> redirects;
1419 redirects.push_back(GURL("http://foo2")); 1426 redirects.push_back(url2);
1420 1427
1421 // Set redirects on the pending entry. 1428 // Set redirects on the pending entry.
1422 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); 1429 NavigationEntryImpl* pending_entry = controller.GetPendingEntry();
1423 pending_entry->SetRedirectChain(redirects); 1430 pending_entry->SetRedirectChain(redirects);
1424 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); 1431 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size());
1425 EXPECT_EQ(GURL("http://foo2"), pending_entry->GetRedirectChain()[0]); 1432 EXPECT_EQ(url2, pending_entry->GetRedirectChain()[0]);
1426 1433
1427 // Normal navigation will preserve redirects in the committed entry. 1434 // Normal navigation will preserve redirects in the committed entry.
1435 main_test_rfh()->PrepareForCommitWithServerRedirect(url2);
1428 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); 1436 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects);
1429 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); 1437 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry();
1430 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); 1438 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size());
1431 EXPECT_EQ(GURL("http://foo2"), committed_entry->GetRedirectChain()[0]); 1439 EXPECT_EQ(url2, committed_entry->GetRedirectChain()[0]);
1432 } 1440 }
1433 1441
1434 // Tests what happens when we navigate back successfully 1442 // Tests what happens when we navigate back successfully
1435 TEST_F(NavigationControllerTest, Back) { 1443 TEST_F(NavigationControllerTest, Back) {
1436 NavigationControllerImpl& controller = controller_impl(); 1444 NavigationControllerImpl& controller = controller_impl();
1437 TestNotificationTracker notifications; 1445 TestNotificationTracker notifications;
1438 RegisterForAllNavNotifications(&notifications, &controller); 1446 RegisterForAllNavNotifications(&notifications, &controller);
1439 1447
1440 const GURL url1("http://foo1"); 1448 const GURL url1("http://foo1");
1441 main_test_rfh()->SendNavigate(0, url1); 1449 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
1442 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1450 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1443 navigation_entry_committed_counter_ = 0; 1451 navigation_entry_committed_counter_ = 0;
1444 1452
1445 const GURL url2("http://foo2"); 1453 const GURL url2("http://foo2");
1446 main_test_rfh()->SendNavigate(1, url2); 1454 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2);
1447 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1455 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1448 navigation_entry_committed_counter_ = 0; 1456 navigation_entry_committed_counter_ = 0;
1449 1457
1450 controller.GoBack(); 1458 controller.GoBack();
1451 EXPECT_EQ(0U, notifications.size()); 1459 EXPECT_EQ(0U, notifications.size());
1452 1460
1453 // We should now have a pending navigation to go back. 1461 // We should now have a pending navigation to go back.
1454 EXPECT_EQ(controller.GetEntryCount(), 2); 1462 EXPECT_EQ(controller.GetEntryCount(), 2);
1455 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1463 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1456 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1464 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1457 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1465 EXPECT_TRUE(controller.GetLastCommittedEntry());
1458 EXPECT_TRUE(controller.GetPendingEntry()); 1466 EXPECT_TRUE(controller.GetPendingEntry());
1459 EXPECT_FALSE(controller.CanGoBack()); 1467 EXPECT_FALSE(controller.CanGoBack());
1460 EXPECT_FALSE(controller.CanGoToOffset(-1)); 1468 EXPECT_FALSE(controller.CanGoToOffset(-1));
1461 EXPECT_TRUE(controller.CanGoForward()); 1469 EXPECT_TRUE(controller.CanGoForward());
1462 EXPECT_TRUE(controller.CanGoToOffset(1)); 1470 EXPECT_TRUE(controller.CanGoToOffset(1));
1463 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. 1471 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps.
1464 1472
1465 // Timestamp for entry 1 should be on or after that of entry 0. 1473 // Timestamp for entry 1 should be on or after that of entry 0.
1466 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); 1474 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null());
1467 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), 1475 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(),
1468 controller.GetEntryAtIndex(0)->GetTimestamp()); 1476 controller.GetEntryAtIndex(0)->GetTimestamp());
1469 1477
1470 main_test_rfh()->SendNavigate(0, url2); 1478 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url2);
1471 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1479 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1472 navigation_entry_committed_counter_ = 0; 1480 navigation_entry_committed_counter_ = 0;
1473 1481
1474 // The back navigation completed successfully. 1482 // The back navigation completed successfully.
1475 EXPECT_EQ(controller.GetEntryCount(), 2); 1483 EXPECT_EQ(controller.GetEntryCount(), 2);
1476 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1484 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1477 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1485 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1478 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1486 EXPECT_TRUE(controller.GetLastCommittedEntry());
1479 EXPECT_FALSE(controller.GetPendingEntry()); 1487 EXPECT_FALSE(controller.GetPendingEntry());
1480 EXPECT_FALSE(controller.CanGoBack()); 1488 EXPECT_FALSE(controller.CanGoBack());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 TEST_F(NavigationControllerTest, Back_NewPending) { 1553 TEST_F(NavigationControllerTest, Back_NewPending) {
1546 NavigationControllerImpl& controller = controller_impl(); 1554 NavigationControllerImpl& controller = controller_impl();
1547 TestNotificationTracker notifications; 1555 TestNotificationTracker notifications;
1548 RegisterForAllNavNotifications(&notifications, &controller); 1556 RegisterForAllNavNotifications(&notifications, &controller);
1549 1557
1550 const GURL kUrl1("http://foo1"); 1558 const GURL kUrl1("http://foo1");
1551 const GURL kUrl2("http://foo2"); 1559 const GURL kUrl2("http://foo2");
1552 const GURL kUrl3("http://foo3"); 1560 const GURL kUrl3("http://foo3");
1553 1561
1554 // First navigate two places so we have some back history. 1562 // First navigate two places so we have some back history.
1555 main_test_rfh()->SendNavigate(0, kUrl1); 1563 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1);
1556 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1564 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1557 navigation_entry_committed_counter_ = 0; 1565 navigation_entry_committed_counter_ = 0;
1558 1566
1559 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); 1567 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED);
1560 main_test_rfh()->SendNavigate(1, kUrl2); 1568 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2);
1561 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1569 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1562 navigation_entry_committed_counter_ = 0; 1570 navigation_entry_committed_counter_ = 0;
1563 1571
1564 // Now start a new pending navigation and go back before it commits. 1572 // Now start a new pending navigation and go back before it commits.
1565 controller.LoadURL( 1573 controller.LoadURL(
1566 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1574 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1567 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1575 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1568 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); 1576 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL());
1569 controller.GoBack(); 1577 controller.GoBack();
1570 1578
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 RegisterForAllNavNotifications(&notifications, &controller); 1774 RegisterForAllNavNotifications(&notifications, &controller);
1767 1775
1768 const GURL url1("http://foo1"); 1776 const GURL url1("http://foo1");
1769 const GURL url2("http://foo2"); // Redirection target 1777 const GURL url2("http://foo2"); // Redirection target
1770 1778
1771 // First request 1779 // First request
1772 controller.LoadURL( 1780 controller.LoadURL(
1773 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1781 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1774 1782
1775 EXPECT_EQ(0U, notifications.size()); 1783 EXPECT_EQ(0U, notifications.size());
1784 main_test_rfh()->PrepareForCommit();
1776 main_test_rfh()->SendNavigate(0, url2); 1785 main_test_rfh()->SendNavigate(0, url2);
1777 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1786 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1778 navigation_entry_committed_counter_ = 0; 1787 navigation_entry_committed_counter_ = 0;
1779 1788
1780 // Second request 1789 // Second request
1781 controller.LoadURL( 1790 controller.LoadURL(
1782 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1791 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1783 1792
1784 EXPECT_TRUE(controller.GetPendingEntry()); 1793 EXPECT_TRUE(controller.GetPendingEntry());
1785 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1794 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 1835
1827 const GURL url1("http://foo1"); 1836 const GURL url1("http://foo1");
1828 const GURL url2("http://foo2"); // Redirection target 1837 const GURL url2("http://foo2"); // Redirection target
1829 1838
1830 // First request as POST 1839 // First request as POST
1831 controller.LoadURL( 1840 controller.LoadURL(
1832 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1841 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1833 controller.GetVisibleEntry()->SetHasPostData(true); 1842 controller.GetVisibleEntry()->SetHasPostData(true);
1834 1843
1835 EXPECT_EQ(0U, notifications.size()); 1844 EXPECT_EQ(0U, notifications.size());
1845 main_test_rfh()->PrepareForCommit();
1836 main_test_rfh()->SendNavigate(0, url2); 1846 main_test_rfh()->SendNavigate(0, url2);
1837 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1847 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1838 navigation_entry_committed_counter_ = 0; 1848 navigation_entry_committed_counter_ = 0;
1839 1849
1840 // Second request 1850 // Second request
1841 controller.LoadURL( 1851 controller.LoadURL(
1842 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1852 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1843 1853
1844 EXPECT_TRUE(controller.GetPendingEntry()); 1854 EXPECT_TRUE(controller.GetPendingEntry());
1845 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1855 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 } 1936 }
1927 1937
1928 // Tests navigation via link click within a subframe. A new navigation entry 1938 // Tests navigation via link click within a subframe. A new navigation entry
1929 // should be created. 1939 // should be created.
1930 TEST_F(NavigationControllerTest, NewSubframe) { 1940 TEST_F(NavigationControllerTest, NewSubframe) {
1931 NavigationControllerImpl& controller = controller_impl(); 1941 NavigationControllerImpl& controller = controller_impl();
1932 TestNotificationTracker notifications; 1942 TestNotificationTracker notifications;
1933 RegisterForAllNavNotifications(&notifications, &controller); 1943 RegisterForAllNavNotifications(&notifications, &controller);
1934 1944
1935 const GURL url1("http://foo1"); 1945 const GURL url1("http://foo1");
1936 main_test_rfh()->SendNavigate(0, url1); 1946 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
1937 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1947 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1938 navigation_entry_committed_counter_ = 0; 1948 navigation_entry_committed_counter_ = 0;
1939 1949
1940 const GURL url2("http://foo2"); 1950 const GURL url2("http://foo2");
1941 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1951 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1942 params.page_id = 1; 1952 params.page_id = 1;
1943 params.url = url2; 1953 params.url = url2;
1944 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 1954 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
1945 params.should_update_history = false; 1955 params.should_update_history = false;
1946 params.gesture = NavigationGestureUser; 1956 params.gesture = NavigationGestureUser;
(...skipping 21 matching lines...) Expand all
1968 // Auto subframes are ones the page loads automatically like ads. They should 1978 // Auto subframes are ones the page loads automatically like ads. They should
1969 // not create new navigation entries. 1979 // not create new navigation entries.
1970 // TODO(creis): Test cross-site and nested iframes. 1980 // TODO(creis): Test cross-site and nested iframes.
1971 // TODO(creis): Test updating entries for history auto subframe navigations. 1981 // TODO(creis): Test updating entries for history auto subframe navigations.
1972 TEST_F(NavigationControllerTest, AutoSubframe) { 1982 TEST_F(NavigationControllerTest, AutoSubframe) {
1973 NavigationControllerImpl& controller = controller_impl(); 1983 NavigationControllerImpl& controller = controller_impl();
1974 TestNotificationTracker notifications; 1984 TestNotificationTracker notifications;
1975 RegisterForAllNavNotifications(&notifications, &controller); 1985 RegisterForAllNavNotifications(&notifications, &controller);
1976 1986
1977 const GURL url1("http://foo/1"); 1987 const GURL url1("http://foo/1");
1978 main_test_rfh()->SendNavigate(1, url1); 1988 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url1);
1979 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1989 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1980 navigation_entry_committed_counter_ = 0; 1990 navigation_entry_committed_counter_ = 0;
1981 1991
1982 // Add a subframe and navigate it. 1992 // Add a subframe and navigate it.
1983 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), 1993 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
1984 SandboxFlags::NONE); 1994 SandboxFlags::NONE);
1985 RenderFrameHostImpl* subframe = 1995 RenderFrameHostImpl* subframe =
1986 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 1996 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
1987 const GURL url2("http://foo/2"); 1997 const GURL url2("http://foo/2");
1988 { 1998 {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 } 2077 }
2068 2078
2069 // Tests navigation and then going back to a subframe navigation. 2079 // Tests navigation and then going back to a subframe navigation.
2070 TEST_F(NavigationControllerTest, BackSubframe) { 2080 TEST_F(NavigationControllerTest, BackSubframe) {
2071 NavigationControllerImpl& controller = controller_impl(); 2081 NavigationControllerImpl& controller = controller_impl();
2072 TestNotificationTracker notifications; 2082 TestNotificationTracker notifications;
2073 RegisterForAllNavNotifications(&notifications, &controller); 2083 RegisterForAllNavNotifications(&notifications, &controller);
2074 2084
2075 // Main page. 2085 // Main page.
2076 const GURL url1("http://foo1"); 2086 const GURL url1("http://foo1");
2077 main_test_rfh()->SendNavigate(0, url1); 2087 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
2078 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2088 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2079 navigation_entry_committed_counter_ = 0; 2089 navigation_entry_committed_counter_ = 0;
2080 2090
2081 // First manual subframe navigation. 2091 // First manual subframe navigation.
2082 const GURL url2("http://foo2"); 2092 const GURL url2("http://foo2");
2083 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2093 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2084 params.page_id = 1; 2094 params.page_id = 1;
2085 params.url = url2; 2095 params.url = url2;
2086 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2096 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2087 params.should_update_history = false; 2097 params.should_update_history = false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 } 2149 }
2140 2150
2141 TEST_F(NavigationControllerTest, LinkClick) { 2151 TEST_F(NavigationControllerTest, LinkClick) {
2142 NavigationControllerImpl& controller = controller_impl(); 2152 NavigationControllerImpl& controller = controller_impl();
2143 TestNotificationTracker notifications; 2153 TestNotificationTracker notifications;
2144 RegisterForAllNavNotifications(&notifications, &controller); 2154 RegisterForAllNavNotifications(&notifications, &controller);
2145 2155
2146 const GURL url1("http://foo1"); 2156 const GURL url1("http://foo1");
2147 const GURL url2("http://foo2"); 2157 const GURL url2("http://foo2");
2148 2158
2149 main_test_rfh()->SendNavigate(0, url1); 2159 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
2150 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2160 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2151 navigation_entry_committed_counter_ = 0; 2161 navigation_entry_committed_counter_ = 0;
2152 2162
2153 main_test_rfh()->SendNavigate(1, url2); 2163 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2);
2154 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2164 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2155 navigation_entry_committed_counter_ = 0; 2165 navigation_entry_committed_counter_ = 0;
2156 2166
2157 // Should not have produced a new session history entry. 2167 // Should not have produced a new session history entry.
2158 EXPECT_EQ(controller.GetEntryCount(), 2); 2168 EXPECT_EQ(controller.GetEntryCount(), 2);
2159 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 2169 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
2160 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2170 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2161 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2171 EXPECT_TRUE(controller.GetLastCommittedEntry());
2162 EXPECT_FALSE(controller.GetPendingEntry()); 2172 EXPECT_FALSE(controller.GetPendingEntry());
2163 EXPECT_TRUE(controller.CanGoBack()); 2173 EXPECT_TRUE(controller.CanGoBack());
2164 EXPECT_FALSE(controller.CanGoForward()); 2174 EXPECT_FALSE(controller.CanGoForward());
2165 } 2175 }
2166 2176
2167 TEST_F(NavigationControllerTest, InPage) { 2177 TEST_F(NavigationControllerTest, InPage) {
2168 NavigationControllerImpl& controller = controller_impl(); 2178 NavigationControllerImpl& controller = controller_impl();
2169 TestNotificationTracker notifications; 2179 TestNotificationTracker notifications;
2170 RegisterForAllNavNotifications(&notifications, &controller); 2180 RegisterForAllNavNotifications(&notifications, &controller);
2171 2181
2172 // Main page. 2182 // Main page.
2173 const GURL url1("http://foo"); 2183 const GURL url1("http://foo");
2174 main_test_rfh()->SendNavigate(0, url1); 2184 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
2175 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2185 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2176 navigation_entry_committed_counter_ = 0; 2186 navigation_entry_committed_counter_ = 0;
2177 2187
2178 // Ensure main page navigation to same url respects the was_within_same_page 2188 // Ensure main page navigation to same url respects the was_within_same_page
2179 // hint provided in the params. 2189 // hint provided in the params.
2180 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; 2190 FrameHostMsg_DidCommitProvisionalLoad_Params self_params;
2181 self_params.page_id = 0; 2191 self_params.page_id = 0;
2182 self_params.url = url1; 2192 self_params.url = url1;
2183 self_params.transition = ui::PAGE_TRANSITION_LINK; 2193 self_params.transition = ui::PAGE_TRANSITION_LINK;
2184 self_params.should_update_history = false; 2194 self_params.should_update_history = false;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2283 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2274 } 2284 }
2275 2285
2276 TEST_F(NavigationControllerTest, InPage_Replace) { 2286 TEST_F(NavigationControllerTest, InPage_Replace) {
2277 NavigationControllerImpl& controller = controller_impl(); 2287 NavigationControllerImpl& controller = controller_impl();
2278 TestNotificationTracker notifications; 2288 TestNotificationTracker notifications;
2279 RegisterForAllNavNotifications(&notifications, &controller); 2289 RegisterForAllNavNotifications(&notifications, &controller);
2280 2290
2281 // Main page. 2291 // Main page.
2282 const GURL url1("http://foo"); 2292 const GURL url1("http://foo");
2283 main_test_rfh()->SendNavigate(0, url1); 2293 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
2284 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2294 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2285 navigation_entry_committed_counter_ = 0; 2295 navigation_entry_committed_counter_ = 0;
2286 2296
2287 // First navigation. 2297 // First navigation.
2288 const GURL url2("http://foo#a"); 2298 const GURL url2("http://foo#a");
2289 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2299 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2290 params.page_id = 0; // Same page_id 2300 params.page_id = 0; // Same page_id
2291 params.url = url2; 2301 params.url = url2;
2292 params.transition = ui::PAGE_TRANSITION_LINK; 2302 params.transition = ui::PAGE_TRANSITION_LINK;
2293 params.should_update_history = false; 2303 params.should_update_history = false;
(...skipping 20 matching lines...) Expand all
2314 // window.location='http://foo3/'; 2324 // window.location='http://foo3/';
2315 // </script> 2325 // </script>
2316 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { 2326 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
2317 NavigationControllerImpl& controller = controller_impl(); 2327 NavigationControllerImpl& controller = controller_impl();
2318 TestNotificationTracker notifications; 2328 TestNotificationTracker notifications;
2319 RegisterForAllNavNotifications(&notifications, &controller); 2329 RegisterForAllNavNotifications(&notifications, &controller);
2320 2330
2321 // Load an initial page. 2331 // Load an initial page.
2322 { 2332 {
2323 const GURL url("http://foo/"); 2333 const GURL url("http://foo/");
2324 main_test_rfh()->SendNavigate(0, url); 2334 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url);
2325 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2335 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2326 navigation_entry_committed_counter_ = 0; 2336 navigation_entry_committed_counter_ = 0;
2327 } 2337 }
2328 2338
2329 // Navigate to a new page. 2339 // Navigate to a new page.
2330 { 2340 {
2331 const GURL url("http://foo2/"); 2341 const GURL url("http://foo2/");
2332 main_test_rfh()->SendNavigate(1, url); 2342 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url);
2333 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2343 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2334 navigation_entry_committed_counter_ = 0; 2344 navigation_entry_committed_counter_ = 0;
2335 } 2345 }
2336 2346
2337 // Navigate within the page. 2347 // Navigate within the page.
2338 { 2348 {
2339 const GURL url("http://foo2/#a"); 2349 const GURL url("http://foo2/#a");
2340 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2350 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2341 params.page_id = 1; // Same page_id 2351 params.page_id = 1; // Same page_id
2342 params.url = url; 2352 params.url = url;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2390 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2381 navigation_entry_committed_counter_ = 0; 2391 navigation_entry_committed_counter_ = 0;
2382 EXPECT_FALSE(details.is_in_page); 2392 EXPECT_FALSE(details.is_in_page);
2383 EXPECT_EQ(3, controller.GetEntryCount()); 2393 EXPECT_EQ(3, controller.GetEntryCount());
2384 } 2394 }
2385 2395
2386 // Verify that BACK brings us back to http://foo2/. 2396 // Verify that BACK brings us back to http://foo2/.
2387 { 2397 {
2388 const GURL url("http://foo2/"); 2398 const GURL url("http://foo2/");
2389 controller.GoBack(); 2399 controller.GoBack();
2400 main_test_rfh()->PrepareForCommit();
2390 main_test_rfh()->SendNavigate(1, url); 2401 main_test_rfh()->SendNavigate(1, url);
2391 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2402 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2392 navigation_entry_committed_counter_ = 0; 2403 navigation_entry_committed_counter_ = 0;
2393 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 2404 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2394 } 2405 }
2395 } 2406 }
2396 2407
2397 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) 2408 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
2398 { 2409 {
2399 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); 2410 ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
2400 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2411 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2401 GURL url("http://foo"); 2412 GURL url("http://foo");
2402 params.page_id = 1; 2413 params.page_id = 1;
2403 params.url = url; 2414 params.url = url;
2404 params.page_state = PageState::CreateFromURL(url); 2415 params.page_state = PageState::CreateFromURL(url);
2405 params.was_within_same_page = true; 2416 params.was_within_same_page = true;
2417 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
2418 main_test_rfh()->PrepareForCommit();
2406 contents()->GetMainFrame()->SendNavigateWithParams(&params); 2419 contents()->GetMainFrame()->SendNavigateWithParams(&params);
carlosk 2015/04/08 16:35:20 In the same line as my previous comment, it seems
clamy 2015/04/10 14:40:15 No because we call SendNavigateWithParams and not
2407 // We pass if we don't crash. 2420 // We pass if we don't crash.
2408 } 2421 }
2409 2422
2410 // NotificationObserver implementation used in verifying we've received the 2423 // NotificationObserver implementation used in verifying we've received the
2411 // NOTIFICATION_NAV_LIST_PRUNED method. 2424 // NOTIFICATION_NAV_LIST_PRUNED method.
2412 class PrunedListener : public NotificationObserver { 2425 class PrunedListener : public NotificationObserver {
2413 public: 2426 public:
2414 explicit PrunedListener(NavigationControllerImpl* controller) 2427 explicit PrunedListener(NavigationControllerImpl* controller)
2415 : notification_count_(0) { 2428 : notification_count_(0) {
2416 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, 2429 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED,
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2998 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing 3011 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing
2999 // the virtual URL to differ from the URL. 3012 // the virtual URL to differ from the URL.
3000 controller.GetPendingEntry()->SetURL(url1_fixed); 3013 controller.GetPendingEntry()->SetURL(url1_fixed);
3001 controller.GetPendingEntry()->SetVirtualURL(url1); 3014 controller.GetPendingEntry()->SetVirtualURL(url1);
3002 3015
3003 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); 3016 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL());
3004 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); 3017 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL());
3005 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3018 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
3006 3019
3007 // If the user clicks another link, we should replace the pending entry. 3020 // If the user clicks another link, we should replace the pending entry.
3021 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
3022 main_test_rfh()->PrepareForCommit();
3008 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); 3023 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false);
3009 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 3024 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
3010 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); 3025 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL());
3011 3026
3012 // Once it commits, the URL and virtual URL should reflect the actual page. 3027 // Once it commits, the URL and virtual URL should reflect the actual page.
3013 main_test_rfh()->SendNavigate(0, url2); 3028 main_test_rfh()->SendNavigate(0, url2);
3014 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3029 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
3015 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); 3030 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL());
3016 3031
3017 // We should not replace the pending entry for an error URL. 3032 // We should not replace the pending entry for an error URL.
3018 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); 3033 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false);
3019 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3034 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3020 navigator->DidStartProvisionalLoad(main_test_rfh(), 3035 navigator->DidStartProvisionalLoad(main_test_rfh(),
3021 GURL(kUnreachableWebDataURL), false); 3036 GURL(kUnreachableWebDataURL), false);
3022 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3037 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3023 3038
3024 // We should remember if the pending entry will replace the current one. 3039 // We should remember if the pending entry will replace the current one.
3025 // http://crbug.com/308444. 3040 // http://crbug.com/308444.
3026 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); 3041 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false);
3027 controller.GetPendingEntry()->set_should_replace_entry(true); 3042 controller.GetPendingEntry()->set_should_replace_entry(true);
3043
3044 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
3045 main_test_rfh()->PrepareForCommit();
3028 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); 3046 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false);
3029 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); 3047 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry());
3030 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need
3031 // to go through the RenderViewHost. The TestRenderViewHost routes navigations
3032 // to the main frame.
3033 main_test_rfh()->SendNavigate(0, url2); 3048 main_test_rfh()->SendNavigate(0, url2);
3034 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3049 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
3035 } 3050 }
3036 3051
3037 // Tests that the URLs for renderer-initiated navigations are not displayed to 3052 // Tests that the URLs for renderer-initiated navigations are not displayed to
3038 // the user until the navigation commits, to prevent URL spoof attacks. 3053 // the user until the navigation commits, to prevent URL spoof attacks.
3039 // See http://crbug.com/99016. 3054 // See http://crbug.com/99016.
3040 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 3055 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
3041 NavigationControllerImpl& controller = controller_impl(); 3056 NavigationControllerImpl& controller = controller_impl();
3042 TestNotificationTracker notifications; 3057 TestNotificationTracker notifications;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 NavigationController::LoadURLParams load_url_params(url1); 3238 NavigationController::LoadURLParams load_url_params(url1);
3224 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; 3239 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK;
3225 load_url_params.is_renderer_initiated = true; 3240 load_url_params.is_renderer_initiated = true;
3226 controller.LoadURLWithParams(load_url_params); 3241 controller.LoadURLWithParams(load_url_params);
3227 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3242 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3228 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3243 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
3229 EXPECT_TRUE(controller.IsInitialNavigation()); 3244 EXPECT_TRUE(controller.IsInitialNavigation());
3230 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); 3245 EXPECT_FALSE(contents()->HasAccessedInitialDocument());
3231 3246
3232 // Simulate a commit and then starting a new pending navigation. 3247 // Simulate a commit and then starting a new pending navigation.
3248 main_test_rfh()->PrepareForCommit();
3233 main_test_rfh()->SendNavigate(0, url1); 3249 main_test_rfh()->SendNavigate(0, url1);
3234 NavigationController::LoadURLParams load_url2_params(url2); 3250 NavigationController::LoadURLParams load_url2_params(url2);
3235 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; 3251 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK;
3236 load_url2_params.is_renderer_initiated = true; 3252 load_url2_params.is_renderer_initiated = true;
3237 controller.LoadURLWithParams(load_url2_params); 3253 controller.LoadURLWithParams(load_url2_params);
3238 3254
3239 // We should not consider this an initial navigation, and thus should 3255 // We should not consider this an initial navigation, and thus should
3240 // not show the pending URL. 3256 // not show the pending URL.
3241 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); 3257 EXPECT_FALSE(contents()->HasAccessedInitialDocument());
3242 EXPECT_FALSE(controller.IsInitialNavigation()); 3258 EXPECT_FALSE(controller.IsInitialNavigation());
(...skipping 10 matching lines...) Expand all
3253 const GURL url("http://www.google.com/home.html"); 3269 const GURL url("http://www.google.com/home.html");
3254 3270
3255 // If the renderer claims it performed an in-page navigation from 3271 // If the renderer claims it performed an in-page navigation from
3256 // about:blank, trust the renderer. 3272 // about:blank, trust the renderer.
3257 // This can happen when an iframe is created and populated via 3273 // This can happen when an iframe is created and populated via
3258 // document.write(), then tries to perform a fragment navigation. 3274 // document.write(), then tries to perform a fragment navigation.
3259 // TODO(japhet): We should only trust the renderer if the about:blank 3275 // TODO(japhet): We should only trust the renderer if the about:blank
3260 // was the first document in the given frame, but we don't have enough 3276 // was the first document in the given frame, but we don't have enough
3261 // information to identify that case currently. 3277 // information to identify that case currently.
3262 const GURL blank_url(url::kAboutBlankURL); 3278 const GURL blank_url(url::kAboutBlankURL);
3263 main_test_rfh()->SendNavigate(0, blank_url); 3279 main_test_rfh()->NavigateAndCommitRendererInitiated(0, blank_url);
3264 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, 3280 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true,
3265 main_test_rfh())); 3281 main_test_rfh()));
3266 3282
3267 // Navigate to URL with no refs. 3283 // Navigate to URL with no refs.
3268 main_test_rfh()->SendNavigate(0, url); 3284 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url);
3269 3285
3270 // Reloading the page is not an in-page navigation. 3286 // Reloading the page is not an in-page navigation.
3271 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, 3287 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false,
3272 main_test_rfh())); 3288 main_test_rfh()));
3273 const GURL other_url("http://www.google.com/add.html"); 3289 const GURL other_url("http://www.google.com/add.html");
3274 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3290 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3275 main_test_rfh())); 3291 main_test_rfh()));
3276 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); 3292 const GURL url_with_ref("http://www.google.com/home.html#my_ref");
3277 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, 3293 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
3278 main_test_rfh())); 3294 main_test_rfh()));
3279 3295
3280 // Navigate to URL with refs. 3296 // Navigate to URL with refs.
3281 main_test_rfh()->SendNavigate(1, url_with_ref); 3297 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url_with_ref);
3282 3298
3283 // Reloading the page is not an in-page navigation. 3299 // Reloading the page is not an in-page navigation.
3284 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, 3300 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false,
3285 main_test_rfh())); 3301 main_test_rfh()));
3286 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, 3302 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false,
3287 main_test_rfh())); 3303 main_test_rfh()));
3288 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3304 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3289 main_test_rfh())); 3305 main_test_rfh()));
3290 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 3306 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
3291 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, 3307 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true,
(...skipping 18 matching lines...) Expand all
3310 const GURL different_origin_url("http://www.example.com"); 3326 const GURL different_origin_url("http://www.example.com");
3311 MockRenderProcessHost* rph = 3327 MockRenderProcessHost* rph =
3312 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); 3328 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess());
3313 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); 3329 WebPreferences prefs = test_rvh()->GetWebkitPreferences();
3314 prefs.allow_universal_access_from_file_urls = true; 3330 prefs.allow_universal_access_from_file_urls = true;
3315 test_rvh()->UpdateWebkitPreferences(prefs); 3331 test_rvh()->UpdateWebkitPreferences(prefs);
3316 prefs = test_rvh()->GetWebkitPreferences(); 3332 prefs = test_rvh()->GetWebkitPreferences();
3317 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); 3333 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls);
3318 // Allow in page navigation if existing URL is file scheme. 3334 // Allow in page navigation if existing URL is file scheme.
3319 const GURL file_url("file:///foo/index.html"); 3335 const GURL file_url("file:///foo/index.html");
3320 main_test_rfh()->SendNavigate(0, file_url); 3336 main_test_rfh()->NavigateAndCommitRendererInitiated(0, file_url);
3321 EXPECT_EQ(0, rph->bad_msg_count()); 3337 EXPECT_EQ(0, rph->bad_msg_count());
3322 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, 3338 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true,
3323 main_test_rfh())); 3339 main_test_rfh()));
3324 EXPECT_EQ(0, rph->bad_msg_count()); 3340 EXPECT_EQ(0, rph->bad_msg_count());
3325 // Don't honor allow_universal_access_from_file_urls if existing URL is 3341 // Don't honor allow_universal_access_from_file_urls if existing URL is
3326 // not file scheme. 3342 // not file scheme.
3327 main_test_rfh()->SendNavigate(0, url); 3343 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url);
3328 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3344 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3329 main_test_rfh())); 3345 main_test_rfh()));
3330 EXPECT_EQ(1, rph->bad_msg_count()); 3346 EXPECT_EQ(1, rph->bad_msg_count());
3331 3347
3332 // Remove allow_universal_access_from_file_urls flag. 3348 // Remove allow_universal_access_from_file_urls flag.
3333 prefs.allow_universal_access_from_file_urls = false; 3349 prefs.allow_universal_access_from_file_urls = false;
3334 test_rvh()->UpdateWebkitPreferences(prefs); 3350 test_rvh()->UpdateWebkitPreferences(prefs);
3335 prefs = test_rvh()->GetWebkitPreferences(); 3351 prefs = test_rvh()->GetWebkitPreferences();
3336 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); 3352 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls);
3337 3353
3338 // Don't believe the renderer if it claims a cross-origin navigation is 3354 // Don't believe the renderer if it claims a cross-origin navigation is
3339 // in-page. 3355 // in-page.
3340 EXPECT_EQ(1, rph->bad_msg_count()); 3356 EXPECT_EQ(1, rph->bad_msg_count());
3341 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3357 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3342 main_test_rfh())); 3358 main_test_rfh()));
3343 EXPECT_EQ(2, rph->bad_msg_count()); 3359 EXPECT_EQ(2, rph->bad_msg_count());
3344 } 3360 }
3345 3361
3346 // Some pages can have subframes with the same base URL (minus the reference) as 3362 // Some pages can have subframes with the same base URL (minus the reference) as
3347 // the main page. Even though this is hard, it can happen, and we don't want 3363 // the main page. Even though this is hard, it can happen, and we don't want
3348 // these subframe navigations to affect the toplevel document. They should 3364 // these subframe navigations to affect the toplevel document. They should
3349 // instead be ignored. http://crbug.com/5585 3365 // instead be ignored. http://crbug.com/5585
3350 TEST_F(NavigationControllerTest, SameSubframe) { 3366 TEST_F(NavigationControllerTest, SameSubframe) {
3351 NavigationControllerImpl& controller = controller_impl(); 3367 NavigationControllerImpl& controller = controller_impl();
3352 // Navigate the main frame. 3368 // Navigate the main frame.
3353 const GURL url("http://www.google.com/"); 3369 const GURL url("http://www.google.com/");
3354 main_test_rfh()->SendNavigate(0, url); 3370 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url);
3355 3371
3356 // We should be at the first navigation entry. 3372 // We should be at the first navigation entry.
3357 EXPECT_EQ(controller.GetEntryCount(), 1); 3373 EXPECT_EQ(controller.GetEntryCount(), 1);
3358 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3374 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3359 3375
3360 // Navigate a subframe that would normally count as in-page. 3376 // Navigate a subframe that would normally count as in-page.
3361 const GURL subframe("http://www.google.com/#"); 3377 const GURL subframe("http://www.google.com/#");
3362 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3378 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3363 params.page_id = 0; 3379 params.page_id = 0;
3364 params.url = subframe; 3380 params.url = subframe;
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
4235 TEST_F(NavigationControllerTest, IsInitialNavigation) { 4251 TEST_F(NavigationControllerTest, IsInitialNavigation) {
4236 NavigationControllerImpl& controller = controller_impl(); 4252 NavigationControllerImpl& controller = controller_impl();
4237 TestNotificationTracker notifications; 4253 TestNotificationTracker notifications;
4238 RegisterForAllNavNotifications(&notifications, &controller); 4254 RegisterForAllNavNotifications(&notifications, &controller);
4239 4255
4240 // Initial state. 4256 // Initial state.
4241 EXPECT_TRUE(controller.IsInitialNavigation()); 4257 EXPECT_TRUE(controller.IsInitialNavigation());
4242 4258
4243 // After commit, it stays false. 4259 // After commit, it stays false.
4244 const GURL url1("http://foo1"); 4260 const GURL url1("http://foo1");
4245 main_test_rfh()->SendNavigate(0, url1); 4261 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1);
4246 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4262 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4247 navigation_entry_committed_counter_ = 0; 4263 navigation_entry_committed_counter_ = 0;
4248 EXPECT_FALSE(controller.IsInitialNavigation()); 4264 EXPECT_FALSE(controller.IsInitialNavigation());
4249 4265
4250 // After starting a new navigation, it stays false. 4266 // After starting a new navigation, it stays false.
4251 const GURL url2("http://foo2"); 4267 const GURL url2("http://foo2");
4252 controller.LoadURL( 4268 controller.LoadURL(
4253 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 4269 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
4254 } 4270 }
4255 4271
4256 // Check that the favicon is not reused across a client redirect. 4272 // Check that the favicon is not reused across a client redirect.
4257 // (crbug.com/28515) 4273 // (crbug.com/28515)
4258 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { 4274 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) {
4259 const GURL kPageWithFavicon("http://withfavicon.html"); 4275 const GURL kPageWithFavicon("http://withfavicon.html");
4260 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); 4276 const GURL kPageWithoutFavicon("http://withoutfavicon.html");
4261 const GURL kIconURL("http://withfavicon.ico"); 4277 const GURL kIconURL("http://withfavicon.ico");
4262 const gfx::Image kDefaultFavicon = FaviconStatus().image; 4278 const gfx::Image kDefaultFavicon = FaviconStatus().image;
4263 4279
4264 NavigationControllerImpl& controller = controller_impl(); 4280 NavigationControllerImpl& controller = controller_impl();
4265 TestNotificationTracker notifications; 4281 TestNotificationTracker notifications;
4266 RegisterForAllNavNotifications(&notifications, &controller); 4282 RegisterForAllNavNotifications(&notifications, &controller);
4267 4283
4268 main_test_rfh()->SendNavigate(0, kPageWithFavicon); 4284 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kPageWithFavicon);
4269 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4285 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4270 navigation_entry_committed_counter_ = 0; 4286 navigation_entry_committed_counter_ = 0;
4271 4287
4272 NavigationEntry* entry = controller.GetLastCommittedEntry(); 4288 NavigationEntry* entry = controller.GetLastCommittedEntry();
4273 EXPECT_TRUE(entry); 4289 EXPECT_TRUE(entry);
4274 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); 4290 EXPECT_EQ(kPageWithFavicon, entry->GetURL());
4275 4291
4276 // Simulate Chromium having set the favicon for |kPageWithFavicon|. 4292 // Simulate Chromium having set the favicon for |kPageWithFavicon|.
4277 content::FaviconStatus& favicon_status = entry->GetFavicon(); 4293 content::FaviconStatus& favicon_status = entry->GetFavicon();
4278 favicon_status.image = CreateImage(SK_ColorWHITE); 4294 favicon_status.image = CreateImage(SK_ColorWHITE);
4279 favicon_status.url = kIconURL; 4295 favicon_status.url = kIconURL;
4280 favicon_status.valid = true; 4296 favicon_status.valid = true;
4281 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); 4297 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
4282 4298
4299 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon,
4300 false);
4301 main_test_rfh()->PrepareForCommit();
4283 main_test_rfh()->SendNavigateWithTransition( 4302 main_test_rfh()->SendNavigateWithTransition(
4284 0, // same page ID. 4303 0, // same page ID.
4285 kPageWithoutFavicon, 4304 kPageWithoutFavicon,
4286 ui::PAGE_TRANSITION_CLIENT_REDIRECT); 4305 ui::PAGE_TRANSITION_CLIENT_REDIRECT);
4287 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4306 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4288 navigation_entry_committed_counter_ = 0; 4307 navigation_entry_committed_counter_ = 0;
4289 4308
4290 entry = controller.GetLastCommittedEntry(); 4309 entry = controller.GetLastCommittedEntry();
4291 EXPECT_TRUE(entry); 4310 EXPECT_TRUE(entry);
4292 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); 4311 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL());
4293 4312
4294 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); 4313 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
4295 } 4314 }
4296 4315
4297 // Check that the favicon is not cleared for NavigationEntries which were 4316 // Check that the favicon is not cleared for NavigationEntries which were
4298 // previously navigated to. 4317 // previously navigated to.
4299 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { 4318 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) {
4300 const GURL kUrl1("http://www.a.com/1"); 4319 const GURL kUrl1("http://www.a.com/1");
4301 const GURL kUrl2("http://www.a.com/2"); 4320 const GURL kUrl2("http://www.a.com/2");
4302 const GURL kIconURL("http://www.a.com/1/favicon.ico"); 4321 const GURL kIconURL("http://www.a.com/1/favicon.ico");
4303 4322
4304 NavigationControllerImpl& controller = controller_impl(); 4323 NavigationControllerImpl& controller = controller_impl();
4305 TestNotificationTracker notifications; 4324 TestNotificationTracker notifications;
4306 RegisterForAllNavNotifications(&notifications, &controller); 4325 RegisterForAllNavNotifications(&notifications, &controller);
4307 4326
4308 main_test_rfh()->SendNavigate(0, kUrl1); 4327 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1);
4309 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4328 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4310 navigation_entry_committed_counter_ = 0; 4329 navigation_entry_committed_counter_ = 0;
4311 4330
4312 // Simulate Chromium having set the favicon for |kUrl1|. 4331 // Simulate Chromium having set the favicon for |kUrl1|.
4313 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); 4332 gfx::Image favicon_image = CreateImage(SK_ColorWHITE);
4314 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); 4333 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
4315 EXPECT_TRUE(entry); 4334 EXPECT_TRUE(entry);
4316 content::FaviconStatus& favicon_status = entry->GetFavicon(); 4335 content::FaviconStatus& favicon_status = entry->GetFavicon();
4317 favicon_status.image = favicon_image; 4336 favicon_status.image = favicon_image;
4318 favicon_status.url = kIconURL; 4337 favicon_status.url = kIconURL;
4319 favicon_status.valid = true; 4338 favicon_status.valid = true;
4320 4339
4321 // Navigate to another page and go back to the original page. 4340 // Navigate to another page and go back to the original page.
4322 main_test_rfh()->SendNavigate(1, kUrl2); 4341 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2);
4323 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4342 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4324 navigation_entry_committed_counter_ = 0; 4343 navigation_entry_committed_counter_ = 0;
4344 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false);
4345 main_test_rfh()->PrepareForCommit();
4325 main_test_rfh()->SendNavigateWithTransition( 4346 main_test_rfh()->SendNavigateWithTransition(
4326 0, 4347 0,
4327 kUrl1, 4348 kUrl1,
4328 ui::PAGE_TRANSITION_FORWARD_BACK); 4349 ui::PAGE_TRANSITION_FORWARD_BACK);
4329 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4350 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4330 navigation_entry_committed_counter_ = 0; 4351 navigation_entry_committed_counter_ = 0;
4331 4352
4332 // Verify that the favicon for the page at |kUrl1| was not cleared. 4353 // Verify that the favicon for the page at |kUrl1| was not cleared.
4333 entry = controller.GetEntryAtIndex(0); 4354 entry = controller.GetEntryAtIndex(0);
4334 EXPECT_TRUE(entry); 4355 EXPECT_TRUE(entry);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4418 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); 4439 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount());
4419 for (int i = 0; i < controller.GetEntryCount(); ++i) { 4440 for (int i = 0; i < controller.GetEntryCount(); ++i) {
4420 entry = controller.GetEntryAtIndex(i); 4441 entry = controller.GetEntryAtIndex(i);
4421 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i 4442 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i
4422 << " not cleared"; 4443 << " not cleared";
4423 } 4444 }
4424 } 4445 }
4425 4446
4426 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { 4447 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) {
4427 // Navigate. 4448 // Navigate.
4428 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo")); 4449 main_test_rfh()->NavigateAndCommitRendererInitiated(1, GURL("http://foo"));
4429 4450
4430 // Set title and favicon. 4451 // Set title and favicon.
4431 base::string16 title(base::ASCIIToUTF16("Title")); 4452 base::string16 title(base::ASCIIToUTF16("Title"));
4432 FaviconStatus favicon; 4453 FaviconStatus favicon;
4433 favicon.valid = true; 4454 favicon.valid = true;
4434 favicon.url = GURL("http://foo/favicon.ico"); 4455 favicon.url = GURL("http://foo/favicon.ico");
4435 controller().GetLastCommittedEntry()->SetTitle(title); 4456 controller().GetLastCommittedEntry()->SetTitle(title);
4436 controller().GetLastCommittedEntry()->GetFavicon() = favicon; 4457 controller().GetLastCommittedEntry()->GetFavicon() = favicon;
4437 4458
4438 // history.pushState() is called. 4459 // history.pushState() is called.
4439 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4460 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4440 GURL url("http://foo#foo"); 4461 GURL kUrl2("http://foo#foo");
4441 params.page_id = 2; 4462 params.page_id = 2;
4442 params.url = url; 4463 params.url = kUrl2;
4443 params.page_state = PageState::CreateFromURL(url); 4464 params.page_state = PageState::CreateFromURL(kUrl2);
4444 params.was_within_same_page = true; 4465 params.was_within_same_page = true;
4445 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4466 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false);
4467 main_test_rfh()->PrepareForCommit();
4468 main_test_rfh()->SendNavigateWithParams(&params);
4446 4469
4447 // The title should immediately be visible on the new NavigationEntry. 4470 // The title should immediately be visible on the new NavigationEntry.
4448 base::string16 new_title = 4471 base::string16 new_title =
4449 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); 4472 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string());
4450 EXPECT_EQ(title, new_title); 4473 EXPECT_EQ(title, new_title);
4451 FaviconStatus new_favicon = 4474 FaviconStatus new_favicon =
4452 controller().GetLastCommittedEntry()->GetFavicon(); 4475 controller().GetLastCommittedEntry()->GetFavicon();
4453 EXPECT_EQ(favicon.valid, new_favicon.valid); 4476 EXPECT_EQ(favicon.valid, new_favicon.valid);
4454 EXPECT_EQ(favicon.url, new_favicon.url); 4477 EXPECT_EQ(favicon.url, new_favicon.url);
4455 } 4478 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4515 GURL url("http://foo"); 4538 GURL url("http://foo");
4516 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4539 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4517 params.page_id = 1; 4540 params.page_id = 1;
4518 params.url = url; 4541 params.url = url;
4519 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; 4542 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT;
4520 params.gesture = NavigationGestureUser; 4543 params.gesture = NavigationGestureUser;
4521 params.page_state = PageState::CreateFromURL(url); 4544 params.page_state = PageState::CreateFromURL(url);
4522 params.was_within_same_page = false; 4545 params.was_within_same_page = false;
4523 params.is_post = true; 4546 params.is_post = true;
4524 params.post_id = 2; 4547 params.post_id = 2;
4548 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
4549 main_test_rfh()->PrepareForCommit();
4525 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4550 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4526 4551
4527 // history.replaceState() is called. 4552 // history.replaceState() is called.
4528 GURL replace_url("http://foo#foo"); 4553 GURL replace_url("http://foo#foo");
4529 params.page_id = 1; 4554 params.page_id = 1;
4530 params.url = replace_url; 4555 params.url = replace_url;
4531 params.transition = ui::PAGE_TRANSITION_LINK; 4556 params.transition = ui::PAGE_TRANSITION_LINK;
4532 params.gesture = NavigationGestureUser; 4557 params.gesture = NavigationGestureUser;
4533 params.page_state = PageState::CreateFromURL(replace_url); 4558 params.page_state = PageState::CreateFromURL(replace_url);
4534 params.was_within_same_page = true; 4559 params.was_within_same_page = true;
4535 params.is_post = false; 4560 params.is_post = false;
4536 params.post_id = -1; 4561 params.post_id = -1;
4562 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false);
4563 main_test_rfh()->PrepareForCommit();
4537 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4564 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4538 4565
4539 // Now reload. replaceState overrides the POST, so we should not show a 4566 // Now reload. replaceState overrides the POST, so we should not show a
4540 // repost warning dialog. 4567 // repost warning dialog.
4541 controller_impl().Reload(true); 4568 controller_impl().Reload(true);
4542 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4569 EXPECT_EQ(0, delegate->repost_form_warning_count());
4543 } 4570 }
4544 4571
4545 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { 4572 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) {
4546 GURL url("http://foo"); 4573 GURL url("http://foo");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4593 { 4620 {
4594 LoadCommittedDetails details; 4621 LoadCommittedDetails details;
4595 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4622 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4596 EXPECT_EQ(PAGE_TYPE_ERROR, 4623 EXPECT_EQ(PAGE_TYPE_ERROR,
4597 controller_impl().GetLastCommittedEntry()->GetPageType()); 4624 controller_impl().GetLastCommittedEntry()->GetPageType());
4598 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4625 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4599 } 4626 }
4600 } 4627 }
4601 4628
4602 } // namespace content 4629 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698