| 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" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 EXPECT_FALSE(controller().CanGoForward()); | 83 EXPECT_FALSE(controller().CanGoForward()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(NavigationControllerTest, LoadURL) { | 86 TEST_F(NavigationControllerTest, LoadURL) { |
| 87 TestNotificationTracker notifications; | 87 TestNotificationTracker notifications; |
| 88 RegisterForAllNavNotifications(¬ifications, &controller()); | 88 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 89 | 89 |
| 90 const GURL url1("http://foo1"); | 90 const GURL url1("http://foo1"); |
| 91 const GURL url2("http://foo2"); | 91 const GURL url2("http://foo2"); |
| 92 | 92 |
| 93 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 93 controller().LoadURL( |
| 94 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 94 // Creating a pending notification should not have issued any of the | 95 // Creating a pending notification should not have issued any of the |
| 95 // notifications we're listening for. | 96 // notifications we're listening for. |
| 96 EXPECT_EQ(0U, notifications.size()); | 97 EXPECT_EQ(0U, notifications.size()); |
| 97 | 98 |
| 98 // The load should now be pending. | 99 // The load should now be pending. |
| 99 EXPECT_EQ(controller().entry_count(), 0); | 100 EXPECT_EQ(controller().entry_count(), 0); |
| 100 EXPECT_EQ(controller().last_committed_entry_index(), -1); | 101 EXPECT_EQ(controller().last_committed_entry_index(), -1); |
| 101 EXPECT_EQ(controller().pending_entry_index(), -1); | 102 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 102 EXPECT_FALSE(controller().GetLastCommittedEntry()); | 103 EXPECT_FALSE(controller().GetLastCommittedEntry()); |
| 103 EXPECT_TRUE(controller().pending_entry()); | 104 EXPECT_TRUE(controller().pending_entry()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 EXPECT_EQ(controller().entry_count(), 1); | 117 EXPECT_EQ(controller().entry_count(), 1); |
| 117 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 118 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 118 EXPECT_EQ(controller().pending_entry_index(), -1); | 119 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 119 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 120 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 120 EXPECT_FALSE(controller().pending_entry()); | 121 EXPECT_FALSE(controller().pending_entry()); |
| 121 EXPECT_FALSE(controller().CanGoBack()); | 122 EXPECT_FALSE(controller().CanGoBack()); |
| 122 EXPECT_FALSE(controller().CanGoForward()); | 123 EXPECT_FALSE(controller().CanGoForward()); |
| 123 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 124 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 124 | 125 |
| 125 // Load another... | 126 // Load another... |
| 126 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 127 controller().LoadURL( |
| 128 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 127 | 129 |
| 128 // The load should now be pending. | 130 // The load should now be pending. |
| 129 EXPECT_EQ(controller().entry_count(), 1); | 131 EXPECT_EQ(controller().entry_count(), 1); |
| 130 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 132 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 131 EXPECT_EQ(controller().pending_entry_index(), -1); | 133 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 132 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 134 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 133 EXPECT_TRUE(controller().pending_entry()); | 135 EXPECT_TRUE(controller().pending_entry()); |
| 134 // TODO(darin): maybe this should really be true? | 136 // TODO(darin): maybe this should really be true? |
| 135 EXPECT_FALSE(controller().CanGoBack()); | 137 EXPECT_FALSE(controller().CanGoBack()); |
| 136 EXPECT_FALSE(controller().CanGoForward()); | 138 EXPECT_FALSE(controller().CanGoForward()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 157 // Tests what happens when the same page is loaded again. Should not create a | 159 // Tests what happens when the same page is loaded again. Should not create a |
| 158 // new session history entry. This is what happens when you press enter in the | 160 // new session history entry. This is what happens when you press enter in the |
| 159 // URL bar to reload: a pending entry is created and then it is discarded when | 161 // URL bar to reload: a pending entry is created and then it is discarded when |
| 160 // the load commits (because WebCore didn't actually make a new entry). | 162 // the load commits (because WebCore didn't actually make a new entry). |
| 161 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 163 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
| 162 TestNotificationTracker notifications; | 164 TestNotificationTracker notifications; |
| 163 RegisterForAllNavNotifications(¬ifications, &controller()); | 165 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 164 | 166 |
| 165 const GURL url1("http://foo1"); | 167 const GURL url1("http://foo1"); |
| 166 | 168 |
| 167 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 169 controller().LoadURL( |
| 170 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 168 EXPECT_EQ(0U, notifications.size()); | 171 EXPECT_EQ(0U, notifications.size()); |
| 169 rvh()->SendNavigate(0, url1); | 172 rvh()->SendNavigate(0, url1); |
| 170 EXPECT_TRUE(notifications.Check1AndReset( | 173 EXPECT_TRUE(notifications.Check1AndReset( |
| 171 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 174 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 172 | 175 |
| 173 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 176 controller().LoadURL( |
| 177 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 174 EXPECT_EQ(0U, notifications.size()); | 178 EXPECT_EQ(0U, notifications.size()); |
| 175 rvh()->SendNavigate(0, url1); | 179 rvh()->SendNavigate(0, url1); |
| 176 EXPECT_TRUE(notifications.Check1AndReset( | 180 EXPECT_TRUE(notifications.Check1AndReset( |
| 177 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 181 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 178 | 182 |
| 179 // We should not have produced a new session history entry. | 183 // We should not have produced a new session history entry. |
| 180 EXPECT_EQ(controller().entry_count(), 1); | 184 EXPECT_EQ(controller().entry_count(), 1); |
| 181 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 185 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 182 EXPECT_EQ(controller().pending_entry_index(), -1); | 186 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 183 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 187 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 184 EXPECT_FALSE(controller().pending_entry()); | 188 EXPECT_FALSE(controller().pending_entry()); |
| 185 EXPECT_FALSE(controller().CanGoBack()); | 189 EXPECT_FALSE(controller().CanGoBack()); |
| 186 EXPECT_FALSE(controller().CanGoForward()); | 190 EXPECT_FALSE(controller().CanGoForward()); |
| 187 } | 191 } |
| 188 | 192 |
| 189 // Tests loading a URL but discarding it before the load commits. | 193 // Tests loading a URL but discarding it before the load commits. |
| 190 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 194 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
| 191 TestNotificationTracker notifications; | 195 TestNotificationTracker notifications; |
| 192 RegisterForAllNavNotifications(¬ifications, &controller()); | 196 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 193 | 197 |
| 194 const GURL url1("http://foo1"); | 198 const GURL url1("http://foo1"); |
| 195 const GURL url2("http://foo2"); | 199 const GURL url2("http://foo2"); |
| 196 | 200 |
| 197 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 201 controller().LoadURL( |
| 202 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 198 EXPECT_EQ(0U, notifications.size()); | 203 EXPECT_EQ(0U, notifications.size()); |
| 199 rvh()->SendNavigate(0, url1); | 204 rvh()->SendNavigate(0, url1); |
| 200 EXPECT_TRUE(notifications.Check1AndReset( | 205 EXPECT_TRUE(notifications.Check1AndReset( |
| 201 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 206 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 202 | 207 |
| 203 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 208 controller().LoadURL( |
| 209 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 204 controller().DiscardNonCommittedEntries(); | 210 controller().DiscardNonCommittedEntries(); |
| 205 EXPECT_EQ(0U, notifications.size()); | 211 EXPECT_EQ(0U, notifications.size()); |
| 206 | 212 |
| 207 // Should not have produced a new session history entry. | 213 // Should not have produced a new session history entry. |
| 208 EXPECT_EQ(controller().entry_count(), 1); | 214 EXPECT_EQ(controller().entry_count(), 1); |
| 209 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 215 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 210 EXPECT_EQ(controller().pending_entry_index(), -1); | 216 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 211 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 217 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 212 EXPECT_FALSE(controller().pending_entry()); | 218 EXPECT_FALSE(controller().pending_entry()); |
| 213 EXPECT_FALSE(controller().CanGoBack()); | 219 EXPECT_FALSE(controller().CanGoBack()); |
| 214 EXPECT_FALSE(controller().CanGoForward()); | 220 EXPECT_FALSE(controller().CanGoForward()); |
| 215 } | 221 } |
| 216 | 222 |
| 217 // Tests navigations that come in unrequested. This happens when the user | 223 // Tests navigations that come in unrequested. This happens when the user |
| 218 // navigates from the web page, and here we test that there is no pending entry. | 224 // navigates from the web page, and here we test that there is no pending entry. |
| 219 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 225 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
| 220 TestNotificationTracker notifications; | 226 TestNotificationTracker notifications; |
| 221 RegisterForAllNavNotifications(¬ifications, &controller()); | 227 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 222 | 228 |
| 223 // First make an existing committed entry. | 229 // First make an existing committed entry. |
| 224 const GURL kExistingURL1("http://eh"); | 230 const GURL kExistingURL1("http://eh"); |
| 225 controller().LoadURL(kExistingURL1, GURL(), | 231 controller().LoadURL(kExistingURL1, GURL(), |
| 226 PageTransition::TYPED, std::string()); | 232 content::PAGE_TRANSITION_TYPED, std::string()); |
| 227 rvh()->SendNavigate(0, kExistingURL1); | 233 rvh()->SendNavigate(0, kExistingURL1); |
| 228 EXPECT_TRUE(notifications.Check1AndReset( | 234 EXPECT_TRUE(notifications.Check1AndReset( |
| 229 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 235 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 230 | 236 |
| 231 // Do a new navigation without making a pending one. | 237 // Do a new navigation without making a pending one. |
| 232 const GURL kNewURL("http://see"); | 238 const GURL kNewURL("http://see"); |
| 233 rvh()->SendNavigate(99, kNewURL); | 239 rvh()->SendNavigate(99, kNewURL); |
| 234 | 240 |
| 235 // There should no longer be any pending entry, and the third navigation we | 241 // There should no longer be any pending entry, and the third navigation we |
| 236 // just made should be committed. | 242 // just made should be committed. |
| 237 EXPECT_TRUE(notifications.Check1AndReset( | 243 EXPECT_TRUE(notifications.Check1AndReset( |
| 238 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 244 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 239 EXPECT_EQ(-1, controller().pending_entry_index()); | 245 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 240 EXPECT_EQ(1, controller().last_committed_entry_index()); | 246 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 241 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 247 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
| 242 } | 248 } |
| 243 | 249 |
| 244 // Tests navigating to a new URL when there is a new pending navigation that is | 250 // Tests navigating to a new URL when there is a new pending navigation that is |
| 245 // not the one that just loaded. This will happen if the user types in a URL to | 251 // not the one that just loaded. This will happen if the user types in a URL to |
| 246 // somewhere slow, and then navigates the current page before the typed URL | 252 // somewhere slow, and then navigates the current page before the typed URL |
| 247 // commits. | 253 // commits. |
| 248 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 254 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 249 TestNotificationTracker notifications; | 255 TestNotificationTracker notifications; |
| 250 RegisterForAllNavNotifications(¬ifications, &controller()); | 256 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 251 | 257 |
| 252 // First make an existing committed entry. | 258 // First make an existing committed entry. |
| 253 const GURL kExistingURL1("http://eh"); | 259 const GURL kExistingURL1("http://eh"); |
| 254 controller().LoadURL(kExistingURL1, GURL(), | 260 controller().LoadURL(kExistingURL1, GURL(), |
| 255 PageTransition::TYPED, std::string()); | 261 content::PAGE_TRANSITION_TYPED, std::string()); |
| 256 rvh()->SendNavigate(0, kExistingURL1); | 262 rvh()->SendNavigate(0, kExistingURL1); |
| 257 EXPECT_TRUE(notifications.Check1AndReset( | 263 EXPECT_TRUE(notifications.Check1AndReset( |
| 258 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 264 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 259 | 265 |
| 260 // Make a pending entry to somewhere new. | 266 // Make a pending entry to somewhere new. |
| 261 const GURL kExistingURL2("http://bee"); | 267 const GURL kExistingURL2("http://bee"); |
| 262 controller().LoadURL(kExistingURL2, GURL(), | 268 controller().LoadURL(kExistingURL2, GURL(), |
| 263 PageTransition::TYPED, std::string()); | 269 content::PAGE_TRANSITION_TYPED, std::string()); |
| 264 EXPECT_EQ(0U, notifications.size()); | 270 EXPECT_EQ(0U, notifications.size()); |
| 265 | 271 |
| 266 // After the beforeunload but before it commits, do a new navigation. | 272 // After the beforeunload but before it commits, do a new navigation. |
| 267 rvh()->SendShouldCloseACK(true); | 273 rvh()->SendShouldCloseACK(true); |
| 268 const GURL kNewURL("http://see"); | 274 const GURL kNewURL("http://see"); |
| 269 contents()->pending_rvh()->SendNavigate(3, kNewURL); | 275 contents()->pending_rvh()->SendNavigate(3, kNewURL); |
| 270 | 276 |
| 271 // There should no longer be any pending entry, and the third navigation we | 277 // There should no longer be any pending entry, and the third navigation we |
| 272 // just made should be committed. | 278 // just made should be committed. |
| 273 EXPECT_TRUE(notifications.Check1AndReset( | 279 EXPECT_TRUE(notifications.Check1AndReset( |
| 274 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 280 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 275 EXPECT_EQ(-1, controller().pending_entry_index()); | 281 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 276 EXPECT_EQ(1, controller().last_committed_entry_index()); | 282 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 277 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 283 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
| 278 } | 284 } |
| 279 | 285 |
| 280 // Tests navigating to a new URL when there is a pending back/forward | 286 // Tests navigating to a new URL when there is a pending back/forward |
| 281 // navigation. This will happen if the user hits back, but before that commits, | 287 // navigation. This will happen if the user hits back, but before that commits, |
| 282 // they navigate somewhere new. | 288 // they navigate somewhere new. |
| 283 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 289 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 284 TestNotificationTracker notifications; | 290 TestNotificationTracker notifications; |
| 285 RegisterForAllNavNotifications(¬ifications, &controller()); | 291 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 286 | 292 |
| 287 // First make some history. | 293 // First make some history. |
| 288 const GURL kExistingURL1("http://foo/eh"); | 294 const GURL kExistingURL1("http://foo/eh"); |
| 289 controller().LoadURL(kExistingURL1, GURL(), | 295 controller().LoadURL(kExistingURL1, GURL(), |
| 290 PageTransition::TYPED, std::string()); | 296 content::PAGE_TRANSITION_TYPED, std::string()); |
| 291 rvh()->SendNavigate(0, kExistingURL1); | 297 rvh()->SendNavigate(0, kExistingURL1); |
| 292 EXPECT_TRUE(notifications.Check1AndReset( | 298 EXPECT_TRUE(notifications.Check1AndReset( |
| 293 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 299 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 294 | 300 |
| 295 const GURL kExistingURL2("http://foo/bee"); | 301 const GURL kExistingURL2("http://foo/bee"); |
| 296 controller().LoadURL(kExistingURL2, GURL(), | 302 controller().LoadURL(kExistingURL2, GURL(), |
| 297 PageTransition::TYPED, std::string()); | 303 content::PAGE_TRANSITION_TYPED, std::string()); |
| 298 rvh()->SendNavigate(1, kExistingURL2); | 304 rvh()->SendNavigate(1, kExistingURL2); |
| 299 EXPECT_TRUE(notifications.Check1AndReset( | 305 EXPECT_TRUE(notifications.Check1AndReset( |
| 300 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 306 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 301 | 307 |
| 302 // Now make a pending back/forward navigation. The zeroth entry should be | 308 // Now make a pending back/forward navigation. The zeroth entry should be |
| 303 // pending. | 309 // pending. |
| 304 controller().GoBack(); | 310 controller().GoBack(); |
| 305 EXPECT_EQ(0U, notifications.size()); | 311 EXPECT_EQ(0U, notifications.size()); |
| 306 EXPECT_EQ(0, controller().pending_entry_index()); | 312 EXPECT_EQ(0, controller().pending_entry_index()); |
| 307 EXPECT_EQ(1, controller().last_committed_entry_index()); | 313 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 322 | 328 |
| 323 // Tests navigating to an existing URL when there is a pending new navigation. | 329 // Tests navigating to an existing URL when there is a pending new navigation. |
| 324 // This will happen if the user enters a URL, but before that commits, the | 330 // This will happen if the user enters a URL, but before that commits, the |
| 325 // current page fires history.back(). | 331 // current page fires history.back(). |
| 326 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 332 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 327 TestNotificationTracker notifications; | 333 TestNotificationTracker notifications; |
| 328 RegisterForAllNavNotifications(¬ifications, &controller()); | 334 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 329 | 335 |
| 330 // First make some history. | 336 // First make some history. |
| 331 const GURL kExistingURL1("http://foo/eh"); | 337 const GURL kExistingURL1("http://foo/eh"); |
| 332 controller().LoadURL(kExistingURL1, GURL(), PageTransition::TYPED, | 338 controller().LoadURL(kExistingURL1, GURL(), content::PAGE_TRANSITION_TYPED, |
| 333 std::string()); | 339 std::string()); |
| 334 rvh()->SendNavigate(0, kExistingURL1); | 340 rvh()->SendNavigate(0, kExistingURL1); |
| 335 EXPECT_TRUE(notifications.Check1AndReset( | 341 EXPECT_TRUE(notifications.Check1AndReset( |
| 336 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 342 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 337 | 343 |
| 338 const GURL kExistingURL2("http://foo/bee"); | 344 const GURL kExistingURL2("http://foo/bee"); |
| 339 controller().LoadURL(kExistingURL2, GURL(), PageTransition::TYPED, | 345 controller().LoadURL(kExistingURL2, GURL(), content::PAGE_TRANSITION_TYPED, |
| 340 std::string()); | 346 std::string()); |
| 341 rvh()->SendNavigate(1, kExistingURL2); | 347 rvh()->SendNavigate(1, kExistingURL2); |
| 342 EXPECT_TRUE(notifications.Check1AndReset( | 348 EXPECT_TRUE(notifications.Check1AndReset( |
| 343 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 349 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 344 | 350 |
| 345 // Now make a pending new navigation. | 351 // Now make a pending new navigation. |
| 346 const GURL kNewURL("http://foo/see"); | 352 const GURL kNewURL("http://foo/see"); |
| 347 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED, std::string()); | 353 controller().LoadURL( |
| 354 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 348 EXPECT_EQ(0U, notifications.size()); | 355 EXPECT_EQ(0U, notifications.size()); |
| 349 EXPECT_EQ(-1, controller().pending_entry_index()); | 356 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 350 EXPECT_EQ(1, controller().last_committed_entry_index()); | 357 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 351 | 358 |
| 352 // Before that commits, a back navigation from the renderer commits. | 359 // Before that commits, a back navigation from the renderer commits. |
| 353 rvh()->SendNavigate(0, kExistingURL1); | 360 rvh()->SendNavigate(0, kExistingURL1); |
| 354 | 361 |
| 355 // There should no longer be any pending entry, and the back navigation we | 362 // There should no longer be any pending entry, and the back navigation we |
| 356 // just made should be committed. | 363 // just made should be committed. |
| 357 EXPECT_TRUE(notifications.Check1AndReset( | 364 EXPECT_TRUE(notifications.Check1AndReset( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 371 // Set a TabContentsDelegate to listen for state changes. | 378 // Set a TabContentsDelegate to listen for state changes. |
| 372 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 379 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 373 EXPECT_FALSE(contents()->delegate()); | 380 EXPECT_FALSE(contents()->delegate()); |
| 374 contents()->set_delegate(delegate.get()); | 381 contents()->set_delegate(delegate.get()); |
| 375 | 382 |
| 376 // Without any navigations, the renderer starts at about:blank. | 383 // Without any navigations, the renderer starts at about:blank. |
| 377 const GURL kExistingURL("about:blank"); | 384 const GURL kExistingURL("about:blank"); |
| 378 | 385 |
| 379 // Now make a pending new navigation. | 386 // Now make a pending new navigation. |
| 380 const GURL kNewURL("http://eh"); | 387 const GURL kNewURL("http://eh"); |
| 381 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED, std::string()); | 388 controller().LoadURL( |
| 389 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 382 EXPECT_EQ(0U, notifications.size()); | 390 EXPECT_EQ(0U, notifications.size()); |
| 383 EXPECT_EQ(-1, controller().pending_entry_index()); | 391 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 384 EXPECT_TRUE(controller().pending_entry()); | 392 EXPECT_TRUE(controller().pending_entry()); |
| 385 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 393 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 386 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 394 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 387 | 395 |
| 388 // Before that commits, a document.write and location.reload can cause the | 396 // Before that commits, a document.write and location.reload can cause the |
| 389 // renderer to send a FrameNavigate with page_id -1. | 397 // renderer to send a FrameNavigate with page_id -1. |
| 390 rvh()->SendNavigate(-1, kExistingURL); | 398 rvh()->SendNavigate(-1, kExistingURL); |
| 391 | 399 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 407 // Set a TabContentsDelegate to listen for state changes. | 415 // Set a TabContentsDelegate to listen for state changes. |
| 408 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 416 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 409 EXPECT_FALSE(contents()->delegate()); | 417 EXPECT_FALSE(contents()->delegate()); |
| 410 contents()->set_delegate(delegate.get()); | 418 contents()->set_delegate(delegate.get()); |
| 411 | 419 |
| 412 // Without any navigations, the renderer starts at about:blank. | 420 // Without any navigations, the renderer starts at about:blank. |
| 413 const GURL kExistingURL("about:blank"); | 421 const GURL kExistingURL("about:blank"); |
| 414 | 422 |
| 415 // Now make a pending new navigation. | 423 // Now make a pending new navigation. |
| 416 const GURL kNewURL("http://eh"); | 424 const GURL kNewURL("http://eh"); |
| 417 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED, std::string()); | 425 controller().LoadURL( |
| 426 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 418 EXPECT_EQ(0U, notifications.size()); | 427 EXPECT_EQ(0U, notifications.size()); |
| 419 EXPECT_EQ(-1, controller().pending_entry_index()); | 428 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 420 EXPECT_TRUE(controller().pending_entry()); | 429 EXPECT_TRUE(controller().pending_entry()); |
| 421 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 430 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 422 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 431 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 423 | 432 |
| 424 // It may abort before committing, if it's a download or due to a stop or | 433 // It may abort before committing, if it's a download or due to a stop or |
| 425 // a new navigation from the user. | 434 // a new navigation from the user. |
| 426 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; | 435 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 427 params.frame_id = 1; | 436 params.frame_id = 1; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 453 // Set a TabContentsDelegate to listen for state changes. | 462 // Set a TabContentsDelegate to listen for state changes. |
| 454 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 463 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 455 EXPECT_FALSE(contents()->delegate()); | 464 EXPECT_FALSE(contents()->delegate()); |
| 456 contents()->set_delegate(delegate.get()); | 465 contents()->set_delegate(delegate.get()); |
| 457 | 466 |
| 458 // Without any navigations, the renderer starts at about:blank. | 467 // Without any navigations, the renderer starts at about:blank. |
| 459 const GURL kExistingURL("about:blank"); | 468 const GURL kExistingURL("about:blank"); |
| 460 | 469 |
| 461 // Now make a pending new navigation. | 470 // Now make a pending new navigation. |
| 462 const GURL kNewURL("http://eh"); | 471 const GURL kNewURL("http://eh"); |
| 463 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED, std::string()); | 472 controller().LoadURL( |
| 473 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 464 EXPECT_EQ(0U, notifications.size()); | 474 EXPECT_EQ(0U, notifications.size()); |
| 465 EXPECT_EQ(-1, controller().pending_entry_index()); | 475 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 466 EXPECT_TRUE(controller().pending_entry()); | 476 EXPECT_TRUE(controller().pending_entry()); |
| 467 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 477 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 468 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 478 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 469 | 479 |
| 470 // Now the navigation redirects. | 480 // Now the navigation redirects. |
| 471 const GURL kRedirectURL("http://bee"); | 481 const GURL kRedirectURL("http://bee"); |
| 472 rvh()->TestOnMessageReceived( | 482 rvh()->TestOnMessageReceived( |
| 473 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id | 483 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id |
| (...skipping 28 matching lines...) Expand all Loading... |
| 502 | 512 |
| 503 contents()->set_delegate(NULL); | 513 contents()->set_delegate(NULL); |
| 504 } | 514 } |
| 505 | 515 |
| 506 TEST_F(NavigationControllerTest, Reload) { | 516 TEST_F(NavigationControllerTest, Reload) { |
| 507 TestNotificationTracker notifications; | 517 TestNotificationTracker notifications; |
| 508 RegisterForAllNavNotifications(¬ifications, &controller()); | 518 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 509 | 519 |
| 510 const GURL url1("http://foo1"); | 520 const GURL url1("http://foo1"); |
| 511 | 521 |
| 512 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 522 controller().LoadURL( |
| 523 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 513 EXPECT_EQ(0U, notifications.size()); | 524 EXPECT_EQ(0U, notifications.size()); |
| 514 rvh()->SendNavigate(0, url1); | 525 rvh()->SendNavigate(0, url1); |
| 515 EXPECT_TRUE(notifications.Check1AndReset( | 526 EXPECT_TRUE(notifications.Check1AndReset( |
| 516 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 527 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 517 | 528 |
| 518 controller().Reload(true); | 529 controller().Reload(true); |
| 519 EXPECT_EQ(0U, notifications.size()); | 530 EXPECT_EQ(0U, notifications.size()); |
| 520 | 531 |
| 521 // The reload is pending. | 532 // The reload is pending. |
| 522 EXPECT_EQ(controller().entry_count(), 1); | 533 EXPECT_EQ(controller().entry_count(), 1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 542 } | 553 } |
| 543 | 554 |
| 544 // Tests what happens when a reload navigation produces a new page. | 555 // Tests what happens when a reload navigation produces a new page. |
| 545 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 556 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 546 TestNotificationTracker notifications; | 557 TestNotificationTracker notifications; |
| 547 RegisterForAllNavNotifications(¬ifications, &controller()); | 558 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 548 | 559 |
| 549 const GURL url1("http://foo1"); | 560 const GURL url1("http://foo1"); |
| 550 const GURL url2("http://foo2"); | 561 const GURL url2("http://foo2"); |
| 551 | 562 |
| 552 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 563 controller().LoadURL( |
| 564 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 553 rvh()->SendNavigate(0, url1); | 565 rvh()->SendNavigate(0, url1); |
| 554 EXPECT_TRUE(notifications.Check1AndReset( | 566 EXPECT_TRUE(notifications.Check1AndReset( |
| 555 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 567 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 556 | 568 |
| 557 controller().Reload(true); | 569 controller().Reload(true); |
| 558 EXPECT_EQ(0U, notifications.size()); | 570 EXPECT_EQ(0U, notifications.size()); |
| 559 | 571 |
| 560 rvh()->SendNavigate(1, url2); | 572 rvh()->SendNavigate(1, url2); |
| 561 EXPECT_TRUE(notifications.Check1AndReset( | 573 EXPECT_TRUE(notifications.Check1AndReset( |
| 562 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 574 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 626 |
| 615 // Tests what happens when a back navigation produces a new page. | 627 // Tests what happens when a back navigation produces a new page. |
| 616 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { | 628 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { |
| 617 TestNotificationTracker notifications; | 629 TestNotificationTracker notifications; |
| 618 RegisterForAllNavNotifications(¬ifications, &controller()); | 630 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 619 | 631 |
| 620 const GURL url1("http://foo/1"); | 632 const GURL url1("http://foo/1"); |
| 621 const GURL url2("http://foo/2"); | 633 const GURL url2("http://foo/2"); |
| 622 const GURL url3("http://foo/3"); | 634 const GURL url3("http://foo/3"); |
| 623 | 635 |
| 624 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 636 controller().LoadURL( |
| 637 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 625 rvh()->SendNavigate(0, url1); | 638 rvh()->SendNavigate(0, url1); |
| 626 EXPECT_TRUE(notifications.Check1AndReset( | 639 EXPECT_TRUE(notifications.Check1AndReset( |
| 627 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 640 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 628 | 641 |
| 629 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 642 controller().LoadURL( |
| 643 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 630 rvh()->SendNavigate(1, url2); | 644 rvh()->SendNavigate(1, url2); |
| 631 EXPECT_TRUE(notifications.Check1AndReset( | 645 EXPECT_TRUE(notifications.Check1AndReset( |
| 632 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 646 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 633 | 647 |
| 634 controller().GoBack(); | 648 controller().GoBack(); |
| 635 EXPECT_EQ(0U, notifications.size()); | 649 EXPECT_EQ(0U, notifications.size()); |
| 636 | 650 |
| 637 // We should now have a pending navigation to go back. | 651 // We should now have a pending navigation to go back. |
| 638 EXPECT_EQ(controller().entry_count(), 2); | 652 EXPECT_EQ(controller().entry_count(), 2); |
| 639 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 653 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 665 | 679 |
| 666 const GURL kUrl1("http://foo1"); | 680 const GURL kUrl1("http://foo1"); |
| 667 const GURL kUrl2("http://foo2"); | 681 const GURL kUrl2("http://foo2"); |
| 668 const GURL kUrl3("http://foo3"); | 682 const GURL kUrl3("http://foo3"); |
| 669 | 683 |
| 670 // First navigate two places so we have some back history. | 684 // First navigate two places so we have some back history. |
| 671 rvh()->SendNavigate(0, kUrl1); | 685 rvh()->SendNavigate(0, kUrl1); |
| 672 EXPECT_TRUE(notifications.Check1AndReset( | 686 EXPECT_TRUE(notifications.Check1AndReset( |
| 673 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 687 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 674 | 688 |
| 675 // controller().LoadURL(kUrl2, PageTransition::TYPED); | 689 // controller().LoadURL(kUrl2, content::PAGE_TRANSITION_TYPED); |
| 676 rvh()->SendNavigate(1, kUrl2); | 690 rvh()->SendNavigate(1, kUrl2); |
| 677 EXPECT_TRUE(notifications.Check1AndReset( | 691 EXPECT_TRUE(notifications.Check1AndReset( |
| 678 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 692 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 679 | 693 |
| 680 // Now start a new pending navigation and go back before it commits. | 694 // Now start a new pending navigation and go back before it commits. |
| 681 controller().LoadURL(kUrl3, GURL(), PageTransition::TYPED, std::string()); | 695 controller().LoadURL( |
| 696 kUrl3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 682 EXPECT_EQ(-1, controller().pending_entry_index()); | 697 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 683 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); | 698 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); |
| 684 controller().GoBack(); | 699 controller().GoBack(); |
| 685 | 700 |
| 686 // The pending navigation should now be the "back" item and the new one | 701 // The pending navigation should now be the "back" item and the new one |
| 687 // should be gone. | 702 // should be gone. |
| 688 EXPECT_EQ(0, controller().pending_entry_index()); | 703 EXPECT_EQ(0, controller().pending_entry_index()); |
| 689 EXPECT_EQ(kUrl1, controller().pending_entry()->url()); | 704 EXPECT_EQ(kUrl1, controller().pending_entry()->url()); |
| 690 } | 705 } |
| 691 | 706 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 // Two consequent navigation for the same URL entered in should be considered | 847 // Two consequent navigation for the same URL entered in should be considered |
| 833 // as SAME_PAGE navigation even when we are redirected to some other page. | 848 // as SAME_PAGE navigation even when we are redirected to some other page. |
| 834 TEST_F(NavigationControllerTest, Redirect) { | 849 TEST_F(NavigationControllerTest, Redirect) { |
| 835 TestNotificationTracker notifications; | 850 TestNotificationTracker notifications; |
| 836 RegisterForAllNavNotifications(¬ifications, &controller()); | 851 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 837 | 852 |
| 838 const GURL url1("http://foo1"); | 853 const GURL url1("http://foo1"); |
| 839 const GURL url2("http://foo2"); // Redirection target | 854 const GURL url2("http://foo2"); // Redirection target |
| 840 | 855 |
| 841 // First request | 856 // First request |
| 842 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 857 controller().LoadURL( |
| 858 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 843 | 859 |
| 844 EXPECT_EQ(0U, notifications.size()); | 860 EXPECT_EQ(0U, notifications.size()); |
| 845 rvh()->SendNavigate(0, url2); | 861 rvh()->SendNavigate(0, url2); |
| 846 EXPECT_TRUE(notifications.Check1AndReset( | 862 EXPECT_TRUE(notifications.Check1AndReset( |
| 847 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 863 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 848 | 864 |
| 849 // Second request | 865 // Second request |
| 850 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 866 controller().LoadURL( |
| 867 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 851 | 868 |
| 852 EXPECT_TRUE(controller().pending_entry()); | 869 EXPECT_TRUE(controller().pending_entry()); |
| 853 EXPECT_EQ(controller().pending_entry_index(), -1); | 870 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 854 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 871 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 855 | 872 |
| 856 ViewHostMsg_FrameNavigate_Params params; | 873 ViewHostMsg_FrameNavigate_Params params; |
| 857 params.page_id = 0; | 874 params.page_id = 0; |
| 858 params.url = url2; | 875 params.url = url2; |
| 859 params.transition = PageTransition::SERVER_REDIRECT; | 876 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 860 params.redirects.push_back(GURL("http://foo1")); | 877 params.redirects.push_back(GURL("http://foo1")); |
| 861 params.redirects.push_back(GURL("http://foo2")); | 878 params.redirects.push_back(GURL("http://foo2")); |
| 862 params.should_update_history = false; | 879 params.should_update_history = false; |
| 863 params.gesture = NavigationGestureAuto; | 880 params.gesture = NavigationGestureAuto; |
| 864 params.is_post = false; | 881 params.is_post = false; |
| 865 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 882 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 866 | 883 |
| 867 content::LoadCommittedDetails details; | 884 content::LoadCommittedDetails details; |
| 868 | 885 |
| 869 EXPECT_EQ(0U, notifications.size()); | 886 EXPECT_EQ(0U, notifications.size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 887 // the second URL is requested by GET. NavigationEntry::has_post_data_ | 904 // the second URL is requested by GET. NavigationEntry::has_post_data_ |
| 888 // must be cleared. http://crbug.com/21245 | 905 // must be cleared. http://crbug.com/21245 |
| 889 TEST_F(NavigationControllerTest, PostThenRedirect) { | 906 TEST_F(NavigationControllerTest, PostThenRedirect) { |
| 890 TestNotificationTracker notifications; | 907 TestNotificationTracker notifications; |
| 891 RegisterForAllNavNotifications(¬ifications, &controller()); | 908 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 892 | 909 |
| 893 const GURL url1("http://foo1"); | 910 const GURL url1("http://foo1"); |
| 894 const GURL url2("http://foo2"); // Redirection target | 911 const GURL url2("http://foo2"); // Redirection target |
| 895 | 912 |
| 896 // First request as POST | 913 // First request as POST |
| 897 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 914 controller().LoadURL( |
| 915 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 898 controller().GetActiveEntry()->set_has_post_data(true); | 916 controller().GetActiveEntry()->set_has_post_data(true); |
| 899 | 917 |
| 900 EXPECT_EQ(0U, notifications.size()); | 918 EXPECT_EQ(0U, notifications.size()); |
| 901 rvh()->SendNavigate(0, url2); | 919 rvh()->SendNavigate(0, url2); |
| 902 EXPECT_TRUE(notifications.Check1AndReset( | 920 EXPECT_TRUE(notifications.Check1AndReset( |
| 903 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 921 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 904 | 922 |
| 905 // Second request | 923 // Second request |
| 906 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 924 controller().LoadURL( |
| 925 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 907 | 926 |
| 908 EXPECT_TRUE(controller().pending_entry()); | 927 EXPECT_TRUE(controller().pending_entry()); |
| 909 EXPECT_EQ(controller().pending_entry_index(), -1); | 928 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 910 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 929 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 911 | 930 |
| 912 ViewHostMsg_FrameNavigate_Params params; | 931 ViewHostMsg_FrameNavigate_Params params; |
| 913 params.page_id = 0; | 932 params.page_id = 0; |
| 914 params.url = url2; | 933 params.url = url2; |
| 915 params.transition = PageTransition::SERVER_REDIRECT; | 934 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 916 params.redirects.push_back(GURL("http://foo1")); | 935 params.redirects.push_back(GURL("http://foo1")); |
| 917 params.redirects.push_back(GURL("http://foo2")); | 936 params.redirects.push_back(GURL("http://foo2")); |
| 918 params.should_update_history = false; | 937 params.should_update_history = false; |
| 919 params.gesture = NavigationGestureAuto; | 938 params.gesture = NavigationGestureAuto; |
| 920 params.is_post = false; | 939 params.is_post = false; |
| 921 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 940 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 922 | 941 |
| 923 content::LoadCommittedDetails details; | 942 content::LoadCommittedDetails details; |
| 924 | 943 |
| 925 EXPECT_EQ(0U, notifications.size()); | 944 EXPECT_EQ(0U, notifications.size()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 942 | 961 |
| 943 // A redirect right off the bat should be a NEW_PAGE. | 962 // A redirect right off the bat should be a NEW_PAGE. |
| 944 TEST_F(NavigationControllerTest, ImmediateRedirect) { | 963 TEST_F(NavigationControllerTest, ImmediateRedirect) { |
| 945 TestNotificationTracker notifications; | 964 TestNotificationTracker notifications; |
| 946 RegisterForAllNavNotifications(¬ifications, &controller()); | 965 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 947 | 966 |
| 948 const GURL url1("http://foo1"); | 967 const GURL url1("http://foo1"); |
| 949 const GURL url2("http://foo2"); // Redirection target | 968 const GURL url2("http://foo2"); // Redirection target |
| 950 | 969 |
| 951 // First request | 970 // First request |
| 952 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 971 controller().LoadURL( |
| 972 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 953 | 973 |
| 954 EXPECT_TRUE(controller().pending_entry()); | 974 EXPECT_TRUE(controller().pending_entry()); |
| 955 EXPECT_EQ(controller().pending_entry_index(), -1); | 975 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 956 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 976 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 957 | 977 |
| 958 ViewHostMsg_FrameNavigate_Params params; | 978 ViewHostMsg_FrameNavigate_Params params; |
| 959 params.page_id = 0; | 979 params.page_id = 0; |
| 960 params.url = url2; | 980 params.url = url2; |
| 961 params.transition = PageTransition::SERVER_REDIRECT; | 981 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 962 params.redirects.push_back(GURL("http://foo1")); | 982 params.redirects.push_back(GURL("http://foo1")); |
| 963 params.redirects.push_back(GURL("http://foo2")); | 983 params.redirects.push_back(GURL("http://foo2")); |
| 964 params.should_update_history = false; | 984 params.should_update_history = false; |
| 965 params.gesture = NavigationGestureAuto; | 985 params.gesture = NavigationGestureAuto; |
| 966 params.is_post = false; | 986 params.is_post = false; |
| 967 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 987 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 968 | 988 |
| 969 content::LoadCommittedDetails details; | 989 content::LoadCommittedDetails details; |
| 970 | 990 |
| 971 EXPECT_EQ(0U, notifications.size()); | 991 EXPECT_EQ(0U, notifications.size()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 993 | 1013 |
| 994 const GURL url1("http://foo1"); | 1014 const GURL url1("http://foo1"); |
| 995 rvh()->SendNavigate(0, url1); | 1015 rvh()->SendNavigate(0, url1); |
| 996 EXPECT_TRUE(notifications.Check1AndReset( | 1016 EXPECT_TRUE(notifications.Check1AndReset( |
| 997 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1017 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 998 | 1018 |
| 999 const GURL url2("http://foo2"); | 1019 const GURL url2("http://foo2"); |
| 1000 ViewHostMsg_FrameNavigate_Params params; | 1020 ViewHostMsg_FrameNavigate_Params params; |
| 1001 params.page_id = 1; | 1021 params.page_id = 1; |
| 1002 params.url = url2; | 1022 params.url = url2; |
| 1003 params.transition = PageTransition::MANUAL_SUBFRAME; | 1023 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; |
| 1004 params.should_update_history = false; | 1024 params.should_update_history = false; |
| 1005 params.gesture = NavigationGestureUser; | 1025 params.gesture = NavigationGestureUser; |
| 1006 params.is_post = false; | 1026 params.is_post = false; |
| 1007 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1027 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 1008 | 1028 |
| 1009 content::LoadCommittedDetails details; | 1029 content::LoadCommittedDetails details; |
| 1010 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1030 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 1011 EXPECT_TRUE(notifications.Check1AndReset( | 1031 EXPECT_TRUE(notifications.Check1AndReset( |
| 1012 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1032 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1013 EXPECT_EQ(url1, details.previous_url); | 1033 EXPECT_EQ(url1, details.previous_url); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1028 // just get thrown on the ground, but we shouldn't crash. | 1048 // just get thrown on the ground, but we shouldn't crash. |
| 1029 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { | 1049 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { |
| 1030 TestNotificationTracker notifications; | 1050 TestNotificationTracker notifications; |
| 1031 RegisterForAllNavNotifications(¬ifications, &controller()); | 1051 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1032 | 1052 |
| 1033 // Navigation controller currently has no entries. | 1053 // Navigation controller currently has no entries. |
| 1034 const GURL url("http://foo2"); | 1054 const GURL url("http://foo2"); |
| 1035 ViewHostMsg_FrameNavigate_Params params; | 1055 ViewHostMsg_FrameNavigate_Params params; |
| 1036 params.page_id = 1; | 1056 params.page_id = 1; |
| 1037 params.url = url; | 1057 params.url = url; |
| 1038 params.transition = PageTransition::AUTO_SUBFRAME; | 1058 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 1039 params.should_update_history = false; | 1059 params.should_update_history = false; |
| 1040 params.gesture = NavigationGestureAuto; | 1060 params.gesture = NavigationGestureAuto; |
| 1041 params.is_post = false; | 1061 params.is_post = false; |
| 1042 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1062 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 1043 | 1063 |
| 1044 content::LoadCommittedDetails details; | 1064 content::LoadCommittedDetails details; |
| 1045 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1065 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 1046 EXPECT_EQ(0U, notifications.size()); | 1066 EXPECT_EQ(0U, notifications.size()); |
| 1047 } | 1067 } |
| 1048 | 1068 |
| 1049 // Auto subframes are ones the page loads automatically like ads. They should | 1069 // Auto subframes are ones the page loads automatically like ads. They should |
| 1050 // not create new navigation entries. | 1070 // not create new navigation entries. |
| 1051 TEST_F(NavigationControllerTest, AutoSubframe) { | 1071 TEST_F(NavigationControllerTest, AutoSubframe) { |
| 1052 TestNotificationTracker notifications; | 1072 TestNotificationTracker notifications; |
| 1053 RegisterForAllNavNotifications(¬ifications, &controller()); | 1073 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1054 | 1074 |
| 1055 const GURL url1("http://foo1"); | 1075 const GURL url1("http://foo1"); |
| 1056 rvh()->SendNavigate(0, url1); | 1076 rvh()->SendNavigate(0, url1); |
| 1057 EXPECT_TRUE(notifications.Check1AndReset( | 1077 EXPECT_TRUE(notifications.Check1AndReset( |
| 1058 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1078 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1059 | 1079 |
| 1060 const GURL url2("http://foo2"); | 1080 const GURL url2("http://foo2"); |
| 1061 ViewHostMsg_FrameNavigate_Params params; | 1081 ViewHostMsg_FrameNavigate_Params params; |
| 1062 params.page_id = 0; | 1082 params.page_id = 0; |
| 1063 params.url = url2; | 1083 params.url = url2; |
| 1064 params.transition = PageTransition::AUTO_SUBFRAME; | 1084 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 1065 params.should_update_history = false; | 1085 params.should_update_history = false; |
| 1066 params.gesture = NavigationGestureUser; | 1086 params.gesture = NavigationGestureUser; |
| 1067 params.is_post = false; | 1087 params.is_post = false; |
| 1068 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1088 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 1069 | 1089 |
| 1070 // Navigating should do nothing. | 1090 // Navigating should do nothing. |
| 1071 content::LoadCommittedDetails details; | 1091 content::LoadCommittedDetails details; |
| 1072 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1092 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 1073 EXPECT_EQ(0U, notifications.size()); | 1093 EXPECT_EQ(0U, notifications.size()); |
| 1074 | 1094 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1085 const GURL url1("http://foo1"); | 1105 const GURL url1("http://foo1"); |
| 1086 rvh()->SendNavigate(0, url1); | 1106 rvh()->SendNavigate(0, url1); |
| 1087 EXPECT_TRUE(notifications.Check1AndReset( | 1107 EXPECT_TRUE(notifications.Check1AndReset( |
| 1088 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1108 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1089 | 1109 |
| 1090 // First manual subframe navigation. | 1110 // First manual subframe navigation. |
| 1091 const GURL url2("http://foo2"); | 1111 const GURL url2("http://foo2"); |
| 1092 ViewHostMsg_FrameNavigate_Params params; | 1112 ViewHostMsg_FrameNavigate_Params params; |
| 1093 params.page_id = 1; | 1113 params.page_id = 1; |
| 1094 params.url = url2; | 1114 params.url = url2; |
| 1095 params.transition = PageTransition::MANUAL_SUBFRAME; | 1115 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; |
| 1096 params.should_update_history = false; | 1116 params.should_update_history = false; |
| 1097 params.gesture = NavigationGestureUser; | 1117 params.gesture = NavigationGestureUser; |
| 1098 params.is_post = false; | 1118 params.is_post = false; |
| 1099 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1119 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 1100 | 1120 |
| 1101 // This should generate a new entry. | 1121 // This should generate a new entry. |
| 1102 content::LoadCommittedDetails details; | 1122 content::LoadCommittedDetails details; |
| 1103 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1123 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 1104 EXPECT_TRUE(notifications.Check1AndReset( | 1124 EXPECT_TRUE(notifications.Check1AndReset( |
| 1105 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1125 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 const GURL url1("http://foo"); | 1189 const GURL url1("http://foo"); |
| 1170 rvh()->SendNavigate(0, url1); | 1190 rvh()->SendNavigate(0, url1); |
| 1171 EXPECT_TRUE(notifications.Check1AndReset( | 1191 EXPECT_TRUE(notifications.Check1AndReset( |
| 1172 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1192 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1173 | 1193 |
| 1174 // First navigation. | 1194 // First navigation. |
| 1175 const GURL url2("http://foo#a"); | 1195 const GURL url2("http://foo#a"); |
| 1176 ViewHostMsg_FrameNavigate_Params params; | 1196 ViewHostMsg_FrameNavigate_Params params; |
| 1177 params.page_id = 1; | 1197 params.page_id = 1; |
| 1178 params.url = url2; | 1198 params.url = url2; |
| 1179 params.transition = PageTransition::LINK; | 1199 params.transition = content::PAGE_TRANSITION_LINK; |
| 1180 params.should_update_history = false; | 1200 params.should_update_history = false; |
| 1181 params.gesture = NavigationGestureUser; | 1201 params.gesture = NavigationGestureUser; |
| 1182 params.is_post = false; | 1202 params.is_post = false; |
| 1183 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1203 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 1184 | 1204 |
| 1185 // This should generate a new entry. | 1205 // This should generate a new entry. |
| 1186 content::LoadCommittedDetails details; | 1206 content::LoadCommittedDetails details; |
| 1187 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1207 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 1188 EXPECT_TRUE(notifications.Check1AndReset( | 1208 EXPECT_TRUE(notifications.Check1AndReset( |
| 1189 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1209 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 const GURL url1("http://foo"); | 1270 const GURL url1("http://foo"); |
| 1251 rvh()->SendNavigate(0, url1); | 1271 rvh()->SendNavigate(0, url1); |
| 1252 EXPECT_TRUE(notifications.Check1AndReset( | 1272 EXPECT_TRUE(notifications.Check1AndReset( |
| 1253 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1273 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1254 | 1274 |
| 1255 // First navigation. | 1275 // First navigation. |
| 1256 const GURL url2("http://foo#a"); | 1276 const GURL url2("http://foo#a"); |
| 1257 ViewHostMsg_FrameNavigate_Params params; | 1277 ViewHostMsg_FrameNavigate_Params params; |
| 1258 params.page_id = 0; // Same page_id | 1278 params.page_id = 0; // Same page_id |
| 1259 params.url = url2; | 1279 params.url = url2; |
| 1260 params.transition = PageTransition::LINK; | 1280 params.transition = content::PAGE_TRANSITION_LINK; |
| 1261 params.should_update_history = false; | 1281 params.should_update_history = false; |
| 1262 params.gesture = NavigationGestureUser; | 1282 params.gesture = NavigationGestureUser; |
| 1263 params.is_post = false; | 1283 params.is_post = false; |
| 1264 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1284 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
| 1265 | 1285 |
| 1266 // This should NOT generate a new entry, nor prune the list. | 1286 // This should NOT generate a new entry, nor prune the list. |
| 1267 content::LoadCommittedDetails details; | 1287 content::LoadCommittedDetails details; |
| 1268 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1288 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 1269 EXPECT_TRUE(notifications.Check1AndReset( | 1289 EXPECT_TRUE(notifications.Check1AndReset( |
| 1270 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1290 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1299 EXPECT_TRUE(notifications.Check1AndReset( | 1319 EXPECT_TRUE(notifications.Check1AndReset( |
| 1300 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1320 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1301 } | 1321 } |
| 1302 | 1322 |
| 1303 // Navigate within the page. | 1323 // Navigate within the page. |
| 1304 { | 1324 { |
| 1305 const GURL url("http://foo2/#a"); | 1325 const GURL url("http://foo2/#a"); |
| 1306 ViewHostMsg_FrameNavigate_Params params; | 1326 ViewHostMsg_FrameNavigate_Params params; |
| 1307 params.page_id = 1; // Same page_id | 1327 params.page_id = 1; // Same page_id |
| 1308 params.url = url; | 1328 params.url = url; |
| 1309 params.transition = PageTransition::LINK; | 1329 params.transition = content::PAGE_TRANSITION_LINK; |
| 1310 params.redirects.push_back(url); | 1330 params.redirects.push_back(url); |
| 1311 params.should_update_history = true; | 1331 params.should_update_history = true; |
| 1312 params.gesture = NavigationGestureUnknown; | 1332 params.gesture = NavigationGestureUnknown; |
| 1313 params.is_post = false; | 1333 params.is_post = false; |
| 1314 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1334 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 1315 | 1335 |
| 1316 // This should NOT generate a new entry, nor prune the list. | 1336 // This should NOT generate a new entry, nor prune the list. |
| 1317 content::LoadCommittedDetails details; | 1337 content::LoadCommittedDetails details; |
| 1318 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1338 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| 1319 EXPECT_TRUE(notifications.Check1AndReset( | 1339 EXPECT_TRUE(notifications.Check1AndReset( |
| 1320 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1340 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 1321 EXPECT_TRUE(details.is_in_page); | 1341 EXPECT_TRUE(details.is_in_page); |
| 1322 EXPECT_TRUE(details.did_replace_entry); | 1342 EXPECT_TRUE(details.did_replace_entry); |
| 1323 EXPECT_EQ(2, controller().entry_count()); | 1343 EXPECT_EQ(2, controller().entry_count()); |
| 1324 } | 1344 } |
| 1325 | 1345 |
| 1326 // Perform a client redirect to a new page. | 1346 // Perform a client redirect to a new page. |
| 1327 { | 1347 { |
| 1328 const GURL url("http://foo3/"); | 1348 const GURL url("http://foo3/"); |
| 1329 ViewHostMsg_FrameNavigate_Params params; | 1349 ViewHostMsg_FrameNavigate_Params params; |
| 1330 params.page_id = 2; // New page_id | 1350 params.page_id = 2; // New page_id |
| 1331 params.url = url; | 1351 params.url = url; |
| 1332 params.transition = PageTransition::CLIENT_REDIRECT; | 1352 params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 1333 params.redirects.push_back(GURL("http://foo2/#a")); | 1353 params.redirects.push_back(GURL("http://foo2/#a")); |
| 1334 params.redirects.push_back(url); | 1354 params.redirects.push_back(url); |
| 1335 params.should_update_history = true; | 1355 params.should_update_history = true; |
| 1336 params.gesture = NavigationGestureUnknown; | 1356 params.gesture = NavigationGestureUnknown; |
| 1337 params.is_post = false; | 1357 params.is_post = false; |
| 1338 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1358 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 1339 | 1359 |
| 1340 // This SHOULD generate a new entry. | 1360 // This SHOULD generate a new entry. |
| 1341 content::LoadCommittedDetails details; | 1361 content::LoadCommittedDetails details; |
| 1342 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1362 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { | 1412 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { |
| 1393 size_t original_count = NavigationController::max_entry_count(); | 1413 size_t original_count = NavigationController::max_entry_count(); |
| 1394 const int kMaxEntryCount = 5; | 1414 const int kMaxEntryCount = 5; |
| 1395 | 1415 |
| 1396 NavigationController::set_max_entry_count_for_testing(kMaxEntryCount); | 1416 NavigationController::set_max_entry_count_for_testing(kMaxEntryCount); |
| 1397 | 1417 |
| 1398 int url_index; | 1418 int url_index; |
| 1399 // Load up to the max count, all entries should be there. | 1419 // Load up to the max count, all entries should be there. |
| 1400 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 1420 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
| 1401 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1421 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
| 1402 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 1422 controller().LoadURL( |
| 1423 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1403 rvh()->SendNavigate(url_index, url); | 1424 rvh()->SendNavigate(url_index, url); |
| 1404 } | 1425 } |
| 1405 | 1426 |
| 1406 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1427 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1407 | 1428 |
| 1408 // Created a PrunedListener to observe prune notifications. | 1429 // Created a PrunedListener to observe prune notifications. |
| 1409 PrunedListener listener(&controller()); | 1430 PrunedListener listener(&controller()); |
| 1410 | 1431 |
| 1411 // Navigate some more. | 1432 // Navigate some more. |
| 1412 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1433 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
| 1413 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 1434 controller().LoadURL( |
| 1435 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1414 rvh()->SendNavigate(url_index, url); | 1436 rvh()->SendNavigate(url_index, url); |
| 1415 url_index++; | 1437 url_index++; |
| 1416 | 1438 |
| 1417 // We should have got a pruned navigation. | 1439 // We should have got a pruned navigation. |
| 1418 EXPECT_EQ(1, listener.notification_count_); | 1440 EXPECT_EQ(1, listener.notification_count_); |
| 1419 EXPECT_TRUE(listener.details_.from_front); | 1441 EXPECT_TRUE(listener.details_.from_front); |
| 1420 EXPECT_EQ(1, listener.details_.count); | 1442 EXPECT_EQ(1, listener.details_.count); |
| 1421 | 1443 |
| 1422 // We expect http://www.a.com/0 to be gone. | 1444 // We expect http://www.a.com/0 to be gone. |
| 1423 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1445 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1424 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), | 1446 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), |
| 1425 GURL("http:////www.a.com/1")); | 1447 GURL("http:////www.a.com/1")); |
| 1426 | 1448 |
| 1427 // More navigations. | 1449 // More navigations. |
| 1428 for (int i = 0; i < 3; i++) { | 1450 for (int i = 0; i < 3; i++) { |
| 1429 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); | 1451 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); |
| 1430 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 1452 controller().LoadURL( |
| 1431 rvh()->SendNavigate(url_index, url); | 1453 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1454 rvh()->SendNavigate(url_index, url); |
| 1432 url_index++; | 1455 url_index++; |
| 1433 } | 1456 } |
| 1434 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1457 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1435 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), | 1458 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), |
| 1436 GURL("http:////www.a.com/4")); | 1459 GURL("http:////www.a.com/4")); |
| 1437 | 1460 |
| 1438 NavigationController::set_max_entry_count_for_testing(original_count); | 1461 NavigationController::set_max_entry_count_for_testing(original_count); |
| 1439 } | 1462 } |
| 1440 | 1463 |
| 1441 // Tests that we can do a restore and navigate to the restored entries and | 1464 // Tests that we can do a restore and navigate to the restored entries and |
| 1442 // everything is updated properly. This can be tricky since there is no | 1465 // everything is updated properly. This can be tricky since there is no |
| 1443 // SiteInstance for the entries created initially. | 1466 // SiteInstance for the entries created initially. |
| 1444 TEST_F(NavigationControllerTest, RestoreNavigate) { | 1467 TEST_F(NavigationControllerTest, RestoreNavigate) { |
| 1445 // Create a NavigationController with a restored set of tabs. | 1468 // Create a NavigationController with a restored set of tabs. |
| 1446 GURL url("http://foo"); | 1469 GURL url("http://foo"); |
| 1447 std::vector<NavigationEntry*> entries; | 1470 std::vector<NavigationEntry*> entries; |
| 1448 NavigationEntry* entry = NavigationController::CreateNavigationEntry( | 1471 NavigationEntry* entry = NavigationController::CreateNavigationEntry( |
| 1449 url, GURL(), PageTransition::RELOAD, std::string(), profile()); | 1472 url, GURL(), content::PAGE_TRANSITION_RELOAD, std::string(), profile()); |
| 1450 entry->set_page_id(0); | 1473 entry->set_page_id(0); |
| 1451 entry->set_title(ASCIIToUTF16("Title")); | 1474 entry->set_title(ASCIIToUTF16("Title")); |
| 1452 entry->set_content_state("state"); | 1475 entry->set_content_state("state"); |
| 1453 entries.push_back(entry); | 1476 entries.push_back(entry); |
| 1454 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1477 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 1455 NavigationController& our_controller = our_contents.controller(); | 1478 NavigationController& our_controller = our_contents.controller(); |
| 1456 our_controller.Restore(0, true, &entries); | 1479 our_controller.Restore(0, true, &entries); |
| 1457 ASSERT_EQ(0u, entries.size()); | 1480 ASSERT_EQ(0u, entries.size()); |
| 1458 | 1481 |
| 1459 // Before navigating to the restored entry, it should have a restore_type | 1482 // Before navigating to the restored entry, it should have a restore_type |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1470 our_controller.pending_entry()); | 1493 our_controller.pending_entry()); |
| 1471 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->page_id()); | 1494 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->page_id()); |
| 1472 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1495 EXPECT_EQ(NavigationEntry::RESTORE_NONE, |
| 1473 our_controller.GetEntryAtIndex(0)->restore_type()); | 1496 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 1474 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 1497 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 1475 | 1498 |
| 1476 // Say we navigated to that entry. | 1499 // Say we navigated to that entry. |
| 1477 ViewHostMsg_FrameNavigate_Params params; | 1500 ViewHostMsg_FrameNavigate_Params params; |
| 1478 params.page_id = 0; | 1501 params.page_id = 0; |
| 1479 params.url = url; | 1502 params.url = url; |
| 1480 params.transition = PageTransition::LINK; | 1503 params.transition = content::PAGE_TRANSITION_LINK; |
| 1481 params.should_update_history = false; | 1504 params.should_update_history = false; |
| 1482 params.gesture = NavigationGestureUser; | 1505 params.gesture = NavigationGestureUser; |
| 1483 params.is_post = false; | 1506 params.is_post = false; |
| 1484 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1507 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 1485 content::LoadCommittedDetails details; | 1508 content::LoadCommittedDetails details; |
| 1486 our_controller.RendererDidNavigate(params, &details); | 1509 our_controller.RendererDidNavigate(params, &details); |
| 1487 | 1510 |
| 1488 // There should be no longer any pending entry and one committed one. This | 1511 // There should be no longer any pending entry and one committed one. This |
| 1489 // means that we were able to locate the entry, assign its site instance, and | 1512 // means that we were able to locate the entry, assign its site instance, and |
| 1490 // commit it properly. | 1513 // commit it properly. |
| 1491 EXPECT_EQ(1, our_controller.entry_count()); | 1514 EXPECT_EQ(1, our_controller.entry_count()); |
| 1492 EXPECT_EQ(0, our_controller.last_committed_entry_index()); | 1515 EXPECT_EQ(0, our_controller.last_committed_entry_index()); |
| 1493 EXPECT_FALSE(our_controller.pending_entry()); | 1516 EXPECT_FALSE(our_controller.pending_entry()); |
| 1494 EXPECT_EQ(url, | 1517 EXPECT_EQ(url, |
| 1495 our_controller.GetLastCommittedEntry()->site_instance()->site()); | 1518 our_controller.GetLastCommittedEntry()->site_instance()->site()); |
| 1496 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1519 EXPECT_EQ(NavigationEntry::RESTORE_NONE, |
| 1497 our_controller.GetEntryAtIndex(0)->restore_type()); | 1520 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 1498 } | 1521 } |
| 1499 | 1522 |
| 1500 // Tests that we can still navigate to a restored entry after a different | 1523 // Tests that we can still navigate to a restored entry after a different |
| 1501 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1524 // navigation fails and clears the pending entry. http://crbug.com/90085 |
| 1502 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1525 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
| 1503 // Create a NavigationController with a restored set of tabs. | 1526 // Create a NavigationController with a restored set of tabs. |
| 1504 GURL url("http://foo"); | 1527 GURL url("http://foo"); |
| 1505 std::vector<NavigationEntry*> entries; | 1528 std::vector<NavigationEntry*> entries; |
| 1506 NavigationEntry* entry = NavigationController::CreateNavigationEntry( | 1529 NavigationEntry* entry = NavigationController::CreateNavigationEntry( |
| 1507 url, GURL(), PageTransition::RELOAD, std::string(), profile()); | 1530 url, GURL(), content::PAGE_TRANSITION_RELOAD, std::string(), profile()); |
| 1508 entry->set_page_id(0); | 1531 entry->set_page_id(0); |
| 1509 entry->set_title(ASCIIToUTF16("Title")); | 1532 entry->set_title(ASCIIToUTF16("Title")); |
| 1510 entry->set_content_state("state"); | 1533 entry->set_content_state("state"); |
| 1511 entries.push_back(entry); | 1534 entries.push_back(entry); |
| 1512 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1535 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 1513 NavigationController& our_controller = our_contents.controller(); | 1536 NavigationController& our_controller = our_contents.controller(); |
| 1514 our_controller.Restore(0, true, &entries); | 1537 our_controller.Restore(0, true, &entries); |
| 1515 ASSERT_EQ(0u, entries.size()); | 1538 ASSERT_EQ(0u, entries.size()); |
| 1516 | 1539 |
| 1517 // Before navigating to the restored entry, it should have a restore_type | 1540 // Before navigating to the restored entry, it should have a restore_type |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1543 fail_load_params.url = url; | 1566 fail_load_params.url = url; |
| 1544 fail_load_params.showing_repost_interstitial = false; | 1567 fail_load_params.showing_repost_interstitial = false; |
| 1545 rvh->TestOnMessageReceived( | 1568 rvh->TestOnMessageReceived( |
| 1546 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 1569 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
| 1547 fail_load_params)); | 1570 fail_load_params)); |
| 1548 | 1571 |
| 1549 // Now the pending restored entry commits. | 1572 // Now the pending restored entry commits. |
| 1550 ViewHostMsg_FrameNavigate_Params params; | 1573 ViewHostMsg_FrameNavigate_Params params; |
| 1551 params.page_id = 0; | 1574 params.page_id = 0; |
| 1552 params.url = url; | 1575 params.url = url; |
| 1553 params.transition = PageTransition::LINK; | 1576 params.transition = content::PAGE_TRANSITION_LINK; |
| 1554 params.should_update_history = false; | 1577 params.should_update_history = false; |
| 1555 params.gesture = NavigationGestureUser; | 1578 params.gesture = NavigationGestureUser; |
| 1556 params.is_post = false; | 1579 params.is_post = false; |
| 1557 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1580 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 1558 content::LoadCommittedDetails details; | 1581 content::LoadCommittedDetails details; |
| 1559 our_controller.RendererDidNavigate(params, &details); | 1582 our_controller.RendererDidNavigate(params, &details); |
| 1560 | 1583 |
| 1561 // There should be no pending entry and one committed one. | 1584 // There should be no pending entry and one committed one. |
| 1562 EXPECT_EQ(1, our_controller.entry_count()); | 1585 EXPECT_EQ(1, our_controller.entry_count()); |
| 1563 EXPECT_EQ(0, our_controller.last_committed_entry_index()); | 1586 EXPECT_EQ(0, our_controller.last_committed_entry_index()); |
| 1564 EXPECT_FALSE(our_controller.pending_entry()); | 1587 EXPECT_FALSE(our_controller.pending_entry()); |
| 1565 EXPECT_EQ(url, | 1588 EXPECT_EQ(url, |
| 1566 our_controller.GetLastCommittedEntry()->site_instance()->site()); | 1589 our_controller.GetLastCommittedEntry()->site_instance()->site()); |
| 1567 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1590 EXPECT_EQ(NavigationEntry::RESTORE_NONE, |
| 1568 our_controller.GetEntryAtIndex(0)->restore_type()); | 1591 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 1569 } | 1592 } |
| 1570 | 1593 |
| 1571 // Make sure that the page type and stuff is correct after an interstitial. | 1594 // Make sure that the page type and stuff is correct after an interstitial. |
| 1572 TEST_F(NavigationControllerTest, Interstitial) { | 1595 TEST_F(NavigationControllerTest, Interstitial) { |
| 1573 // First navigate somewhere normal. | 1596 // First navigate somewhere normal. |
| 1574 const GURL url1("http://foo"); | 1597 const GURL url1("http://foo"); |
| 1575 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 1598 controller().LoadURL( |
| 1599 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1576 rvh()->SendNavigate(0, url1); | 1600 rvh()->SendNavigate(0, url1); |
| 1577 | 1601 |
| 1578 // Now navigate somewhere with an interstitial. | 1602 // Now navigate somewhere with an interstitial. |
| 1579 const GURL url2("http://bar"); | 1603 const GURL url2("http://bar"); |
| 1580 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 1604 controller().LoadURL( |
| 1605 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1581 controller().pending_entry()->set_page_type(INTERSTITIAL_PAGE); | 1606 controller().pending_entry()->set_page_type(INTERSTITIAL_PAGE); |
| 1582 | 1607 |
| 1583 // At this point the interstitial will be displayed and the load will still | 1608 // At this point the interstitial will be displayed and the load will still |
| 1584 // be pending. If the user continues, the load will commit. | 1609 // be pending. If the user continues, the load will commit. |
| 1585 rvh()->SendNavigate(1, url2); | 1610 rvh()->SendNavigate(1, url2); |
| 1586 | 1611 |
| 1587 // The page should be a normal page again. | 1612 // The page should be a normal page again. |
| 1588 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); | 1613 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); |
| 1589 EXPECT_EQ(NORMAL_PAGE, controller().GetLastCommittedEntry()->page_type()); | 1614 EXPECT_EQ(NORMAL_PAGE, controller().GetLastCommittedEntry()->page_type()); |
| 1590 } | 1615 } |
| 1591 | 1616 |
| 1592 TEST_F(NavigationControllerTest, RemoveEntry) { | 1617 TEST_F(NavigationControllerTest, RemoveEntry) { |
| 1593 const GURL url1("http://foo/1"); | 1618 const GURL url1("http://foo/1"); |
| 1594 const GURL url2("http://foo/2"); | 1619 const GURL url2("http://foo/2"); |
| 1595 const GURL url3("http://foo/3"); | 1620 const GURL url3("http://foo/3"); |
| 1596 const GURL url4("http://foo/4"); | 1621 const GURL url4("http://foo/4"); |
| 1597 const GURL url5("http://foo/5"); | 1622 const GURL url5("http://foo/5"); |
| 1598 const GURL pending_url("http://foo/pending"); | 1623 const GURL pending_url("http://foo/pending"); |
| 1599 const GURL default_url("http://foo/default"); | 1624 const GURL default_url("http://foo/default"); |
| 1600 | 1625 |
| 1601 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 1626 controller().LoadURL( |
| 1627 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1602 rvh()->SendNavigate(0, url1); | 1628 rvh()->SendNavigate(0, url1); |
| 1603 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 1629 controller().LoadURL( |
| 1630 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1604 rvh()->SendNavigate(1, url2); | 1631 rvh()->SendNavigate(1, url2); |
| 1605 controller().LoadURL(url3, GURL(), PageTransition::TYPED, std::string()); | 1632 controller().LoadURL( |
| 1633 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1606 rvh()->SendNavigate(2, url3); | 1634 rvh()->SendNavigate(2, url3); |
| 1607 controller().LoadURL(url4, GURL(), PageTransition::TYPED, std::string()); | 1635 controller().LoadURL( |
| 1636 url4, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1608 rvh()->SendNavigate(3, url4); | 1637 rvh()->SendNavigate(3, url4); |
| 1609 controller().LoadURL(url5, GURL(), PageTransition::TYPED, std::string()); | 1638 controller().LoadURL( |
| 1639 url5, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1610 rvh()->SendNavigate(4, url5); | 1640 rvh()->SendNavigate(4, url5); |
| 1611 | 1641 |
| 1612 // Remove the last entry. | 1642 // Remove the last entry. |
| 1613 controller().RemoveEntryAtIndex( | 1643 controller().RemoveEntryAtIndex( |
| 1614 controller().entry_count() - 1, default_url); | 1644 controller().entry_count() - 1, default_url); |
| 1615 EXPECT_EQ(4, controller().entry_count()); | 1645 EXPECT_EQ(4, controller().entry_count()); |
| 1616 EXPECT_EQ(3, controller().last_committed_entry_index()); | 1646 EXPECT_EQ(3, controller().last_committed_entry_index()); |
| 1617 NavigationEntry* pending_entry = controller().pending_entry(); | 1647 NavigationEntry* pending_entry = controller().pending_entry(); |
| 1618 EXPECT_TRUE(pending_entry && pending_entry->url() == url4); | 1648 EXPECT_TRUE(pending_entry && pending_entry->url() == url4); |
| 1619 | 1649 |
| 1620 // Add a pending entry. | 1650 // Add a pending entry. |
| 1621 controller().LoadURL(pending_url, GURL(), PageTransition::TYPED, | 1651 controller().LoadURL(pending_url, GURL(), content::PAGE_TRANSITION_TYPED, |
| 1622 std::string()); | 1652 std::string()); |
| 1623 // Now remove the last entry. | 1653 // Now remove the last entry. |
| 1624 controller().RemoveEntryAtIndex( | 1654 controller().RemoveEntryAtIndex( |
| 1625 controller().entry_count() - 1, default_url); | 1655 controller().entry_count() - 1, default_url); |
| 1626 // The pending entry should have been discarded and the last committed entry | 1656 // The pending entry should have been discarded and the last committed entry |
| 1627 // removed. | 1657 // removed. |
| 1628 EXPECT_EQ(3, controller().entry_count()); | 1658 EXPECT_EQ(3, controller().entry_count()); |
| 1629 EXPECT_EQ(2, controller().last_committed_entry_index()); | 1659 EXPECT_EQ(2, controller().last_committed_entry_index()); |
| 1630 pending_entry = controller().pending_entry(); | 1660 pending_entry = controller().pending_entry(); |
| 1631 EXPECT_TRUE(pending_entry && pending_entry->url() == url3); | 1661 EXPECT_TRUE(pending_entry && pending_entry->url() == url3); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1654 TestNotificationTracker notifications; | 1684 TestNotificationTracker notifications; |
| 1655 RegisterForAllNavNotifications(¬ifications, &controller()); | 1685 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1656 | 1686 |
| 1657 const GURL url0("http://foo/0"); | 1687 const GURL url0("http://foo/0"); |
| 1658 const GURL url1("http://foo/1"); | 1688 const GURL url1("http://foo/1"); |
| 1659 const GURL url2("http://foo/2"); | 1689 const GURL url2("http://foo/2"); |
| 1660 const GURL url3("http://foo/3"); | 1690 const GURL url3("http://foo/3"); |
| 1661 const GURL url4("http://foo/4"); | 1691 const GURL url4("http://foo/4"); |
| 1662 const GURL transient_url("http://foo/transient"); | 1692 const GURL transient_url("http://foo/transient"); |
| 1663 | 1693 |
| 1664 controller().LoadURL(url0, GURL(), PageTransition::TYPED, std::string()); | 1694 controller().LoadURL( |
| 1695 url0, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1665 rvh()->SendNavigate(0, url0); | 1696 rvh()->SendNavigate(0, url0); |
| 1666 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 1697 controller().LoadURL( |
| 1698 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1667 rvh()->SendNavigate(1, url1); | 1699 rvh()->SendNavigate(1, url1); |
| 1668 | 1700 |
| 1669 notifications.Reset(); | 1701 notifications.Reset(); |
| 1670 | 1702 |
| 1671 // Adding a transient with no pending entry. | 1703 // Adding a transient with no pending entry. |
| 1672 NavigationEntry* transient_entry = new NavigationEntry; | 1704 NavigationEntry* transient_entry = new NavigationEntry; |
| 1673 transient_entry->set_url(transient_url); | 1705 transient_entry->set_url(transient_url); |
| 1674 controller().AddTransientEntry(transient_entry); | 1706 controller().AddTransientEntry(transient_entry); |
| 1675 | 1707 |
| 1676 // We should not have received any notifications. | 1708 // We should not have received any notifications. |
| 1677 EXPECT_EQ(0U, notifications.size()); | 1709 EXPECT_EQ(0U, notifications.size()); |
| 1678 | 1710 |
| 1679 // Check our state. | 1711 // Check our state. |
| 1680 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1712 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1681 EXPECT_EQ(controller().entry_count(), 3); | 1713 EXPECT_EQ(controller().entry_count(), 3); |
| 1682 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 1714 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
| 1683 EXPECT_EQ(controller().pending_entry_index(), -1); | 1715 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 1684 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 1716 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 1685 EXPECT_FALSE(controller().pending_entry()); | 1717 EXPECT_FALSE(controller().pending_entry()); |
| 1686 EXPECT_TRUE(controller().CanGoBack()); | 1718 EXPECT_TRUE(controller().CanGoBack()); |
| 1687 EXPECT_FALSE(controller().CanGoForward()); | 1719 EXPECT_FALSE(controller().CanGoForward()); |
| 1688 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 1720 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 1689 | 1721 |
| 1690 // Navigate. | 1722 // Navigate. |
| 1691 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 1723 controller().LoadURL( |
| 1724 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1692 rvh()->SendNavigate(2, url2); | 1725 rvh()->SendNavigate(2, url2); |
| 1693 | 1726 |
| 1694 // We should have navigated, transient entry should be gone. | 1727 // We should have navigated, transient entry should be gone. |
| 1695 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); | 1728 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); |
| 1696 EXPECT_EQ(controller().entry_count(), 3); | 1729 EXPECT_EQ(controller().entry_count(), 3); |
| 1697 | 1730 |
| 1698 // Add a transient again, then navigate with no pending entry this time. | 1731 // Add a transient again, then navigate with no pending entry this time. |
| 1699 transient_entry = new NavigationEntry; | 1732 transient_entry = new NavigationEntry; |
| 1700 transient_entry->set_url(transient_url); | 1733 transient_entry->set_url(transient_url); |
| 1701 controller().AddTransientEntry(transient_entry); | 1734 controller().AddTransientEntry(transient_entry); |
| 1702 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1735 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1703 rvh()->SendNavigate(3, url3); | 1736 rvh()->SendNavigate(3, url3); |
| 1704 // Transient entry should be gone. | 1737 // Transient entry should be gone. |
| 1705 EXPECT_EQ(url3, controller().GetActiveEntry()->url()); | 1738 EXPECT_EQ(url3, controller().GetActiveEntry()->url()); |
| 1706 EXPECT_EQ(controller().entry_count(), 4); | 1739 EXPECT_EQ(controller().entry_count(), 4); |
| 1707 | 1740 |
| 1708 // Initiate a navigation, add a transient then commit navigation. | 1741 // Initiate a navigation, add a transient then commit navigation. |
| 1709 controller().LoadURL(url4, GURL(), PageTransition::TYPED, std::string()); | 1742 controller().LoadURL( |
| 1743 url4, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1710 transient_entry = new NavigationEntry; | 1744 transient_entry = new NavigationEntry; |
| 1711 transient_entry->set_url(transient_url); | 1745 transient_entry->set_url(transient_url); |
| 1712 controller().AddTransientEntry(transient_entry); | 1746 controller().AddTransientEntry(transient_entry); |
| 1713 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1747 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1714 rvh()->SendNavigate(4, url4); | 1748 rvh()->SendNavigate(4, url4); |
| 1715 EXPECT_EQ(url4, controller().GetActiveEntry()->url()); | 1749 EXPECT_EQ(url4, controller().GetActiveEntry()->url()); |
| 1716 EXPECT_EQ(controller().entry_count(), 5); | 1750 EXPECT_EQ(controller().entry_count(), 5); |
| 1717 | 1751 |
| 1718 // Add a transient and go back. This should simply remove the transient. | 1752 // Add a transient and go back. This should simply remove the transient. |
| 1719 transient_entry = new NavigationEntry; | 1753 transient_entry = new NavigationEntry; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 | 1848 |
| 1815 // We should be at the first navigation entry. | 1849 // We should be at the first navigation entry. |
| 1816 EXPECT_EQ(controller().entry_count(), 1); | 1850 EXPECT_EQ(controller().entry_count(), 1); |
| 1817 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 1851 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 1818 | 1852 |
| 1819 // Navigate a subframe that would normally count as in-page. | 1853 // Navigate a subframe that would normally count as in-page. |
| 1820 const GURL subframe("http://www.google.com/#"); | 1854 const GURL subframe("http://www.google.com/#"); |
| 1821 ViewHostMsg_FrameNavigate_Params params; | 1855 ViewHostMsg_FrameNavigate_Params params; |
| 1822 params.page_id = 0; | 1856 params.page_id = 0; |
| 1823 params.url = subframe; | 1857 params.url = subframe; |
| 1824 params.transition = PageTransition::AUTO_SUBFRAME; | 1858 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 1825 params.should_update_history = false; | 1859 params.should_update_history = false; |
| 1826 params.gesture = NavigationGestureAuto; | 1860 params.gesture = NavigationGestureAuto; |
| 1827 params.is_post = false; | 1861 params.is_post = false; |
| 1828 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(subframe)); | 1862 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(subframe)); |
| 1829 content::LoadCommittedDetails details; | 1863 content::LoadCommittedDetails details; |
| 1830 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1864 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 1831 | 1865 |
| 1832 // Nothing should have changed. | 1866 // Nothing should have changed. |
| 1833 EXPECT_EQ(controller().entry_count(), 1); | 1867 EXPECT_EQ(controller().entry_count(), 1); |
| 1834 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 1868 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 | 1905 |
| 1872 // Tests a subframe navigation while a toplevel navigation is pending. | 1906 // Tests a subframe navigation while a toplevel navigation is pending. |
| 1873 // http://crbug.com/43967 | 1907 // http://crbug.com/43967 |
| 1874 TEST_F(NavigationControllerTest, SubframeWhilePending) { | 1908 TEST_F(NavigationControllerTest, SubframeWhilePending) { |
| 1875 // Load the first page. | 1909 // Load the first page. |
| 1876 const GURL url1("http://foo/"); | 1910 const GURL url1("http://foo/"); |
| 1877 NavigateAndCommit(url1); | 1911 NavigateAndCommit(url1); |
| 1878 | 1912 |
| 1879 // Now start a pending load to a totally different page, but don't commit it. | 1913 // Now start a pending load to a totally different page, but don't commit it. |
| 1880 const GURL url2("http://bar/"); | 1914 const GURL url2("http://bar/"); |
| 1881 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 1915 controller().LoadURL( |
| 1916 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1882 | 1917 |
| 1883 // Send a subframe update from the first page, as if one had just | 1918 // Send a subframe update from the first page, as if one had just |
| 1884 // automatically loaded. Auto subframes don't increment the page ID. | 1919 // automatically loaded. Auto subframes don't increment the page ID. |
| 1885 const GURL url1_sub("http://foo/subframe"); | 1920 const GURL url1_sub("http://foo/subframe"); |
| 1886 ViewHostMsg_FrameNavigate_Params params; | 1921 ViewHostMsg_FrameNavigate_Params params; |
| 1887 params.page_id = controller().GetLastCommittedEntry()->page_id(); | 1922 params.page_id = controller().GetLastCommittedEntry()->page_id(); |
| 1888 params.url = url1_sub; | 1923 params.url = url1_sub; |
| 1889 params.transition = PageTransition::AUTO_SUBFRAME; | 1924 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 1890 params.should_update_history = false; | 1925 params.should_update_history = false; |
| 1891 params.gesture = NavigationGestureAuto; | 1926 params.gesture = NavigationGestureAuto; |
| 1892 params.is_post = false; | 1927 params.is_post = false; |
| 1893 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1_sub)); | 1928 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1_sub)); |
| 1894 content::LoadCommittedDetails details; | 1929 content::LoadCommittedDetails details; |
| 1895 | 1930 |
| 1896 // This should return false meaning that nothing was actually updated. | 1931 // This should return false meaning that nothing was actually updated. |
| 1897 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1932 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
| 1898 | 1933 |
| 1899 // The notification should have updated the last committed one, and not | 1934 // The notification should have updated the last committed one, and not |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 const GURL url1("http://foo1"); | 1998 const GURL url1("http://foo1"); |
| 1964 const GURL url2("http://foo2"); | 1999 const GURL url2("http://foo2"); |
| 1965 const GURL url3("http://foo3"); | 2000 const GURL url3("http://foo3"); |
| 1966 | 2001 |
| 1967 NavigateAndCommit(url1); | 2002 NavigateAndCommit(url1); |
| 1968 NavigateAndCommit(url2); | 2003 NavigateAndCommit(url2); |
| 1969 controller().GoBack(); | 2004 controller().GoBack(); |
| 1970 | 2005 |
| 1971 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 2006 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 1972 NavigationController& other_controller = other_contents->controller(); | 2007 NavigationController& other_controller = other_contents->controller(); |
| 1973 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED, std::string()); | 2008 other_controller.LoadURL( |
| 2009 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1974 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); | 2010 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); |
| 1975 other_controller.CopyStateFromAndPrune(&controller()); | 2011 other_controller.CopyStateFromAndPrune(&controller()); |
| 1976 | 2012 |
| 1977 // other_controller should now contain 1 entry for url1, and a pending entry | 2013 // other_controller should now contain 1 entry for url1, and a pending entry |
| 1978 // for url3. | 2014 // for url3. |
| 1979 | 2015 |
| 1980 ASSERT_EQ(1, other_controller.entry_count()); | 2016 ASSERT_EQ(1, other_controller.entry_count()); |
| 1981 | 2017 |
| 1982 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2018 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); |
| 1983 | 2019 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2099 | 2135 |
| 2100 EXPECT_EQ(0, controller().pending_entry_index()); | 2136 EXPECT_EQ(0, controller().pending_entry_index()); |
| 2101 } | 2137 } |
| 2102 | 2138 |
| 2103 // Test call to PruneAllButActive for transient entry. | 2139 // Test call to PruneAllButActive for transient entry. |
| 2104 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { | 2140 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { |
| 2105 const GURL url0("http://foo/0"); | 2141 const GURL url0("http://foo/0"); |
| 2106 const GURL url1("http://foo/1"); | 2142 const GURL url1("http://foo/1"); |
| 2107 const GURL transient_url("http://foo/transient"); | 2143 const GURL transient_url("http://foo/transient"); |
| 2108 | 2144 |
| 2109 controller().LoadURL(url0, GURL(), PageTransition::TYPED, std::string()); | 2145 controller().LoadURL( |
| 2146 url0, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 2110 rvh()->SendNavigate(0, url0); | 2147 rvh()->SendNavigate(0, url0); |
| 2111 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 2148 controller().LoadURL( |
| 2149 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 2112 rvh()->SendNavigate(1, url1); | 2150 rvh()->SendNavigate(1, url1); |
| 2113 | 2151 |
| 2114 // Adding a transient with no pending entry. | 2152 // Adding a transient with no pending entry. |
| 2115 NavigationEntry* transient_entry = new NavigationEntry; | 2153 NavigationEntry* transient_entry = new NavigationEntry; |
| 2116 transient_entry->set_url(transient_url); | 2154 transient_entry->set_url(transient_url); |
| 2117 controller().AddTransientEntry(transient_entry); | 2155 controller().AddTransientEntry(transient_entry); |
| 2118 | 2156 |
| 2119 controller().PruneAllButActive(); | 2157 controller().PruneAllButActive(); |
| 2120 | 2158 |
| 2121 EXPECT_EQ(-1, controller().pending_entry_index()); | 2159 EXPECT_EQ(-1, controller().pending_entry_index()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 SessionServiceTestHelper session_helper_; | 2279 SessionServiceTestHelper session_helper_; |
| 2242 | 2280 |
| 2243 private: | 2281 private: |
| 2244 ProfileManager* profile_manager_; | 2282 ProfileManager* profile_manager_; |
| 2245 FilePath test_dir_; | 2283 FilePath test_dir_; |
| 2246 }; | 2284 }; |
| 2247 | 2285 |
| 2248 // A basic test case. Navigates to a single url, and make sure the history | 2286 // A basic test case. Navigates to a single url, and make sure the history |
| 2249 // db matches. | 2287 // db matches. |
| 2250 TEST_F(NavigationControllerHistoryTest, Basic) { | 2288 TEST_F(NavigationControllerHistoryTest, Basic) { |
| 2251 controller().LoadURL(url0, GURL(), PageTransition::LINK); | 2289 controller().LoadURL(url0, GURL(), content::PAGE_TRANSITION_LINK); |
| 2252 rvh()->SendNavigate(0, url0); | 2290 rvh()->SendNavigate(0, url0); |
| 2253 | 2291 |
| 2254 GetLastSession(); | 2292 GetLastSession(); |
| 2255 | 2293 |
| 2256 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); | 2294 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); |
| 2257 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); | 2295 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); |
| 2258 TabNavigation nav1(0, url0, GURL(), string16(), | 2296 TabNavigation nav1(0, url0, GURL(), string16(), |
| 2259 webkit_glue::CreateHistoryStateForURL(url0), | 2297 webkit_glue::CreateHistoryStateForURL(url0), |
| 2260 PageTransition::LINK); | 2298 content::PAGE_TRANSITION_LINK); |
| 2261 session_helper_.AssertNavigationEquals(nav1, | 2299 session_helper_.AssertNavigationEquals(nav1, |
| 2262 windows_[0]->tabs[0]->navigations[0]); | 2300 windows_[0]->tabs[0]->navigations[0]); |
| 2263 } | 2301 } |
| 2264 | 2302 |
| 2265 // Navigates to three urls, then goes back and make sure the history database | 2303 // Navigates to three urls, then goes back and make sure the history database |
| 2266 // is in sync. | 2304 // is in sync. |
| 2267 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { | 2305 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { |
| 2268 rvh()->SendNavigate(0, url0); | 2306 rvh()->SendNavigate(0, url0); |
| 2269 rvh()->SendNavigate(1, url1); | 2307 rvh()->SendNavigate(1, url1); |
| 2270 rvh()->SendNavigate(2, url2); | 2308 rvh()->SendNavigate(2, url2); |
| 2271 | 2309 |
| 2272 controller().GoBack(); | 2310 controller().GoBack(); |
| 2273 rvh()->SendNavigate(1, url1); | 2311 rvh()->SendNavigate(1, url1); |
| 2274 | 2312 |
| 2275 GetLastSession(); | 2313 GetLastSession(); |
| 2276 | 2314 |
| 2277 session_helper_.AssertSingleWindowWithSingleTab(windows_, 3); | 2315 session_helper_.AssertSingleWindowWithSingleTab(windows_, 3); |
| 2278 session_helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); | 2316 session_helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); |
| 2279 | 2317 |
| 2280 TabNavigation nav(0, url0, GURL(), string16(), | 2318 TabNavigation nav(0, url0, GURL(), string16(), |
| 2281 webkit_glue::CreateHistoryStateForURL(url0), | 2319 webkit_glue::CreateHistoryStateForURL(url0), |
| 2282 PageTransition::LINK); | 2320 content::PAGE_TRANSITION_LINK); |
| 2283 session_helper_.AssertNavigationEquals(nav, | 2321 session_helper_.AssertNavigationEquals(nav, |
| 2284 windows_[0]->tabs[0]->navigations[0]); | 2322 windows_[0]->tabs[0]->navigations[0]); |
| 2285 nav.set_url(url1); | 2323 nav.set_url(url1); |
| 2286 session_helper_.AssertNavigationEquals(nav, | 2324 session_helper_.AssertNavigationEquals(nav, |
| 2287 windows_[0]->tabs[0]->navigations[1]); | 2325 windows_[0]->tabs[0]->navigations[1]); |
| 2288 nav.set_url(url2); | 2326 nav.set_url(url2); |
| 2289 session_helper_.AssertNavigationEquals(nav, | 2327 session_helper_.AssertNavigationEquals(nav, |
| 2290 windows_[0]->tabs[0]->navigations[2]); | 2328 windows_[0]->tabs[0]->navigations[2]); |
| 2291 } | 2329 } |
| 2292 | 2330 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2306 | 2344 |
| 2307 // Now have url0, and url2. | 2345 // Now have url0, and url2. |
| 2308 | 2346 |
| 2309 GetLastSession(); | 2347 GetLastSession(); |
| 2310 | 2348 |
| 2311 session_helper_.AssertSingleWindowWithSingleTab(windows_, 2); | 2349 session_helper_.AssertSingleWindowWithSingleTab(windows_, 2); |
| 2312 session_helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); | 2350 session_helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); |
| 2313 | 2351 |
| 2314 TabNavigation nav(0, url0, GURL(), string16(), | 2352 TabNavigation nav(0, url0, GURL(), string16(), |
| 2315 webkit_glue::CreateHistoryStateForURL(url0), | 2353 webkit_glue::CreateHistoryStateForURL(url0), |
| 2316 PageTransition::LINK); | 2354 content::PAGE_TRANSITION_LINK); |
| 2317 session_helper_.AssertNavigationEquals(nav, | 2355 session_helper_.AssertNavigationEquals(nav, |
| 2318 windows_[0]->tabs[0]->navigations[0]); | 2356 windows_[0]->tabs[0]->navigations[0]); |
| 2319 nav.set_url(url2); | 2357 nav.set_url(url2); |
| 2320 session_helper_.AssertNavigationEquals(nav, | 2358 session_helper_.AssertNavigationEquals(nav, |
| 2321 windows_[0]->tabs[0]->navigations[1]); | 2359 windows_[0]->tabs[0]->navigations[1]); |
| 2322 } | 2360 } |
| 2323 */ | 2361 */ |
| OLD | NEW |