| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST_F(NavigationControllerTest, LoadURL) { | 87 TEST_F(NavigationControllerTest, LoadURL) { |
| 88 TestNotificationTracker notifications; | 88 TestNotificationTracker notifications; |
| 89 RegisterForAllNavNotifications(¬ifications, &controller()); | 89 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 90 | 90 |
| 91 const GURL url1("http://foo1"); | 91 const GURL url1("http://foo1"); |
| 92 const GURL url2("http://foo2"); | 92 const GURL url2("http://foo2"); |
| 93 | 93 |
| 94 controller().LoadURL( | 94 controller().LoadURL( |
| 95 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 95 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 96 // Creating a pending notification should not have issued any of the | 96 // Creating a pending notification should not have issued any of the |
| 97 // notifications we're listening for. | 97 // notifications we're listening for. |
| 98 EXPECT_EQ(0U, notifications.size()); | 98 EXPECT_EQ(0U, notifications.size()); |
| 99 | 99 |
| 100 // The load should now be pending. | 100 // The load should now be pending. |
| 101 EXPECT_EQ(controller().entry_count(), 0); | 101 EXPECT_EQ(controller().entry_count(), 0); |
| 102 EXPECT_EQ(controller().last_committed_entry_index(), -1); | 102 EXPECT_EQ(controller().last_committed_entry_index(), -1); |
| 103 EXPECT_EQ(controller().pending_entry_index(), -1); | 103 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 104 EXPECT_FALSE(controller().GetLastCommittedEntry()); | 104 EXPECT_FALSE(controller().GetLastCommittedEntry()); |
| 105 EXPECT_TRUE(controller().pending_entry()); | 105 EXPECT_TRUE(controller().pending_entry()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 119 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 120 EXPECT_EQ(controller().pending_entry_index(), -1); | 120 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 121 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 121 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 122 EXPECT_FALSE(controller().pending_entry()); | 122 EXPECT_FALSE(controller().pending_entry()); |
| 123 EXPECT_FALSE(controller().CanGoBack()); | 123 EXPECT_FALSE(controller().CanGoBack()); |
| 124 EXPECT_FALSE(controller().CanGoForward()); | 124 EXPECT_FALSE(controller().CanGoForward()); |
| 125 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 125 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 126 | 126 |
| 127 // Load another... | 127 // Load another... |
| 128 controller().LoadURL( | 128 controller().LoadURL( |
| 129 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 129 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 130 | 130 |
| 131 // The load should now be pending. | 131 // The load should now be pending. |
| 132 EXPECT_EQ(controller().entry_count(), 1); | 132 EXPECT_EQ(controller().entry_count(), 1); |
| 133 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 133 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 134 EXPECT_EQ(controller().pending_entry_index(), -1); | 134 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 135 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 135 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 136 EXPECT_TRUE(controller().pending_entry()); | 136 EXPECT_TRUE(controller().pending_entry()); |
| 137 // TODO(darin): maybe this should really be true? | 137 // TODO(darin): maybe this should really be true? |
| 138 EXPECT_FALSE(controller().CanGoBack()); | 138 EXPECT_FALSE(controller().CanGoBack()); |
| 139 EXPECT_FALSE(controller().CanGoForward()); | 139 EXPECT_FALSE(controller().CanGoForward()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 161 // new session history entry. This is what happens when you press enter in the | 161 // new session history entry. This is what happens when you press enter in the |
| 162 // URL bar to reload: a pending entry is created and then it is discarded when | 162 // URL bar to reload: a pending entry is created and then it is discarded when |
| 163 // the load commits (because WebCore didn't actually make a new entry). | 163 // the load commits (because WebCore didn't actually make a new entry). |
| 164 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 164 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
| 165 TestNotificationTracker notifications; | 165 TestNotificationTracker notifications; |
| 166 RegisterForAllNavNotifications(¬ifications, &controller()); | 166 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 167 | 167 |
| 168 const GURL url1("http://foo1"); | 168 const GURL url1("http://foo1"); |
| 169 | 169 |
| 170 controller().LoadURL( | 170 controller().LoadURL( |
| 171 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 171 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 172 EXPECT_EQ(0U, notifications.size()); | 172 EXPECT_EQ(0U, notifications.size()); |
| 173 rvh()->SendNavigate(0, url1); | 173 rvh()->SendNavigate(0, url1); |
| 174 EXPECT_TRUE(notifications.Check1AndReset( | 174 EXPECT_TRUE(notifications.Check1AndReset( |
| 175 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 175 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 176 | 176 |
| 177 controller().LoadURL( | 177 controller().LoadURL( |
| 178 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 178 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 179 EXPECT_EQ(0U, notifications.size()); | 179 EXPECT_EQ(0U, notifications.size()); |
| 180 rvh()->SendNavigate(0, url1); | 180 rvh()->SendNavigate(0, url1); |
| 181 EXPECT_TRUE(notifications.Check1AndReset( | 181 EXPECT_TRUE(notifications.Check1AndReset( |
| 182 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 182 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 183 | 183 |
| 184 // We should not have produced a new session history entry. | 184 // We should not have produced a new session history entry. |
| 185 EXPECT_EQ(controller().entry_count(), 1); | 185 EXPECT_EQ(controller().entry_count(), 1); |
| 186 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 186 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 187 EXPECT_EQ(controller().pending_entry_index(), -1); | 187 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 188 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 188 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 189 EXPECT_FALSE(controller().pending_entry()); | 189 EXPECT_FALSE(controller().pending_entry()); |
| 190 EXPECT_FALSE(controller().CanGoBack()); | 190 EXPECT_FALSE(controller().CanGoBack()); |
| 191 EXPECT_FALSE(controller().CanGoForward()); | 191 EXPECT_FALSE(controller().CanGoForward()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Tests loading a URL but discarding it before the load commits. | 194 // Tests loading a URL but discarding it before the load commits. |
| 195 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 195 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
| 196 TestNotificationTracker notifications; | 196 TestNotificationTracker notifications; |
| 197 RegisterForAllNavNotifications(¬ifications, &controller()); | 197 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 198 | 198 |
| 199 const GURL url1("http://foo1"); | 199 const GURL url1("http://foo1"); |
| 200 const GURL url2("http://foo2"); | 200 const GURL url2("http://foo2"); |
| 201 | 201 |
| 202 controller().LoadURL( | 202 controller().LoadURL( |
| 203 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 203 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 204 EXPECT_EQ(0U, notifications.size()); | 204 EXPECT_EQ(0U, notifications.size()); |
| 205 rvh()->SendNavigate(0, url1); | 205 rvh()->SendNavigate(0, url1); |
| 206 EXPECT_TRUE(notifications.Check1AndReset( | 206 EXPECT_TRUE(notifications.Check1AndReset( |
| 207 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 207 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 208 | 208 |
| 209 controller().LoadURL( | 209 controller().LoadURL( |
| 210 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 210 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 211 controller().DiscardNonCommittedEntries(); | 211 controller().DiscardNonCommittedEntries(); |
| 212 EXPECT_EQ(0U, notifications.size()); | 212 EXPECT_EQ(0U, notifications.size()); |
| 213 | 213 |
| 214 // Should not have produced a new session history entry. | 214 // Should not have produced a new session history entry. |
| 215 EXPECT_EQ(controller().entry_count(), 1); | 215 EXPECT_EQ(controller().entry_count(), 1); |
| 216 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 216 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
| 217 EXPECT_EQ(controller().pending_entry_index(), -1); | 217 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 218 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 218 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 219 EXPECT_FALSE(controller().pending_entry()); | 219 EXPECT_FALSE(controller().pending_entry()); |
| 220 EXPECT_FALSE(controller().CanGoBack()); | 220 EXPECT_FALSE(controller().CanGoBack()); |
| 221 EXPECT_FALSE(controller().CanGoForward()); | 221 EXPECT_FALSE(controller().CanGoForward()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Tests navigations that come in unrequested. This happens when the user | 224 // Tests navigations that come in unrequested. This happens when the user |
| 225 // navigates from the web page, and here we test that there is no pending entry. | 225 // navigates from the web page, and here we test that there is no pending entry. |
| 226 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 226 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
| 227 TestNotificationTracker notifications; | 227 TestNotificationTracker notifications; |
| 228 RegisterForAllNavNotifications(¬ifications, &controller()); | 228 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 229 | 229 |
| 230 // First make an existing committed entry. | 230 // First make an existing committed entry. |
| 231 const GURL kExistingURL1("http://eh"); | 231 const GURL kExistingURL1("http://eh"); |
| 232 controller().LoadURL(kExistingURL1, GURL(), | 232 controller().LoadURL(kExistingURL1, content::Referrer(), |
| 233 content::PAGE_TRANSITION_TYPED, std::string()); | 233 content::PAGE_TRANSITION_TYPED, std::string()); |
| 234 rvh()->SendNavigate(0, kExistingURL1); | 234 rvh()->SendNavigate(0, kExistingURL1); |
| 235 EXPECT_TRUE(notifications.Check1AndReset( | 235 EXPECT_TRUE(notifications.Check1AndReset( |
| 236 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 236 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 237 | 237 |
| 238 // Do a new navigation without making a pending one. | 238 // Do a new navigation without making a pending one. |
| 239 const GURL kNewURL("http://see"); | 239 const GURL kNewURL("http://see"); |
| 240 rvh()->SendNavigate(99, kNewURL); | 240 rvh()->SendNavigate(99, kNewURL); |
| 241 | 241 |
| 242 // There should no longer be any pending entry, and the third navigation we | 242 // There should no longer be any pending entry, and the third navigation we |
| 243 // just made should be committed. | 243 // just made should be committed. |
| 244 EXPECT_TRUE(notifications.Check1AndReset( | 244 EXPECT_TRUE(notifications.Check1AndReset( |
| 245 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 245 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 246 EXPECT_EQ(-1, controller().pending_entry_index()); | 246 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 247 EXPECT_EQ(1, controller().last_committed_entry_index()); | 247 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 248 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 248 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // Tests navigating to a new URL when there is a new pending navigation that is | 251 // Tests navigating to a new URL when there is a new pending navigation that is |
| 252 // not the one that just loaded. This will happen if the user types in a URL to | 252 // not the one that just loaded. This will happen if the user types in a URL to |
| 253 // somewhere slow, and then navigates the current page before the typed URL | 253 // somewhere slow, and then navigates the current page before the typed URL |
| 254 // commits. | 254 // commits. |
| 255 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 255 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 256 TestNotificationTracker notifications; | 256 TestNotificationTracker notifications; |
| 257 RegisterForAllNavNotifications(¬ifications, &controller()); | 257 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 258 | 258 |
| 259 // First make an existing committed entry. | 259 // First make an existing committed entry. |
| 260 const GURL kExistingURL1("http://eh"); | 260 const GURL kExistingURL1("http://eh"); |
| 261 controller().LoadURL(kExistingURL1, GURL(), | 261 controller().LoadURL(kExistingURL1, content::Referrer(), |
| 262 content::PAGE_TRANSITION_TYPED, std::string()); | 262 content::PAGE_TRANSITION_TYPED, std::string()); |
| 263 rvh()->SendNavigate(0, kExistingURL1); | 263 rvh()->SendNavigate(0, kExistingURL1); |
| 264 EXPECT_TRUE(notifications.Check1AndReset( | 264 EXPECT_TRUE(notifications.Check1AndReset( |
| 265 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 265 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 266 | 266 |
| 267 // Make a pending entry to somewhere new. | 267 // Make a pending entry to somewhere new. |
| 268 const GURL kExistingURL2("http://bee"); | 268 const GURL kExistingURL2("http://bee"); |
| 269 controller().LoadURL(kExistingURL2, GURL(), | 269 controller().LoadURL(kExistingURL2, content::Referrer(), |
| 270 content::PAGE_TRANSITION_TYPED, std::string()); | 270 content::PAGE_TRANSITION_TYPED, std::string()); |
| 271 EXPECT_EQ(0U, notifications.size()); | 271 EXPECT_EQ(0U, notifications.size()); |
| 272 | 272 |
| 273 // After the beforeunload but before it commits, do a new navigation. | 273 // After the beforeunload but before it commits, do a new navigation. |
| 274 rvh()->SendShouldCloseACK(true); | 274 rvh()->SendShouldCloseACK(true); |
| 275 const GURL kNewURL("http://see"); | 275 const GURL kNewURL("http://see"); |
| 276 contents()->pending_rvh()->SendNavigate(3, kNewURL); | 276 contents()->pending_rvh()->SendNavigate(3, kNewURL); |
| 277 | 277 |
| 278 // There should no longer be any pending entry, and the third navigation we | 278 // There should no longer be any pending entry, and the third navigation we |
| 279 // just made should be committed. | 279 // just made should be committed. |
| 280 EXPECT_TRUE(notifications.Check1AndReset( | 280 EXPECT_TRUE(notifications.Check1AndReset( |
| 281 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 281 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 282 EXPECT_EQ(-1, controller().pending_entry_index()); | 282 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 283 EXPECT_EQ(1, controller().last_committed_entry_index()); | 283 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 284 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 284 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // Tests navigating to a new URL when there is a pending back/forward | 287 // Tests navigating to a new URL when there is a pending back/forward |
| 288 // navigation. This will happen if the user hits back, but before that commits, | 288 // navigation. This will happen if the user hits back, but before that commits, |
| 289 // they navigate somewhere new. | 289 // they navigate somewhere new. |
| 290 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 290 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 291 TestNotificationTracker notifications; | 291 TestNotificationTracker notifications; |
| 292 RegisterForAllNavNotifications(¬ifications, &controller()); | 292 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 293 | 293 |
| 294 // First make some history. | 294 // First make some history. |
| 295 const GURL kExistingURL1("http://foo/eh"); | 295 const GURL kExistingURL1("http://foo/eh"); |
| 296 controller().LoadURL(kExistingURL1, GURL(), | 296 controller().LoadURL(kExistingURL1, content::Referrer(), |
| 297 content::PAGE_TRANSITION_TYPED, std::string()); | 297 content::PAGE_TRANSITION_TYPED, std::string()); |
| 298 rvh()->SendNavigate(0, kExistingURL1); | 298 rvh()->SendNavigate(0, kExistingURL1); |
| 299 EXPECT_TRUE(notifications.Check1AndReset( | 299 EXPECT_TRUE(notifications.Check1AndReset( |
| 300 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 300 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 301 | 301 |
| 302 const GURL kExistingURL2("http://foo/bee"); | 302 const GURL kExistingURL2("http://foo/bee"); |
| 303 controller().LoadURL(kExistingURL2, GURL(), | 303 controller().LoadURL(kExistingURL2, content::Referrer(), |
| 304 content::PAGE_TRANSITION_TYPED, std::string()); | 304 content::PAGE_TRANSITION_TYPED, std::string()); |
| 305 rvh()->SendNavigate(1, kExistingURL2); | 305 rvh()->SendNavigate(1, kExistingURL2); |
| 306 EXPECT_TRUE(notifications.Check1AndReset( | 306 EXPECT_TRUE(notifications.Check1AndReset( |
| 307 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 307 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 308 | 308 |
| 309 // Now make a pending back/forward navigation. The zeroth entry should be | 309 // Now make a pending back/forward navigation. The zeroth entry should be |
| 310 // pending. | 310 // pending. |
| 311 controller().GoBack(); | 311 controller().GoBack(); |
| 312 EXPECT_EQ(0U, notifications.size()); | 312 EXPECT_EQ(0U, notifications.size()); |
| 313 EXPECT_EQ(0, controller().pending_entry_index()); | 313 EXPECT_EQ(0, controller().pending_entry_index()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 329 | 329 |
| 330 // Tests navigating to an existing URL when there is a pending new navigation. | 330 // Tests navigating to an existing URL when there is a pending new navigation. |
| 331 // This will happen if the user enters a URL, but before that commits, the | 331 // This will happen if the user enters a URL, but before that commits, the |
| 332 // current page fires history.back(). | 332 // current page fires history.back(). |
| 333 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 333 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 334 TestNotificationTracker notifications; | 334 TestNotificationTracker notifications; |
| 335 RegisterForAllNavNotifications(¬ifications, &controller()); | 335 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 336 | 336 |
| 337 // First make some history. | 337 // First make some history. |
| 338 const GURL kExistingURL1("http://foo/eh"); | 338 const GURL kExistingURL1("http://foo/eh"); |
| 339 controller().LoadURL(kExistingURL1, GURL(), content::PAGE_TRANSITION_TYPED, | 339 controller().LoadURL(kExistingURL1, content::Referrer(), |
| 340 std::string()); | 340 content::PAGE_TRANSITION_TYPED, std::string()); |
| 341 rvh()->SendNavigate(0, kExistingURL1); | 341 rvh()->SendNavigate(0, kExistingURL1); |
| 342 EXPECT_TRUE(notifications.Check1AndReset( | 342 EXPECT_TRUE(notifications.Check1AndReset( |
| 343 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 343 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 344 | 344 |
| 345 const GURL kExistingURL2("http://foo/bee"); | 345 const GURL kExistingURL2("http://foo/bee"); |
| 346 controller().LoadURL(kExistingURL2, GURL(), content::PAGE_TRANSITION_TYPED, | 346 controller().LoadURL(kExistingURL2, content::Referrer(), |
| 347 std::string()); | 347 content::PAGE_TRANSITION_TYPED, std::string()); |
| 348 rvh()->SendNavigate(1, kExistingURL2); | 348 rvh()->SendNavigate(1, kExistingURL2); |
| 349 EXPECT_TRUE(notifications.Check1AndReset( | 349 EXPECT_TRUE(notifications.Check1AndReset( |
| 350 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 350 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 351 | 351 |
| 352 // Now make a pending new navigation. | 352 // Now make a pending new navigation. |
| 353 const GURL kNewURL("http://foo/see"); | 353 const GURL kNewURL("http://foo/see"); |
| 354 controller().LoadURL( | 354 controller().LoadURL( |
| 355 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 355 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 356 std::string()); |
| 356 EXPECT_EQ(0U, notifications.size()); | 357 EXPECT_EQ(0U, notifications.size()); |
| 357 EXPECT_EQ(-1, controller().pending_entry_index()); | 358 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 358 EXPECT_EQ(1, controller().last_committed_entry_index()); | 359 EXPECT_EQ(1, controller().last_committed_entry_index()); |
| 359 | 360 |
| 360 // Before that commits, a back navigation from the renderer commits. | 361 // Before that commits, a back navigation from the renderer commits. |
| 361 rvh()->SendNavigate(0, kExistingURL1); | 362 rvh()->SendNavigate(0, kExistingURL1); |
| 362 | 363 |
| 363 // There should no longer be any pending entry, and the back navigation we | 364 // There should no longer be any pending entry, and the back navigation we |
| 364 // just made should be committed. | 365 // just made should be committed. |
| 365 EXPECT_TRUE(notifications.Check1AndReset( | 366 EXPECT_TRUE(notifications.Check1AndReset( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 380 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 381 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 381 EXPECT_FALSE(contents()->delegate()); | 382 EXPECT_FALSE(contents()->delegate()); |
| 382 contents()->set_delegate(delegate.get()); | 383 contents()->set_delegate(delegate.get()); |
| 383 | 384 |
| 384 // Without any navigations, the renderer starts at about:blank. | 385 // Without any navigations, the renderer starts at about:blank. |
| 385 const GURL kExistingURL("about:blank"); | 386 const GURL kExistingURL("about:blank"); |
| 386 | 387 |
| 387 // Now make a pending new navigation. | 388 // Now make a pending new navigation. |
| 388 const GURL kNewURL("http://eh"); | 389 const GURL kNewURL("http://eh"); |
| 389 controller().LoadURL( | 390 controller().LoadURL( |
| 390 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 391 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 392 std::string()); |
| 391 EXPECT_EQ(0U, notifications.size()); | 393 EXPECT_EQ(0U, notifications.size()); |
| 392 EXPECT_EQ(-1, controller().pending_entry_index()); | 394 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 393 EXPECT_TRUE(controller().pending_entry()); | 395 EXPECT_TRUE(controller().pending_entry()); |
| 394 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 396 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 395 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 397 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 396 | 398 |
| 397 // Before that commits, a document.write and location.reload can cause the | 399 // Before that commits, a document.write and location.reload can cause the |
| 398 // renderer to send a FrameNavigate with page_id -1. | 400 // renderer to send a FrameNavigate with page_id -1. |
| 399 rvh()->SendNavigate(-1, kExistingURL); | 401 rvh()->SendNavigate(-1, kExistingURL); |
| 400 | 402 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 417 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 419 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 418 EXPECT_FALSE(contents()->delegate()); | 420 EXPECT_FALSE(contents()->delegate()); |
| 419 contents()->set_delegate(delegate.get()); | 421 contents()->set_delegate(delegate.get()); |
| 420 | 422 |
| 421 // Without any navigations, the renderer starts at about:blank. | 423 // Without any navigations, the renderer starts at about:blank. |
| 422 const GURL kExistingURL("about:blank"); | 424 const GURL kExistingURL("about:blank"); |
| 423 | 425 |
| 424 // Now make a pending new navigation. | 426 // Now make a pending new navigation. |
| 425 const GURL kNewURL("http://eh"); | 427 const GURL kNewURL("http://eh"); |
| 426 controller().LoadURL( | 428 controller().LoadURL( |
| 427 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 429 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 430 std::string()); |
| 428 EXPECT_EQ(0U, notifications.size()); | 431 EXPECT_EQ(0U, notifications.size()); |
| 429 EXPECT_EQ(-1, controller().pending_entry_index()); | 432 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 430 EXPECT_TRUE(controller().pending_entry()); | 433 EXPECT_TRUE(controller().pending_entry()); |
| 431 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 434 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 432 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 435 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 433 | 436 |
| 434 // It may abort before committing, if it's a download or due to a stop or | 437 // It may abort before committing, if it's a download or due to a stop or |
| 435 // a new navigation from the user. | 438 // a new navigation from the user. |
| 436 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; | 439 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 437 params.frame_id = 1; | 440 params.frame_id = 1; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 464 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); | 467 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 465 EXPECT_FALSE(contents()->delegate()); | 468 EXPECT_FALSE(contents()->delegate()); |
| 466 contents()->set_delegate(delegate.get()); | 469 contents()->set_delegate(delegate.get()); |
| 467 | 470 |
| 468 // Without any navigations, the renderer starts at about:blank. | 471 // Without any navigations, the renderer starts at about:blank. |
| 469 const GURL kExistingURL("about:blank"); | 472 const GURL kExistingURL("about:blank"); |
| 470 | 473 |
| 471 // Now make a pending new navigation. | 474 // Now make a pending new navigation. |
| 472 const GURL kNewURL("http://eh"); | 475 const GURL kNewURL("http://eh"); |
| 473 controller().LoadURL( | 476 controller().LoadURL( |
| 474 kNewURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 477 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 478 std::string()); |
| 475 EXPECT_EQ(0U, notifications.size()); | 479 EXPECT_EQ(0U, notifications.size()); |
| 476 EXPECT_EQ(-1, controller().pending_entry_index()); | 480 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 477 EXPECT_TRUE(controller().pending_entry()); | 481 EXPECT_TRUE(controller().pending_entry()); |
| 478 EXPECT_EQ(-1, controller().last_committed_entry_index()); | 482 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 479 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 483 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 480 | 484 |
| 481 // Now the navigation redirects. | 485 // Now the navigation redirects. |
| 482 const GURL kRedirectURL("http://bee"); | 486 const GURL kRedirectURL("http://bee"); |
| 483 rvh()->TestOnMessageReceived( | 487 rvh()->TestOnMessageReceived( |
| 484 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id | 488 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id |
| (...skipping 29 matching lines...) Expand all Loading... |
| 514 contents()->set_delegate(NULL); | 518 contents()->set_delegate(NULL); |
| 515 } | 519 } |
| 516 | 520 |
| 517 TEST_F(NavigationControllerTest, Reload) { | 521 TEST_F(NavigationControllerTest, Reload) { |
| 518 TestNotificationTracker notifications; | 522 TestNotificationTracker notifications; |
| 519 RegisterForAllNavNotifications(¬ifications, &controller()); | 523 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 520 | 524 |
| 521 const GURL url1("http://foo1"); | 525 const GURL url1("http://foo1"); |
| 522 | 526 |
| 523 controller().LoadURL( | 527 controller().LoadURL( |
| 524 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 528 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 525 EXPECT_EQ(0U, notifications.size()); | 529 EXPECT_EQ(0U, notifications.size()); |
| 526 rvh()->SendNavigate(0, url1); | 530 rvh()->SendNavigate(0, url1); |
| 527 EXPECT_TRUE(notifications.Check1AndReset( | 531 EXPECT_TRUE(notifications.Check1AndReset( |
| 528 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 532 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 529 | 533 |
| 530 controller().Reload(true); | 534 controller().Reload(true); |
| 531 EXPECT_EQ(0U, notifications.size()); | 535 EXPECT_EQ(0U, notifications.size()); |
| 532 | 536 |
| 533 // The reload is pending. | 537 // The reload is pending. |
| 534 EXPECT_EQ(controller().entry_count(), 1); | 538 EXPECT_EQ(controller().entry_count(), 1); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 555 | 559 |
| 556 // Tests what happens when a reload navigation produces a new page. | 560 // Tests what happens when a reload navigation produces a new page. |
| 557 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 561 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 558 TestNotificationTracker notifications; | 562 TestNotificationTracker notifications; |
| 559 RegisterForAllNavNotifications(¬ifications, &controller()); | 563 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 560 | 564 |
| 561 const GURL url1("http://foo1"); | 565 const GURL url1("http://foo1"); |
| 562 const GURL url2("http://foo2"); | 566 const GURL url2("http://foo2"); |
| 563 | 567 |
| 564 controller().LoadURL( | 568 controller().LoadURL( |
| 565 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 569 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 566 rvh()->SendNavigate(0, url1); | 570 rvh()->SendNavigate(0, url1); |
| 567 EXPECT_TRUE(notifications.Check1AndReset( | 571 EXPECT_TRUE(notifications.Check1AndReset( |
| 568 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 572 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 569 | 573 |
| 570 controller().Reload(true); | 574 controller().Reload(true); |
| 571 EXPECT_EQ(0U, notifications.size()); | 575 EXPECT_EQ(0U, notifications.size()); |
| 572 | 576 |
| 573 rvh()->SendNavigate(1, url2); | 577 rvh()->SendNavigate(1, url2); |
| 574 EXPECT_TRUE(notifications.Check1AndReset( | 578 EXPECT_TRUE(notifications.Check1AndReset( |
| 575 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 579 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 // Tests what happens when a back navigation produces a new page. | 632 // Tests what happens when a back navigation produces a new page. |
| 629 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { | 633 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { |
| 630 TestNotificationTracker notifications; | 634 TestNotificationTracker notifications; |
| 631 RegisterForAllNavNotifications(¬ifications, &controller()); | 635 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 632 | 636 |
| 633 const GURL url1("http://foo/1"); | 637 const GURL url1("http://foo/1"); |
| 634 const GURL url2("http://foo/2"); | 638 const GURL url2("http://foo/2"); |
| 635 const GURL url3("http://foo/3"); | 639 const GURL url3("http://foo/3"); |
| 636 | 640 |
| 637 controller().LoadURL( | 641 controller().LoadURL( |
| 638 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 642 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 639 rvh()->SendNavigate(0, url1); | 643 rvh()->SendNavigate(0, url1); |
| 640 EXPECT_TRUE(notifications.Check1AndReset( | 644 EXPECT_TRUE(notifications.Check1AndReset( |
| 641 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 645 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 642 | 646 |
| 643 controller().LoadURL( | 647 controller().LoadURL( |
| 644 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 648 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 645 rvh()->SendNavigate(1, url2); | 649 rvh()->SendNavigate(1, url2); |
| 646 EXPECT_TRUE(notifications.Check1AndReset( | 650 EXPECT_TRUE(notifications.Check1AndReset( |
| 647 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 651 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 648 | 652 |
| 649 controller().GoBack(); | 653 controller().GoBack(); |
| 650 EXPECT_EQ(0U, notifications.size()); | 654 EXPECT_EQ(0U, notifications.size()); |
| 651 | 655 |
| 652 // We should now have a pending navigation to go back. | 656 // We should now have a pending navigation to go back. |
| 653 EXPECT_EQ(controller().entry_count(), 2); | 657 EXPECT_EQ(controller().entry_count(), 2); |
| 654 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 658 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 EXPECT_TRUE(notifications.Check1AndReset( | 691 EXPECT_TRUE(notifications.Check1AndReset( |
| 688 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 692 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 689 | 693 |
| 690 // controller().LoadURL(kUrl2, content::PAGE_TRANSITION_TYPED); | 694 // controller().LoadURL(kUrl2, content::PAGE_TRANSITION_TYPED); |
| 691 rvh()->SendNavigate(1, kUrl2); | 695 rvh()->SendNavigate(1, kUrl2); |
| 692 EXPECT_TRUE(notifications.Check1AndReset( | 696 EXPECT_TRUE(notifications.Check1AndReset( |
| 693 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 697 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 694 | 698 |
| 695 // Now start a new pending navigation and go back before it commits. | 699 // Now start a new pending navigation and go back before it commits. |
| 696 controller().LoadURL( | 700 controller().LoadURL( |
| 697 kUrl3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 701 kUrl3, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 702 std::string()); |
| 698 EXPECT_EQ(-1, controller().pending_entry_index()); | 703 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 699 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); | 704 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); |
| 700 controller().GoBack(); | 705 controller().GoBack(); |
| 701 | 706 |
| 702 // The pending navigation should now be the "back" item and the new one | 707 // The pending navigation should now be the "back" item and the new one |
| 703 // should be gone. | 708 // should be gone. |
| 704 EXPECT_EQ(0, controller().pending_entry_index()); | 709 EXPECT_EQ(0, controller().pending_entry_index()); |
| 705 EXPECT_EQ(kUrl1, controller().pending_entry()->url()); | 710 EXPECT_EQ(kUrl1, controller().pending_entry()->url()); |
| 706 } | 711 } |
| 707 | 712 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 // as SAME_PAGE navigation even when we are redirected to some other page. | 854 // as SAME_PAGE navigation even when we are redirected to some other page. |
| 850 TEST_F(NavigationControllerTest, Redirect) { | 855 TEST_F(NavigationControllerTest, Redirect) { |
| 851 TestNotificationTracker notifications; | 856 TestNotificationTracker notifications; |
| 852 RegisterForAllNavNotifications(¬ifications, &controller()); | 857 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 853 | 858 |
| 854 const GURL url1("http://foo1"); | 859 const GURL url1("http://foo1"); |
| 855 const GURL url2("http://foo2"); // Redirection target | 860 const GURL url2("http://foo2"); // Redirection target |
| 856 | 861 |
| 857 // First request | 862 // First request |
| 858 controller().LoadURL( | 863 controller().LoadURL( |
| 859 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 864 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 860 | 865 |
| 861 EXPECT_EQ(0U, notifications.size()); | 866 EXPECT_EQ(0U, notifications.size()); |
| 862 rvh()->SendNavigate(0, url2); | 867 rvh()->SendNavigate(0, url2); |
| 863 EXPECT_TRUE(notifications.Check1AndReset( | 868 EXPECT_TRUE(notifications.Check1AndReset( |
| 864 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 869 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 865 | 870 |
| 866 // Second request | 871 // Second request |
| 867 controller().LoadURL( | 872 controller().LoadURL( |
| 868 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 873 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 869 | 874 |
| 870 EXPECT_TRUE(controller().pending_entry()); | 875 EXPECT_TRUE(controller().pending_entry()); |
| 871 EXPECT_EQ(controller().pending_entry_index(), -1); | 876 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 872 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 877 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 873 | 878 |
| 874 ViewHostMsg_FrameNavigate_Params params; | 879 ViewHostMsg_FrameNavigate_Params params; |
| 875 params.page_id = 0; | 880 params.page_id = 0; |
| 876 params.url = url2; | 881 params.url = url2; |
| 877 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 882 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 878 params.redirects.push_back(GURL("http://foo1")); | 883 params.redirects.push_back(GURL("http://foo1")); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 906 // must be cleared. http://crbug.com/21245 | 911 // must be cleared. http://crbug.com/21245 |
| 907 TEST_F(NavigationControllerTest, PostThenRedirect) { | 912 TEST_F(NavigationControllerTest, PostThenRedirect) { |
| 908 TestNotificationTracker notifications; | 913 TestNotificationTracker notifications; |
| 909 RegisterForAllNavNotifications(¬ifications, &controller()); | 914 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 910 | 915 |
| 911 const GURL url1("http://foo1"); | 916 const GURL url1("http://foo1"); |
| 912 const GURL url2("http://foo2"); // Redirection target | 917 const GURL url2("http://foo2"); // Redirection target |
| 913 | 918 |
| 914 // First request as POST | 919 // First request as POST |
| 915 controller().LoadURL( | 920 controller().LoadURL( |
| 916 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 921 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 917 controller().GetActiveEntry()->set_has_post_data(true); | 922 controller().GetActiveEntry()->set_has_post_data(true); |
| 918 | 923 |
| 919 EXPECT_EQ(0U, notifications.size()); | 924 EXPECT_EQ(0U, notifications.size()); |
| 920 rvh()->SendNavigate(0, url2); | 925 rvh()->SendNavigate(0, url2); |
| 921 EXPECT_TRUE(notifications.Check1AndReset( | 926 EXPECT_TRUE(notifications.Check1AndReset( |
| 922 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 927 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 923 | 928 |
| 924 // Second request | 929 // Second request |
| 925 controller().LoadURL( | 930 controller().LoadURL( |
| 926 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 931 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 927 | 932 |
| 928 EXPECT_TRUE(controller().pending_entry()); | 933 EXPECT_TRUE(controller().pending_entry()); |
| 929 EXPECT_EQ(controller().pending_entry_index(), -1); | 934 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 930 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 935 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 931 | 936 |
| 932 ViewHostMsg_FrameNavigate_Params params; | 937 ViewHostMsg_FrameNavigate_Params params; |
| 933 params.page_id = 0; | 938 params.page_id = 0; |
| 934 params.url = url2; | 939 params.url = url2; |
| 935 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 940 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 936 params.redirects.push_back(GURL("http://foo1")); | 941 params.redirects.push_back(GURL("http://foo1")); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 963 // A redirect right off the bat should be a NEW_PAGE. | 968 // A redirect right off the bat should be a NEW_PAGE. |
| 964 TEST_F(NavigationControllerTest, ImmediateRedirect) { | 969 TEST_F(NavigationControllerTest, ImmediateRedirect) { |
| 965 TestNotificationTracker notifications; | 970 TestNotificationTracker notifications; |
| 966 RegisterForAllNavNotifications(¬ifications, &controller()); | 971 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 967 | 972 |
| 968 const GURL url1("http://foo1"); | 973 const GURL url1("http://foo1"); |
| 969 const GURL url2("http://foo2"); // Redirection target | 974 const GURL url2("http://foo2"); // Redirection target |
| 970 | 975 |
| 971 // First request | 976 // First request |
| 972 controller().LoadURL( | 977 controller().LoadURL( |
| 973 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 978 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 974 | 979 |
| 975 EXPECT_TRUE(controller().pending_entry()); | 980 EXPECT_TRUE(controller().pending_entry()); |
| 976 EXPECT_EQ(controller().pending_entry_index(), -1); | 981 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 977 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 982 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 978 | 983 |
| 979 ViewHostMsg_FrameNavigate_Params params; | 984 ViewHostMsg_FrameNavigate_Params params; |
| 980 params.page_id = 0; | 985 params.page_id = 0; |
| 981 params.url = url2; | 986 params.url = url2; |
| 982 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 987 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 983 params.redirects.push_back(GURL("http://foo1")); | 988 params.redirects.push_back(GURL("http://foo1")); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 size_t original_count = NavigationController::max_entry_count(); | 1419 size_t original_count = NavigationController::max_entry_count(); |
| 1415 const int kMaxEntryCount = 5; | 1420 const int kMaxEntryCount = 5; |
| 1416 | 1421 |
| 1417 NavigationController::set_max_entry_count_for_testing(kMaxEntryCount); | 1422 NavigationController::set_max_entry_count_for_testing(kMaxEntryCount); |
| 1418 | 1423 |
| 1419 int url_index; | 1424 int url_index; |
| 1420 // Load up to the max count, all entries should be there. | 1425 // Load up to the max count, all entries should be there. |
| 1421 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 1426 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
| 1422 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1427 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
| 1423 controller().LoadURL( | 1428 controller().LoadURL( |
| 1424 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1429 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 1430 std::string()); |
| 1425 rvh()->SendNavigate(url_index, url); | 1431 rvh()->SendNavigate(url_index, url); |
| 1426 } | 1432 } |
| 1427 | 1433 |
| 1428 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1434 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1429 | 1435 |
| 1430 // Created a PrunedListener to observe prune notifications. | 1436 // Created a PrunedListener to observe prune notifications. |
| 1431 PrunedListener listener(&controller()); | 1437 PrunedListener listener(&controller()); |
| 1432 | 1438 |
| 1433 // Navigate some more. | 1439 // Navigate some more. |
| 1434 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1440 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
| 1435 controller().LoadURL( | 1441 controller().LoadURL( |
| 1436 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1442 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1437 rvh()->SendNavigate(url_index, url); | 1443 rvh()->SendNavigate(url_index, url); |
| 1438 url_index++; | 1444 url_index++; |
| 1439 | 1445 |
| 1440 // We should have got a pruned navigation. | 1446 // We should have got a pruned navigation. |
| 1441 EXPECT_EQ(1, listener.notification_count_); | 1447 EXPECT_EQ(1, listener.notification_count_); |
| 1442 EXPECT_TRUE(listener.details_.from_front); | 1448 EXPECT_TRUE(listener.details_.from_front); |
| 1443 EXPECT_EQ(1, listener.details_.count); | 1449 EXPECT_EQ(1, listener.details_.count); |
| 1444 | 1450 |
| 1445 // We expect http://www.a.com/0 to be gone. | 1451 // We expect http://www.a.com/0 to be gone. |
| 1446 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1452 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1447 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), | 1453 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), |
| 1448 GURL("http:////www.a.com/1")); | 1454 GURL("http:////www.a.com/1")); |
| 1449 | 1455 |
| 1450 // More navigations. | 1456 // More navigations. |
| 1451 for (int i = 0; i < 3; i++) { | 1457 for (int i = 0; i < 3; i++) { |
| 1452 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); | 1458 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); |
| 1453 controller().LoadURL( | 1459 controller().LoadURL( |
| 1454 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1460 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 1461 std::string()); |
| 1455 rvh()->SendNavigate(url_index, url); | 1462 rvh()->SendNavigate(url_index, url); |
| 1456 url_index++; | 1463 url_index++; |
| 1457 } | 1464 } |
| 1458 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); | 1465 EXPECT_EQ(controller().entry_count(), kMaxEntryCount); |
| 1459 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), | 1466 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), |
| 1460 GURL("http:////www.a.com/4")); | 1467 GURL("http:////www.a.com/4")); |
| 1461 | 1468 |
| 1462 NavigationController::set_max_entry_count_for_testing(original_count); | 1469 NavigationController::set_max_entry_count_for_testing(original_count); |
| 1463 } | 1470 } |
| 1464 | 1471 |
| 1465 // Tests that we can do a restore and navigate to the restored entries and | 1472 // Tests that we can do a restore and navigate to the restored entries and |
| 1466 // everything is updated properly. This can be tricky since there is no | 1473 // everything is updated properly. This can be tricky since there is no |
| 1467 // SiteInstance for the entries created initially. | 1474 // SiteInstance for the entries created initially. |
| 1468 TEST_F(NavigationControllerTest, RestoreNavigate) { | 1475 TEST_F(NavigationControllerTest, RestoreNavigate) { |
| 1469 // Create a NavigationController with a restored set of tabs. | 1476 // Create a NavigationController with a restored set of tabs. |
| 1470 GURL url("http://foo"); | 1477 GURL url("http://foo"); |
| 1471 std::vector<NavigationEntry*> entries; | 1478 std::vector<NavigationEntry*> entries; |
| 1472 NavigationEntry* entry = NavigationController::CreateNavigationEntry( | 1479 NavigationEntry* entry = NavigationController::CreateNavigationEntry( |
| 1473 url, GURL(), content::PAGE_TRANSITION_RELOAD, false, std::string(), | 1480 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, |
| 1474 browser_context()); | 1481 std::string(), browser_context()); |
| 1475 entry->set_page_id(0); | 1482 entry->set_page_id(0); |
| 1476 entry->set_title(ASCIIToUTF16("Title")); | 1483 entry->set_title(ASCIIToUTF16("Title")); |
| 1477 entry->set_content_state("state"); | 1484 entry->set_content_state("state"); |
| 1478 entries.push_back(entry); | 1485 entries.push_back(entry); |
| 1479 TabContents our_contents( | 1486 TabContents our_contents( |
| 1480 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1487 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 1481 NavigationController& our_controller = our_contents.controller(); | 1488 NavigationController& our_controller = our_contents.controller(); |
| 1482 our_controller.Restore(0, true, &entries); | 1489 our_controller.Restore(0, true, &entries); |
| 1483 ASSERT_EQ(0u, entries.size()); | 1490 ASSERT_EQ(0u, entries.size()); |
| 1484 | 1491 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 our_controller.GetEntryAtIndex(0)->restore_type()); | 1530 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 1524 } | 1531 } |
| 1525 | 1532 |
| 1526 // Tests that we can still navigate to a restored entry after a different | 1533 // Tests that we can still navigate to a restored entry after a different |
| 1527 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1534 // navigation fails and clears the pending entry. http://crbug.com/90085 |
| 1528 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1535 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
| 1529 // Create a NavigationController with a restored set of tabs. | 1536 // Create a NavigationController with a restored set of tabs. |
| 1530 GURL url("http://foo"); | 1537 GURL url("http://foo"); |
| 1531 std::vector<NavigationEntry*> entries; | 1538 std::vector<NavigationEntry*> entries; |
| 1532 NavigationEntry* entry = NavigationController::CreateNavigationEntry( | 1539 NavigationEntry* entry = NavigationController::CreateNavigationEntry( |
| 1533 url, GURL(), content::PAGE_TRANSITION_RELOAD, false, std::string(), | 1540 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, |
| 1534 browser_context()); | 1541 std::string(), browser_context()); |
| 1535 entry->set_page_id(0); | 1542 entry->set_page_id(0); |
| 1536 entry->set_title(ASCIIToUTF16("Title")); | 1543 entry->set_title(ASCIIToUTF16("Title")); |
| 1537 entry->set_content_state("state"); | 1544 entry->set_content_state("state"); |
| 1538 entries.push_back(entry); | 1545 entries.push_back(entry); |
| 1539 TabContents our_contents( | 1546 TabContents our_contents( |
| 1540 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1547 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 1541 NavigationController& our_controller = our_contents.controller(); | 1548 NavigationController& our_controller = our_contents.controller(); |
| 1542 our_controller.Restore(0, true, &entries); | 1549 our_controller.Restore(0, true, &entries); |
| 1543 ASSERT_EQ(0u, entries.size()); | 1550 ASSERT_EQ(0u, entries.size()); |
| 1544 | 1551 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 our_controller.GetLastCommittedEntry()->site_instance()->site()); | 1601 our_controller.GetLastCommittedEntry()->site_instance()->site()); |
| 1595 EXPECT_EQ(NavigationEntry::RESTORE_NONE, | 1602 EXPECT_EQ(NavigationEntry::RESTORE_NONE, |
| 1596 our_controller.GetEntryAtIndex(0)->restore_type()); | 1603 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 1597 } | 1604 } |
| 1598 | 1605 |
| 1599 // Make sure that the page type and stuff is correct after an interstitial. | 1606 // Make sure that the page type and stuff is correct after an interstitial. |
| 1600 TEST_F(NavigationControllerTest, Interstitial) { | 1607 TEST_F(NavigationControllerTest, Interstitial) { |
| 1601 // First navigate somewhere normal. | 1608 // First navigate somewhere normal. |
| 1602 const GURL url1("http://foo"); | 1609 const GURL url1("http://foo"); |
| 1603 controller().LoadURL( | 1610 controller().LoadURL( |
| 1604 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1611 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1605 rvh()->SendNavigate(0, url1); | 1612 rvh()->SendNavigate(0, url1); |
| 1606 | 1613 |
| 1607 // Now navigate somewhere with an interstitial. | 1614 // Now navigate somewhere with an interstitial. |
| 1608 const GURL url2("http://bar"); | 1615 const GURL url2("http://bar"); |
| 1609 controller().LoadURL( | 1616 controller().LoadURL( |
| 1610 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1617 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1611 controller().pending_entry()->set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 1618 controller().pending_entry()->set_page_type(content::PAGE_TYPE_INTERSTITIAL); |
| 1612 | 1619 |
| 1613 // At this point the interstitial will be displayed and the load will still | 1620 // At this point the interstitial will be displayed and the load will still |
| 1614 // be pending. If the user continues, the load will commit. | 1621 // be pending. If the user continues, the load will commit. |
| 1615 rvh()->SendNavigate(1, url2); | 1622 rvh()->SendNavigate(1, url2); |
| 1616 | 1623 |
| 1617 // The page should be a normal page again. | 1624 // The page should be a normal page again. |
| 1618 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); | 1625 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); |
| 1619 EXPECT_EQ(content::PAGE_TYPE_NORMAL, | 1626 EXPECT_EQ(content::PAGE_TYPE_NORMAL, |
| 1620 controller().GetLastCommittedEntry()->page_type()); | 1627 controller().GetLastCommittedEntry()->page_type()); |
| 1621 } | 1628 } |
| 1622 | 1629 |
| 1623 TEST_F(NavigationControllerTest, RemoveEntry) { | 1630 TEST_F(NavigationControllerTest, RemoveEntry) { |
| 1624 const GURL url1("http://foo/1"); | 1631 const GURL url1("http://foo/1"); |
| 1625 const GURL url2("http://foo/2"); | 1632 const GURL url2("http://foo/2"); |
| 1626 const GURL url3("http://foo/3"); | 1633 const GURL url3("http://foo/3"); |
| 1627 const GURL url4("http://foo/4"); | 1634 const GURL url4("http://foo/4"); |
| 1628 const GURL url5("http://foo/5"); | 1635 const GURL url5("http://foo/5"); |
| 1629 const GURL pending_url("http://foo/pending"); | 1636 const GURL pending_url("http://foo/pending"); |
| 1630 const GURL default_url("http://foo/default"); | 1637 const GURL default_url("http://foo/default"); |
| 1631 | 1638 |
| 1632 controller().LoadURL( | 1639 controller().LoadURL( |
| 1633 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1640 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1634 rvh()->SendNavigate(0, url1); | 1641 rvh()->SendNavigate(0, url1); |
| 1635 controller().LoadURL( | 1642 controller().LoadURL( |
| 1636 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1643 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1637 rvh()->SendNavigate(1, url2); | 1644 rvh()->SendNavigate(1, url2); |
| 1638 controller().LoadURL( | 1645 controller().LoadURL( |
| 1639 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1646 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1640 rvh()->SendNavigate(2, url3); | 1647 rvh()->SendNavigate(2, url3); |
| 1641 controller().LoadURL( | 1648 controller().LoadURL( |
| 1642 url4, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1649 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1643 rvh()->SendNavigate(3, url4); | 1650 rvh()->SendNavigate(3, url4); |
| 1644 controller().LoadURL( | 1651 controller().LoadURL( |
| 1645 url5, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1652 url5, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1646 rvh()->SendNavigate(4, url5); | 1653 rvh()->SendNavigate(4, url5); |
| 1647 | 1654 |
| 1648 // Remove the last entry. | 1655 // Remove the last entry. |
| 1649 controller().RemoveEntryAtIndex( | 1656 controller().RemoveEntryAtIndex( |
| 1650 controller().entry_count() - 1, default_url); | 1657 controller().entry_count() - 1, default_url); |
| 1651 EXPECT_EQ(4, controller().entry_count()); | 1658 EXPECT_EQ(4, controller().entry_count()); |
| 1652 EXPECT_EQ(3, controller().last_committed_entry_index()); | 1659 EXPECT_EQ(3, controller().last_committed_entry_index()); |
| 1653 NavigationEntry* pending_entry = controller().pending_entry(); | 1660 NavigationEntry* pending_entry = controller().pending_entry(); |
| 1654 EXPECT_TRUE(pending_entry && pending_entry->url() == url4); | 1661 EXPECT_TRUE(pending_entry && pending_entry->url() == url4); |
| 1655 | 1662 |
| 1656 // Add a pending entry. | 1663 // Add a pending entry. |
| 1657 controller().LoadURL(pending_url, GURL(), content::PAGE_TRANSITION_TYPED, | 1664 controller().LoadURL(pending_url, content::Referrer(), |
| 1658 std::string()); | 1665 content::PAGE_TRANSITION_TYPED, std::string()); |
| 1659 // Now remove the last entry. | 1666 // Now remove the last entry. |
| 1660 controller().RemoveEntryAtIndex( | 1667 controller().RemoveEntryAtIndex( |
| 1661 controller().entry_count() - 1, default_url); | 1668 controller().entry_count() - 1, default_url); |
| 1662 // The pending entry should have been discarded and the last committed entry | 1669 // The pending entry should have been discarded and the last committed entry |
| 1663 // removed. | 1670 // removed. |
| 1664 EXPECT_EQ(3, controller().entry_count()); | 1671 EXPECT_EQ(3, controller().entry_count()); |
| 1665 EXPECT_EQ(2, controller().last_committed_entry_index()); | 1672 EXPECT_EQ(2, controller().last_committed_entry_index()); |
| 1666 pending_entry = controller().pending_entry(); | 1673 pending_entry = controller().pending_entry(); |
| 1667 EXPECT_TRUE(pending_entry && pending_entry->url() == url3); | 1674 EXPECT_TRUE(pending_entry && pending_entry->url() == url3); |
| 1668 | 1675 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1691 RegisterForAllNavNotifications(¬ifications, &controller()); | 1698 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1692 | 1699 |
| 1693 const GURL url0("http://foo/0"); | 1700 const GURL url0("http://foo/0"); |
| 1694 const GURL url1("http://foo/1"); | 1701 const GURL url1("http://foo/1"); |
| 1695 const GURL url2("http://foo/2"); | 1702 const GURL url2("http://foo/2"); |
| 1696 const GURL url3("http://foo/3"); | 1703 const GURL url3("http://foo/3"); |
| 1697 const GURL url4("http://foo/4"); | 1704 const GURL url4("http://foo/4"); |
| 1698 const GURL transient_url("http://foo/transient"); | 1705 const GURL transient_url("http://foo/transient"); |
| 1699 | 1706 |
| 1700 controller().LoadURL( | 1707 controller().LoadURL( |
| 1701 url0, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1708 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1702 rvh()->SendNavigate(0, url0); | 1709 rvh()->SendNavigate(0, url0); |
| 1703 controller().LoadURL( | 1710 controller().LoadURL( |
| 1704 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1711 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1705 rvh()->SendNavigate(1, url1); | 1712 rvh()->SendNavigate(1, url1); |
| 1706 | 1713 |
| 1707 notifications.Reset(); | 1714 notifications.Reset(); |
| 1708 | 1715 |
| 1709 // Adding a transient with no pending entry. | 1716 // Adding a transient with no pending entry. |
| 1710 NavigationEntry* transient_entry = new NavigationEntry; | 1717 NavigationEntry* transient_entry = new NavigationEntry; |
| 1711 transient_entry->set_url(transient_url); | 1718 transient_entry->set_url(transient_url); |
| 1712 controller().AddTransientEntry(transient_entry); | 1719 controller().AddTransientEntry(transient_entry); |
| 1713 | 1720 |
| 1714 // We should not have received any notifications. | 1721 // We should not have received any notifications. |
| 1715 EXPECT_EQ(0U, notifications.size()); | 1722 EXPECT_EQ(0U, notifications.size()); |
| 1716 | 1723 |
| 1717 // Check our state. | 1724 // Check our state. |
| 1718 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1725 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1719 EXPECT_EQ(controller().entry_count(), 3); | 1726 EXPECT_EQ(controller().entry_count(), 3); |
| 1720 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 1727 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
| 1721 EXPECT_EQ(controller().pending_entry_index(), -1); | 1728 EXPECT_EQ(controller().pending_entry_index(), -1); |
| 1722 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 1729 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
| 1723 EXPECT_FALSE(controller().pending_entry()); | 1730 EXPECT_FALSE(controller().pending_entry()); |
| 1724 EXPECT_TRUE(controller().CanGoBack()); | 1731 EXPECT_TRUE(controller().CanGoBack()); |
| 1725 EXPECT_FALSE(controller().CanGoForward()); | 1732 EXPECT_FALSE(controller().CanGoForward()); |
| 1726 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 1733 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 1727 | 1734 |
| 1728 // Navigate. | 1735 // Navigate. |
| 1729 controller().LoadURL( | 1736 controller().LoadURL( |
| 1730 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1737 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1731 rvh()->SendNavigate(2, url2); | 1738 rvh()->SendNavigate(2, url2); |
| 1732 | 1739 |
| 1733 // We should have navigated, transient entry should be gone. | 1740 // We should have navigated, transient entry should be gone. |
| 1734 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); | 1741 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); |
| 1735 EXPECT_EQ(controller().entry_count(), 3); | 1742 EXPECT_EQ(controller().entry_count(), 3); |
| 1736 | 1743 |
| 1737 // Add a transient again, then navigate with no pending entry this time. | 1744 // Add a transient again, then navigate with no pending entry this time. |
| 1738 transient_entry = new NavigationEntry; | 1745 transient_entry = new NavigationEntry; |
| 1739 transient_entry->set_url(transient_url); | 1746 transient_entry->set_url(transient_url); |
| 1740 controller().AddTransientEntry(transient_entry); | 1747 controller().AddTransientEntry(transient_entry); |
| 1741 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1748 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1742 rvh()->SendNavigate(3, url3); | 1749 rvh()->SendNavigate(3, url3); |
| 1743 // Transient entry should be gone. | 1750 // Transient entry should be gone. |
| 1744 EXPECT_EQ(url3, controller().GetActiveEntry()->url()); | 1751 EXPECT_EQ(url3, controller().GetActiveEntry()->url()); |
| 1745 EXPECT_EQ(controller().entry_count(), 4); | 1752 EXPECT_EQ(controller().entry_count(), 4); |
| 1746 | 1753 |
| 1747 // Initiate a navigation, add a transient then commit navigation. | 1754 // Initiate a navigation, add a transient then commit navigation. |
| 1748 controller().LoadURL( | 1755 controller().LoadURL( |
| 1749 url4, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1756 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1750 transient_entry = new NavigationEntry; | 1757 transient_entry = new NavigationEntry; |
| 1751 transient_entry->set_url(transient_url); | 1758 transient_entry->set_url(transient_url); |
| 1752 controller().AddTransientEntry(transient_entry); | 1759 controller().AddTransientEntry(transient_entry); |
| 1753 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); | 1760 EXPECT_EQ(transient_url, controller().GetActiveEntry()->url()); |
| 1754 rvh()->SendNavigate(4, url4); | 1761 rvh()->SendNavigate(4, url4); |
| 1755 EXPECT_EQ(url4, controller().GetActiveEntry()->url()); | 1762 EXPECT_EQ(url4, controller().GetActiveEntry()->url()); |
| 1756 EXPECT_EQ(controller().entry_count(), 5); | 1763 EXPECT_EQ(controller().entry_count(), 5); |
| 1757 | 1764 |
| 1758 // Add a transient and go back. This should simply remove the transient. | 1765 // Add a transient and go back. This should simply remove the transient. |
| 1759 transient_entry = new NavigationEntry; | 1766 transient_entry = new NavigationEntry; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 // See http://crbug.com/99016. | 1829 // See http://crbug.com/99016. |
| 1823 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 1830 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 1824 TestNotificationTracker notifications; | 1831 TestNotificationTracker notifications; |
| 1825 RegisterForAllNavNotifications(¬ifications, &controller()); | 1832 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 1826 | 1833 |
| 1827 const GURL url0("http://foo/0"); | 1834 const GURL url0("http://foo/0"); |
| 1828 const GURL url1("http://foo/1"); | 1835 const GURL url1("http://foo/1"); |
| 1829 | 1836 |
| 1830 // For typed navigations (browser-initiated), both active and visible entries | 1837 // For typed navigations (browser-initiated), both active and visible entries |
| 1831 // should update before commit. | 1838 // should update before commit. |
| 1832 controller().LoadURL(url0, GURL(), content::PAGE_TRANSITION_TYPED, | 1839 controller().LoadURL(url0, content::Referrer(), |
| 1833 std::string()); | 1840 content::PAGE_TRANSITION_TYPED, std::string()); |
| 1834 EXPECT_EQ(url0, controller().GetActiveEntry()->url()); | 1841 EXPECT_EQ(url0, controller().GetActiveEntry()->url()); |
| 1835 EXPECT_EQ(url0, controller().GetVisibleEntry()->url()); | 1842 EXPECT_EQ(url0, controller().GetVisibleEntry()->url()); |
| 1836 rvh()->SendNavigate(0, url0); | 1843 rvh()->SendNavigate(0, url0); |
| 1837 | 1844 |
| 1838 // For link clicks (renderer-initiated navigations), the active entry should | 1845 // For link clicks (renderer-initiated navigations), the active entry should |
| 1839 // update before commit but the visible should not. | 1846 // update before commit but the visible should not. |
| 1840 controller().LoadURLFromRenderer(url1, GURL(), content::PAGE_TRANSITION_LINK, | 1847 controller().LoadURLFromRenderer(url1, content::Referrer(), |
| 1848 content::PAGE_TRANSITION_LINK, |
| 1841 std::string()); | 1849 std::string()); |
| 1842 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 1850 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 1843 EXPECT_EQ(url0, controller().GetVisibleEntry()->url()); | 1851 EXPECT_EQ(url0, controller().GetVisibleEntry()->url()); |
| 1844 EXPECT_TRUE(controller().pending_entry()->is_renderer_initiated()); | 1852 EXPECT_TRUE(controller().pending_entry()->is_renderer_initiated()); |
| 1845 | 1853 |
| 1846 // After commit, both should be updated, and we should no longer treat the | 1854 // After commit, both should be updated, and we should no longer treat the |
| 1847 // entry as renderer-initiated. | 1855 // entry as renderer-initiated. |
| 1848 rvh()->SendNavigate(1, url1); | 1856 rvh()->SendNavigate(1, url1); |
| 1849 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 1857 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
| 1850 EXPECT_EQ(url1, controller().GetVisibleEntry()->url()); | 1858 EXPECT_EQ(url1, controller().GetVisibleEntry()->url()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 // Tests a subframe navigation while a toplevel navigation is pending. | 1956 // Tests a subframe navigation while a toplevel navigation is pending. |
| 1949 // http://crbug.com/43967 | 1957 // http://crbug.com/43967 |
| 1950 TEST_F(NavigationControllerTest, SubframeWhilePending) { | 1958 TEST_F(NavigationControllerTest, SubframeWhilePending) { |
| 1951 // Load the first page. | 1959 // Load the first page. |
| 1952 const GURL url1("http://foo/"); | 1960 const GURL url1("http://foo/"); |
| 1953 NavigateAndCommit(url1); | 1961 NavigateAndCommit(url1); |
| 1954 | 1962 |
| 1955 // Now start a pending load to a totally different page, but don't commit it. | 1963 // Now start a pending load to a totally different page, but don't commit it. |
| 1956 const GURL url2("http://bar/"); | 1964 const GURL url2("http://bar/"); |
| 1957 controller().LoadURL( | 1965 controller().LoadURL( |
| 1958 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1966 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1959 | 1967 |
| 1960 // Send a subframe update from the first page, as if one had just | 1968 // Send a subframe update from the first page, as if one had just |
| 1961 // automatically loaded. Auto subframes don't increment the page ID. | 1969 // automatically loaded. Auto subframes don't increment the page ID. |
| 1962 const GURL url1_sub("http://foo/subframe"); | 1970 const GURL url1_sub("http://foo/subframe"); |
| 1963 ViewHostMsg_FrameNavigate_Params params; | 1971 ViewHostMsg_FrameNavigate_Params params; |
| 1964 params.page_id = controller().GetLastCommittedEntry()->page_id(); | 1972 params.page_id = controller().GetLastCommittedEntry()->page_id(); |
| 1965 params.url = url1_sub; | 1973 params.url = url1_sub; |
| 1966 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; | 1974 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 1967 params.should_update_history = false; | 1975 params.should_update_history = false; |
| 1968 params.gesture = NavigationGestureAuto; | 1976 params.gesture = NavigationGestureAuto; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 const GURL url2("http://foo2"); | 2049 const GURL url2("http://foo2"); |
| 2042 const GURL url3("http://foo3"); | 2050 const GURL url3("http://foo3"); |
| 2043 | 2051 |
| 2044 NavigateAndCommit(url1); | 2052 NavigateAndCommit(url1); |
| 2045 NavigateAndCommit(url2); | 2053 NavigateAndCommit(url2); |
| 2046 controller().GoBack(); | 2054 controller().GoBack(); |
| 2047 | 2055 |
| 2048 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 2056 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 2049 NavigationController& other_controller = other_contents->controller(); | 2057 NavigationController& other_controller = other_contents->controller(); |
| 2050 other_controller.LoadURL( | 2058 other_controller.LoadURL( |
| 2051 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 2059 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 2052 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); | 2060 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); |
| 2053 other_controller.CopyStateFromAndPrune(&controller()); | 2061 other_controller.CopyStateFromAndPrune(&controller()); |
| 2054 | 2062 |
| 2055 // other_controller should now contain 1 entry for url1, and a pending entry | 2063 // other_controller should now contain 1 entry for url1, and a pending entry |
| 2056 // for url3. | 2064 // for url3. |
| 2057 | 2065 |
| 2058 ASSERT_EQ(1, other_controller.entry_count()); | 2066 ASSERT_EQ(1, other_controller.entry_count()); |
| 2059 | 2067 |
| 2060 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2068 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); |
| 2061 | 2069 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 EXPECT_EQ(0, controller().pending_entry_index()); | 2186 EXPECT_EQ(0, controller().pending_entry_index()); |
| 2179 } | 2187 } |
| 2180 | 2188 |
| 2181 // Test call to PruneAllButActive for transient entry. | 2189 // Test call to PruneAllButActive for transient entry. |
| 2182 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { | 2190 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { |
| 2183 const GURL url0("http://foo/0"); | 2191 const GURL url0("http://foo/0"); |
| 2184 const GURL url1("http://foo/1"); | 2192 const GURL url1("http://foo/1"); |
| 2185 const GURL transient_url("http://foo/transient"); | 2193 const GURL transient_url("http://foo/transient"); |
| 2186 | 2194 |
| 2187 controller().LoadURL( | 2195 controller().LoadURL( |
| 2188 url0, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 2196 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 2189 rvh()->SendNavigate(0, url0); | 2197 rvh()->SendNavigate(0, url0); |
| 2190 controller().LoadURL( | 2198 controller().LoadURL( |
| 2191 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 2199 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 2192 rvh()->SendNavigate(1, url1); | 2200 rvh()->SendNavigate(1, url1); |
| 2193 | 2201 |
| 2194 // Adding a transient with no pending entry. | 2202 // Adding a transient with no pending entry. |
| 2195 NavigationEntry* transient_entry = new NavigationEntry; | 2203 NavigationEntry* transient_entry = new NavigationEntry; |
| 2196 transient_entry->set_url(transient_url); | 2204 transient_entry->set_url(transient_url); |
| 2197 controller().AddTransientEntry(transient_entry); | 2205 controller().AddTransientEntry(transient_entry); |
| 2198 | 2206 |
| 2199 controller().PruneAllButActive(); | 2207 controller().PruneAllButActive(); |
| 2200 | 2208 |
| 2201 EXPECT_EQ(-1, controller().pending_entry_index()); | 2209 EXPECT_EQ(-1, controller().pending_entry_index()); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2394 TabNavigation nav(0, url0, GURL(), string16(), | 2402 TabNavigation nav(0, url0, GURL(), string16(), |
| 2395 webkit_glue::CreateHistoryStateForURL(url0), | 2403 webkit_glue::CreateHistoryStateForURL(url0), |
| 2396 content::PAGE_TRANSITION_LINK); | 2404 content::PAGE_TRANSITION_LINK); |
| 2397 session_helper_.AssertNavigationEquals(nav, | 2405 session_helper_.AssertNavigationEquals(nav, |
| 2398 windows_[0]->tabs[0]->navigations[0]); | 2406 windows_[0]->tabs[0]->navigations[0]); |
| 2399 nav.set_url(url2); | 2407 nav.set_url(url2); |
| 2400 session_helper_.AssertNavigationEquals(nav, | 2408 session_helper_.AssertNavigationEquals(nav, |
| 2401 windows_[0]->tabs[0]->navigations[1]); | 2409 windows_[0]->tabs[0]->navigations[1]); |
| 2402 } | 2410 } |
| 2403 */ | 2411 */ |
| OLD | NEW |