OLD | NEW |
1 // Copyright (c) 2009 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/profile_manager.h" | 10 #include "chrome/browser/profile_manager.h" |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 1036 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
1037 EXPECT_FALSE(controller().pending_entry()); | 1037 EXPECT_FALSE(controller().pending_entry()); |
1038 EXPECT_TRUE(controller().CanGoBack()); | 1038 EXPECT_TRUE(controller().CanGoBack()); |
1039 EXPECT_FALSE(controller().CanGoForward()); | 1039 EXPECT_FALSE(controller().CanGoForward()); |
1040 } | 1040 } |
1041 | 1041 |
1042 TEST_F(NavigationControllerTest, InPage) { | 1042 TEST_F(NavigationControllerTest, InPage) { |
1043 TestNotificationTracker notifications; | 1043 TestNotificationTracker notifications; |
1044 RegisterForAllNavNotifications(¬ifications, &controller()); | 1044 RegisterForAllNavNotifications(¬ifications, &controller()); |
1045 | 1045 |
1046 // Main page. Note that we need "://" so this URL is treated as "standard" | 1046 // Main page. |
1047 // which are the only ones that can have a ref. | 1047 const GURL url1("http://foo"); |
1048 const GURL url1("http:////foo"); | |
1049 rvh()->SendNavigate(0, url1); | 1048 rvh()->SendNavigate(0, url1); |
1050 EXPECT_TRUE(notifications.Check1AndReset( | 1049 EXPECT_TRUE(notifications.Check1AndReset( |
1051 NotificationType::NAV_ENTRY_COMMITTED)); | 1050 NotificationType::NAV_ENTRY_COMMITTED)); |
1052 | 1051 |
1053 // First navigation. | 1052 // First navigation. |
1054 const GURL url2("http:////foo#a"); | 1053 const GURL url2("http://foo#a"); |
1055 ViewHostMsg_FrameNavigate_Params params = {0}; | 1054 ViewHostMsg_FrameNavigate_Params params = {0}; |
1056 params.page_id = 1; | 1055 params.page_id = 1; |
1057 params.url = url2; | 1056 params.url = url2; |
1058 params.transition = PageTransition::LINK; | 1057 params.transition = PageTransition::LINK; |
1059 params.should_update_history = false; | 1058 params.should_update_history = false; |
1060 params.gesture = NavigationGestureUser; | 1059 params.gesture = NavigationGestureUser; |
1061 params.is_post = false; | 1060 params.is_post = false; |
1062 | 1061 |
1063 // This should generate a new entry. | 1062 // This should generate a new entry. |
1064 NavigationController::LoadCommittedDetails details; | 1063 NavigationController::LoadCommittedDetails details; |
1065 EXPECT_TRUE(controller().RendererDidNavigate(params, 0, &details)); | 1064 EXPECT_TRUE(controller().RendererDidNavigate(params, 0, &details)); |
1066 EXPECT_TRUE(notifications.Check1AndReset( | 1065 EXPECT_TRUE(notifications.Check1AndReset( |
1067 NotificationType::NAV_ENTRY_COMMITTED)); | 1066 NotificationType::NAV_ENTRY_COMMITTED)); |
1068 EXPECT_TRUE(details.is_in_page); | 1067 EXPECT_TRUE(details.is_in_page); |
| 1068 EXPECT_FALSE(details.did_replace_entry); |
1069 EXPECT_EQ(2, controller().entry_count()); | 1069 EXPECT_EQ(2, controller().entry_count()); |
1070 | 1070 |
1071 // Go back one. | 1071 // Go back one. |
1072 ViewHostMsg_FrameNavigate_Params back_params(params); | 1072 ViewHostMsg_FrameNavigate_Params back_params(params); |
1073 controller().GoBack(); | 1073 controller().GoBack(); |
1074 back_params.url = url1; | 1074 back_params.url = url1; |
1075 back_params.page_id = 0; | 1075 back_params.page_id = 0; |
1076 EXPECT_TRUE(controller().RendererDidNavigate(back_params, 0, &details)); | 1076 EXPECT_TRUE(controller().RendererDidNavigate(back_params, 0, &details)); |
1077 EXPECT_TRUE(notifications.Check1AndReset( | 1077 EXPECT_TRUE(notifications.Check1AndReset( |
1078 NotificationType::NAV_ENTRY_COMMITTED)); | 1078 NotificationType::NAV_ENTRY_COMMITTED)); |
(...skipping 23 matching lines...) Expand all Loading... |
1102 // one identified by an existing page ID. This would result in the second URL | 1102 // one identified by an existing page ID. This would result in the second URL |
1103 // losing the reference fragment when you navigate away from it and then back. | 1103 // losing the reference fragment when you navigate away from it and then back. |
1104 controller().GoBack(); | 1104 controller().GoBack(); |
1105 EXPECT_TRUE(controller().RendererDidNavigate(back_params, 0, &details)); | 1105 EXPECT_TRUE(controller().RendererDidNavigate(back_params, 0, &details)); |
1106 controller().GoForward(); | 1106 controller().GoForward(); |
1107 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, 0, &details)); | 1107 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, 0, &details)); |
1108 EXPECT_EQ(forward_params.url, | 1108 EXPECT_EQ(forward_params.url, |
1109 controller().GetActiveEntry()->url()); | 1109 controller().GetActiveEntry()->url()); |
1110 | 1110 |
1111 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 1111 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
1112 const GURL url3("http:////bar"); | 1112 const GURL url3("http://bar"); |
1113 params.page_id = 2; | 1113 params.page_id = 2; |
1114 params.url = url3; | 1114 params.url = url3; |
1115 notifications.Reset(); | 1115 notifications.Reset(); |
1116 EXPECT_TRUE(controller().RendererDidNavigate(params, 0, &details)); | 1116 EXPECT_TRUE(controller().RendererDidNavigate(params, 0, &details)); |
1117 EXPECT_TRUE(notifications.Check1AndReset( | 1117 EXPECT_TRUE(notifications.Check1AndReset( |
1118 NotificationType::NAV_ENTRY_COMMITTED)); | 1118 NotificationType::NAV_ENTRY_COMMITTED)); |
1119 EXPECT_FALSE(details.is_in_page); | 1119 EXPECT_FALSE(details.is_in_page); |
1120 } | 1120 } |
1121 | 1121 |
| 1122 TEST_F(NavigationControllerTest, InPage_Replace) { |
| 1123 TestNotificationTracker notifications; |
| 1124 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1125 |
| 1126 // Main page. |
| 1127 const GURL url1("http://foo"); |
| 1128 rvh()->SendNavigate(0, url1); |
| 1129 EXPECT_TRUE(notifications.Check1AndReset( |
| 1130 NotificationType::NAV_ENTRY_COMMITTED)); |
| 1131 |
| 1132 // First navigation. |
| 1133 const GURL url2("http://foo#a"); |
| 1134 ViewHostMsg_FrameNavigate_Params params = {0}; |
| 1135 params.page_id = 0; // Same page_id |
| 1136 params.url = url2; |
| 1137 params.transition = PageTransition::LINK; |
| 1138 params.should_update_history = false; |
| 1139 params.gesture = NavigationGestureUser; |
| 1140 params.is_post = false; |
| 1141 |
| 1142 // This should NOT generate a new entry. |
| 1143 NavigationController::LoadCommittedDetails details; |
| 1144 EXPECT_TRUE(controller().RendererDidNavigate(params, 0, &details)); |
| 1145 EXPECT_TRUE(notifications.Check2AndReset( |
| 1146 NotificationType::NAV_LIST_PRUNED, |
| 1147 NotificationType::NAV_ENTRY_COMMITTED)); |
| 1148 EXPECT_TRUE(details.is_in_page); |
| 1149 EXPECT_TRUE(details.did_replace_entry); |
| 1150 EXPECT_EQ(1, controller().entry_count()); |
| 1151 } |
| 1152 |
1122 // NotificationObserver implementation used in verifying we've received the | 1153 // NotificationObserver implementation used in verifying we've received the |
1123 // NotificationType::NAV_LIST_PRUNED method. | 1154 // NotificationType::NAV_LIST_PRUNED method. |
1124 class PrunedListener : public NotificationObserver { | 1155 class PrunedListener : public NotificationObserver { |
1125 public: | 1156 public: |
1126 explicit PrunedListener(NavigationController* controller) | 1157 explicit PrunedListener(NavigationController* controller) |
1127 : notification_count_(0) { | 1158 : notification_count_(0) { |
1128 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, | 1159 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, |
1129 Source<NavigationController>(controller)); | 1160 Source<NavigationController>(controller)); |
1130 } | 1161 } |
1131 | 1162 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 PageTransition::LINK); | 1670 PageTransition::LINK); |
1640 session_helper_.AssertNavigationEquals(nav, | 1671 session_helper_.AssertNavigationEquals(nav, |
1641 windows_[0]->tabs[0]->navigations[0]); | 1672 windows_[0]->tabs[0]->navigations[0]); |
1642 nav.set_url(url2); | 1673 nav.set_url(url2); |
1643 session_helper_.AssertNavigationEquals(nav, | 1674 session_helper_.AssertNavigationEquals(nav, |
1644 windows_[0]->tabs[0]->navigations[1]); | 1675 windows_[0]->tabs[0]->navigations[1]); |
1645 } | 1676 } |
1646 */ | 1677 */ |
1647 | 1678 |
1648 } // namespace | 1679 } // namespace |
OLD | NEW |