OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" |
21 #include "content/browser/tab_contents/navigation_controller_impl.h" | 21 #include "content/browser/tab_contents/navigation_controller_impl.h" |
22 #include "content/browser/tab_contents/navigation_entry_impl.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::NavigationController; | 37 using content::NavigationController; |
38 using content::NavigationEntry; | 38 using content::NavigationEntry; |
39 using content::NavigationEntryImpl; | 39 using content::NavigationEntryImpl; |
| 40 using content::SiteInstance; |
40 using content::WebContents; | 41 using content::WebContents; |
41 | 42 |
42 // NavigationControllerTest ---------------------------------------------------- | 43 // NavigationControllerTest ---------------------------------------------------- |
43 | 44 |
44 class NavigationControllerTest : public RenderViewHostTestHarness { | 45 class NavigationControllerTest : public RenderViewHostTestHarness { |
45 public: | 46 public: |
46 NavigationControllerTest() {} | 47 NavigationControllerTest() {} |
47 | 48 |
48 NavigationControllerImpl& controller_impl() { | 49 NavigationControllerImpl& controller_impl() { |
49 return static_cast<NavigationControllerImpl&>(controller()); | 50 return static_cast<NavigationControllerImpl&>(controller()); |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // First navigate three places so we have some back history. | 754 // First navigate three places so we have some back history. |
754 rvh()->SendNavigate(0, kUrl1); | 755 rvh()->SendNavigate(0, kUrl1); |
755 rvh()->SendNavigate(1, kUrl2); | 756 rvh()->SendNavigate(1, kUrl2); |
756 rvh()->SendNavigate(2, kUrl3); | 757 rvh()->SendNavigate(2, kUrl3); |
757 | 758 |
758 // With nothing pending, say we get a navigation to the second entry. | 759 // With nothing pending, say we get a navigation to the second entry. |
759 rvh()->SendNavigate(1, kUrl2); | 760 rvh()->SendNavigate(1, kUrl2); |
760 | 761 |
761 // We know all the entries have the same site instance, so we can just grab | 762 // We know all the entries have the same site instance, so we can just grab |
762 // a random one for looking up other entries. | 763 // a random one for looking up other entries. |
763 SiteInstance* site_instance = NavigationEntryImpl::FromNavigationEntry( | 764 SiteInstance* site_instance = |
764 controller.GetLastCommittedEntry())->site_instance(); | 765 NavigationEntryImpl::FromNavigationEntry( |
| 766 controller.GetLastCommittedEntry())->site_instance(); |
765 | 767 |
766 // That second URL should be the last committed and it should have gotten the | 768 // That second URL should be the last committed and it should have gotten the |
767 // new title. | 769 // new title. |
768 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 770 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
769 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 771 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
770 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 772 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
771 | 773 |
772 // Now go forward to the last item again and say it was committed. | 774 // Now go forward to the last item again and say it was committed. |
773 controller.GoForward(); | 775 controller.GoForward(); |
774 rvh()->SendNavigate(2, kUrl3); | 776 rvh()->SendNavigate(2, kUrl3); |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 | 1573 |
1572 // There should be no longer any pending entry and one committed one. This | 1574 // There should be no longer any pending entry and one committed one. This |
1573 // means that we were able to locate the entry, assign its site instance, and | 1575 // means that we were able to locate the entry, assign its site instance, and |
1574 // commit it properly. | 1576 // commit it properly. |
1575 EXPECT_EQ(1, our_controller.GetEntryCount()); | 1577 EXPECT_EQ(1, our_controller.GetEntryCount()); |
1576 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 1578 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
1577 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1579 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1578 EXPECT_EQ(url, | 1580 EXPECT_EQ(url, |
1579 NavigationEntryImpl::FromNavigationEntry( | 1581 NavigationEntryImpl::FromNavigationEntry( |
1580 our_controller.GetLastCommittedEntry())->site_instance()-> | 1582 our_controller.GetLastCommittedEntry())->site_instance()-> |
1581 site()); | 1583 GetSite()); |
1582 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 1584 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1583 NavigationEntryImpl::FromNavigationEntry( | 1585 NavigationEntryImpl::FromNavigationEntry( |
1584 our_controller.GetEntryAtIndex(0))->restore_type()); | 1586 our_controller.GetEntryAtIndex(0))->restore_type()); |
1585 } | 1587 } |
1586 | 1588 |
1587 // Tests that we can still navigate to a restored entry after a different | 1589 // Tests that we can still navigate to a restored entry after a different |
1588 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1590 // navigation fails and clears the pending entry. http://crbug.com/90085 |
1589 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1591 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
1590 // Create a NavigationController with a restored set of tabs. | 1592 // Create a NavigationController with a restored set of tabs. |
1591 GURL url("http://foo"); | 1593 GURL url("http://foo"); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 content::LoadCommittedDetails details; | 1653 content::LoadCommittedDetails details; |
1652 our_controller.RendererDidNavigate(params, &details); | 1654 our_controller.RendererDidNavigate(params, &details); |
1653 | 1655 |
1654 // There should be no pending entry and one committed one. | 1656 // There should be no pending entry and one committed one. |
1655 EXPECT_EQ(1, our_controller.GetEntryCount()); | 1657 EXPECT_EQ(1, our_controller.GetEntryCount()); |
1656 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 1658 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
1657 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1659 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1658 EXPECT_EQ(url, | 1660 EXPECT_EQ(url, |
1659 NavigationEntryImpl::FromNavigationEntry( | 1661 NavigationEntryImpl::FromNavigationEntry( |
1660 our_controller.GetLastCommittedEntry())->site_instance()-> | 1662 our_controller.GetLastCommittedEntry())->site_instance()-> |
1661 site()); | 1663 GetSite()); |
1662 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 1664 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1663 NavigationEntryImpl::FromNavigationEntry( | 1665 NavigationEntryImpl::FromNavigationEntry( |
1664 our_controller.GetEntryAtIndex(0))->restore_type()); | 1666 our_controller.GetEntryAtIndex(0))->restore_type()); |
1665 } | 1667 } |
1666 | 1668 |
1667 // Make sure that the page type and stuff is correct after an interstitial. | 1669 // Make sure that the page type and stuff is correct after an interstitial. |
1668 TEST_F(NavigationControllerTest, Interstitial) { | 1670 TEST_F(NavigationControllerTest, Interstitial) { |
1669 NavigationControllerImpl& controller = controller_impl(); | 1671 NavigationControllerImpl& controller = controller_impl(); |
1670 // First navigate somewhere normal. | 1672 // First navigate somewhere normal. |
1671 const GURL url1("http://foo"); | 1673 const GURL url1("http://foo"); |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 TabNavigation nav(0, url0, GURL(), string16(), | 2518 TabNavigation nav(0, url0, GURL(), string16(), |
2517 webkit_glue::CreateHistoryStateForURL(url0), | 2519 webkit_glue::CreateHistoryStateForURL(url0), |
2518 content::PAGE_TRANSITION_LINK); | 2520 content::PAGE_TRANSITION_LINK); |
2519 session_helper_.AssertNavigationEquals(nav, | 2521 session_helper_.AssertNavigationEquals(nav, |
2520 windows_[0]->tabs[0]->navigations[0]); | 2522 windows_[0]->tabs[0]->navigations[0]); |
2521 nav.set_url(url2); | 2523 nav.set_url(url2); |
2522 session_helper_.AssertNavigationEquals(nav, | 2524 session_helper_.AssertNavigationEquals(nav, |
2523 windows_[0]->tabs[0]->navigations[1]); | 2525 windows_[0]->tabs[0]->navigations[1]); |
2524 } | 2526 } |
2525 */ | 2527 */ |
OLD | NEW |