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