| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // The number of times NavigationStateChanged has been called. | 246 // The number of times NavigationStateChanged has been called. |
| 247 int navigation_state_change_count_; | 247 int navigation_state_change_count_; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 // ----------------------------------------------------------------------------- | 250 // ----------------------------------------------------------------------------- |
| 251 | 251 |
| 252 TEST_F(NavigationControllerTest, Defaults) { | 252 TEST_F(NavigationControllerTest, Defaults) { |
| 253 NavigationControllerImpl& controller = controller_impl(); | 253 NavigationControllerImpl& controller = controller_impl(); |
| 254 | 254 |
| 255 EXPECT_FALSE(controller.GetPendingEntry()); | 255 EXPECT_FALSE(controller.GetPendingEntry()); |
| 256 EXPECT_FALSE(controller.GetActiveEntry()); | |
| 257 EXPECT_FALSE(controller.GetVisibleEntry()); | 256 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 258 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 257 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
| 259 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 258 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 260 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | 259 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); |
| 261 EXPECT_EQ(controller.GetEntryCount(), 0); | 260 EXPECT_EQ(controller.GetEntryCount(), 0); |
| 262 EXPECT_FALSE(controller.CanGoBack()); | 261 EXPECT_FALSE(controller.CanGoBack()); |
| 263 EXPECT_FALSE(controller.CanGoForward()); | 262 EXPECT_FALSE(controller.CanGoForward()); |
| 264 } | 263 } |
| 265 | 264 |
| 266 TEST_F(NavigationControllerTest, GoToOffset) { | 265 TEST_F(NavigationControllerTest, GoToOffset) { |
| 267 NavigationControllerImpl& controller = controller_impl(); | 266 NavigationControllerImpl& controller = controller_impl(); |
| 268 TestNotificationTracker notifications; | 267 TestNotificationTracker notifications; |
| 269 RegisterForAllNavNotifications(¬ifications, &controller); | 268 RegisterForAllNavNotifications(¬ifications, &controller); |
| 270 | 269 |
| 271 const int kNumUrls = 5; | 270 const int kNumUrls = 5; |
| 272 std::vector<GURL> urls(kNumUrls); | 271 std::vector<GURL> urls(kNumUrls); |
| 273 for (int i = 0; i < kNumUrls; ++i) { | 272 for (int i = 0; i < kNumUrls; ++i) { |
| 274 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 273 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
| 275 } | 274 } |
| 276 | 275 |
| 277 test_rvh()->SendNavigate(0, urls[0]); | 276 test_rvh()->SendNavigate(0, urls[0]); |
| 278 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 277 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 279 navigation_entry_committed_counter_ = 0; | 278 navigation_entry_committed_counter_ = 0; |
| 280 EXPECT_EQ(urls[0], controller.GetActiveEntry()->GetVirtualURL()); | 279 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
| 281 EXPECT_FALSE(controller.CanGoBack()); | 280 EXPECT_FALSE(controller.CanGoBack()); |
| 282 EXPECT_FALSE(controller.CanGoForward()); | 281 EXPECT_FALSE(controller.CanGoForward()); |
| 283 EXPECT_FALSE(controller.CanGoToOffset(1)); | 282 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 284 | 283 |
| 285 for (int i = 1; i <= 4; ++i) { | 284 for (int i = 1; i <= 4; ++i) { |
| 286 test_rvh()->SendNavigate(i, urls[i]); | 285 test_rvh()->SendNavigate(i, urls[i]); |
| 287 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 286 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 288 navigation_entry_committed_counter_ = 0; | 287 navigation_entry_committed_counter_ = 0; |
| 289 EXPECT_EQ(urls[i], controller.GetActiveEntry()->GetVirtualURL()); | 288 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
| 290 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 289 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
| 291 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 290 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
| 292 EXPECT_FALSE(controller.CanGoToOffset(1)); | 291 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 293 } | 292 } |
| 294 | 293 |
| 295 // We have loaded 5 pages, and are currently at the last-loaded page. | 294 // We have loaded 5 pages, and are currently at the last-loaded page. |
| 296 int url_index = 4; | 295 int url_index = 4; |
| 297 | 296 |
| 298 enum Tests { | 297 enum Tests { |
| 299 GO_TO_MIDDLE_PAGE = -2, | 298 GO_TO_MIDDLE_PAGE = -2, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // Creating a pending notification should not have issued any of the | 341 // Creating a pending notification should not have issued any of the |
| 343 // notifications we're listening for. | 342 // notifications we're listening for. |
| 344 EXPECT_EQ(0U, notifications.size()); | 343 EXPECT_EQ(0U, notifications.size()); |
| 345 | 344 |
| 346 // The load should now be pending. | 345 // The load should now be pending. |
| 347 EXPECT_EQ(controller.GetEntryCount(), 0); | 346 EXPECT_EQ(controller.GetEntryCount(), 0); |
| 348 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | 347 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); |
| 349 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 348 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 350 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 349 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
| 351 ASSERT_TRUE(controller.GetPendingEntry()); | 350 ASSERT_TRUE(controller.GetPendingEntry()); |
| 352 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); | |
| 353 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 351 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 354 EXPECT_FALSE(controller.CanGoBack()); | 352 EXPECT_FALSE(controller.CanGoBack()); |
| 355 EXPECT_FALSE(controller.CanGoForward()); | 353 EXPECT_FALSE(controller.CanGoForward()); |
| 356 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 354 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
| 357 | 355 |
| 358 // Neither the timestamp nor the status code should have been set yet. | 356 // Neither the timestamp nor the status code should have been set yet. |
| 359 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 357 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 360 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 358 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
| 361 | 359 |
| 362 // We should have gotten no notifications from the preceeding checks. | 360 // We should have gotten no notifications from the preceeding checks. |
| 363 EXPECT_EQ(0U, notifications.size()); | 361 EXPECT_EQ(0U, notifications.size()); |
| 364 | 362 |
| 365 test_rvh()->SendNavigate(0, url1); | 363 test_rvh()->SendNavigate(0, url1); |
| 366 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 364 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 367 navigation_entry_committed_counter_ = 0; | 365 navigation_entry_committed_counter_ = 0; |
| 368 | 366 |
| 369 // The load should now be committed. | 367 // The load should now be committed. |
| 370 EXPECT_EQ(controller.GetEntryCount(), 1); | 368 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 371 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 369 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 372 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 370 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 373 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 371 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 374 EXPECT_FALSE(controller.GetPendingEntry()); | 372 EXPECT_FALSE(controller.GetPendingEntry()); |
| 375 ASSERT_TRUE(controller.GetActiveEntry()); | 373 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 376 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); | |
| 377 EXPECT_FALSE(controller.CanGoBack()); | 374 EXPECT_FALSE(controller.CanGoBack()); |
| 378 EXPECT_FALSE(controller.CanGoForward()); | 375 EXPECT_FALSE(controller.CanGoForward()); |
| 379 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 376 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 380 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 377 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 381 controller.GetLastCommittedEntry())->bindings()); | 378 controller.GetLastCommittedEntry())->bindings()); |
| 382 | 379 |
| 383 // The timestamp should have been set. | 380 // The timestamp should have been set. |
| 384 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); | 381 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); |
| 385 | 382 |
| 386 // Load another... | 383 // Load another... |
| 387 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 384 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 388 | 385 |
| 389 // The load should now be pending. | 386 // The load should now be pending. |
| 390 EXPECT_EQ(controller.GetEntryCount(), 1); | 387 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 391 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 388 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 392 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 389 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 393 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 390 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 394 ASSERT_TRUE(controller.GetPendingEntry()); | 391 ASSERT_TRUE(controller.GetPendingEntry()); |
| 395 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); | |
| 396 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 392 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 397 // TODO(darin): maybe this should really be true? | 393 // TODO(darin): maybe this should really be true? |
| 398 EXPECT_FALSE(controller.CanGoBack()); | 394 EXPECT_FALSE(controller.CanGoBack()); |
| 399 EXPECT_FALSE(controller.CanGoForward()); | 395 EXPECT_FALSE(controller.CanGoForward()); |
| 400 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 396 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 401 | 397 |
| 402 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 398 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 403 | 399 |
| 404 // Simulate the beforeunload ack for the cross-site transition, and then the | 400 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 405 // commit. | 401 // commit. |
| 406 test_rvh()->SendShouldCloseACK(true); | 402 test_rvh()->SendShouldCloseACK(true); |
| 407 static_cast<TestRenderViewHost*>( | 403 static_cast<TestRenderViewHost*>( |
| 408 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); | 404 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); |
| 409 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 405 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 410 navigation_entry_committed_counter_ = 0; | 406 navigation_entry_committed_counter_ = 0; |
| 411 | 407 |
| 412 // The load should now be committed. | 408 // The load should now be committed. |
| 413 EXPECT_EQ(controller.GetEntryCount(), 2); | 409 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 414 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 410 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 415 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 411 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 416 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 412 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 417 EXPECT_FALSE(controller.GetPendingEntry()); | 413 EXPECT_FALSE(controller.GetPendingEntry()); |
| 418 ASSERT_TRUE(controller.GetActiveEntry()); | 414 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 419 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); | |
| 420 EXPECT_TRUE(controller.CanGoBack()); | 415 EXPECT_TRUE(controller.CanGoBack()); |
| 421 EXPECT_FALSE(controller.CanGoForward()); | 416 EXPECT_FALSE(controller.CanGoForward()); |
| 422 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 417 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 423 | 418 |
| 424 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); | 419 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); |
| 425 } | 420 } |
| 426 | 421 |
| 427 namespace { | 422 namespace { |
| 428 | 423 |
| 429 base::Time GetFixedTime(base::Time time) { | 424 base::Time GetFixedTime(base::Time time) { |
| 430 return time; | 425 return time; |
| 431 } | 426 } |
| 432 | 427 |
| 433 } // namespace | 428 } // namespace |
| 434 | 429 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 RegisterForAllNavNotifications(¬ifications, &controller); | 571 RegisterForAllNavNotifications(¬ifications, &controller); |
| 577 | 572 |
| 578 const GURL url1("http://foo1"); | 573 const GURL url1("http://foo1"); |
| 579 | 574 |
| 580 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 575 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 581 EXPECT_EQ(0U, notifications.size()); | 576 EXPECT_EQ(0U, notifications.size()); |
| 582 test_rvh()->SendNavigate(0, url1); | 577 test_rvh()->SendNavigate(0, url1); |
| 583 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 578 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 584 navigation_entry_committed_counter_ = 0; | 579 navigation_entry_committed_counter_ = 0; |
| 585 | 580 |
| 586 ASSERT_TRUE(controller.GetActiveEntry()); | 581 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 587 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 582 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 588 EXPECT_FALSE(timestamp.is_null()); | 583 EXPECT_FALSE(timestamp.is_null()); |
| 589 | 584 |
| 590 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 585 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 591 EXPECT_EQ(0U, notifications.size()); | 586 EXPECT_EQ(0U, notifications.size()); |
| 592 test_rvh()->SendNavigate(0, url1); | 587 test_rvh()->SendNavigate(0, url1); |
| 593 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 588 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 594 navigation_entry_committed_counter_ = 0; | 589 navigation_entry_committed_counter_ = 0; |
| 595 | 590 |
| 596 // We should not have produced a new session history entry. | 591 // We should not have produced a new session history entry. |
| 597 EXPECT_EQ(controller.GetEntryCount(), 1); | 592 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 598 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 593 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 599 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 594 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 600 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 595 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 601 EXPECT_FALSE(controller.GetPendingEntry()); | 596 EXPECT_FALSE(controller.GetPendingEntry()); |
| 602 ASSERT_TRUE(controller.GetActiveEntry()); | 597 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 603 EXPECT_FALSE(controller.CanGoBack()); | 598 EXPECT_FALSE(controller.CanGoBack()); |
| 604 EXPECT_FALSE(controller.CanGoForward()); | 599 EXPECT_FALSE(controller.CanGoForward()); |
| 605 | 600 |
| 606 // The timestamp should have been updated. | 601 // The timestamp should have been updated. |
| 607 // | 602 // |
| 608 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to | 603 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to |
| 609 // EXPECT_GT once we guarantee that timestamps are unique. | 604 // EXPECT_GT once we guarantee that timestamps are unique. |
| 610 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); | 605 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
| 611 } | 606 } |
| 612 | 607 |
| 613 // Tests loading a URL but discarding it before the load commits. | 608 // Tests loading a URL but discarding it before the load commits. |
| 614 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 609 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
| 615 NavigationControllerImpl& controller = controller_impl(); | 610 NavigationControllerImpl& controller = controller_impl(); |
| 616 TestNotificationTracker notifications; | 611 TestNotificationTracker notifications; |
| 617 RegisterForAllNavNotifications(¬ifications, &controller); | 612 RegisterForAllNavNotifications(¬ifications, &controller); |
| 618 | 613 |
| 619 const GURL url1("http://foo1"); | 614 const GURL url1("http://foo1"); |
| 620 const GURL url2("http://foo2"); | 615 const GURL url2("http://foo2"); |
| 621 | 616 |
| 622 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 617 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 623 EXPECT_EQ(0U, notifications.size()); | 618 EXPECT_EQ(0U, notifications.size()); |
| 624 test_rvh()->SendNavigate(0, url1); | 619 test_rvh()->SendNavigate(0, url1); |
| 625 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 620 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 626 navigation_entry_committed_counter_ = 0; | 621 navigation_entry_committed_counter_ = 0; |
| 627 | 622 |
| 628 ASSERT_TRUE(controller.GetActiveEntry()); | 623 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 629 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 624 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 630 EXPECT_FALSE(timestamp.is_null()); | 625 EXPECT_FALSE(timestamp.is_null()); |
| 631 | 626 |
| 632 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 627 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 633 controller.DiscardNonCommittedEntries(); | 628 controller.DiscardNonCommittedEntries(); |
| 634 EXPECT_EQ(0U, notifications.size()); | 629 EXPECT_EQ(0U, notifications.size()); |
| 635 | 630 |
| 636 // Should not have produced a new session history entry. | 631 // Should not have produced a new session history entry. |
| 637 EXPECT_EQ(controller.GetEntryCount(), 1); | 632 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 638 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 633 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 639 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 634 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 640 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 635 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 641 EXPECT_FALSE(controller.GetPendingEntry()); | 636 EXPECT_FALSE(controller.GetPendingEntry()); |
| 642 ASSERT_TRUE(controller.GetActiveEntry()); | 637 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 643 EXPECT_FALSE(controller.CanGoBack()); | 638 EXPECT_FALSE(controller.CanGoBack()); |
| 644 EXPECT_FALSE(controller.CanGoForward()); | 639 EXPECT_FALSE(controller.CanGoForward()); |
| 645 | 640 |
| 646 // Timestamp should not have changed. | 641 // Timestamp should not have changed. |
| 647 EXPECT_EQ(timestamp, controller.GetActiveEntry()->GetTimestamp()); | 642 EXPECT_EQ(timestamp, controller.GetVisibleEntry()->GetTimestamp()); |
| 648 } | 643 } |
| 649 | 644 |
| 650 // Tests navigations that come in unrequested. This happens when the user | 645 // Tests navigations that come in unrequested. This happens when the user |
| 651 // navigates from the web page, and here we test that there is no pending entry. | 646 // navigates from the web page, and here we test that there is no pending entry. |
| 652 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 647 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
| 653 NavigationControllerImpl& controller = controller_impl(); | 648 NavigationControllerImpl& controller = controller_impl(); |
| 654 TestNotificationTracker notifications; | 649 TestNotificationTracker notifications; |
| 655 RegisterForAllNavNotifications(¬ifications, &controller); | 650 RegisterForAllNavNotifications(¬ifications, &controller); |
| 656 | 651 |
| 657 // First make an existing committed entry. | 652 // First make an existing committed entry. |
| 658 const GURL kExistingURL1("http://eh"); | 653 const GURL kExistingURL1("http://eh"); |
| 659 controller.LoadURL( | 654 controller.LoadURL( |
| 660 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 655 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 661 test_rvh()->SendNavigate(0, kExistingURL1); | 656 test_rvh()->SendNavigate(0, kExistingURL1); |
| 662 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 657 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 663 navigation_entry_committed_counter_ = 0; | 658 navigation_entry_committed_counter_ = 0; |
| 664 | 659 |
| 665 // Do a new navigation without making a pending one. | 660 // Do a new navigation without making a pending one. |
| 666 const GURL kNewURL("http://see"); | 661 const GURL kNewURL("http://see"); |
| 667 test_rvh()->SendNavigate(99, kNewURL); | 662 test_rvh()->SendNavigate(99, kNewURL); |
| 668 | 663 |
| 669 // There should no longer be any pending entry, and the third navigation we | 664 // There should no longer be any pending entry, and the third navigation we |
| 670 // just made should be committed. | 665 // just made should be committed. |
| 671 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 666 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 672 navigation_entry_committed_counter_ = 0; | 667 navigation_entry_committed_counter_ = 0; |
| 673 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 668 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 674 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 669 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 675 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 670 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 676 } | 671 } |
| 677 | 672 |
| 678 // Tests navigating to a new URL when there is a new pending navigation that is | 673 // Tests navigating to a new URL when there is a new pending navigation that is |
| 679 // not the one that just loaded. This will happen if the user types in a URL to | 674 // not the one that just loaded. This will happen if the user types in a URL to |
| 680 // somewhere slow, and then navigates the current page before the typed URL | 675 // somewhere slow, and then navigates the current page before the typed URL |
| 681 // commits. | 676 // commits. |
| 682 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 677 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 683 NavigationControllerImpl& controller = controller_impl(); | 678 NavigationControllerImpl& controller = controller_impl(); |
| 684 TestNotificationTracker notifications; | 679 TestNotificationTracker notifications; |
| 685 RegisterForAllNavNotifications(¬ifications, &controller); | 680 RegisterForAllNavNotifications(¬ifications, &controller); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 703 const GURL kNewURL("http://see"); | 698 const GURL kNewURL("http://see"); |
| 704 static_cast<TestRenderViewHost*>( | 699 static_cast<TestRenderViewHost*>( |
| 705 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL); | 700 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL); |
| 706 | 701 |
| 707 // There should no longer be any pending entry, and the third navigation we | 702 // There should no longer be any pending entry, and the third navigation we |
| 708 // just made should be committed. | 703 // just made should be committed. |
| 709 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 704 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 710 navigation_entry_committed_counter_ = 0; | 705 navigation_entry_committed_counter_ = 0; |
| 711 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 706 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 712 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 707 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 713 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 708 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 714 } | 709 } |
| 715 | 710 |
| 716 // Tests navigating to a new URL when there is a pending back/forward | 711 // Tests navigating to a new URL when there is a pending back/forward |
| 717 // navigation. This will happen if the user hits back, but before that commits, | 712 // navigation. This will happen if the user hits back, but before that commits, |
| 718 // they navigate somewhere new. | 713 // they navigate somewhere new. |
| 719 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 714 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 720 NavigationControllerImpl& controller = controller_impl(); | 715 NavigationControllerImpl& controller = controller_impl(); |
| 721 TestNotificationTracker notifications; | 716 TestNotificationTracker notifications; |
| 722 RegisterForAllNavNotifications(¬ifications, &controller); | 717 RegisterForAllNavNotifications(¬ifications, &controller); |
| 723 | 718 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 747 const GURL kNewURL("http://foo/see"); | 742 const GURL kNewURL("http://foo/see"); |
| 748 LoadCommittedDetails details; | 743 LoadCommittedDetails details; |
| 749 test_rvh()->SendNavigate(3, kNewURL); | 744 test_rvh()->SendNavigate(3, kNewURL); |
| 750 | 745 |
| 751 // There should no longer be any pending entry, and the third navigation we | 746 // There should no longer be any pending entry, and the third navigation we |
| 752 // just made should be committed. | 747 // just made should be committed. |
| 753 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 748 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 754 navigation_entry_committed_counter_ = 0; | 749 navigation_entry_committed_counter_ = 0; |
| 755 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 750 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 756 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 751 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 757 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 752 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 758 } | 753 } |
| 759 | 754 |
| 760 // Tests navigating to a new URL when there is a pending back/forward | 755 // Tests navigating to a new URL when there is a pending back/forward |
| 761 // navigation to a cross-process, privileged URL. This will happen if the user | 756 // navigation to a cross-process, privileged URL. This will happen if the user |
| 762 // hits back, but before that commits, they navigate somewhere new. | 757 // hits back, but before that commits, they navigate somewhere new. |
| 763 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 758 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
| 764 NavigationControllerImpl& controller = controller_impl(); | 759 NavigationControllerImpl& controller = controller_impl(); |
| 765 TestNotificationTracker notifications; | 760 TestNotificationTracker notifications; |
| 766 RegisterForAllNavNotifications(¬ifications, &controller); | 761 RegisterForAllNavNotifications(¬ifications, &controller); |
| 767 | 762 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 const GURL kNewURL("http://foo/bee"); | 795 const GURL kNewURL("http://foo/bee"); |
| 801 LoadCommittedDetails details; | 796 LoadCommittedDetails details; |
| 802 foo_rvh->SendNavigate(3, kNewURL); | 797 foo_rvh->SendNavigate(3, kNewURL); |
| 803 | 798 |
| 804 // There should no longer be any pending entry, and the third navigation we | 799 // There should no longer be any pending entry, and the third navigation we |
| 805 // just made should be committed. | 800 // just made should be committed. |
| 806 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 801 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 807 navigation_entry_committed_counter_ = 0; | 802 navigation_entry_committed_counter_ = 0; |
| 808 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 803 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 809 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 804 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 810 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 805 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 811 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 806 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 812 controller.GetLastCommittedEntry())->bindings()); | 807 controller.GetLastCommittedEntry())->bindings()); |
| 813 } | 808 } |
| 814 | 809 |
| 815 // Tests navigating to an existing URL when there is a pending new navigation. | 810 // Tests navigating to an existing URL when there is a pending new navigation. |
| 816 // This will happen if the user enters a URL, but before that commits, the | 811 // This will happen if the user enters a URL, but before that commits, the |
| 817 // current page fires history.back(). | 812 // current page fires history.back(). |
| 818 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 813 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 819 NavigationControllerImpl& controller = controller_impl(); | 814 NavigationControllerImpl& controller = controller_impl(); |
| 820 TestNotificationTracker notifications; | 815 TestNotificationTracker notifications; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 845 | 840 |
| 846 // Before that commits, a back navigation from the renderer commits. | 841 // Before that commits, a back navigation from the renderer commits. |
| 847 test_rvh()->SendNavigate(0, kExistingURL1); | 842 test_rvh()->SendNavigate(0, kExistingURL1); |
| 848 | 843 |
| 849 // There should no longer be any pending entry, and the back navigation we | 844 // There should no longer be any pending entry, and the back navigation we |
| 850 // just made should be committed. | 845 // just made should be committed. |
| 851 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 846 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 852 navigation_entry_committed_counter_ = 0; | 847 navigation_entry_committed_counter_ = 0; |
| 853 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 848 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 854 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 849 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 855 EXPECT_EQ(kExistingURL1, controller.GetActiveEntry()->GetURL()); | 850 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
| 856 } | 851 } |
| 857 | 852 |
| 858 // Tests an ignored navigation when there is a pending new navigation. | 853 // Tests an ignored navigation when there is a pending new navigation. |
| 859 // This will happen if the user enters a URL, but before that commits, the | 854 // This will happen if the user enters a URL, but before that commits, the |
| 860 // current blank page reloads. See http://crbug.com/77507. | 855 // current blank page reloads. See http://crbug.com/77507. |
| 861 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { | 856 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { |
| 862 NavigationControllerImpl& controller = controller_impl(); | 857 NavigationControllerImpl& controller = controller_impl(); |
| 863 TestNotificationTracker notifications; | 858 TestNotificationTracker notifications; |
| 864 RegisterForAllNavNotifications(¬ifications, &controller); | 859 RegisterForAllNavNotifications(¬ifications, &controller); |
| 865 | 860 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 TestNotificationTracker notifications; | 1078 TestNotificationTracker notifications; |
| 1084 RegisterForAllNavNotifications(¬ifications, &controller); | 1079 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1085 | 1080 |
| 1086 const GURL url1("http://foo1"); | 1081 const GURL url1("http://foo1"); |
| 1087 | 1082 |
| 1088 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1083 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1089 EXPECT_EQ(0U, notifications.size()); | 1084 EXPECT_EQ(0U, notifications.size()); |
| 1090 test_rvh()->SendNavigate(0, url1); | 1085 test_rvh()->SendNavigate(0, url1); |
| 1091 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1086 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1092 navigation_entry_committed_counter_ = 0; | 1087 navigation_entry_committed_counter_ = 0; |
| 1093 ASSERT_TRUE(controller.GetActiveEntry()); | 1088 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1094 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); | 1089 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title")); |
| 1095 controller.Reload(true); | 1090 controller.Reload(true); |
| 1096 EXPECT_EQ(0U, notifications.size()); | 1091 EXPECT_EQ(0U, notifications.size()); |
| 1097 | 1092 |
| 1098 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 1093 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 1099 EXPECT_FALSE(timestamp.is_null()); | 1094 EXPECT_FALSE(timestamp.is_null()); |
| 1100 | 1095 |
| 1101 // The reload is pending. | 1096 // The reload is pending. |
| 1102 EXPECT_EQ(controller.GetEntryCount(), 1); | 1097 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1103 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1098 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1104 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1099 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1105 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1100 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1106 EXPECT_TRUE(controller.GetPendingEntry()); | 1101 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1107 EXPECT_FALSE(controller.CanGoBack()); | 1102 EXPECT_FALSE(controller.CanGoBack()); |
| 1108 EXPECT_FALSE(controller.CanGoForward()); | 1103 EXPECT_FALSE(controller.CanGoForward()); |
| 1109 // Make sure the title has been cleared (will be redrawn just after reload). | 1104 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1110 // Avoids a stale cached title when the new page being reloaded has no title. | 1105 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1111 // See http://crbug.com/96041. | 1106 // See http://crbug.com/96041. |
| 1112 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); | 1107 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1113 | 1108 |
| 1114 test_rvh()->SendNavigate(0, url1); | 1109 test_rvh()->SendNavigate(0, url1); |
| 1115 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1110 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1116 navigation_entry_committed_counter_ = 0; | 1111 navigation_entry_committed_counter_ = 0; |
| 1117 | 1112 |
| 1118 // Now the reload is committed. | 1113 // Now the reload is committed. |
| 1119 EXPECT_EQ(controller.GetEntryCount(), 1); | 1114 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1120 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1115 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1121 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1116 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1122 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1117 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1123 EXPECT_FALSE(controller.GetPendingEntry()); | 1118 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1124 EXPECT_FALSE(controller.CanGoBack()); | 1119 EXPECT_FALSE(controller.CanGoBack()); |
| 1125 EXPECT_FALSE(controller.CanGoForward()); | 1120 EXPECT_FALSE(controller.CanGoForward()); |
| 1126 | 1121 |
| 1127 // The timestamp should have been updated. | 1122 // The timestamp should have been updated. |
| 1128 ASSERT_TRUE(controller.GetActiveEntry()); | 1123 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1129 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); | 1124 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
| 1130 } | 1125 } |
| 1131 | 1126 |
| 1132 // Tests what happens when a reload navigation produces a new page. | 1127 // Tests what happens when a reload navigation produces a new page. |
| 1133 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1128 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 1134 NavigationControllerImpl& controller = controller_impl(); | 1129 NavigationControllerImpl& controller = controller_impl(); |
| 1135 TestNotificationTracker notifications; | 1130 TestNotificationTracker notifications; |
| 1136 RegisterForAllNavNotifications(¬ifications, &controller); | 1131 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1137 | 1132 |
| 1138 const GURL url1("http://foo1"); | 1133 const GURL url1("http://foo1"); |
| 1139 const GURL url2("http://foo2"); | 1134 const GURL url2("http://foo2"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 // Load up the original URL, but get redirected. | 1187 // Load up the original URL, but get redirected. |
| 1193 controller.LoadURL( | 1188 controller.LoadURL( |
| 1194 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1189 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1195 EXPECT_EQ(0U, notifications.size()); | 1190 EXPECT_EQ(0U, notifications.size()); |
| 1196 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); | 1191 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); |
| 1197 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1192 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1198 navigation_entry_committed_counter_ = 0; | 1193 navigation_entry_committed_counter_ = 0; |
| 1199 | 1194 |
| 1200 // The NavigationEntry should save both the original URL and the final | 1195 // The NavigationEntry should save both the original URL and the final |
| 1201 // redirected URL. | 1196 // redirected URL. |
| 1202 EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL()); | 1197 EXPECT_EQ( |
| 1203 EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL()); | 1198 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
| 1199 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
| 1204 | 1200 |
| 1205 // Reload using the original URL. | 1201 // Reload using the original URL. |
| 1206 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); | 1202 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title")); |
| 1207 controller.ReloadOriginalRequestURL(false); | 1203 controller.ReloadOriginalRequestURL(false); |
| 1208 EXPECT_EQ(0U, notifications.size()); | 1204 EXPECT_EQ(0U, notifications.size()); |
| 1209 | 1205 |
| 1210 // The reload is pending. The request should point to the original URL. | 1206 // The reload is pending. The request should point to the original URL. |
| 1211 EXPECT_EQ(original_url, observer.navigated_url()); | 1207 EXPECT_EQ(original_url, observer.navigated_url()); |
| 1212 EXPECT_EQ(controller.GetEntryCount(), 1); | 1208 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1213 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1209 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1214 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1210 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1215 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1211 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1216 EXPECT_TRUE(controller.GetPendingEntry()); | 1212 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1217 EXPECT_FALSE(controller.CanGoBack()); | 1213 EXPECT_FALSE(controller.CanGoBack()); |
| 1218 EXPECT_FALSE(controller.CanGoForward()); | 1214 EXPECT_FALSE(controller.CanGoForward()); |
| 1219 | 1215 |
| 1220 // Make sure the title has been cleared (will be redrawn just after reload). | 1216 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1221 // Avoids a stale cached title when the new page being reloaded has no title. | 1217 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1222 // See http://crbug.com/96041. | 1218 // See http://crbug.com/96041. |
| 1223 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); | 1219 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1224 | 1220 |
| 1225 // Send that the navigation has proceeded; say it got redirected again. | 1221 // Send that the navigation has proceeded; say it got redirected again. |
| 1226 test_rvh()->SendNavigate(0, final_url); | 1222 test_rvh()->SendNavigate(0, final_url); |
| 1227 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1223 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1228 navigation_entry_committed_counter_ = 0; | 1224 navigation_entry_committed_counter_ = 0; |
| 1229 | 1225 |
| 1230 // Now the reload is committed. | 1226 // Now the reload is committed. |
| 1231 EXPECT_EQ(controller.GetEntryCount(), 1); | 1227 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1232 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1228 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1233 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1229 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 EXPECT_EQ(0U, notifications.size()); | 1550 EXPECT_EQ(0U, notifications.size()); |
| 1555 test_rvh()->SendNavigate(0, url2); | 1551 test_rvh()->SendNavigate(0, url2); |
| 1556 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1552 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1557 navigation_entry_committed_counter_ = 0; | 1553 navigation_entry_committed_counter_ = 0; |
| 1558 | 1554 |
| 1559 // Second request | 1555 // Second request |
| 1560 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1556 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1561 | 1557 |
| 1562 EXPECT_TRUE(controller.GetPendingEntry()); | 1558 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1563 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1559 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1564 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1560 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1565 | 1561 |
| 1566 ViewHostMsg_FrameNavigate_Params params; | 1562 ViewHostMsg_FrameNavigate_Params params; |
| 1567 params.page_id = 0; | 1563 params.page_id = 0; |
| 1568 params.url = url2; | 1564 params.url = url2; |
| 1569 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1565 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
| 1570 params.redirects.push_back(GURL("http://foo1")); | 1566 params.redirects.push_back(GURL("http://foo1")); |
| 1571 params.redirects.push_back(GURL("http://foo2")); | 1567 params.redirects.push_back(GURL("http://foo2")); |
| 1572 params.should_update_history = false; | 1568 params.should_update_history = false; |
| 1573 params.gesture = NavigationGestureAuto; | 1569 params.gesture = NavigationGestureAuto; |
| 1574 params.is_post = false; | 1570 params.is_post = false; |
| 1575 params.page_state = PageState::CreateFromURL(url2); | 1571 params.page_state = PageState::CreateFromURL(url2); |
| 1576 | 1572 |
| 1577 LoadCommittedDetails details; | 1573 LoadCommittedDetails details; |
| 1578 | 1574 |
| 1579 EXPECT_EQ(0U, notifications.size()); | 1575 EXPECT_EQ(0U, notifications.size()); |
| 1580 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1576 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
| 1581 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1577 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1582 navigation_entry_committed_counter_ = 0; | 1578 navigation_entry_committed_counter_ = 0; |
| 1583 | 1579 |
| 1584 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1580 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
| 1585 EXPECT_EQ(controller.GetEntryCount(), 1); | 1581 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1586 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1582 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1587 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1583 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1588 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1584 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1589 EXPECT_FALSE(controller.GetPendingEntry()); | 1585 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1590 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1586 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 1591 | 1587 |
| 1592 EXPECT_FALSE(controller.CanGoBack()); | 1588 EXPECT_FALSE(controller.CanGoBack()); |
| 1593 EXPECT_FALSE(controller.CanGoForward()); | 1589 EXPECT_FALSE(controller.CanGoForward()); |
| 1594 } | 1590 } |
| 1595 | 1591 |
| 1596 // Similar to Redirect above, but the first URL is requested by POST, | 1592 // Similar to Redirect above, but the first URL is requested by POST, |
| 1597 // the second URL is requested by GET. NavigationEntry::has_post_data_ | 1593 // the second URL is requested by GET. NavigationEntry::has_post_data_ |
| 1598 // must be cleared. http://crbug.com/21245 | 1594 // must be cleared. http://crbug.com/21245 |
| 1599 TEST_F(NavigationControllerTest, PostThenRedirect) { | 1595 TEST_F(NavigationControllerTest, PostThenRedirect) { |
| 1600 NavigationControllerImpl& controller = controller_impl(); | 1596 NavigationControllerImpl& controller = controller_impl(); |
| 1601 TestNotificationTracker notifications; | 1597 TestNotificationTracker notifications; |
| 1602 RegisterForAllNavNotifications(¬ifications, &controller); | 1598 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1603 | 1599 |
| 1604 const GURL url1("http://foo1"); | 1600 const GURL url1("http://foo1"); |
| 1605 const GURL url2("http://foo2"); // Redirection target | 1601 const GURL url2("http://foo2"); // Redirection target |
| 1606 | 1602 |
| 1607 // First request as POST | 1603 // First request as POST |
| 1608 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1604 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1609 controller.GetActiveEntry()->SetHasPostData(true); | 1605 controller.GetVisibleEntry()->SetHasPostData(true); |
| 1610 | 1606 |
| 1611 EXPECT_EQ(0U, notifications.size()); | 1607 EXPECT_EQ(0U, notifications.size()); |
| 1612 test_rvh()->SendNavigate(0, url2); | 1608 test_rvh()->SendNavigate(0, url2); |
| 1613 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1609 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1614 navigation_entry_committed_counter_ = 0; | 1610 navigation_entry_committed_counter_ = 0; |
| 1615 | 1611 |
| 1616 // Second request | 1612 // Second request |
| 1617 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1613 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1618 | 1614 |
| 1619 EXPECT_TRUE(controller.GetPendingEntry()); | 1615 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1620 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1616 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1621 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1617 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1622 | 1618 |
| 1623 ViewHostMsg_FrameNavigate_Params params; | 1619 ViewHostMsg_FrameNavigate_Params params; |
| 1624 params.page_id = 0; | 1620 params.page_id = 0; |
| 1625 params.url = url2; | 1621 params.url = url2; |
| 1626 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1622 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
| 1627 params.redirects.push_back(GURL("http://foo1")); | 1623 params.redirects.push_back(GURL("http://foo1")); |
| 1628 params.redirects.push_back(GURL("http://foo2")); | 1624 params.redirects.push_back(GURL("http://foo2")); |
| 1629 params.should_update_history = false; | 1625 params.should_update_history = false; |
| 1630 params.gesture = NavigationGestureAuto; | 1626 params.gesture = NavigationGestureAuto; |
| 1631 params.is_post = false; | 1627 params.is_post = false; |
| 1632 params.page_state = PageState::CreateFromURL(url2); | 1628 params.page_state = PageState::CreateFromURL(url2); |
| 1633 | 1629 |
| 1634 LoadCommittedDetails details; | 1630 LoadCommittedDetails details; |
| 1635 | 1631 |
| 1636 EXPECT_EQ(0U, notifications.size()); | 1632 EXPECT_EQ(0U, notifications.size()); |
| 1637 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1633 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
| 1638 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1634 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1639 navigation_entry_committed_counter_ = 0; | 1635 navigation_entry_committed_counter_ = 0; |
| 1640 | 1636 |
| 1641 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1637 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
| 1642 EXPECT_EQ(controller.GetEntryCount(), 1); | 1638 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1643 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1639 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1644 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1640 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1645 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1641 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1646 EXPECT_FALSE(controller.GetPendingEntry()); | 1642 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1647 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1643 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 1648 EXPECT_FALSE(controller.GetActiveEntry()->GetHasPostData()); | 1644 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData()); |
| 1649 | 1645 |
| 1650 EXPECT_FALSE(controller.CanGoBack()); | 1646 EXPECT_FALSE(controller.CanGoBack()); |
| 1651 EXPECT_FALSE(controller.CanGoForward()); | 1647 EXPECT_FALSE(controller.CanGoForward()); |
| 1652 } | 1648 } |
| 1653 | 1649 |
| 1654 // A redirect right off the bat should be a NEW_PAGE. | 1650 // A redirect right off the bat should be a NEW_PAGE. |
| 1655 TEST_F(NavigationControllerTest, ImmediateRedirect) { | 1651 TEST_F(NavigationControllerTest, ImmediateRedirect) { |
| 1656 NavigationControllerImpl& controller = controller_impl(); | 1652 NavigationControllerImpl& controller = controller_impl(); |
| 1657 TestNotificationTracker notifications; | 1653 TestNotificationTracker notifications; |
| 1658 RegisterForAllNavNotifications(¬ifications, &controller); | 1654 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1659 | 1655 |
| 1660 const GURL url1("http://foo1"); | 1656 const GURL url1("http://foo1"); |
| 1661 const GURL url2("http://foo2"); // Redirection target | 1657 const GURL url2("http://foo2"); // Redirection target |
| 1662 | 1658 |
| 1663 // First request | 1659 // First request |
| 1664 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1660 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 1665 | 1661 |
| 1666 EXPECT_TRUE(controller.GetPendingEntry()); | 1662 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1667 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1663 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1668 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1664 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1669 | 1665 |
| 1670 ViewHostMsg_FrameNavigate_Params params; | 1666 ViewHostMsg_FrameNavigate_Params params; |
| 1671 params.page_id = 0; | 1667 params.page_id = 0; |
| 1672 params.url = url2; | 1668 params.url = url2; |
| 1673 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1669 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
| 1674 params.redirects.push_back(GURL("http://foo1")); | 1670 params.redirects.push_back(GURL("http://foo1")); |
| 1675 params.redirects.push_back(GURL("http://foo2")); | 1671 params.redirects.push_back(GURL("http://foo2")); |
| 1676 params.should_update_history = false; | 1672 params.should_update_history = false; |
| 1677 params.gesture = NavigationGestureAuto; | 1673 params.gesture = NavigationGestureAuto; |
| 1678 params.is_post = false; | 1674 params.is_post = false; |
| 1679 params.page_state = PageState::CreateFromURL(url2); | 1675 params.page_state = PageState::CreateFromURL(url2); |
| 1680 | 1676 |
| 1681 LoadCommittedDetails details; | 1677 LoadCommittedDetails details; |
| 1682 | 1678 |
| 1683 EXPECT_EQ(0U, notifications.size()); | 1679 EXPECT_EQ(0U, notifications.size()); |
| 1684 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1680 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
| 1685 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1681 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1686 navigation_entry_committed_counter_ = 0; | 1682 navigation_entry_committed_counter_ = 0; |
| 1687 | 1683 |
| 1688 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); | 1684 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); |
| 1689 EXPECT_EQ(controller.GetEntryCount(), 1); | 1685 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1690 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1686 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1691 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1687 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1692 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1688 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1693 EXPECT_FALSE(controller.GetPendingEntry()); | 1689 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1694 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1690 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 1695 | 1691 |
| 1696 EXPECT_FALSE(controller.CanGoBack()); | 1692 EXPECT_FALSE(controller.CanGoBack()); |
| 1697 EXPECT_FALSE(controller.CanGoForward()); | 1693 EXPECT_FALSE(controller.CanGoForward()); |
| 1698 } | 1694 } |
| 1699 | 1695 |
| 1700 // Tests navigation via link click within a subframe. A new navigation entry | 1696 // Tests navigation via link click within a subframe. A new navigation entry |
| 1701 // should be created. | 1697 // should be created. |
| 1702 TEST_F(NavigationControllerTest, NewSubframe) { | 1698 TEST_F(NavigationControllerTest, NewSubframe) { |
| 1703 NavigationControllerImpl& controller = controller_impl(); | 1699 NavigationControllerImpl& controller = controller_impl(); |
| 1704 TestNotificationTracker notifications; | 1700 TestNotificationTracker notifications; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 ViewHostMsg_FrameNavigate_Params back_params(params); | 1933 ViewHostMsg_FrameNavigate_Params back_params(params); |
| 1938 controller.GoBack(); | 1934 controller.GoBack(); |
| 1939 back_params.url = url1; | 1935 back_params.url = url1; |
| 1940 back_params.page_id = 0; | 1936 back_params.page_id = 0; |
| 1941 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); | 1937 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); |
| 1942 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1938 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1943 navigation_entry_committed_counter_ = 0; | 1939 navigation_entry_committed_counter_ = 0; |
| 1944 EXPECT_TRUE(details.is_in_page); | 1940 EXPECT_TRUE(details.is_in_page); |
| 1945 EXPECT_EQ(2, controller.GetEntryCount()); | 1941 EXPECT_EQ(2, controller.GetEntryCount()); |
| 1946 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 1942 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 1947 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); | 1943 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
| 1948 | 1944 |
| 1949 // Go forward | 1945 // Go forward |
| 1950 ViewHostMsg_FrameNavigate_Params forward_params(params); | 1946 ViewHostMsg_FrameNavigate_Params forward_params(params); |
| 1951 controller.GoForward(); | 1947 controller.GoForward(); |
| 1952 forward_params.url = url2; | 1948 forward_params.url = url2; |
| 1953 forward_params.page_id = 1; | 1949 forward_params.page_id = 1; |
| 1954 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); | 1950 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); |
| 1955 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1951 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1956 navigation_entry_committed_counter_ = 0; | 1952 navigation_entry_committed_counter_ = 0; |
| 1957 EXPECT_TRUE(details.is_in_page); | 1953 EXPECT_TRUE(details.is_in_page); |
| 1958 EXPECT_EQ(2, controller.GetEntryCount()); | 1954 EXPECT_EQ(2, controller.GetEntryCount()); |
| 1959 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 1955 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 1960 EXPECT_EQ(forward_params.url, | 1956 EXPECT_EQ(forward_params.url, |
| 1961 controller.GetActiveEntry()->GetURL()); | 1957 controller.GetVisibleEntry()->GetURL()); |
| 1962 | 1958 |
| 1963 // Now go back and forward again. This is to work around a bug where we would | 1959 // Now go back and forward again. This is to work around a bug where we would |
| 1964 // compare the incoming URL with the last committed entry rather than the | 1960 // compare the incoming URL with the last committed entry rather than the |
| 1965 // one identified by an existing page ID. This would result in the second URL | 1961 // one identified by an existing page ID. This would result in the second URL |
| 1966 // losing the reference fragment when you navigate away from it and then back. | 1962 // losing the reference fragment when you navigate away from it and then back. |
| 1967 controller.GoBack(); | 1963 controller.GoBack(); |
| 1968 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); | 1964 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); |
| 1969 controller.GoForward(); | 1965 controller.GoForward(); |
| 1970 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); | 1966 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); |
| 1971 EXPECT_EQ(forward_params.url, | 1967 EXPECT_EQ(forward_params.url, |
| 1972 controller.GetActiveEntry()->GetURL()); | 1968 controller.GetVisibleEntry()->GetURL()); |
| 1973 | 1969 |
| 1974 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 1970 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
| 1975 const GURL url3("http://bar"); | 1971 const GURL url3("http://bar"); |
| 1976 params.page_id = 2; | 1972 params.page_id = 2; |
| 1977 params.url = url3; | 1973 params.url = url3; |
| 1978 navigation_entry_committed_counter_ = 0; | 1974 navigation_entry_committed_counter_ = 0; |
| 1979 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1975 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
| 1980 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1976 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1981 navigation_entry_committed_counter_ = 0; | 1977 navigation_entry_committed_counter_ = 0; |
| 1982 EXPECT_FALSE(details.is_in_page); | 1978 EXPECT_FALSE(details.is_in_page); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 EXPECT_EQ(3, controller.GetEntryCount()); | 2085 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2090 } | 2086 } |
| 2091 | 2087 |
| 2092 // Verify that BACK brings us back to http://foo2/. | 2088 // Verify that BACK brings us back to http://foo2/. |
| 2093 { | 2089 { |
| 2094 const GURL url("http://foo2/"); | 2090 const GURL url("http://foo2/"); |
| 2095 controller.GoBack(); | 2091 controller.GoBack(); |
| 2096 test_rvh()->SendNavigate(1, url); | 2092 test_rvh()->SendNavigate(1, url); |
| 2097 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2093 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2098 navigation_entry_committed_counter_ = 0; | 2094 navigation_entry_committed_counter_ = 0; |
| 2099 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); | 2095 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2100 } | 2096 } |
| 2101 } | 2097 } |
| 2102 | 2098 |
| 2103 // NotificationObserver implementation used in verifying we've received the | 2099 // NotificationObserver implementation used in verifying we've received the |
| 2104 // NOTIFICATION_NAV_LIST_PRUNED method. | 2100 // NOTIFICATION_NAV_LIST_PRUNED method. |
| 2105 class PrunedListener : public NotificationObserver { | 2101 class PrunedListener : public NotificationObserver { |
| 2106 public: | 2102 public: |
| 2107 explicit PrunedListener(NavigationControllerImpl* controller) | 2103 explicit PrunedListener(NavigationControllerImpl* controller) |
| 2108 : notification_count_(0) { | 2104 : notification_count_(0) { |
| 2109 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, | 2105 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 | 2452 |
| 2457 // Adding a transient with no pending entry. | 2453 // Adding a transient with no pending entry. |
| 2458 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2454 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2459 transient_entry->SetURL(transient_url); | 2455 transient_entry->SetURL(transient_url); |
| 2460 controller.SetTransientEntry(transient_entry); | 2456 controller.SetTransientEntry(transient_entry); |
| 2461 | 2457 |
| 2462 // We should not have received any notifications. | 2458 // We should not have received any notifications. |
| 2463 EXPECT_EQ(0U, notifications.size()); | 2459 EXPECT_EQ(0U, notifications.size()); |
| 2464 | 2460 |
| 2465 // Check our state. | 2461 // Check our state. |
| 2466 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2462 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2467 EXPECT_EQ(controller.GetEntryCount(), 3); | 2463 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2468 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2464 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2469 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2465 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2470 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2466 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2471 EXPECT_FALSE(controller.GetPendingEntry()); | 2467 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2472 EXPECT_TRUE(controller.CanGoBack()); | 2468 EXPECT_TRUE(controller.CanGoBack()); |
| 2473 EXPECT_FALSE(controller.CanGoForward()); | 2469 EXPECT_FALSE(controller.CanGoForward()); |
| 2474 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2470 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 2475 | 2471 |
| 2476 // Navigate. | 2472 // Navigate. |
| 2477 controller.LoadURL( | 2473 controller.LoadURL( |
| 2478 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2474 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2479 test_rvh()->SendNavigate(2, url2); | 2475 test_rvh()->SendNavigate(2, url2); |
| 2480 | 2476 |
| 2481 // We should have navigated, transient entry should be gone. | 2477 // We should have navigated, transient entry should be gone. |
| 2482 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 2478 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2483 EXPECT_EQ(controller.GetEntryCount(), 3); | 2479 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2484 | 2480 |
| 2485 // Add a transient again, then navigate with no pending entry this time. | 2481 // Add a transient again, then navigate with no pending entry this time. |
| 2486 transient_entry = new NavigationEntryImpl; | 2482 transient_entry = new NavigationEntryImpl; |
| 2487 transient_entry->SetURL(transient_url); | 2483 transient_entry->SetURL(transient_url); |
| 2488 controller.SetTransientEntry(transient_entry); | 2484 controller.SetTransientEntry(transient_entry); |
| 2489 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2485 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2490 test_rvh()->SendNavigate(3, url3); | 2486 test_rvh()->SendNavigate(3, url3); |
| 2491 // Transient entry should be gone. | 2487 // Transient entry should be gone. |
| 2492 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); | 2488 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2493 EXPECT_EQ(controller.GetEntryCount(), 4); | 2489 EXPECT_EQ(controller.GetEntryCount(), 4); |
| 2494 | 2490 |
| 2495 // Initiate a navigation, add a transient then commit navigation. | 2491 // Initiate a navigation, add a transient then commit navigation. |
| 2496 controller.LoadURL( | 2492 controller.LoadURL( |
| 2497 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2493 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2498 transient_entry = new NavigationEntryImpl; | 2494 transient_entry = new NavigationEntryImpl; |
| 2499 transient_entry->SetURL(transient_url); | 2495 transient_entry->SetURL(transient_url); |
| 2500 controller.SetTransientEntry(transient_entry); | 2496 controller.SetTransientEntry(transient_entry); |
| 2501 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2497 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2502 test_rvh()->SendNavigate(4, url4); | 2498 test_rvh()->SendNavigate(4, url4); |
| 2503 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); | 2499 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2504 EXPECT_EQ(controller.GetEntryCount(), 5); | 2500 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2505 | 2501 |
| 2506 // Add a transient and go back. This should simply remove the transient. | 2502 // Add a transient and go back. This should simply remove the transient. |
| 2507 transient_entry = new NavigationEntryImpl; | 2503 transient_entry = new NavigationEntryImpl; |
| 2508 transient_entry->SetURL(transient_url); | 2504 transient_entry->SetURL(transient_url); |
| 2509 controller.SetTransientEntry(transient_entry); | 2505 controller.SetTransientEntry(transient_entry); |
| 2510 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2506 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2511 EXPECT_TRUE(controller.CanGoBack()); | 2507 EXPECT_TRUE(controller.CanGoBack()); |
| 2512 EXPECT_FALSE(controller.CanGoForward()); | 2508 EXPECT_FALSE(controller.CanGoForward()); |
| 2513 controller.GoBack(); | 2509 controller.GoBack(); |
| 2514 // Transient entry should be gone. | 2510 // Transient entry should be gone. |
| 2515 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); | 2511 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2516 EXPECT_EQ(controller.GetEntryCount(), 5); | 2512 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2517 test_rvh()->SendNavigate(3, url3); | 2513 test_rvh()->SendNavigate(3, url3); |
| 2518 | 2514 |
| 2519 // Add a transient and go to an entry before the current one. | 2515 // Add a transient and go to an entry before the current one. |
| 2520 transient_entry = new NavigationEntryImpl; | 2516 transient_entry = new NavigationEntryImpl; |
| 2521 transient_entry->SetURL(transient_url); | 2517 transient_entry->SetURL(transient_url); |
| 2522 controller.SetTransientEntry(transient_entry); | 2518 controller.SetTransientEntry(transient_entry); |
| 2523 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2519 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2524 controller.GoToIndex(1); | 2520 controller.GoToIndex(1); |
| 2525 // The navigation should have been initiated, transient entry should be gone. | 2521 // The navigation should have been initiated, transient entry should be gone. |
| 2526 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2522 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2523 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2527 // Visible entry does not update for history navigations until commit. | 2524 // Visible entry does not update for history navigations until commit. |
| 2528 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2525 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2529 test_rvh()->SendNavigate(1, url1); | 2526 test_rvh()->SendNavigate(1, url1); |
| 2530 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2527 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2531 | 2528 |
| 2532 // Add a transient and go to an entry after the current one. | 2529 // Add a transient and go to an entry after the current one. |
| 2533 transient_entry = new NavigationEntryImpl; | 2530 transient_entry = new NavigationEntryImpl; |
| 2534 transient_entry->SetURL(transient_url); | 2531 transient_entry->SetURL(transient_url); |
| 2535 controller.SetTransientEntry(transient_entry); | 2532 controller.SetTransientEntry(transient_entry); |
| 2536 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2533 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2537 controller.GoToIndex(3); | 2534 controller.GoToIndex(3); |
| 2538 // The navigation should have been initiated, transient entry should be gone. | 2535 // The navigation should have been initiated, transient entry should be gone. |
| 2539 // Because of the transient entry that is removed, going to index 3 makes us | 2536 // Because of the transient entry that is removed, going to index 3 makes us |
| 2540 // land on url2 (which is visible after the commit). | 2537 // land on url2 (which is visible after the commit). |
| 2541 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 2538 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 2542 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2539 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2543 test_rvh()->SendNavigate(2, url2); | 2540 test_rvh()->SendNavigate(2, url2); |
| 2544 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2541 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2545 | 2542 |
| 2546 // Add a transient and go forward. | 2543 // Add a transient and go forward. |
| 2547 transient_entry = new NavigationEntryImpl; | 2544 transient_entry = new NavigationEntryImpl; |
| 2548 transient_entry->SetURL(transient_url); | 2545 transient_entry->SetURL(transient_url); |
| 2549 controller.SetTransientEntry(transient_entry); | 2546 controller.SetTransientEntry(transient_entry); |
| 2550 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2547 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2551 EXPECT_TRUE(controller.CanGoForward()); | 2548 EXPECT_TRUE(controller.CanGoForward()); |
| 2552 controller.GoForward(); | 2549 controller.GoForward(); |
| 2553 // We should have navigated, transient entry should be gone. | 2550 // We should have navigated, transient entry should be gone. |
| 2554 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); | 2551 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2552 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
| 2555 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2553 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2556 test_rvh()->SendNavigate(3, url3); | 2554 test_rvh()->SendNavigate(3, url3); |
| 2557 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2555 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2558 | 2556 |
| 2559 // Add a transient and do an in-page navigation, replacing the current entry. | 2557 // Add a transient and do an in-page navigation, replacing the current entry. |
| 2560 transient_entry = new NavigationEntryImpl; | 2558 transient_entry = new NavigationEntryImpl; |
| 2561 transient_entry->SetURL(transient_url); | 2559 transient_entry->SetURL(transient_url); |
| 2562 controller.SetTransientEntry(transient_entry); | 2560 controller.SetTransientEntry(transient_entry); |
| 2563 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2561 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2564 test_rvh()->SendNavigate(3, url3_ref); | 2562 test_rvh()->SendNavigate(3, url3_ref); |
| 2565 // Transient entry should be gone. | 2563 // Transient entry should be gone. |
| 2566 EXPECT_EQ(url3_ref, controller.GetActiveEntry()->GetURL()); | 2564 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2565 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
| 2567 | 2566 |
| 2568 // Ensure the URLs are correct. | 2567 // Ensure the URLs are correct. |
| 2569 EXPECT_EQ(controller.GetEntryCount(), 5); | 2568 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2570 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2569 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2571 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2570 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
| 2572 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2571 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
| 2573 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2572 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
| 2574 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2573 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
| 2575 } | 2574 } |
| 2576 | 2575 |
| 2577 // Test that Reload initiates a new navigation to a transient entry's URL. | 2576 // Test that Reload initiates a new navigation to a transient entry's URL. |
| 2578 TEST_F(NavigationControllerTest, ReloadTransient) { | 2577 TEST_F(NavigationControllerTest, ReloadTransient) { |
| 2579 NavigationControllerImpl& controller = controller_impl(); | 2578 NavigationControllerImpl& controller = controller_impl(); |
| 2580 const GURL url0("http://foo/0"); | 2579 const GURL url0("http://foo/0"); |
| 2581 const GURL url1("http://foo/1"); | 2580 const GURL url1("http://foo/1"); |
| 2582 const GURL transient_url("http://foo/transient"); | 2581 const GURL transient_url("http://foo/transient"); |
| 2583 | 2582 |
| 2584 // Load |url0|, and start a pending navigation to |url1|. | 2583 // Load |url0|, and start a pending navigation to |url1|. |
| 2585 controller.LoadURL( | 2584 controller.LoadURL( |
| 2586 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2585 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2587 test_rvh()->SendNavigate(0, url0); | 2586 test_rvh()->SendNavigate(0, url0); |
| 2588 controller.LoadURL( | 2587 controller.LoadURL( |
| 2589 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2588 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2590 | 2589 |
| 2591 // A transient entry is added, interrupting the navigation. | 2590 // A transient entry is added, interrupting the navigation. |
| 2592 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2591 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2593 transient_entry->SetURL(transient_url); | 2592 transient_entry->SetURL(transient_url); |
| 2594 controller.SetTransientEntry(transient_entry); | 2593 controller.SetTransientEntry(transient_entry); |
| 2595 EXPECT_TRUE(controller.GetTransientEntry()); | 2594 EXPECT_TRUE(controller.GetTransientEntry()); |
| 2596 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2595 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2597 | 2596 |
| 2598 // The page is reloaded, which should remove the pending entry for |url1| and | 2597 // The page is reloaded, which should remove the pending entry for |url1| and |
| 2599 // the transient entry for |transient_url|, and start a navigation to | 2598 // the transient entry for |transient_url|, and start a navigation to |
| 2600 // |transient_url|. | 2599 // |transient_url|. |
| 2601 controller.Reload(true); | 2600 controller.Reload(true); |
| 2602 EXPECT_FALSE(controller.GetTransientEntry()); | 2601 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2603 EXPECT_TRUE(controller.GetPendingEntry()); | 2602 EXPECT_TRUE(controller.GetPendingEntry()); |
| 2604 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2603 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2605 ASSERT_EQ(controller.GetEntryCount(), 1); | 2604 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2606 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2605 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2607 | 2606 |
| 2608 // Load of |transient_url| completes. | 2607 // Load of |transient_url| completes. |
| 2609 test_rvh()->SendNavigate(1, transient_url); | 2608 test_rvh()->SendNavigate(1, transient_url); |
| 2610 ASSERT_EQ(controller.GetEntryCount(), 2); | 2609 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2611 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2610 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2612 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2611 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2613 } | 2612 } |
| 2614 | 2613 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2662 // the user until the navigation commits, to prevent URL spoof attacks. | 2661 // the user until the navigation commits, to prevent URL spoof attacks. |
| 2663 // See http://crbug.com/99016. | 2662 // See http://crbug.com/99016. |
| 2664 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2663 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 2665 NavigationControllerImpl& controller = controller_impl(); | 2664 NavigationControllerImpl& controller = controller_impl(); |
| 2666 TestNotificationTracker notifications; | 2665 TestNotificationTracker notifications; |
| 2667 RegisterForAllNavNotifications(¬ifications, &controller); | 2666 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2668 | 2667 |
| 2669 const GURL url0("http://foo/0"); | 2668 const GURL url0("http://foo/0"); |
| 2670 const GURL url1("http://foo/1"); | 2669 const GURL url1("http://foo/1"); |
| 2671 | 2670 |
| 2672 // For typed navigations (browser-initiated), both active and visible entries | 2671 // For typed navigations (browser-initiated), both pending and visible entries |
| 2673 // should update before commit. | 2672 // should update before commit. |
| 2674 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2673 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2675 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); | 2674 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
| 2676 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2675 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 2677 test_rvh()->SendNavigate(0, url0); | 2676 test_rvh()->SendNavigate(0, url0); |
| 2678 | 2677 |
| 2679 // For link clicks (renderer-initiated navigations), the active entry should | 2678 // For link clicks (renderer-initiated navigations), the pending entry should |
| 2680 // update before commit but the visible should not. | 2679 // update before commit but the visible should not. |
| 2681 NavigationController::LoadURLParams load_url_params(url1); | 2680 NavigationController::LoadURLParams load_url_params(url1); |
| 2682 load_url_params.is_renderer_initiated = true; | 2681 load_url_params.is_renderer_initiated = true; |
| 2683 controller.LoadURLWithParams(load_url_params); | 2682 controller.LoadURLWithParams(load_url_params); |
| 2684 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | |
| 2685 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2683 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 2684 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2686 EXPECT_TRUE( | 2685 EXPECT_TRUE( |
| 2687 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2686 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2688 is_renderer_initiated()); | 2687 is_renderer_initiated()); |
| 2689 | 2688 |
| 2690 // After commit, both should be updated, and we should no longer treat the | 2689 // After commit, both visible should be updated, there should be no pending |
| 2691 // entry as renderer-initiated. | 2690 // entry, and we should no longer treat the entry as renderer-initiated. |
| 2692 test_rvh()->SendNavigate(1, url1); | 2691 test_rvh()->SendNavigate(1, url1); |
| 2693 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | |
| 2694 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2692 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2693 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2695 EXPECT_FALSE( | 2694 EXPECT_FALSE( |
| 2696 NavigationEntryImpl::FromNavigationEntry( | 2695 NavigationEntryImpl::FromNavigationEntry( |
| 2697 controller.GetLastCommittedEntry())->is_renderer_initiated()); | 2696 controller.GetLastCommittedEntry())->is_renderer_initiated()); |
| 2698 | 2697 |
| 2699 notifications.Reset(); | 2698 notifications.Reset(); |
| 2700 } | 2699 } |
| 2701 | 2700 |
| 2702 // Tests that the URLs for renderer-initiated navigations in new tabs are | 2701 // Tests that the URLs for renderer-initiated navigations in new tabs are |
| 2703 // displayed to the user before commit, as long as the initial about:blank | 2702 // displayed to the user before commit, as long as the initial about:blank |
| 2704 // page has not been modified. If so, we must revert to showing about:blank. | 2703 // page has not been modified. If so, we must revert to showing about:blank. |
| 2705 // See http://crbug.com/9682. | 2704 // See http://crbug.com/9682. |
| 2706 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { | 2705 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { |
| 2707 NavigationControllerImpl& controller = controller_impl(); | 2706 NavigationControllerImpl& controller = controller_impl(); |
| 2708 TestNotificationTracker notifications; | 2707 TestNotificationTracker notifications; |
| 2709 RegisterForAllNavNotifications(¬ifications, &controller); | 2708 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2710 | 2709 |
| 2711 const GURL url("http://foo"); | 2710 const GURL url("http://foo"); |
| 2712 | 2711 |
| 2713 // For renderer-initiated navigations in new tabs (with no committed entries), | 2712 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 2714 // we show the pending entry's URL as long as the about:blank page is not | 2713 // we show the pending entry's URL as long as the about:blank page is not |
| 2715 // modified. | 2714 // modified. |
| 2716 NavigationController::LoadURLParams load_url_params(url); | 2715 NavigationController::LoadURLParams load_url_params(url); |
| 2717 load_url_params.transition_type = PAGE_TRANSITION_LINK; | 2716 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 2718 load_url_params.is_renderer_initiated = true; | 2717 load_url_params.is_renderer_initiated = true; |
| 2719 controller.LoadURLWithParams(load_url_params); | 2718 controller.LoadURLWithParams(load_url_params); |
| 2720 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); | |
| 2721 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2719 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2720 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2722 EXPECT_TRUE( | 2721 EXPECT_TRUE( |
| 2723 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2722 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2724 is_renderer_initiated()); | 2723 is_renderer_initiated()); |
| 2725 EXPECT_TRUE(controller.IsInitialNavigation()); | 2724 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2726 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2725 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); |
| 2727 | 2726 |
| 2728 // There should be no title yet. | 2727 // There should be no title yet. |
| 2729 EXPECT_TRUE(contents()->GetTitle().empty()); | 2728 EXPECT_TRUE(contents()->GetTitle().empty()); |
| 2730 | 2729 |
| 2731 // If something else modifies the contents of the about:blank page, then | 2730 // If something else modifies the contents of the about:blank page, then |
| 2732 // we must revert to showing about:blank to avoid a URL spoof. | 2731 // we must revert to showing about:blank to avoid a URL spoof. |
| 2733 test_rvh()->OnMessageReceived( | 2732 test_rvh()->OnMessageReceived( |
| 2734 ViewHostMsg_DidAccessInitialDocument(0)); | 2733 ViewHostMsg_DidAccessInitialDocument(0)); |
| 2735 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | 2734 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); |
| 2736 EXPECT_FALSE(controller.GetVisibleEntry()); | 2735 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 2737 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); | 2736 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2738 | 2737 |
| 2739 notifications.Reset(); | 2738 notifications.Reset(); |
| 2740 } | 2739 } |
| 2741 | 2740 |
| 2742 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { | 2741 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { |
| 2743 NavigationControllerImpl& controller = controller_impl(); | 2742 NavigationControllerImpl& controller = controller_impl(); |
| 2744 TestNotificationTracker notifications; | 2743 TestNotificationTracker notifications; |
| 2745 RegisterForAllNavNotifications(¬ifications, &controller); | 2744 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2746 | 2745 |
| 2747 const GURL url1("http://foo/eh"); | 2746 const GURL url1("http://foo/eh"); |
| 2748 const GURL url2("http://foo/bee"); | 2747 const GURL url2("http://foo/bee"); |
| 2749 | 2748 |
| 2750 // For renderer-initiated navigations in new tabs (with no committed entries), | 2749 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 2751 // we show the pending entry's URL as long as the about:blank page is not | 2750 // we show the pending entry's URL as long as the about:blank page is not |
| 2752 // modified. | 2751 // modified. |
| 2753 NavigationController::LoadURLParams load_url_params(url1); | 2752 NavigationController::LoadURLParams load_url_params(url1); |
| 2754 load_url_params.transition_type = PAGE_TRANSITION_LINK; | 2753 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 2755 load_url_params.is_renderer_initiated = true; | 2754 load_url_params.is_renderer_initiated = true; |
| 2756 controller.LoadURLWithParams(load_url_params); | 2755 controller.LoadURLWithParams(load_url_params); |
| 2757 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | |
| 2758 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2756 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2759 EXPECT_TRUE( | 2757 EXPECT_TRUE( |
| 2760 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2758 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2761 is_renderer_initiated()); | 2759 is_renderer_initiated()); |
| 2762 EXPECT_TRUE(controller.IsInitialNavigation()); | 2760 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2763 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2761 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); |
| 2764 | 2762 |
| 2765 // Simulate a commit and then starting a new pending navigation. | 2763 // Simulate a commit and then starting a new pending navigation. |
| 2766 test_rvh()->SendNavigate(0, url1); | 2764 test_rvh()->SendNavigate(0, url1); |
| 2767 NavigationController::LoadURLParams load_url2_params(url2); | 2765 NavigationController::LoadURLParams load_url2_params(url2); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2849 | 2847 |
| 2850 // Make sure that on cloning a WebContentsImpl and going back needs_reload is | 2848 // Make sure that on cloning a WebContentsImpl and going back needs_reload is |
| 2851 // false. | 2849 // false. |
| 2852 TEST_F(NavigationControllerTest, CloneAndGoBack) { | 2850 TEST_F(NavigationControllerTest, CloneAndGoBack) { |
| 2853 NavigationControllerImpl& controller = controller_impl(); | 2851 NavigationControllerImpl& controller = controller_impl(); |
| 2854 const GURL url1("http://foo1"); | 2852 const GURL url1("http://foo1"); |
| 2855 const GURL url2("http://foo2"); | 2853 const GURL url2("http://foo2"); |
| 2856 const string16 title(ASCIIToUTF16("Title")); | 2854 const string16 title(ASCIIToUTF16("Title")); |
| 2857 | 2855 |
| 2858 NavigateAndCommit(url1); | 2856 NavigateAndCommit(url1); |
| 2859 controller.GetActiveEntry()->SetTitle(title); | 2857 controller.GetVisibleEntry()->SetTitle(title); |
| 2860 NavigateAndCommit(url2); | 2858 NavigateAndCommit(url2); |
| 2861 | 2859 |
| 2862 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 2860 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
| 2863 | 2861 |
| 2864 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 2862 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
| 2865 EXPECT_TRUE(clone->GetController().NeedsReload()); | 2863 EXPECT_TRUE(clone->GetController().NeedsReload()); |
| 2866 clone->GetController().GoBack(); | 2864 clone->GetController().GoBack(); |
| 2867 // Navigating back should have triggered needs_reload_ to go false. | 2865 // Navigating back should have triggered needs_reload_ to go false. |
| 2868 EXPECT_FALSE(clone->GetController().NeedsReload()); | 2866 EXPECT_FALSE(clone->GetController().NeedsReload()); |
| 2869 | 2867 |
| 2870 // Ensure that the pending URL and its title are visible. | 2868 // Ensure that the pending URL and its title are visible. |
| 2871 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL()); | 2869 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL()); |
| 2872 EXPECT_EQ(title, clone->GetTitle()); | 2870 EXPECT_EQ(title, clone->GetTitle()); |
| 2873 } | 2871 } |
| 2874 | 2872 |
| 2875 // Make sure that reloading a cloned tab doesn't change its pending entry index. | 2873 // Make sure that reloading a cloned tab doesn't change its pending entry index. |
| 2876 // See http://crbug.com/234491. | 2874 // See http://crbug.com/234491. |
| 2877 TEST_F(NavigationControllerTest, CloneAndReload) { | 2875 TEST_F(NavigationControllerTest, CloneAndReload) { |
| 2878 NavigationControllerImpl& controller = controller_impl(); | 2876 NavigationControllerImpl& controller = controller_impl(); |
| 2879 const GURL url1("http://foo1"); | 2877 const GURL url1("http://foo1"); |
| 2880 const GURL url2("http://foo2"); | 2878 const GURL url2("http://foo2"); |
| 2881 const string16 title(ASCIIToUTF16("Title")); | 2879 const string16 title(ASCIIToUTF16("Title")); |
| 2882 | 2880 |
| 2883 NavigateAndCommit(url1); | 2881 NavigateAndCommit(url1); |
| 2884 controller.GetActiveEntry()->SetTitle(title); | 2882 controller.GetVisibleEntry()->SetTitle(title); |
| 2885 NavigateAndCommit(url2); | 2883 NavigateAndCommit(url2); |
| 2886 | 2884 |
| 2887 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 2885 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
| 2888 clone->GetController().LoadIfNecessary(); | 2886 clone->GetController().LoadIfNecessary(); |
| 2889 | 2887 |
| 2890 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 2888 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
| 2891 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); | 2889 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); |
| 2892 | 2890 |
| 2893 clone->GetController().Reload(true); | 2891 clone->GetController().Reload(true); |
| 2894 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); | 2892 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 LoadCommittedDetails details; | 2955 LoadCommittedDetails details; |
| 2958 | 2956 |
| 2959 // This should return false meaning that nothing was actually updated. | 2957 // This should return false meaning that nothing was actually updated. |
| 2960 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); | 2958 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); |
| 2961 | 2959 |
| 2962 // The notification should have updated the last committed one, and not | 2960 // The notification should have updated the last committed one, and not |
| 2963 // the pending load. | 2961 // the pending load. |
| 2964 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); | 2962 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); |
| 2965 | 2963 |
| 2966 // The active entry should be unchanged by the subframe load. | 2964 // The active entry should be unchanged by the subframe load. |
| 2967 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 2965 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2968 } | 2966 } |
| 2969 | 2967 |
| 2970 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. | 2968 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. |
| 2971 TEST_F(NavigationControllerTest, CopyStateFrom) { | 2969 TEST_F(NavigationControllerTest, CopyStateFrom) { |
| 2972 NavigationControllerImpl& controller = controller_impl(); | 2970 NavigationControllerImpl& controller = controller_impl(); |
| 2973 const GURL url1("http://foo1"); | 2971 const GURL url1("http://foo1"); |
| 2974 const GURL url2("http://foo2"); | 2972 const GURL url2("http://foo2"); |
| 2975 | 2973 |
| 2976 NavigateAndCommit(url1); | 2974 NavigateAndCommit(url1); |
| 2977 NavigateAndCommit(url2); | 2975 NavigateAndCommit(url2); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3787 contents()->CommitPendingNavigation(); | 3785 contents()->CommitPendingNavigation(); |
| 3788 | 3786 |
| 3789 // Verify that the NavigationController's session history was correctly | 3787 // Verify that the NavigationController's session history was correctly |
| 3790 // cleared. | 3788 // cleared. |
| 3791 EXPECT_EQ(1, controller.GetEntryCount()); | 3789 EXPECT_EQ(1, controller.GetEntryCount()); |
| 3792 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 3790 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 3793 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3791 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 3794 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3792 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 3795 EXPECT_FALSE(controller.CanGoBack()); | 3793 EXPECT_FALSE(controller.CanGoBack()); |
| 3796 EXPECT_FALSE(controller.CanGoForward()); | 3794 EXPECT_FALSE(controller.CanGoForward()); |
| 3797 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); | 3795 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 3798 } | 3796 } |
| 3799 | 3797 |
| 3800 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot | 3798 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot |
| 3801 (but not Vista) cleaning up the directory after they run. | 3799 (but not Vista) cleaning up the directory after they run. |
| 3802 This should be fixed. | 3800 This should be fixed. |
| 3803 | 3801 |
| 3804 // NavigationControllerHistoryTest --------------------------------------------- | 3802 // NavigationControllerHistoryTest --------------------------------------------- |
| 3805 | 3803 |
| 3806 class NavigationControllerHistoryTest : public NavigationControllerTest { | 3804 class NavigationControllerHistoryTest : public NavigationControllerTest { |
| 3807 public: | 3805 public: |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3969 PAGE_TRANSITION_LINK); | 3967 PAGE_TRANSITION_LINK); |
| 3970 session_helper_.AssertNavigationEquals(nav, | 3968 session_helper_.AssertNavigationEquals(nav, |
| 3971 windows_[0]->tabs[0]->navigations[0]); | 3969 windows_[0]->tabs[0]->navigations[0]); |
| 3972 nav.set_url(url2); | 3970 nav.set_url(url2); |
| 3973 session_helper_.AssertNavigationEquals(nav, | 3971 session_helper_.AssertNavigationEquals(nav, |
| 3974 windows_[0]->tabs[0]->navigations[1]); | 3972 windows_[0]->tabs[0]->navigations[1]); |
| 3975 } | 3973 } |
| 3976 */ | 3974 */ |
| 3977 | 3975 |
| 3978 } // namespace content | 3976 } // namespace content |
| OLD | NEW |