| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/profile_manager.h" | 9 #include "chrome/browser/profile_manager.h" |
| 10 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
| 11 #include "chrome/browser/renderer_host/test_render_view_host.h" | 11 #include "chrome/browser/renderer_host/test_render_view_host.h" |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 EXPECT_TRUE(notifications.Check1AndReset( | 731 EXPECT_TRUE(notifications.Check1AndReset( |
| 732 NotificationType::NAV_ENTRY_COMMITTED)); | 732 NotificationType::NAV_ENTRY_COMMITTED)); |
| 733 | 733 |
| 734 // Second request | 734 // Second request |
| 735 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 735 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
| 736 | 736 |
| 737 EXPECT_TRUE(controller().pending_entry()); | 737 EXPECT_TRUE(controller().pending_entry()); |
| 738 EXPECT_EQ(controller().pending_entry_index(), -1); | 738 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 739 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 739 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 740 | 740 |
| 741 ViewHostMsg_FrameNavigate_Params params; | 741 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 742 params.page_id = 0; | 742 params.page_id = 0; |
| 743 params.url = url2; | 743 params.url = url2; |
| 744 params.transition = PageTransition::SERVER_REDIRECT; | 744 params.transition = PageTransition::SERVER_REDIRECT; |
| 745 params.redirects.push_back(GURL("http://foo1")); | 745 params.redirects.push_back(GURL("http://foo1")); |
| 746 params.redirects.push_back(GURL("http://foo2")); | 746 params.redirects.push_back(GURL("http://foo2")); |
| 747 params.should_update_history = false; | 747 params.should_update_history = false; |
| 748 params.gesture = NavigationGestureAuto; | 748 params.gesture = NavigationGestureAuto; |
| 749 params.is_post = false; | 749 params.is_post = false; |
| 750 | 750 |
| 751 NavigationController::LoadCommittedDetails details; | 751 NavigationController::LoadCommittedDetails details; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 772 TEST_F(NavigationControllerTest, NewSubframe) { | 772 TEST_F(NavigationControllerTest, NewSubframe) { |
| 773 TestNotificationTracker notifications; | 773 TestNotificationTracker notifications; |
| 774 RegisterForAllNavNotifications(¬ifications, &controller()); | 774 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 775 | 775 |
| 776 const GURL url1("http://foo1"); | 776 const GURL url1("http://foo1"); |
| 777 rvh()->SendNavigate(0, url1); | 777 rvh()->SendNavigate(0, url1); |
| 778 EXPECT_TRUE(notifications.Check1AndReset( | 778 EXPECT_TRUE(notifications.Check1AndReset( |
| 779 NotificationType::NAV_ENTRY_COMMITTED)); | 779 NotificationType::NAV_ENTRY_COMMITTED)); |
| 780 | 780 |
| 781 const GURL url2("http://foo2"); | 781 const GURL url2("http://foo2"); |
| 782 ViewHostMsg_FrameNavigate_Params params; | 782 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 783 params.page_id = 1; | 783 params.page_id = 1; |
| 784 params.url = url2; | 784 params.url = url2; |
| 785 params.transition = PageTransition::MANUAL_SUBFRAME; | 785 params.transition = PageTransition::MANUAL_SUBFRAME; |
| 786 params.should_update_history = false; | 786 params.should_update_history = false; |
| 787 params.gesture = NavigationGestureUser; | 787 params.gesture = NavigationGestureUser; |
| 788 params.is_post = false; | 788 params.is_post = false; |
| 789 | 789 |
| 790 NavigationController::LoadCommittedDetails details; | 790 NavigationController::LoadCommittedDetails details; |
| 791 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 791 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 792 EXPECT_TRUE(notifications.Check1AndReset( | 792 EXPECT_TRUE(notifications.Check1AndReset( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 807 | 807 |
| 808 // Some pages create a popup, then write an iframe into it. This causes a | 808 // Some pages create a popup, then write an iframe into it. This causes a |
| 809 // subframe navigation without having any committed entry. Such navigations | 809 // subframe navigation without having any committed entry. Such navigations |
| 810 // just get thrown on the ground, but we shouldn't crash. | 810 // just get thrown on the ground, but we shouldn't crash. |
| 811 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { | 811 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { |
| 812 TestNotificationTracker notifications; | 812 TestNotificationTracker notifications; |
| 813 RegisterForAllNavNotifications(¬ifications, &controller()); | 813 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 814 | 814 |
| 815 // Navigation controller currently has no entries. | 815 // Navigation controller currently has no entries. |
| 816 const GURL url("http://foo2"); | 816 const GURL url("http://foo2"); |
| 817 ViewHostMsg_FrameNavigate_Params params; | 817 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 818 params.page_id = 1; | 818 params.page_id = 1; |
| 819 params.url = url; | 819 params.url = url; |
| 820 params.transition = PageTransition::AUTO_SUBFRAME; | 820 params.transition = PageTransition::AUTO_SUBFRAME; |
| 821 params.should_update_history = false; | 821 params.should_update_history = false; |
| 822 params.gesture = NavigationGestureAuto; | 822 params.gesture = NavigationGestureAuto; |
| 823 params.is_post = false; | 823 params.is_post = false; |
| 824 | 824 |
| 825 NavigationController::LoadCommittedDetails details; | 825 NavigationController::LoadCommittedDetails details; |
| 826 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 826 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 827 EXPECT_EQ(0U, notifications.size()); | 827 EXPECT_EQ(0U, notifications.size()); |
| 828 } | 828 } |
| 829 | 829 |
| 830 // Auto subframes are ones the page loads automatically like ads. They should | 830 // Auto subframes are ones the page loads automatically like ads. They should |
| 831 // not create new navigation entries. | 831 // not create new navigation entries. |
| 832 TEST_F(NavigationControllerTest, AutoSubframe) { | 832 TEST_F(NavigationControllerTest, AutoSubframe) { |
| 833 TestNotificationTracker notifications; | 833 TestNotificationTracker notifications; |
| 834 RegisterForAllNavNotifications(¬ifications, &controller()); | 834 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 835 | 835 |
| 836 const GURL url1("http://foo1"); | 836 const GURL url1("http://foo1"); |
| 837 rvh()->SendNavigate(0, url1); | 837 rvh()->SendNavigate(0, url1); |
| 838 EXPECT_TRUE(notifications.Check1AndReset( | 838 EXPECT_TRUE(notifications.Check1AndReset( |
| 839 NotificationType::NAV_ENTRY_COMMITTED)); | 839 NotificationType::NAV_ENTRY_COMMITTED)); |
| 840 | 840 |
| 841 const GURL url2("http://foo2"); | 841 const GURL url2("http://foo2"); |
| 842 ViewHostMsg_FrameNavigate_Params params; | 842 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 843 params.page_id = 0; | 843 params.page_id = 0; |
| 844 params.url = url2; | 844 params.url = url2; |
| 845 params.transition = PageTransition::AUTO_SUBFRAME; | 845 params.transition = PageTransition::AUTO_SUBFRAME; |
| 846 params.should_update_history = false; | 846 params.should_update_history = false; |
| 847 params.gesture = NavigationGestureUser; | 847 params.gesture = NavigationGestureUser; |
| 848 params.is_post = false; | 848 params.is_post = false; |
| 849 | 849 |
| 850 // Navigating should do nothing. | 850 // Navigating should do nothing. |
| 851 NavigationController::LoadCommittedDetails details; | 851 NavigationController::LoadCommittedDetails details; |
| 852 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 852 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 853 EXPECT_EQ(0U, notifications.size()); | 853 EXPECT_EQ(0U, notifications.size()); |
| 854 | 854 |
| 855 // There should still be only one entry. | 855 // There should still be only one entry. |
| 856 EXPECT_EQ(1, controller().entry_count()); | 856 EXPECT_EQ(1, controller().entry_count()); |
| 857 } | 857 } |
| 858 | 858 |
| 859 // Tests navigation and then going back to a subframe navigation. | 859 // Tests navigation and then going back to a subframe navigation. |
| 860 TEST_F(NavigationControllerTest, BackSubframe) { | 860 TEST_F(NavigationControllerTest, BackSubframe) { |
| 861 TestNotificationTracker notifications; | 861 TestNotificationTracker notifications; |
| 862 RegisterForAllNavNotifications(¬ifications, &controller()); | 862 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 863 | 863 |
| 864 // Main page. | 864 // Main page. |
| 865 const GURL url1("http://foo1"); | 865 const GURL url1("http://foo1"); |
| 866 rvh()->SendNavigate(0, url1); | 866 rvh()->SendNavigate(0, url1); |
| 867 EXPECT_TRUE(notifications.Check1AndReset( | 867 EXPECT_TRUE(notifications.Check1AndReset( |
| 868 NotificationType::NAV_ENTRY_COMMITTED)); | 868 NotificationType::NAV_ENTRY_COMMITTED)); |
| 869 | 869 |
| 870 // First manual subframe navigation. | 870 // First manual subframe navigation. |
| 871 const GURL url2("http://foo2"); | 871 const GURL url2("http://foo2"); |
| 872 ViewHostMsg_FrameNavigate_Params params; | 872 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 873 params.page_id = 1; | 873 params.page_id = 1; |
| 874 params.url = url2; | 874 params.url = url2; |
| 875 params.transition = PageTransition::MANUAL_SUBFRAME; | 875 params.transition = PageTransition::MANUAL_SUBFRAME; |
| 876 params.should_update_history = false; | 876 params.should_update_history = false; |
| 877 params.gesture = NavigationGestureUser; | 877 params.gesture = NavigationGestureUser; |
| 878 params.is_post = false; | 878 params.is_post = false; |
| 879 | 879 |
| 880 // This should generate a new entry. | 880 // This should generate a new entry. |
| 881 NavigationController::LoadCommittedDetails details; | 881 NavigationController::LoadCommittedDetails details; |
| 882 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 882 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 | 946 |
| 947 // Main page. Note that we need "://" so this URL is treated as "standard" | 947 // Main page. Note that we need "://" so this URL is treated as "standard" |
| 948 // which are the only ones that can have a ref. | 948 // which are the only ones that can have a ref. |
| 949 const GURL url1("http:////foo"); | 949 const GURL url1("http:////foo"); |
| 950 rvh()->SendNavigate(0, url1); | 950 rvh()->SendNavigate(0, url1); |
| 951 EXPECT_TRUE(notifications.Check1AndReset( | 951 EXPECT_TRUE(notifications.Check1AndReset( |
| 952 NotificationType::NAV_ENTRY_COMMITTED)); | 952 NotificationType::NAV_ENTRY_COMMITTED)); |
| 953 | 953 |
| 954 // First navigation. | 954 // First navigation. |
| 955 const GURL url2("http:////foo#a"); | 955 const GURL url2("http:////foo#a"); |
| 956 ViewHostMsg_FrameNavigate_Params params; | 956 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 957 params.page_id = 1; | 957 params.page_id = 1; |
| 958 params.url = url2; | 958 params.url = url2; |
| 959 params.transition = PageTransition::LINK; | 959 params.transition = PageTransition::LINK; |
| 960 params.should_update_history = false; | 960 params.should_update_history = false; |
| 961 params.gesture = NavigationGestureUser; | 961 params.gesture = NavigationGestureUser; |
| 962 params.is_post = false; | 962 params.is_post = false; |
| 963 | 963 |
| 964 // This should generate a new entry. | 964 // This should generate a new entry. |
| 965 NavigationController::LoadCommittedDetails details; | 965 NavigationController::LoadCommittedDetails details; |
| 966 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 966 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 our_controller.RestoreFromState(navigations, 0); | 1109 our_controller.RestoreFromState(navigations, 0); |
| 1110 our_controller.GoToIndex(0); | 1110 our_controller.GoToIndex(0); |
| 1111 | 1111 |
| 1112 // We should now have one entry, and it should be "pending". | 1112 // We should now have one entry, and it should be "pending". |
| 1113 EXPECT_EQ(1, our_controller.entry_count()); | 1113 EXPECT_EQ(1, our_controller.entry_count()); |
| 1114 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 1114 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 1115 our_controller.pending_entry()); | 1115 our_controller.pending_entry()); |
| 1116 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->page_id()); | 1116 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->page_id()); |
| 1117 | 1117 |
| 1118 // Say we navigated to that entry. | 1118 // Say we navigated to that entry. |
| 1119 ViewHostMsg_FrameNavigate_Params params; | 1119 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 1120 params.page_id = 0; | 1120 params.page_id = 0; |
| 1121 params.url = url; | 1121 params.url = url; |
| 1122 params.transition = PageTransition::LINK; | 1122 params.transition = PageTransition::LINK; |
| 1123 params.should_update_history = false; | 1123 params.should_update_history = false; |
| 1124 params.gesture = NavigationGestureUser; | 1124 params.gesture = NavigationGestureUser; |
| 1125 params.is_post = false; | 1125 params.is_post = false; |
| 1126 NavigationController::LoadCommittedDetails details; | 1126 NavigationController::LoadCommittedDetails details; |
| 1127 our_controller.RendererDidNavigate(params, &details); | 1127 our_controller.RendererDidNavigate(params, &details); |
| 1128 | 1128 |
| 1129 // There should be no longer any pending entry and one committed one. This | 1129 // There should be no longer any pending entry and one committed one. This |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 // Navigate the main frame. | 1373 // Navigate the main frame. |
| 1374 const GURL url("http://www.google.com/"); | 1374 const GURL url("http://www.google.com/"); |
| 1375 rvh()->SendNavigate(0, url); | 1375 rvh()->SendNavigate(0, url); |
| 1376 | 1376 |
| 1377 // We should be at the first navigation entry. | 1377 // We should be at the first navigation entry. |
| 1378 EXPECT_EQ(controller().entry_count(), 1); | 1378 EXPECT_EQ(controller().entry_count(), 1); |
| 1379 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 1379 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 1380 | 1380 |
| 1381 // Navigate a subframe that would normally count as in-page. | 1381 // Navigate a subframe that would normally count as in-page. |
| 1382 const GURL subframe("http://www.google.com/#"); | 1382 const GURL subframe("http://www.google.com/#"); |
| 1383 ViewHostMsg_FrameNavigate_Params params; | 1383 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 1384 params.page_id = 0; | 1384 params.page_id = 0; |
| 1385 params.url = subframe; | 1385 params.url = subframe; |
| 1386 params.transition = PageTransition::AUTO_SUBFRAME; | 1386 params.transition = PageTransition::AUTO_SUBFRAME; |
| 1387 params.should_update_history = false; | 1387 params.should_update_history = false; |
| 1388 params.gesture = NavigationGestureAuto; | 1388 params.gesture = NavigationGestureAuto; |
| 1389 params.is_post = false; | 1389 params.is_post = false; |
| 1390 NavigationController::LoadCommittedDetails details; | 1390 NavigationController::LoadCommittedDetails details; |
| 1391 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1391 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 1392 | 1392 |
| 1393 // Nothing should have changed. | 1393 // Nothing should have changed. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 TabNavigation nav(0, url0, GURL(), string16(), | 1467 TabNavigation nav(0, url0, GURL(), string16(), |
| 1468 webkit_glue::CreateHistoryStateForURL(url0), | 1468 webkit_glue::CreateHistoryStateForURL(url0), |
| 1469 PageTransition::LINK); | 1469 PageTransition::LINK); |
| 1470 session_helper_.AssertNavigationEquals(nav, | 1470 session_helper_.AssertNavigationEquals(nav, |
| 1471 windows_[0]->tabs[0]->navigations[0]); | 1471 windows_[0]->tabs[0]->navigations[0]); |
| 1472 nav.set_url(url2); | 1472 nav.set_url(url2); |
| 1473 session_helper_.AssertNavigationEquals(nav, | 1473 session_helper_.AssertNavigationEquals(nav, |
| 1474 windows_[0]->tabs[0]->navigations[1]); | 1474 windows_[0]->tabs[0]->navigations[1]); |
| 1475 } | 1475 } |
| 1476 */ | 1476 */ |
| OLD | NEW |