OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/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 Loading... |
702 NavigationControllerImpl& controller = controller_impl(); | 702 NavigationControllerImpl& controller = controller_impl(); |
703 TestNotificationTracker notifications; | 703 TestNotificationTracker notifications; |
704 RegisterForAllNavNotifications(¬ifications, &controller); | 704 RegisterForAllNavNotifications(¬ifications, &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 Loading... |
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(¬ifications, &controller); | 745 RegisterForAllNavNotifications(¬ifications, &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); |
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 Loading... |
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(¬ifications, &controller); | 1061 RegisterForAllNavNotifications(¬ifications, &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 Loading... |
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 Loading... |
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 Loading... |
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(¬ifications, &controller); | 1446 RegisterForAllNavNotifications(¬ifications, &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 Loading... |
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(¬ifications, &controller); | 1556 RegisterForAllNavNotifications(¬ifications, &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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 } | 1939 } |
1932 | 1940 |
1933 // Tests navigation via link click within a subframe. A new navigation entry | 1941 // Tests navigation via link click within a subframe. A new navigation entry |
1934 // should be created. | 1942 // should be created. |
1935 TEST_F(NavigationControllerTest, NewSubframe) { | 1943 TEST_F(NavigationControllerTest, NewSubframe) { |
1936 NavigationControllerImpl& controller = controller_impl(); | 1944 NavigationControllerImpl& controller = controller_impl(); |
1937 TestNotificationTracker notifications; | 1945 TestNotificationTracker notifications; |
1938 RegisterForAllNavNotifications(¬ifications, &controller); | 1946 RegisterForAllNavNotifications(¬ifications, &controller); |
1939 | 1947 |
1940 const GURL url1("http://foo1"); | 1948 const GURL url1("http://foo1"); |
1941 main_test_rfh()->SendNavigate(0, url1); | 1949 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
1942 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1950 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1943 navigation_entry_committed_counter_ = 0; | 1951 navigation_entry_committed_counter_ = 0; |
1944 | 1952 |
1945 const GURL url2("http://foo2"); | 1953 const GURL url2("http://foo2"); |
1946 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1954 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1947 params.page_id = 1; | 1955 params.page_id = 1; |
1948 params.url = url2; | 1956 params.url = url2; |
1949 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 1957 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
1950 params.should_update_history = false; | 1958 params.should_update_history = false; |
1951 params.gesture = NavigationGestureUser; | 1959 params.gesture = NavigationGestureUser; |
(...skipping 21 matching lines...) Expand all Loading... |
1973 // Auto subframes are ones the page loads automatically like ads. They should | 1981 // Auto subframes are ones the page loads automatically like ads. They should |
1974 // not create new navigation entries. | 1982 // not create new navigation entries. |
1975 // TODO(creis): Test cross-site and nested iframes. | 1983 // TODO(creis): Test cross-site and nested iframes. |
1976 // TODO(creis): Test updating entries for history auto subframe navigations. | 1984 // TODO(creis): Test updating entries for history auto subframe navigations. |
1977 TEST_F(NavigationControllerTest, AutoSubframe) { | 1985 TEST_F(NavigationControllerTest, AutoSubframe) { |
1978 NavigationControllerImpl& controller = controller_impl(); | 1986 NavigationControllerImpl& controller = controller_impl(); |
1979 TestNotificationTracker notifications; | 1987 TestNotificationTracker notifications; |
1980 RegisterForAllNavNotifications(¬ifications, &controller); | 1988 RegisterForAllNavNotifications(¬ifications, &controller); |
1981 | 1989 |
1982 const GURL url1("http://foo/1"); | 1990 const GURL url1("http://foo/1"); |
1983 main_test_rfh()->SendNavigate(1, url1); | 1991 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url1); |
1984 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1992 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1985 navigation_entry_committed_counter_ = 0; | 1993 navigation_entry_committed_counter_ = 0; |
1986 | 1994 |
1987 // Add a subframe and navigate it. | 1995 // Add a subframe and navigate it. |
1988 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), | 1996 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
1989 SandboxFlags::NONE); | 1997 SandboxFlags::NONE); |
1990 RenderFrameHostImpl* subframe = | 1998 RenderFrameHostImpl* subframe = |
1991 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); | 1999 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
1992 const GURL url2("http://foo/2"); | 2000 const GURL url2("http://foo/2"); |
1993 { | 2001 { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2072 } | 2080 } |
2073 | 2081 |
2074 // Tests navigation and then going back to a subframe navigation. | 2082 // Tests navigation and then going back to a subframe navigation. |
2075 TEST_F(NavigationControllerTest, BackSubframe) { | 2083 TEST_F(NavigationControllerTest, BackSubframe) { |
2076 NavigationControllerImpl& controller = controller_impl(); | 2084 NavigationControllerImpl& controller = controller_impl(); |
2077 TestNotificationTracker notifications; | 2085 TestNotificationTracker notifications; |
2078 RegisterForAllNavNotifications(¬ifications, &controller); | 2086 RegisterForAllNavNotifications(¬ifications, &controller); |
2079 | 2087 |
2080 // Main page. | 2088 // Main page. |
2081 const GURL url1("http://foo1"); | 2089 const GURL url1("http://foo1"); |
2082 main_test_rfh()->SendNavigate(0, url1); | 2090 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2083 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2091 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2084 navigation_entry_committed_counter_ = 0; | 2092 navigation_entry_committed_counter_ = 0; |
2085 | 2093 |
2086 // First manual subframe navigation. | 2094 // First manual subframe navigation. |
2087 const GURL url2("http://foo2"); | 2095 const GURL url2("http://foo2"); |
2088 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2096 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2089 params.page_id = 1; | 2097 params.page_id = 1; |
2090 params.url = url2; | 2098 params.url = url2; |
2091 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2099 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2092 params.should_update_history = false; | 2100 params.should_update_history = false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 } | 2152 } |
2145 | 2153 |
2146 TEST_F(NavigationControllerTest, LinkClick) { | 2154 TEST_F(NavigationControllerTest, LinkClick) { |
2147 NavigationControllerImpl& controller = controller_impl(); | 2155 NavigationControllerImpl& controller = controller_impl(); |
2148 TestNotificationTracker notifications; | 2156 TestNotificationTracker notifications; |
2149 RegisterForAllNavNotifications(¬ifications, &controller); | 2157 RegisterForAllNavNotifications(¬ifications, &controller); |
2150 | 2158 |
2151 const GURL url1("http://foo1"); | 2159 const GURL url1("http://foo1"); |
2152 const GURL url2("http://foo2"); | 2160 const GURL url2("http://foo2"); |
2153 | 2161 |
2154 main_test_rfh()->SendNavigate(0, url1); | 2162 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2155 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2163 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2156 navigation_entry_committed_counter_ = 0; | 2164 navigation_entry_committed_counter_ = 0; |
2157 | 2165 |
2158 main_test_rfh()->SendNavigate(1, url2); | 2166 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); |
2159 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2167 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2160 navigation_entry_committed_counter_ = 0; | 2168 navigation_entry_committed_counter_ = 0; |
2161 | 2169 |
2162 // Should not have produced a new session history entry. | 2170 // Should not have produced a new session history entry. |
2163 EXPECT_EQ(controller.GetEntryCount(), 2); | 2171 EXPECT_EQ(controller.GetEntryCount(), 2); |
2164 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2172 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2165 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2173 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2166 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2174 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2167 EXPECT_FALSE(controller.GetPendingEntry()); | 2175 EXPECT_FALSE(controller.GetPendingEntry()); |
2168 EXPECT_TRUE(controller.CanGoBack()); | 2176 EXPECT_TRUE(controller.CanGoBack()); |
2169 EXPECT_FALSE(controller.CanGoForward()); | 2177 EXPECT_FALSE(controller.CanGoForward()); |
2170 } | 2178 } |
2171 | 2179 |
2172 TEST_F(NavigationControllerTest, InPage) { | 2180 TEST_F(NavigationControllerTest, InPage) { |
2173 NavigationControllerImpl& controller = controller_impl(); | 2181 NavigationControllerImpl& controller = controller_impl(); |
2174 TestNotificationTracker notifications; | 2182 TestNotificationTracker notifications; |
2175 RegisterForAllNavNotifications(¬ifications, &controller); | 2183 RegisterForAllNavNotifications(¬ifications, &controller); |
2176 | 2184 |
2177 // Main page. | 2185 // Main page. |
2178 const GURL url1("http://foo"); | 2186 const GURL url1("http://foo"); |
2179 main_test_rfh()->SendNavigate(0, url1); | 2187 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2180 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2188 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2181 navigation_entry_committed_counter_ = 0; | 2189 navigation_entry_committed_counter_ = 0; |
2182 | 2190 |
2183 // Ensure main page navigation to same url respects the was_within_same_page | 2191 // Ensure main page navigation to same url respects the was_within_same_page |
2184 // hint provided in the params. | 2192 // hint provided in the params. |
2185 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; | 2193 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; |
2186 self_params.page_id = 0; | 2194 self_params.page_id = 0; |
2187 self_params.url = url1; | 2195 self_params.url = url1; |
2188 self_params.transition = ui::PAGE_TRANSITION_LINK; | 2196 self_params.transition = ui::PAGE_TRANSITION_LINK; |
2189 self_params.should_update_history = false; | 2197 self_params.should_update_history = false; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2286 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2279 } | 2287 } |
2280 | 2288 |
2281 TEST_F(NavigationControllerTest, InPage_Replace) { | 2289 TEST_F(NavigationControllerTest, InPage_Replace) { |
2282 NavigationControllerImpl& controller = controller_impl(); | 2290 NavigationControllerImpl& controller = controller_impl(); |
2283 TestNotificationTracker notifications; | 2291 TestNotificationTracker notifications; |
2284 RegisterForAllNavNotifications(¬ifications, &controller); | 2292 RegisterForAllNavNotifications(¬ifications, &controller); |
2285 | 2293 |
2286 // Main page. | 2294 // Main page. |
2287 const GURL url1("http://foo"); | 2295 const GURL url1("http://foo"); |
2288 main_test_rfh()->SendNavigate(0, url1); | 2296 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2289 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2297 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2290 navigation_entry_committed_counter_ = 0; | 2298 navigation_entry_committed_counter_ = 0; |
2291 | 2299 |
2292 // First navigation. | 2300 // First navigation. |
2293 const GURL url2("http://foo#a"); | 2301 const GURL url2("http://foo#a"); |
2294 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2302 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2295 params.page_id = 0; // Same page_id | 2303 params.page_id = 0; // Same page_id |
2296 params.url = url2; | 2304 params.url = url2; |
2297 params.transition = ui::PAGE_TRANSITION_LINK; | 2305 params.transition = ui::PAGE_TRANSITION_LINK; |
2298 params.should_update_history = false; | 2306 params.should_update_history = false; |
(...skipping 20 matching lines...) Expand all Loading... |
2319 // window.location='http://foo3/'; | 2327 // window.location='http://foo3/'; |
2320 // </script> | 2328 // </script> |
2321 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 2329 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
2322 NavigationControllerImpl& controller = controller_impl(); | 2330 NavigationControllerImpl& controller = controller_impl(); |
2323 TestNotificationTracker notifications; | 2331 TestNotificationTracker notifications; |
2324 RegisterForAllNavNotifications(¬ifications, &controller); | 2332 RegisterForAllNavNotifications(¬ifications, &controller); |
2325 | 2333 |
2326 // Load an initial page. | 2334 // Load an initial page. |
2327 { | 2335 { |
2328 const GURL url("http://foo/"); | 2336 const GURL url("http://foo/"); |
2329 main_test_rfh()->SendNavigate(0, url); | 2337 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
2330 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2338 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2331 navigation_entry_committed_counter_ = 0; | 2339 navigation_entry_committed_counter_ = 0; |
2332 } | 2340 } |
2333 | 2341 |
2334 // Navigate to a new page. | 2342 // Navigate to a new page. |
2335 { | 2343 { |
2336 const GURL url("http://foo2/"); | 2344 const GURL url("http://foo2/"); |
2337 main_test_rfh()->SendNavigate(1, url); | 2345 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url); |
2338 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2346 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2339 navigation_entry_committed_counter_ = 0; | 2347 navigation_entry_committed_counter_ = 0; |
2340 } | 2348 } |
2341 | 2349 |
2342 // Navigate within the page. | 2350 // Navigate within the page. |
2343 { | 2351 { |
2344 const GURL url("http://foo2/#a"); | 2352 const GURL url("http://foo2/#a"); |
2345 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2353 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2346 params.page_id = 1; // Same page_id | 2354 params.page_id = 1; // Same page_id |
2347 params.url = url; | 2355 params.url = url; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2385 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2393 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2386 navigation_entry_committed_counter_ = 0; | 2394 navigation_entry_committed_counter_ = 0; |
2387 EXPECT_FALSE(details.is_in_page); | 2395 EXPECT_FALSE(details.is_in_page); |
2388 EXPECT_EQ(3, controller.GetEntryCount()); | 2396 EXPECT_EQ(3, controller.GetEntryCount()); |
2389 } | 2397 } |
2390 | 2398 |
2391 // Verify that BACK brings us back to http://foo2/. | 2399 // Verify that BACK brings us back to http://foo2/. |
2392 { | 2400 { |
2393 const GURL url("http://foo2/"); | 2401 const GURL url("http://foo2/"); |
2394 controller.GoBack(); | 2402 controller.GoBack(); |
| 2403 main_test_rfh()->PrepareForCommit(); |
2395 main_test_rfh()->SendNavigate(1, url); | 2404 main_test_rfh()->SendNavigate(1, url); |
2396 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2405 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2397 navigation_entry_committed_counter_ = 0; | 2406 navigation_entry_committed_counter_ = 0; |
2398 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2407 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
2399 } | 2408 } |
2400 } | 2409 } |
2401 | 2410 |
2402 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) | 2411 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) |
2403 { | 2412 { |
2404 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); | 2413 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); |
2405 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2414 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2406 GURL url("http://foo"); | 2415 GURL url("http://foo"); |
2407 params.page_id = 1; | 2416 params.page_id = 1; |
2408 params.url = url; | 2417 params.url = url; |
2409 params.page_state = PageState::CreateFromURL(url); | 2418 params.page_state = PageState::CreateFromURL(url); |
2410 params.was_within_same_page = true; | 2419 params.was_within_same_page = true; |
| 2420 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
| 2421 main_test_rfh()->PrepareForCommit(); |
2411 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 2422 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
2412 // We pass if we don't crash. | 2423 // We pass if we don't crash. |
2413 } | 2424 } |
2414 | 2425 |
2415 // NotificationObserver implementation used in verifying we've received the | 2426 // NotificationObserver implementation used in verifying we've received the |
2416 // NOTIFICATION_NAV_LIST_PRUNED method. | 2427 // NOTIFICATION_NAV_LIST_PRUNED method. |
2417 class PrunedListener : public NotificationObserver { | 2428 class PrunedListener : public NotificationObserver { |
2418 public: | 2429 public: |
2419 explicit PrunedListener(NavigationControllerImpl* controller) | 2430 explicit PrunedListener(NavigationControllerImpl* controller) |
2420 : notification_count_(0) { | 2431 : notification_count_(0) { |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3003 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing | 3014 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing |
3004 // the virtual URL to differ from the URL. | 3015 // the virtual URL to differ from the URL. |
3005 controller.GetPendingEntry()->SetURL(url1_fixed); | 3016 controller.GetPendingEntry()->SetURL(url1_fixed); |
3006 controller.GetPendingEntry()->SetVirtualURL(url1); | 3017 controller.GetPendingEntry()->SetVirtualURL(url1); |
3007 | 3018 |
3008 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); | 3019 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); |
3009 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); | 3020 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); |
3010 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3021 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3011 | 3022 |
3012 // If the user clicks another link, we should replace the pending entry. | 3023 // If the user clicks another link, we should replace the pending entry. |
| 3024 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3025 main_test_rfh()->PrepareForCommit(); |
3013 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3026 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3014 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3027 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
3015 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3028 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
3016 | 3029 |
3017 // Once it commits, the URL and virtual URL should reflect the actual page. | 3030 // Once it commits, the URL and virtual URL should reflect the actual page. |
3018 main_test_rfh()->SendNavigate(0, url2); | 3031 main_test_rfh()->SendNavigate(0, url2); |
3019 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3032 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3020 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3033 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
3021 | 3034 |
3022 // We should not replace the pending entry for an error URL. | 3035 // We should not replace the pending entry for an error URL. |
3023 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3036 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3024 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3037 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3025 navigator->DidStartProvisionalLoad(main_test_rfh(), | 3038 navigator->DidStartProvisionalLoad(main_test_rfh(), |
3026 GURL(kUnreachableWebDataURL), false); | 3039 GURL(kUnreachableWebDataURL), false); |
3027 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3040 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3028 | 3041 |
3029 // We should remember if the pending entry will replace the current one. | 3042 // We should remember if the pending entry will replace the current one. |
3030 // http://crbug.com/308444. | 3043 // http://crbug.com/308444. |
3031 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3044 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3032 controller.GetPendingEntry()->set_should_replace_entry(true); | 3045 controller.GetPendingEntry()->set_should_replace_entry(true); |
| 3046 |
| 3047 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3048 main_test_rfh()->PrepareForCommit(); |
3033 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3049 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3034 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3050 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
3035 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need | |
3036 // to go through the RenderViewHost. The TestRenderViewHost routes navigations | |
3037 // to the main frame. | |
3038 main_test_rfh()->SendNavigate(0, url2); | 3051 main_test_rfh()->SendNavigate(0, url2); |
3039 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3052 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3040 } | 3053 } |
3041 | 3054 |
3042 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3055 // Tests that the URLs for renderer-initiated navigations are not displayed to |
3043 // the user until the navigation commits, to prevent URL spoof attacks. | 3056 // the user until the navigation commits, to prevent URL spoof attacks. |
3044 // See http://crbug.com/99016. | 3057 // See http://crbug.com/99016. |
3045 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3058 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
3046 NavigationControllerImpl& controller = controller_impl(); | 3059 NavigationControllerImpl& controller = controller_impl(); |
3047 TestNotificationTracker notifications; | 3060 TestNotificationTracker notifications; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3228 NavigationController::LoadURLParams load_url_params(url1); | 3241 NavigationController::LoadURLParams load_url_params(url1); |
3229 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3242 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3230 load_url_params.is_renderer_initiated = true; | 3243 load_url_params.is_renderer_initiated = true; |
3231 controller.LoadURLWithParams(load_url_params); | 3244 controller.LoadURLWithParams(load_url_params); |
3232 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3245 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3233 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3246 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3234 EXPECT_TRUE(controller.IsInitialNavigation()); | 3247 EXPECT_TRUE(controller.IsInitialNavigation()); |
3235 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3248 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3236 | 3249 |
3237 // Simulate a commit and then starting a new pending navigation. | 3250 // Simulate a commit and then starting a new pending navigation. |
| 3251 main_test_rfh()->PrepareForCommit(); |
3238 main_test_rfh()->SendNavigate(0, url1); | 3252 main_test_rfh()->SendNavigate(0, url1); |
3239 NavigationController::LoadURLParams load_url2_params(url2); | 3253 NavigationController::LoadURLParams load_url2_params(url2); |
3240 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3254 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3241 load_url2_params.is_renderer_initiated = true; | 3255 load_url2_params.is_renderer_initiated = true; |
3242 controller.LoadURLWithParams(load_url2_params); | 3256 controller.LoadURLWithParams(load_url2_params); |
3243 | 3257 |
3244 // We should not consider this an initial navigation, and thus should | 3258 // We should not consider this an initial navigation, and thus should |
3245 // not show the pending URL. | 3259 // not show the pending URL. |
3246 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3260 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3247 EXPECT_FALSE(controller.IsInitialNavigation()); | 3261 EXPECT_FALSE(controller.IsInitialNavigation()); |
(...skipping 10 matching lines...) Expand all Loading... |
3258 const GURL url("http://www.google.com/home.html"); | 3272 const GURL url("http://www.google.com/home.html"); |
3259 | 3273 |
3260 // If the renderer claims it performed an in-page navigation from | 3274 // If the renderer claims it performed an in-page navigation from |
3261 // about:blank, trust the renderer. | 3275 // about:blank, trust the renderer. |
3262 // This can happen when an iframe is created and populated via | 3276 // This can happen when an iframe is created and populated via |
3263 // document.write(), then tries to perform a fragment navigation. | 3277 // document.write(), then tries to perform a fragment navigation. |
3264 // TODO(japhet): We should only trust the renderer if the about:blank | 3278 // TODO(japhet): We should only trust the renderer if the about:blank |
3265 // was the first document in the given frame, but we don't have enough | 3279 // was the first document in the given frame, but we don't have enough |
3266 // information to identify that case currently. | 3280 // information to identify that case currently. |
3267 const GURL blank_url(url::kAboutBlankURL); | 3281 const GURL blank_url(url::kAboutBlankURL); |
3268 main_test_rfh()->SendNavigate(0, blank_url); | 3282 main_test_rfh()->NavigateAndCommitRendererInitiated(0, blank_url); |
3269 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3283 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3270 main_test_rfh())); | 3284 main_test_rfh())); |
3271 | 3285 |
3272 // Navigate to URL with no refs. | 3286 // Navigate to URL with no refs. |
3273 main_test_rfh()->SendNavigate(0, url); | 3287 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3274 | 3288 |
3275 // Reloading the page is not an in-page navigation. | 3289 // Reloading the page is not an in-page navigation. |
3276 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3290 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3277 main_test_rfh())); | 3291 main_test_rfh())); |
3278 const GURL other_url("http://www.google.com/add.html"); | 3292 const GURL other_url("http://www.google.com/add.html"); |
3279 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3293 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3280 main_test_rfh())); | 3294 main_test_rfh())); |
3281 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3295 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3282 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3296 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3283 main_test_rfh())); | 3297 main_test_rfh())); |
3284 | 3298 |
3285 // Navigate to URL with refs. | 3299 // Navigate to URL with refs. |
3286 main_test_rfh()->SendNavigate(1, url_with_ref); | 3300 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url_with_ref); |
3287 | 3301 |
3288 // Reloading the page is not an in-page navigation. | 3302 // Reloading the page is not an in-page navigation. |
3289 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, | 3303 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3290 main_test_rfh())); | 3304 main_test_rfh())); |
3291 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3305 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3292 main_test_rfh())); | 3306 main_test_rfh())); |
3293 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3307 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3294 main_test_rfh())); | 3308 main_test_rfh())); |
3295 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3309 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3296 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, | 3310 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
(...skipping 18 matching lines...) Expand all Loading... |
3315 const GURL different_origin_url("http://www.example.com"); | 3329 const GURL different_origin_url("http://www.example.com"); |
3316 MockRenderProcessHost* rph = | 3330 MockRenderProcessHost* rph = |
3317 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); | 3331 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); |
3318 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); | 3332 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); |
3319 prefs.allow_universal_access_from_file_urls = true; | 3333 prefs.allow_universal_access_from_file_urls = true; |
3320 test_rvh()->UpdateWebkitPreferences(prefs); | 3334 test_rvh()->UpdateWebkitPreferences(prefs); |
3321 prefs = test_rvh()->GetWebkitPreferences(); | 3335 prefs = test_rvh()->GetWebkitPreferences(); |
3322 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); | 3336 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); |
3323 // Allow in page navigation if existing URL is file scheme. | 3337 // Allow in page navigation if existing URL is file scheme. |
3324 const GURL file_url("file:///foo/index.html"); | 3338 const GURL file_url("file:///foo/index.html"); |
3325 main_test_rfh()->SendNavigate(0, file_url); | 3339 main_test_rfh()->NavigateAndCommitRendererInitiated(0, file_url); |
3326 EXPECT_EQ(0, rph->bad_msg_count()); | 3340 EXPECT_EQ(0, rph->bad_msg_count()); |
3327 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, | 3341 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, |
3328 main_test_rfh())); | 3342 main_test_rfh())); |
3329 EXPECT_EQ(0, rph->bad_msg_count()); | 3343 EXPECT_EQ(0, rph->bad_msg_count()); |
3330 // Don't honor allow_universal_access_from_file_urls if existing URL is | 3344 // Don't honor allow_universal_access_from_file_urls if existing URL is |
3331 // not file scheme. | 3345 // not file scheme. |
3332 main_test_rfh()->SendNavigate(0, url); | 3346 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3333 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3347 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3334 main_test_rfh())); | 3348 main_test_rfh())); |
3335 EXPECT_EQ(1, rph->bad_msg_count()); | 3349 EXPECT_EQ(1, rph->bad_msg_count()); |
3336 | 3350 |
3337 // Remove allow_universal_access_from_file_urls flag. | 3351 // Remove allow_universal_access_from_file_urls flag. |
3338 prefs.allow_universal_access_from_file_urls = false; | 3352 prefs.allow_universal_access_from_file_urls = false; |
3339 test_rvh()->UpdateWebkitPreferences(prefs); | 3353 test_rvh()->UpdateWebkitPreferences(prefs); |
3340 prefs = test_rvh()->GetWebkitPreferences(); | 3354 prefs = test_rvh()->GetWebkitPreferences(); |
3341 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); | 3355 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); |
3342 | 3356 |
3343 // Don't believe the renderer if it claims a cross-origin navigation is | 3357 // Don't believe the renderer if it claims a cross-origin navigation is |
3344 // in-page. | 3358 // in-page. |
3345 EXPECT_EQ(1, rph->bad_msg_count()); | 3359 EXPECT_EQ(1, rph->bad_msg_count()); |
3346 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3360 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3347 main_test_rfh())); | 3361 main_test_rfh())); |
3348 EXPECT_EQ(2, rph->bad_msg_count()); | 3362 EXPECT_EQ(2, rph->bad_msg_count()); |
3349 } | 3363 } |
3350 | 3364 |
3351 // Some pages can have subframes with the same base URL (minus the reference) as | 3365 // Some pages can have subframes with the same base URL (minus the reference) as |
3352 // the main page. Even though this is hard, it can happen, and we don't want | 3366 // the main page. Even though this is hard, it can happen, and we don't want |
3353 // these subframe navigations to affect the toplevel document. They should | 3367 // these subframe navigations to affect the toplevel document. They should |
3354 // instead be ignored. http://crbug.com/5585 | 3368 // instead be ignored. http://crbug.com/5585 |
3355 TEST_F(NavigationControllerTest, SameSubframe) { | 3369 TEST_F(NavigationControllerTest, SameSubframe) { |
3356 NavigationControllerImpl& controller = controller_impl(); | 3370 NavigationControllerImpl& controller = controller_impl(); |
3357 // Navigate the main frame. | 3371 // Navigate the main frame. |
3358 const GURL url("http://www.google.com/"); | 3372 const GURL url("http://www.google.com/"); |
3359 main_test_rfh()->SendNavigate(0, url); | 3373 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3360 | 3374 |
3361 // We should be at the first navigation entry. | 3375 // We should be at the first navigation entry. |
3362 EXPECT_EQ(controller.GetEntryCount(), 1); | 3376 EXPECT_EQ(controller.GetEntryCount(), 1); |
3363 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 3377 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
3364 | 3378 |
3365 // Navigate a subframe that would normally count as in-page. | 3379 // Navigate a subframe that would normally count as in-page. |
3366 const GURL subframe("http://www.google.com/#"); | 3380 const GURL subframe("http://www.google.com/#"); |
3367 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3381 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3368 params.page_id = 0; | 3382 params.page_id = 0; |
3369 params.url = subframe; | 3383 params.url = subframe; |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4240 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 4254 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
4241 NavigationControllerImpl& controller = controller_impl(); | 4255 NavigationControllerImpl& controller = controller_impl(); |
4242 TestNotificationTracker notifications; | 4256 TestNotificationTracker notifications; |
4243 RegisterForAllNavNotifications(¬ifications, &controller); | 4257 RegisterForAllNavNotifications(¬ifications, &controller); |
4244 | 4258 |
4245 // Initial state. | 4259 // Initial state. |
4246 EXPECT_TRUE(controller.IsInitialNavigation()); | 4260 EXPECT_TRUE(controller.IsInitialNavigation()); |
4247 | 4261 |
4248 // After commit, it stays false. | 4262 // After commit, it stays false. |
4249 const GURL url1("http://foo1"); | 4263 const GURL url1("http://foo1"); |
4250 main_test_rfh()->SendNavigate(0, url1); | 4264 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
4251 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4265 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4252 navigation_entry_committed_counter_ = 0; | 4266 navigation_entry_committed_counter_ = 0; |
4253 EXPECT_FALSE(controller.IsInitialNavigation()); | 4267 EXPECT_FALSE(controller.IsInitialNavigation()); |
4254 | 4268 |
4255 // After starting a new navigation, it stays false. | 4269 // After starting a new navigation, it stays false. |
4256 const GURL url2("http://foo2"); | 4270 const GURL url2("http://foo2"); |
4257 controller.LoadURL( | 4271 controller.LoadURL( |
4258 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4272 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
4259 } | 4273 } |
4260 | 4274 |
4261 // Check that the favicon is not reused across a client redirect. | 4275 // Check that the favicon is not reused across a client redirect. |
4262 // (crbug.com/28515) | 4276 // (crbug.com/28515) |
4263 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 4277 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
4264 const GURL kPageWithFavicon("http://withfavicon.html"); | 4278 const GURL kPageWithFavicon("http://withfavicon.html"); |
4265 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 4279 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
4266 const GURL kIconURL("http://withfavicon.ico"); | 4280 const GURL kIconURL("http://withfavicon.ico"); |
4267 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 4281 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
4268 | 4282 |
4269 NavigationControllerImpl& controller = controller_impl(); | 4283 NavigationControllerImpl& controller = controller_impl(); |
4270 TestNotificationTracker notifications; | 4284 TestNotificationTracker notifications; |
4271 RegisterForAllNavNotifications(¬ifications, &controller); | 4285 RegisterForAllNavNotifications(¬ifications, &controller); |
4272 | 4286 |
4273 main_test_rfh()->SendNavigate(0, kPageWithFavicon); | 4287 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kPageWithFavicon); |
4274 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4288 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4275 navigation_entry_committed_counter_ = 0; | 4289 navigation_entry_committed_counter_ = 0; |
4276 | 4290 |
4277 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4291 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4278 EXPECT_TRUE(entry); | 4292 EXPECT_TRUE(entry); |
4279 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 4293 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
4280 | 4294 |
4281 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 4295 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
4282 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4296 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4283 favicon_status.image = CreateImage(SK_ColorWHITE); | 4297 favicon_status.image = CreateImage(SK_ColorWHITE); |
4284 favicon_status.url = kIconURL; | 4298 favicon_status.url = kIconURL; |
4285 favicon_status.valid = true; | 4299 favicon_status.valid = true; |
4286 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4300 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4287 | 4301 |
| 4302 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, |
| 4303 false); |
| 4304 main_test_rfh()->PrepareForCommit(); |
4288 main_test_rfh()->SendNavigateWithTransition( | 4305 main_test_rfh()->SendNavigateWithTransition( |
4289 0, // same page ID. | 4306 0, // same page ID. |
4290 kPageWithoutFavicon, | 4307 kPageWithoutFavicon, |
4291 ui::PAGE_TRANSITION_CLIENT_REDIRECT); | 4308 ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
4292 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4309 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4293 navigation_entry_committed_counter_ = 0; | 4310 navigation_entry_committed_counter_ = 0; |
4294 | 4311 |
4295 entry = controller.GetLastCommittedEntry(); | 4312 entry = controller.GetLastCommittedEntry(); |
4296 EXPECT_TRUE(entry); | 4313 EXPECT_TRUE(entry); |
4297 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 4314 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
4298 | 4315 |
4299 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4316 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4300 } | 4317 } |
4301 | 4318 |
4302 // Check that the favicon is not cleared for NavigationEntries which were | 4319 // Check that the favicon is not cleared for NavigationEntries which were |
4303 // previously navigated to. | 4320 // previously navigated to. |
4304 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 4321 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
4305 const GURL kUrl1("http://www.a.com/1"); | 4322 const GURL kUrl1("http://www.a.com/1"); |
4306 const GURL kUrl2("http://www.a.com/2"); | 4323 const GURL kUrl2("http://www.a.com/2"); |
4307 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 4324 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
4308 | 4325 |
4309 NavigationControllerImpl& controller = controller_impl(); | 4326 NavigationControllerImpl& controller = controller_impl(); |
4310 TestNotificationTracker notifications; | 4327 TestNotificationTracker notifications; |
4311 RegisterForAllNavNotifications(¬ifications, &controller); | 4328 RegisterForAllNavNotifications(¬ifications, &controller); |
4312 | 4329 |
4313 main_test_rfh()->SendNavigate(0, kUrl1); | 4330 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); |
4314 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4331 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4315 navigation_entry_committed_counter_ = 0; | 4332 navigation_entry_committed_counter_ = 0; |
4316 | 4333 |
4317 // Simulate Chromium having set the favicon for |kUrl1|. | 4334 // Simulate Chromium having set the favicon for |kUrl1|. |
4318 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); | 4335 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); |
4319 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4336 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4320 EXPECT_TRUE(entry); | 4337 EXPECT_TRUE(entry); |
4321 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4338 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4322 favicon_status.image = favicon_image; | 4339 favicon_status.image = favicon_image; |
4323 favicon_status.url = kIconURL; | 4340 favicon_status.url = kIconURL; |
4324 favicon_status.valid = true; | 4341 favicon_status.valid = true; |
4325 | 4342 |
4326 // Navigate to another page and go back to the original page. | 4343 // Navigate to another page and go back to the original page. |
4327 main_test_rfh()->SendNavigate(1, kUrl2); | 4344 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); |
4328 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4345 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4329 navigation_entry_committed_counter_ = 0; | 4346 navigation_entry_committed_counter_ = 0; |
| 4347 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); |
| 4348 main_test_rfh()->PrepareForCommit(); |
4330 main_test_rfh()->SendNavigateWithTransition( | 4349 main_test_rfh()->SendNavigateWithTransition( |
4331 0, | 4350 0, |
4332 kUrl1, | 4351 kUrl1, |
4333 ui::PAGE_TRANSITION_FORWARD_BACK); | 4352 ui::PAGE_TRANSITION_FORWARD_BACK); |
4334 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4353 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4335 navigation_entry_committed_counter_ = 0; | 4354 navigation_entry_committed_counter_ = 0; |
4336 | 4355 |
4337 // Verify that the favicon for the page at |kUrl1| was not cleared. | 4356 // Verify that the favicon for the page at |kUrl1| was not cleared. |
4338 entry = controller.GetEntryAtIndex(0); | 4357 entry = controller.GetEntryAtIndex(0); |
4339 EXPECT_TRUE(entry); | 4358 EXPECT_TRUE(entry); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4423 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); | 4442 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); |
4424 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4443 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
4425 entry = controller.GetEntryAtIndex(i); | 4444 entry = controller.GetEntryAtIndex(i); |
4426 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4445 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4427 << " not cleared"; | 4446 << " not cleared"; |
4428 } | 4447 } |
4429 } | 4448 } |
4430 | 4449 |
4431 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { | 4450 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { |
4432 // Navigate. | 4451 // Navigate. |
4433 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo")); | 4452 main_test_rfh()->NavigateAndCommitRendererInitiated(1, GURL("http://foo")); |
4434 | 4453 |
4435 // Set title and favicon. | 4454 // Set title and favicon. |
4436 base::string16 title(base::ASCIIToUTF16("Title")); | 4455 base::string16 title(base::ASCIIToUTF16("Title")); |
4437 FaviconStatus favicon; | 4456 FaviconStatus favicon; |
4438 favicon.valid = true; | 4457 favicon.valid = true; |
4439 favicon.url = GURL("http://foo/favicon.ico"); | 4458 favicon.url = GURL("http://foo/favicon.ico"); |
4440 controller().GetLastCommittedEntry()->SetTitle(title); | 4459 controller().GetLastCommittedEntry()->SetTitle(title); |
4441 controller().GetLastCommittedEntry()->GetFavicon() = favicon; | 4460 controller().GetLastCommittedEntry()->GetFavicon() = favicon; |
4442 | 4461 |
4443 // history.pushState() is called. | 4462 // history.pushState() is called. |
4444 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4463 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4445 GURL url("http://foo#foo"); | 4464 GURL kUrl2("http://foo#foo"); |
4446 params.page_id = 2; | 4465 params.page_id = 2; |
4447 params.url = url; | 4466 params.url = kUrl2; |
4448 params.page_state = PageState::CreateFromURL(url); | 4467 params.page_state = PageState::CreateFromURL(kUrl2); |
4449 params.was_within_same_page = true; | 4468 params.was_within_same_page = true; |
4450 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4469 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); |
| 4470 main_test_rfh()->PrepareForCommit(); |
| 4471 main_test_rfh()->SendNavigateWithParams(¶ms); |
4451 | 4472 |
4452 // The title should immediately be visible on the new NavigationEntry. | 4473 // The title should immediately be visible on the new NavigationEntry. |
4453 base::string16 new_title = | 4474 base::string16 new_title = |
4454 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); | 4475 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); |
4455 EXPECT_EQ(title, new_title); | 4476 EXPECT_EQ(title, new_title); |
4456 FaviconStatus new_favicon = | 4477 FaviconStatus new_favicon = |
4457 controller().GetLastCommittedEntry()->GetFavicon(); | 4478 controller().GetLastCommittedEntry()->GetFavicon(); |
4458 EXPECT_EQ(favicon.valid, new_favicon.valid); | 4479 EXPECT_EQ(favicon.valid, new_favicon.valid); |
4459 EXPECT_EQ(favicon.url, new_favicon.url); | 4480 EXPECT_EQ(favicon.url, new_favicon.url); |
4460 } | 4481 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4520 GURL url("http://foo"); | 4541 GURL url("http://foo"); |
4521 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4542 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4522 params.page_id = 1; | 4543 params.page_id = 1; |
4523 params.url = url; | 4544 params.url = url; |
4524 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; | 4545 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; |
4525 params.gesture = NavigationGestureUser; | 4546 params.gesture = NavigationGestureUser; |
4526 params.page_state = PageState::CreateFromURL(url); | 4547 params.page_state = PageState::CreateFromURL(url); |
4527 params.was_within_same_page = false; | 4548 params.was_within_same_page = false; |
4528 params.is_post = true; | 4549 params.is_post = true; |
4529 params.post_id = 2; | 4550 params.post_id = 2; |
| 4551 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
| 4552 main_test_rfh()->PrepareForCommit(); |
4530 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4553 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4531 | 4554 |
4532 // history.replaceState() is called. | 4555 // history.replaceState() is called. |
4533 GURL replace_url("http://foo#foo"); | 4556 GURL replace_url("http://foo#foo"); |
4534 params.page_id = 1; | 4557 params.page_id = 1; |
4535 params.url = replace_url; | 4558 params.url = replace_url; |
4536 params.transition = ui::PAGE_TRANSITION_LINK; | 4559 params.transition = ui::PAGE_TRANSITION_LINK; |
4537 params.gesture = NavigationGestureUser; | 4560 params.gesture = NavigationGestureUser; |
4538 params.page_state = PageState::CreateFromURL(replace_url); | 4561 params.page_state = PageState::CreateFromURL(replace_url); |
4539 params.was_within_same_page = true; | 4562 params.was_within_same_page = true; |
4540 params.is_post = false; | 4563 params.is_post = false; |
4541 params.post_id = -1; | 4564 params.post_id = -1; |
| 4565 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); |
| 4566 main_test_rfh()->PrepareForCommit(); |
4542 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4567 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4543 | 4568 |
4544 // Now reload. replaceState overrides the POST, so we should not show a | 4569 // Now reload. replaceState overrides the POST, so we should not show a |
4545 // repost warning dialog. | 4570 // repost warning dialog. |
4546 controller_impl().Reload(true); | 4571 controller_impl().Reload(true); |
4547 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4572 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4548 } | 4573 } |
4549 | 4574 |
4550 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { | 4575 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
4551 GURL url("http://foo"); | 4576 GURL url("http://foo"); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4598 { | 4623 { |
4599 LoadCommittedDetails details; | 4624 LoadCommittedDetails details; |
4600 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4625 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4601 EXPECT_EQ(PAGE_TYPE_ERROR, | 4626 EXPECT_EQ(PAGE_TYPE_ERROR, |
4602 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4627 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4603 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4628 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
4604 } | 4629 } |
4605 } | 4630 } |
4606 | 4631 |
4607 } // namespace content | 4632 } // namespace content |
OLD | NEW |