OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 // These are only used for commented out tests. If someone wants to enable | 11 // These are only used for commented out tests. If someone wants to enable |
12 // them, they should be moved to chrome first. | 12 // them, they should be moved to chrome first. |
13 // #include "chrome/browser/history/history.h" | 13 // #include "chrome/browser/history/history.h" |
14 // #include "chrome/browser/profiles/profile_manager.h" | 14 // #include "chrome/browser/profiles/profile_manager.h" |
15 // #include "chrome/browser/sessions/session_service.h" | 15 // #include "chrome/browser/sessions/session_service.h" |
16 // #include "chrome/browser/sessions/session_service_factory.h" | 16 // #include "chrome/browser/sessions/session_service_factory.h" |
17 // #include "chrome/browser/sessions/session_service_test_helper.h" | 17 // #include "chrome/browser/sessions/session_service_test_helper.h" |
18 // #include "chrome/browser/sessions/session_types.h" | 18 // #include "chrome/browser/sessions/session_types.h" |
19 #include "content/browser/renderer_host/test_render_view_host.h" | 19 #include "content/browser/renderer_host/test_render_view_host.h" |
20 #include "content/browser/site_instance.h" | 20 #include "content/browser/site_instance.h" |
21 #include "content/browser/tab_contents/navigation_controller.h" | 21 #include "content/browser/tab_contents/navigation_controller.h" |
22 #include "content/browser/tab_contents/navigation_entry.h" | 22 #include "content/browser/tab_contents/navigation_entry_impl.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/browser/tab_contents/test_tab_contents.h" | 24 #include "content/browser/tab_contents/test_tab_contents.h" |
25 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
26 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
27 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
30 #include "content/test/test_browser_context.h" | 30 #include "content/test/test_browser_context.h" |
31 #include "content/test/test_notification_tracker.h" | 31 #include "content/test/test_notification_tracker.h" |
32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
35 | 35 |
36 using base::Time; | 36 using base::Time; |
| 37 using content::NavigationEntry; |
| 38 using content::NavigationEntryImpl; |
37 | 39 |
38 // NavigationControllerTest ---------------------------------------------------- | 40 // NavigationControllerTest ---------------------------------------------------- |
39 | 41 |
40 class NavigationControllerTest : public RenderViewHostTestHarness { | 42 class NavigationControllerTest : public RenderViewHostTestHarness { |
41 public: | 43 public: |
42 NavigationControllerTest() {} | 44 NavigationControllerTest() {} |
43 }; | 45 }; |
44 | 46 |
45 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 47 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
46 NavigationController* controller) { | 48 NavigationController* controller) { |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 // First navigate three places so we have some back history. | 722 // First navigate three places so we have some back history. |
721 rvh()->SendNavigate(0, kUrl1); | 723 rvh()->SendNavigate(0, kUrl1); |
722 rvh()->SendNavigate(1, kUrl2); | 724 rvh()->SendNavigate(1, kUrl2); |
723 rvh()->SendNavigate(2, kUrl3); | 725 rvh()->SendNavigate(2, kUrl3); |
724 | 726 |
725 // With nothing pending, say we get a navigation to the second entry. | 727 // With nothing pending, say we get a navigation to the second entry. |
726 rvh()->SendNavigate(1, kUrl2); | 728 rvh()->SendNavigate(1, kUrl2); |
727 | 729 |
728 // We know all the entries have the same site instance, so we can just grab | 730 // We know all the entries have the same site instance, so we can just grab |
729 // a random one for looking up other entries. | 731 // a random one for looking up other entries. |
730 SiteInstance* site_instance = NavigationEntry::FromNavigationEntry( | 732 SiteInstance* site_instance = NavigationEntryImpl::FromNavigationEntry( |
731 controller().GetLastCommittedEntry())->site_instance(); | 733 controller().GetLastCommittedEntry())->site_instance(); |
732 | 734 |
733 // That second URL should be the last committed and it should have gotten the | 735 // That second URL should be the last committed and it should have gotten the |
734 // new title. | 736 // new title. |
735 EXPECT_EQ(kUrl2, controller().GetEntryWithPageID(site_instance, 1)->GetURL()); | 737 EXPECT_EQ(kUrl2, controller().GetEntryWithPageID(site_instance, 1)->GetURL()); |
736 EXPECT_EQ(1, controller().last_committed_entry_index()); | 738 EXPECT_EQ(1, controller().last_committed_entry_index()); |
737 EXPECT_EQ(-1, controller().pending_entry_index()); | 739 EXPECT_EQ(-1, controller().pending_entry_index()); |
738 | 740 |
739 // Now go forward to the last item again and say it was committed. | 741 // Now go forward to the last item again and say it was committed. |
740 controller().GoForward(); | 742 controller().GoForward(); |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1470 |
1469 NavigationController::set_max_entry_count_for_testing(original_count); | 1471 NavigationController::set_max_entry_count_for_testing(original_count); |
1470 } | 1472 } |
1471 | 1473 |
1472 // Tests that we can do a restore and navigate to the restored entries and | 1474 // Tests that we can do a restore and navigate to the restored entries and |
1473 // everything is updated properly. This can be tricky since there is no | 1475 // everything is updated properly. This can be tricky since there is no |
1474 // SiteInstance for the entries created initially. | 1476 // SiteInstance for the entries created initially. |
1475 TEST_F(NavigationControllerTest, RestoreNavigate) { | 1477 TEST_F(NavigationControllerTest, RestoreNavigate) { |
1476 // Create a NavigationController with a restored set of tabs. | 1478 // Create a NavigationController with a restored set of tabs. |
1477 GURL url("http://foo"); | 1479 GURL url("http://foo"); |
1478 std::vector<content::NavigationEntry*> entries; | 1480 std::vector<NavigationEntry*> entries; |
1479 NavigationEntry* entry = NavigationController::CreateNavigationEntryImpl( | 1481 NavigationEntry* entry = NavigationController::CreateNavigationEntryImpl( |
1480 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, | 1482 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, |
1481 std::string(), browser_context()); | 1483 std::string(), browser_context()); |
1482 entry->SetPageID(0); | 1484 entry->SetPageID(0); |
1483 entry->SetTitle(ASCIIToUTF16("Title")); | 1485 entry->SetTitle(ASCIIToUTF16("Title")); |
1484 entry->SetContentState("state"); | 1486 entry->SetContentState("state"); |
1485 entries.push_back(entry); | 1487 entries.push_back(entry); |
1486 TabContents our_contents( | 1488 TabContents our_contents( |
1487 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1489 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
1488 NavigationController& our_controller = our_contents.GetController(); | 1490 NavigationController& our_controller = our_contents.GetController(); |
1489 our_controller.Restore(0, true, &entries); | 1491 our_controller.Restore(0, true, &entries); |
1490 ASSERT_EQ(0u, entries.size()); | 1492 ASSERT_EQ(0u, entries.size()); |
1491 | 1493 |
1492 // Before navigating to the restored entry, it should have a restore_type | 1494 // Before navigating to the restored entry, it should have a restore_type |
1493 // and no SiteInstance. | 1495 // and no SiteInstance. |
1494 EXPECT_EQ(NavigationEntry::RESTORE_LAST_SESSION, | 1496 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION, |
1495 NavigationEntry::FromNavigationEntry( | 1497 NavigationEntryImpl::FromNavigationEntry( |
1496 our_controller.GetEntryAtIndex(0))->restore_type()); | 1498 our_controller.GetEntryAtIndex(0))->restore_type()); |
1497 EXPECT_FALSE(NavigationEntry::FromNavigationEntry( | 1499 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( |
1498 our_controller.GetEntryAtIndex(0))->site_instance()); | 1500 our_controller.GetEntryAtIndex(0))->site_instance()); |
1499 | 1501 |
1500 // After navigating, we should have one entry, and it should be "pending". | 1502 // After navigating, we should have one entry, and it should be "pending". |
1501 // It should now have a SiteInstance and no restore_type. | 1503 // It should now have a SiteInstance and no restore_type. |
1502 our_controller.GoToIndex(0); | 1504 our_controller.GoToIndex(0); |
1503 EXPECT_EQ(1, our_controller.entry_count()); | 1505 EXPECT_EQ(1, our_controller.entry_count()); |
1504 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 1506 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
1505 our_controller.GetPendingEntry()); | 1507 our_controller.GetPendingEntry()); |
1506 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 1508 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
1507 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1509 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1508 NavigationEntry::FromNavigationEntry | 1510 NavigationEntryImpl::FromNavigationEntry |
1509 (our_controller.GetEntryAtIndex(0))->restore_type()); | 1511 (our_controller.GetEntryAtIndex(0))->restore_type()); |
1510 EXPECT_TRUE(NavigationEntry::FromNavigationEntry( | 1512 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( |
1511 our_controller.GetEntryAtIndex(0))->site_instance()); | 1513 our_controller.GetEntryAtIndex(0))->site_instance()); |
1512 | 1514 |
1513 // Say we navigated to that entry. | 1515 // Say we navigated to that entry. |
1514 ViewHostMsg_FrameNavigate_Params params; | 1516 ViewHostMsg_FrameNavigate_Params params; |
1515 params.page_id = 0; | 1517 params.page_id = 0; |
1516 params.url = url; | 1518 params.url = url; |
1517 params.transition = content::PAGE_TRANSITION_LINK; | 1519 params.transition = content::PAGE_TRANSITION_LINK; |
1518 params.should_update_history = false; | 1520 params.should_update_history = false; |
1519 params.gesture = NavigationGestureUser; | 1521 params.gesture = NavigationGestureUser; |
1520 params.is_post = false; | 1522 params.is_post = false; |
1521 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1523 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1522 content::LoadCommittedDetails details; | 1524 content::LoadCommittedDetails details; |
1523 our_controller.RendererDidNavigate(params, &details); | 1525 our_controller.RendererDidNavigate(params, &details); |
1524 | 1526 |
1525 // There should be no longer any pending entry and one committed one. This | 1527 // There should be no longer any pending entry and one committed one. This |
1526 // means that we were able to locate the entry, assign its site instance, and | 1528 // means that we were able to locate the entry, assign its site instance, and |
1527 // commit it properly. | 1529 // commit it properly. |
1528 EXPECT_EQ(1, our_controller.entry_count()); | 1530 EXPECT_EQ(1, our_controller.entry_count()); |
1529 EXPECT_EQ(0, our_controller.last_committed_entry_index()); | 1531 EXPECT_EQ(0, our_controller.last_committed_entry_index()); |
1530 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1532 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1531 EXPECT_EQ(url, | 1533 EXPECT_EQ(url, |
1532 NavigationEntry::FromNavigationEntry( | 1534 NavigationEntryImpl::FromNavigationEntry( |
1533 our_controller.GetLastCommittedEntry())->site_instance()-> | 1535 our_controller.GetLastCommittedEntry())->site_instance()-> |
1534 site()); | 1536 site()); |
1535 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1537 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1536 NavigationEntry::FromNavigationEntry( | 1538 NavigationEntryImpl::FromNavigationEntry( |
1537 our_controller.GetEntryAtIndex(0))->restore_type()); | 1539 our_controller.GetEntryAtIndex(0))->restore_type()); |
1538 } | 1540 } |
1539 | 1541 |
1540 // Tests that we can still navigate to a restored entry after a different | 1542 // Tests that we can still navigate to a restored entry after a different |
1541 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1543 // navigation fails and clears the pending entry. http://crbug.com/90085 |
1542 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1544 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
1543 // Create a NavigationController with a restored set of tabs. | 1545 // Create a NavigationController with a restored set of tabs. |
1544 GURL url("http://foo"); | 1546 GURL url("http://foo"); |
1545 std::vector<content::NavigationEntry*> entries; | 1547 std::vector<NavigationEntry*> entries; |
1546 NavigationEntry* entry = NavigationController::CreateNavigationEntryImpl( | 1548 NavigationEntry* entry = NavigationController::CreateNavigationEntryImpl( |
1547 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, | 1549 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, |
1548 std::string(), browser_context()); | 1550 std::string(), browser_context()); |
1549 entry->SetPageID(0); | 1551 entry->SetPageID(0); |
1550 entry->SetTitle(ASCIIToUTF16("Title")); | 1552 entry->SetTitle(ASCIIToUTF16("Title")); |
1551 entry->SetContentState("state"); | 1553 entry->SetContentState("state"); |
1552 entries.push_back(entry); | 1554 entries.push_back(entry); |
1553 TabContents our_contents( | 1555 TabContents our_contents( |
1554 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1556 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
1555 NavigationController& our_controller = our_contents.GetController(); | 1557 NavigationController& our_controller = our_contents.GetController(); |
1556 our_controller.Restore(0, true, &entries); | 1558 our_controller.Restore(0, true, &entries); |
1557 ASSERT_EQ(0u, entries.size()); | 1559 ASSERT_EQ(0u, entries.size()); |
1558 | 1560 |
1559 // Before navigating to the restored entry, it should have a restore_type | 1561 // Before navigating to the restored entry, it should have a restore_type |
1560 // and no SiteInstance. | 1562 // and no SiteInstance. |
1561 EXPECT_EQ(NavigationEntry::RESTORE_LAST_SESSION, | 1563 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION, |
1562 NavigationEntry::FromNavigationEntry( | 1564 NavigationEntryImpl::FromNavigationEntry( |
1563 our_controller.GetEntryAtIndex(0))->restore_type()); | 1565 our_controller.GetEntryAtIndex(0))->restore_type()); |
1564 EXPECT_FALSE(NavigationEntry::FromNavigationEntry( | 1566 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( |
1565 our_controller.GetEntryAtIndex(0))->site_instance()); | 1567 our_controller.GetEntryAtIndex(0))->site_instance()); |
1566 | 1568 |
1567 // After navigating, we should have one entry, and it should be "pending". | 1569 // After navigating, we should have one entry, and it should be "pending". |
1568 // It should now have a SiteInstance and no restore_type. | 1570 // It should now have a SiteInstance and no restore_type. |
1569 our_controller.GoToIndex(0); | 1571 our_controller.GoToIndex(0); |
1570 EXPECT_EQ(1, our_controller.entry_count()); | 1572 EXPECT_EQ(1, our_controller.entry_count()); |
1571 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 1573 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
1572 our_controller.GetPendingEntry()); | 1574 our_controller.GetPendingEntry()); |
1573 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 1575 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
1574 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1576 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1575 NavigationEntry::FromNavigationEntry( | 1577 NavigationEntryImpl::FromNavigationEntry( |
1576 our_controller.GetEntryAtIndex(0))->restore_type()); | 1578 our_controller.GetEntryAtIndex(0))->restore_type()); |
1577 EXPECT_TRUE(NavigationEntry::FromNavigationEntry( | 1579 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( |
1578 our_controller.GetEntryAtIndex(0))->site_instance()); | 1580 our_controller.GetEntryAtIndex(0))->site_instance()); |
1579 | 1581 |
1580 // This pending navigation may have caused a different navigation to fail, | 1582 // This pending navigation may have caused a different navigation to fail, |
1581 // which causes the pending entry to be cleared. | 1583 // which causes the pending entry to be cleared. |
1582 TestRenderViewHost* rvh = | 1584 TestRenderViewHost* rvh = |
1583 static_cast<TestRenderViewHost*>(our_contents.GetRenderViewHost()); | 1585 static_cast<TestRenderViewHost*>(our_contents.GetRenderViewHost()); |
1584 ViewHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; | 1586 ViewHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; |
1585 fail_load_params.frame_id = 1; | 1587 fail_load_params.frame_id = 1; |
1586 fail_load_params.is_main_frame = true; | 1588 fail_load_params.is_main_frame = true; |
1587 fail_load_params.error_code = net::ERR_ABORTED; | 1589 fail_load_params.error_code = net::ERR_ABORTED; |
(...skipping 14 matching lines...) Expand all Loading... |
1602 params.is_post = false; | 1604 params.is_post = false; |
1603 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1605 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1604 content::LoadCommittedDetails details; | 1606 content::LoadCommittedDetails details; |
1605 our_controller.RendererDidNavigate(params, &details); | 1607 our_controller.RendererDidNavigate(params, &details); |
1606 | 1608 |
1607 // There should be no pending entry and one committed one. | 1609 // There should be no pending entry and one committed one. |
1608 EXPECT_EQ(1, our_controller.entry_count()); | 1610 EXPECT_EQ(1, our_controller.entry_count()); |
1609 EXPECT_EQ(0, our_controller.last_committed_entry_index()); | 1611 EXPECT_EQ(0, our_controller.last_committed_entry_index()); |
1610 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1612 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1611 EXPECT_EQ(url, | 1613 EXPECT_EQ(url, |
1612 NavigationEntry::FromNavigationEntry( | 1614 NavigationEntryImpl::FromNavigationEntry( |
1613 our_controller.GetLastCommittedEntry())->site_instance()-> | 1615 our_controller.GetLastCommittedEntry())->site_instance()-> |
1614 site()); | 1616 site()); |
1615 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1617 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1616 NavigationEntry::FromNavigationEntry( | 1618 NavigationEntryImpl::FromNavigationEntry( |
1617 our_controller.GetEntryAtIndex(0))->restore_type()); | 1619 our_controller.GetEntryAtIndex(0))->restore_type()); |
1618 } | 1620 } |
1619 | 1621 |
1620 // Make sure that the page type and stuff is correct after an interstitial. | 1622 // Make sure that the page type and stuff is correct after an interstitial. |
1621 TEST_F(NavigationControllerTest, Interstitial) { | 1623 TEST_F(NavigationControllerTest, Interstitial) { |
1622 // First navigate somewhere normal. | 1624 // First navigate somewhere normal. |
1623 const GURL url1("http://foo"); | 1625 const GURL url1("http://foo"); |
1624 controller().LoadURL( | 1626 controller().LoadURL( |
1625 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1627 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1626 rvh()->SendNavigate(0, url1); | 1628 rvh()->SendNavigate(0, url1); |
1627 | 1629 |
1628 // Now navigate somewhere with an interstitial. | 1630 // Now navigate somewhere with an interstitial. |
1629 const GURL url2("http://bar"); | 1631 const GURL url2("http://bar"); |
1630 controller().LoadURL( | 1632 controller().LoadURL( |
1631 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1633 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1632 NavigationEntry::FromNavigationEntry(controller().GetPendingEntry())-> | 1634 NavigationEntryImpl::FromNavigationEntry(controller().GetPendingEntry())-> |
1633 set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 1635 set_page_type(content::PAGE_TYPE_INTERSTITIAL); |
1634 | 1636 |
1635 // At this point the interstitial will be displayed and the load will still | 1637 // At this point the interstitial will be displayed and the load will still |
1636 // be pending. If the user continues, the load will commit. | 1638 // be pending. If the user continues, the load will commit. |
1637 rvh()->SendNavigate(1, url2); | 1639 rvh()->SendNavigate(1, url2); |
1638 | 1640 |
1639 // The page should be a normal page again. | 1641 // The page should be a normal page again. |
1640 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); | 1642 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); |
1641 EXPECT_EQ(content::PAGE_TYPE_NORMAL, | 1643 EXPECT_EQ(content::PAGE_TYPE_NORMAL, |
1642 controller().GetLastCommittedEntry()->GetPageType()); | 1644 controller().GetLastCommittedEntry()->GetPageType()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 controller().LoadURL( | 1712 controller().LoadURL( |
1711 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1713 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1712 rvh()->SendNavigate(0, url0); | 1714 rvh()->SendNavigate(0, url0); |
1713 controller().LoadURL( | 1715 controller().LoadURL( |
1714 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1716 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1715 rvh()->SendNavigate(1, url1); | 1717 rvh()->SendNavigate(1, url1); |
1716 | 1718 |
1717 notifications.Reset(); | 1719 notifications.Reset(); |
1718 | 1720 |
1719 // Adding a transient with no pending entry. | 1721 // Adding a transient with no pending entry. |
1720 NavigationEntry* transient_entry = new NavigationEntry; | 1722 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
1721 transient_entry->SetURL(transient_url); | 1723 transient_entry->SetURL(transient_url); |
1722 controller().AddTransientEntry(transient_entry); | 1724 controller().AddTransientEntry(transient_entry); |
1723 | 1725 |
1724 // We should not have received any notifications. | 1726 // We should not have received any notifications. |
1725 EXPECT_EQ(0U, notifications.size()); | 1727 EXPECT_EQ(0U, notifications.size()); |
1726 | 1728 |
1727 // Check our state. | 1729 // Check our state. |
1728 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1730 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1729 EXPECT_EQ(controller().entry_count(), 3); | 1731 EXPECT_EQ(controller().entry_count(), 3); |
1730 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 1732 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
1731 EXPECT_EQ(controller().pending_entry_index(), -1); | 1733 EXPECT_EQ(controller().pending_entry_index(), -1); |
1732 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 1734 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
1733 EXPECT_FALSE(controller().GetPendingEntry()); | 1735 EXPECT_FALSE(controller().GetPendingEntry()); |
1734 EXPECT_TRUE(controller().CanGoBack()); | 1736 EXPECT_TRUE(controller().CanGoBack()); |
1735 EXPECT_FALSE(controller().CanGoForward()); | 1737 EXPECT_FALSE(controller().CanGoForward()); |
1736 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 1738 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
1737 | 1739 |
1738 // Navigate. | 1740 // Navigate. |
1739 controller().LoadURL( | 1741 controller().LoadURL( |
1740 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1742 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1741 rvh()->SendNavigate(2, url2); | 1743 rvh()->SendNavigate(2, url2); |
1742 | 1744 |
1743 // We should have navigated, transient entry should be gone. | 1745 // We should have navigated, transient entry should be gone. |
1744 EXPECT_EQ(url2, controller().GetActiveEntry()->GetURL()); | 1746 EXPECT_EQ(url2, controller().GetActiveEntry()->GetURL()); |
1745 EXPECT_EQ(controller().entry_count(), 3); | 1747 EXPECT_EQ(controller().entry_count(), 3); |
1746 | 1748 |
1747 // Add a transient again, then navigate with no pending entry this time. | 1749 // Add a transient again, then navigate with no pending entry this time. |
1748 transient_entry = new NavigationEntry; | 1750 transient_entry = new NavigationEntryImpl; |
1749 transient_entry->SetURL(transient_url); | 1751 transient_entry->SetURL(transient_url); |
1750 controller().AddTransientEntry(transient_entry); | 1752 controller().AddTransientEntry(transient_entry); |
1751 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1753 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1752 rvh()->SendNavigate(3, url3); | 1754 rvh()->SendNavigate(3, url3); |
1753 // Transient entry should be gone. | 1755 // Transient entry should be gone. |
1754 EXPECT_EQ(url3, controller().GetActiveEntry()->GetURL()); | 1756 EXPECT_EQ(url3, controller().GetActiveEntry()->GetURL()); |
1755 EXPECT_EQ(controller().entry_count(), 4); | 1757 EXPECT_EQ(controller().entry_count(), 4); |
1756 | 1758 |
1757 // Initiate a navigation, add a transient then commit navigation. | 1759 // Initiate a navigation, add a transient then commit navigation. |
1758 controller().LoadURL( | 1760 controller().LoadURL( |
1759 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1761 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
1760 transient_entry = new NavigationEntry; | 1762 transient_entry = new NavigationEntryImpl; |
1761 transient_entry->SetURL(transient_url); | 1763 transient_entry->SetURL(transient_url); |
1762 controller().AddTransientEntry(transient_entry); | 1764 controller().AddTransientEntry(transient_entry); |
1763 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1765 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1764 rvh()->SendNavigate(4, url4); | 1766 rvh()->SendNavigate(4, url4); |
1765 EXPECT_EQ(url4, controller().GetActiveEntry()->GetURL()); | 1767 EXPECT_EQ(url4, controller().GetActiveEntry()->GetURL()); |
1766 EXPECT_EQ(controller().entry_count(), 5); | 1768 EXPECT_EQ(controller().entry_count(), 5); |
1767 | 1769 |
1768 // Add a transient and go back. This should simply remove the transient. | 1770 // Add a transient and go back. This should simply remove the transient. |
1769 transient_entry = new NavigationEntry; | 1771 transient_entry = new NavigationEntryImpl; |
1770 transient_entry->SetURL(transient_url); | 1772 transient_entry->SetURL(transient_url); |
1771 controller().AddTransientEntry(transient_entry); | 1773 controller().AddTransientEntry(transient_entry); |
1772 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1774 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1773 EXPECT_TRUE(controller().CanGoBack()); | 1775 EXPECT_TRUE(controller().CanGoBack()); |
1774 EXPECT_FALSE(controller().CanGoForward()); | 1776 EXPECT_FALSE(controller().CanGoForward()); |
1775 controller().GoBack(); | 1777 controller().GoBack(); |
1776 // Transient entry should be gone. | 1778 // Transient entry should be gone. |
1777 EXPECT_EQ(url4, controller().GetActiveEntry()->GetURL()); | 1779 EXPECT_EQ(url4, controller().GetActiveEntry()->GetURL()); |
1778 EXPECT_EQ(controller().entry_count(), 5); | 1780 EXPECT_EQ(controller().entry_count(), 5); |
1779 rvh()->SendNavigate(3, url3); | 1781 rvh()->SendNavigate(3, url3); |
1780 | 1782 |
1781 // Add a transient and go to an entry before the current one. | 1783 // Add a transient and go to an entry before the current one. |
1782 transient_entry = new NavigationEntry; | 1784 transient_entry = new NavigationEntryImpl; |
1783 transient_entry->SetURL(transient_url); | 1785 transient_entry->SetURL(transient_url); |
1784 controller().AddTransientEntry(transient_entry); | 1786 controller().AddTransientEntry(transient_entry); |
1785 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1787 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1786 controller().GoToIndex(1); | 1788 controller().GoToIndex(1); |
1787 // The navigation should have been initiated, transient entry should be gone. | 1789 // The navigation should have been initiated, transient entry should be gone. |
1788 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); | 1790 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); |
1789 // Visible entry does not update for history navigations until commit. | 1791 // Visible entry does not update for history navigations until commit. |
1790 EXPECT_EQ(url3, controller().GetVisibleEntry()->GetURL()); | 1792 EXPECT_EQ(url3, controller().GetVisibleEntry()->GetURL()); |
1791 rvh()->SendNavigate(1, url1); | 1793 rvh()->SendNavigate(1, url1); |
1792 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); | 1794 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); |
1793 | 1795 |
1794 // Add a transient and go to an entry after the current one. | 1796 // Add a transient and go to an entry after the current one. |
1795 transient_entry = new NavigationEntry; | 1797 transient_entry = new NavigationEntryImpl; |
1796 transient_entry->SetURL(transient_url); | 1798 transient_entry->SetURL(transient_url); |
1797 controller().AddTransientEntry(transient_entry); | 1799 controller().AddTransientEntry(transient_entry); |
1798 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1800 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1799 controller().GoToIndex(3); | 1801 controller().GoToIndex(3); |
1800 // The navigation should have been initiated, transient entry should be gone. | 1802 // The navigation should have been initiated, transient entry should be gone. |
1801 // Because of the transient entry that is removed, going to index 3 makes us | 1803 // Because of the transient entry that is removed, going to index 3 makes us |
1802 // land on url2 (which is visible after the commit). | 1804 // land on url2 (which is visible after the commit). |
1803 EXPECT_EQ(url2, controller().GetActiveEntry()->GetURL()); | 1805 EXPECT_EQ(url2, controller().GetActiveEntry()->GetURL()); |
1804 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); | 1806 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); |
1805 rvh()->SendNavigate(2, url2); | 1807 rvh()->SendNavigate(2, url2); |
1806 EXPECT_EQ(url2, controller().GetVisibleEntry()->GetURL()); | 1808 EXPECT_EQ(url2, controller().GetVisibleEntry()->GetURL()); |
1807 | 1809 |
1808 // Add a transient and go forward. | 1810 // Add a transient and go forward. |
1809 transient_entry = new NavigationEntry; | 1811 transient_entry = new NavigationEntryImpl; |
1810 transient_entry->SetURL(transient_url); | 1812 transient_entry->SetURL(transient_url); |
1811 controller().AddTransientEntry(transient_entry); | 1813 controller().AddTransientEntry(transient_entry); |
1812 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); | 1814 EXPECT_EQ(transient_url, controller().GetActiveEntry()->GetURL()); |
1813 EXPECT_TRUE(controller().CanGoForward()); | 1815 EXPECT_TRUE(controller().CanGoForward()); |
1814 controller().GoForward(); | 1816 controller().GoForward(); |
1815 // We should have navigated, transient entry should be gone. | 1817 // We should have navigated, transient entry should be gone. |
1816 EXPECT_EQ(url3, controller().GetActiveEntry()->GetURL()); | 1818 EXPECT_EQ(url3, controller().GetActiveEntry()->GetURL()); |
1817 EXPECT_EQ(url2, controller().GetVisibleEntry()->GetURL()); | 1819 EXPECT_EQ(url2, controller().GetVisibleEntry()->GetURL()); |
1818 rvh()->SendNavigate(3, url3); | 1820 rvh()->SendNavigate(3, url3); |
1819 EXPECT_EQ(url3, controller().GetVisibleEntry()->GetURL()); | 1821 EXPECT_EQ(url3, controller().GetVisibleEntry()->GetURL()); |
(...skipping 26 matching lines...) Expand all Loading... |
1846 rvh()->SendNavigate(0, url0); | 1848 rvh()->SendNavigate(0, url0); |
1847 | 1849 |
1848 // For link clicks (renderer-initiated navigations), the active entry should | 1850 // For link clicks (renderer-initiated navigations), the active entry should |
1849 // update before commit but the visible should not. | 1851 // update before commit but the visible should not. |
1850 controller().LoadURLFromRenderer(url1, content::Referrer(), | 1852 controller().LoadURLFromRenderer(url1, content::Referrer(), |
1851 content::PAGE_TRANSITION_LINK, | 1853 content::PAGE_TRANSITION_LINK, |
1852 std::string()); | 1854 std::string()); |
1853 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); | 1855 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); |
1854 EXPECT_EQ(url0, controller().GetVisibleEntry()->GetURL()); | 1856 EXPECT_EQ(url0, controller().GetVisibleEntry()->GetURL()); |
1855 EXPECT_TRUE( | 1857 EXPECT_TRUE( |
1856 NavigationEntry::FromNavigationEntry(controller().GetPendingEntry())-> | 1858 NavigationEntryImpl::FromNavigationEntry(controller().GetPendingEntry())-> |
1857 is_renderer_initiated()); | 1859 is_renderer_initiated()); |
1858 | 1860 |
1859 // After commit, both should be updated, and we should no longer treat the | 1861 // After commit, both should be updated, and we should no longer treat the |
1860 // entry as renderer-initiated. | 1862 // entry as renderer-initiated. |
1861 rvh()->SendNavigate(1, url1); | 1863 rvh()->SendNavigate(1, url1); |
1862 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); | 1864 EXPECT_EQ(url1, controller().GetActiveEntry()->GetURL()); |
1863 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); | 1865 EXPECT_EQ(url1, controller().GetVisibleEntry()->GetURL()); |
1864 EXPECT_FALSE( | 1866 EXPECT_FALSE( |
1865 NavigationEntry::FromNavigationEntry( | 1867 NavigationEntryImpl::FromNavigationEntry( |
1866 controller().GetLastCommittedEntry())->is_renderer_initiated()); | 1868 controller().GetLastCommittedEntry())->is_renderer_initiated()); |
1867 | 1869 |
1868 notifications.Reset(); | 1870 notifications.Reset(); |
1869 } | 1871 } |
1870 | 1872 |
1871 // Tests that IsInPageNavigation returns appropriate results. Prevents | 1873 // Tests that IsInPageNavigation returns appropriate results. Prevents |
1872 // regression for bug 1126349. | 1874 // regression for bug 1126349. |
1873 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 1875 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
1874 // Navigate to URL with no refs. | 1876 // Navigate to URL with no refs. |
1875 const GURL url("http://www.google.com/home.html"); | 1877 const GURL url("http://www.google.com/home.html"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 | 1946 |
1945 // Make sure that cloning a tabcontents doesn't copy interstitials. | 1947 // Make sure that cloning a tabcontents doesn't copy interstitials. |
1946 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { | 1948 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { |
1947 const GURL url1("http://foo1"); | 1949 const GURL url1("http://foo1"); |
1948 const GURL url2("http://foo2"); | 1950 const GURL url2("http://foo2"); |
1949 | 1951 |
1950 NavigateAndCommit(url1); | 1952 NavigateAndCommit(url1); |
1951 NavigateAndCommit(url2); | 1953 NavigateAndCommit(url2); |
1952 | 1954 |
1953 // Add an interstitial entry. Should be deleted with controller. | 1955 // Add an interstitial entry. Should be deleted with controller. |
1954 NavigationEntry* interstitial_entry = new NavigationEntry(); | 1956 NavigationEntryImpl* interstitial_entry = new NavigationEntryImpl(); |
1955 interstitial_entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 1957 interstitial_entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); |
1956 controller().AddTransientEntry(interstitial_entry); | 1958 controller().AddTransientEntry(interstitial_entry); |
1957 | 1959 |
1958 scoped_ptr<TabContents> clone(controller().tab_contents()->Clone()); | 1960 scoped_ptr<TabContents> clone(controller().tab_contents()->Clone()); |
1959 | 1961 |
1960 ASSERT_EQ(2, clone->GetController().entry_count()); | 1962 ASSERT_EQ(2, clone->GetController().entry_count()); |
1961 } | 1963 } |
1962 | 1964 |
1963 // Tests a subframe navigation while a toplevel navigation is pending. | 1965 // Tests a subframe navigation while a toplevel navigation is pending. |
1964 // http://crbug.com/43967 | 1966 // http://crbug.com/43967 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 const GURL url2("http://foo2"); | 2004 const GURL url2("http://foo2"); |
2003 const GURL url3("http://foo3"); | 2005 const GURL url3("http://foo3"); |
2004 | 2006 |
2005 NavigateAndCommit(url1); | 2007 NavigateAndCommit(url1); |
2006 NavigateAndCommit(url2); | 2008 NavigateAndCommit(url2); |
2007 | 2009 |
2008 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 2010 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
2009 NavigationController& other_controller = other_contents->GetController(); | 2011 NavigationController& other_controller = other_contents->GetController(); |
2010 other_contents->NavigateAndCommit(url3); | 2012 other_contents->NavigateAndCommit(url3); |
2011 other_contents->ExpectSetHistoryLengthAndPrune( | 2013 other_contents->ExpectSetHistoryLengthAndPrune( |
2012 NavigationEntry::FromNavigationEntry( | 2014 NavigationEntryImpl::FromNavigationEntry( |
2013 other_controller.GetEntryAtIndex(0))->site_instance(), 2, | 2015 other_controller.GetEntryAtIndex(0))->site_instance(), 2, |
2014 other_controller.GetEntryAtIndex(0)->GetPageID()); | 2016 other_controller.GetEntryAtIndex(0)->GetPageID()); |
2015 other_controller.CopyStateFromAndPrune(&controller()); | 2017 other_controller.CopyStateFromAndPrune(&controller()); |
2016 | 2018 |
2017 // other_controller should now contain the 3 urls: url1, url2 and url3. | 2019 // other_controller should now contain the 3 urls: url1, url2 and url3. |
2018 | 2020 |
2019 ASSERT_EQ(3, other_controller.entry_count()); | 2021 ASSERT_EQ(3, other_controller.entry_count()); |
2020 | 2022 |
2021 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 2023 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
2022 | 2024 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 const GURL transient_url("http://foo/transient"); | 2203 const GURL transient_url("http://foo/transient"); |
2202 | 2204 |
2203 controller().LoadURL( | 2205 controller().LoadURL( |
2204 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2206 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
2205 rvh()->SendNavigate(0, url0); | 2207 rvh()->SendNavigate(0, url0); |
2206 controller().LoadURL( | 2208 controller().LoadURL( |
2207 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2209 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
2208 rvh()->SendNavigate(1, url1); | 2210 rvh()->SendNavigate(1, url1); |
2209 | 2211 |
2210 // Adding a transient with no pending entry. | 2212 // Adding a transient with no pending entry. |
2211 NavigationEntry* transient_entry = new NavigationEntry; | 2213 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2212 transient_entry->SetURL(transient_url); | 2214 transient_entry->SetURL(transient_url); |
2213 controller().AddTransientEntry(transient_entry); | 2215 controller().AddTransientEntry(transient_entry); |
2214 | 2216 |
2215 controller().PruneAllButActive(); | 2217 controller().PruneAllButActive(); |
2216 | 2218 |
2217 EXPECT_EQ(-1, controller().pending_entry_index()); | 2219 EXPECT_EQ(-1, controller().pending_entry_index()); |
2218 EXPECT_EQ(-1, controller().pending_entry_index()); | 2220 EXPECT_EQ(-1, controller().pending_entry_index()); |
2219 EXPECT_EQ(controller().GetTransientEntry()->GetURL(), transient_url); | 2221 EXPECT_EQ(controller().GetTransientEntry()->GetURL(), transient_url); |
2220 } | 2222 } |
2221 | 2223 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2410 TabNavigation nav(0, url0, GURL(), string16(), | 2412 TabNavigation nav(0, url0, GURL(), string16(), |
2411 webkit_glue::CreateHistoryStateForURL(url0), | 2413 webkit_glue::CreateHistoryStateForURL(url0), |
2412 content::PAGE_TRANSITION_LINK); | 2414 content::PAGE_TRANSITION_LINK); |
2413 session_helper_.AssertNavigationEquals(nav, | 2415 session_helper_.AssertNavigationEquals(nav, |
2414 windows_[0]->tabs[0]->navigations[0]); | 2416 windows_[0]->tabs[0]->navigations[0]); |
2415 nav.set_url(url2); | 2417 nav.set_url(url2); |
2416 session_helper_.AssertNavigationEquals(nav, | 2418 session_helper_.AssertNavigationEquals(nav, |
2417 windows_[0]->tabs[0]->navigations[1]); | 2419 windows_[0]->tabs[0]->navigations[1]); |
2418 } | 2420 } |
2419 */ | 2421 */ |
OLD | NEW |