| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 RegisterForAllNavNotifications(¬ifications, &controller); | 310 RegisterForAllNavNotifications(¬ifications, &controller); |
| 311 | 311 |
| 312 const int kNumUrls = 5; | 312 const int kNumUrls = 5; |
| 313 std::vector<GURL> urls(kNumUrls); | 313 std::vector<GURL> urls(kNumUrls); |
| 314 for (int i = 0; i < kNumUrls; ++i) { | 314 for (int i = 0; i < kNumUrls; ++i) { |
| 315 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 315 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
| 316 } | 316 } |
| 317 | 317 |
| 318 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); | 318 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); |
| 319 main_test_rfh()->PrepareForCommit(); | 319 main_test_rfh()->PrepareForCommit(); |
| 320 main_test_rfh()->SendNavigate(0, urls[0]); | 320 main_test_rfh()->SendNavigate(0, 0, true, urls[0]); |
| 321 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 321 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 322 navigation_entry_committed_counter_ = 0; | 322 navigation_entry_committed_counter_ = 0; |
| 323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
| 324 EXPECT_FALSE(controller.CanGoBack()); | 324 EXPECT_FALSE(controller.CanGoBack()); |
| 325 EXPECT_FALSE(controller.CanGoForward()); | 325 EXPECT_FALSE(controller.CanGoForward()); |
| 326 EXPECT_FALSE(controller.CanGoToOffset(1)); | 326 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 327 | 327 |
| 328 for (int i = 1; i <= 4; ++i) { | 328 for (int i = 1; i <= 4; ++i) { |
| 329 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); | 329 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); |
| 330 main_test_rfh()->PrepareForCommit(); | 330 main_test_rfh()->PrepareForCommit(); |
| 331 main_test_rfh()->SendNavigate(i, urls[i]); | 331 main_test_rfh()->SendNavigate(i, 0, true, urls[i]); |
| 332 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 332 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 333 navigation_entry_committed_counter_ = 0; | 333 navigation_entry_committed_counter_ = 0; |
| 334 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 334 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
| 335 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 335 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
| 336 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 336 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
| 337 EXPECT_FALSE(controller.CanGoToOffset(1)); | 337 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // We have loaded 5 pages, and are currently at the last-loaded page. | 340 // We have loaded 5 pages, and are currently at the last-loaded page. |
| 341 int url_index = 4; | 341 int url_index = 4; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 353 GO_TO_MIDDLE_PAGE, | 353 GO_TO_MIDDLE_PAGE, |
| 354 GO_FORWARDS, | 354 GO_FORWARDS, |
| 355 GO_BACKWARDS, | 355 GO_BACKWARDS, |
| 356 GO_TO_BEGINNING, | 356 GO_TO_BEGINNING, |
| 357 GO_TO_END | 357 GO_TO_END |
| 358 }; | 358 }; |
| 359 | 359 |
| 360 for (int test = 0; test < NUM_TESTS; ++test) { | 360 for (int test = 0; test < NUM_TESTS; ++test) { |
| 361 int offset = test_offsets[test]; | 361 int offset = test_offsets[test]; |
| 362 controller.GoToOffset(offset); | 362 controller.GoToOffset(offset); |
| 363 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 363 url_index += offset; | 364 url_index += offset; |
| 364 // Check that the GoToOffset will land on the expected page. | 365 // Check that the GoToOffset will land on the expected page. |
| 365 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 366 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
| 366 main_test_rfh()->PrepareForCommit(); | 367 main_test_rfh()->PrepareForCommit(); |
| 367 main_test_rfh()->SendNavigate(url_index, urls[url_index]); | 368 main_test_rfh()->SendNavigate(url_index, entry_id, false, urls[url_index]); |
| 368 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 369 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 369 navigation_entry_committed_counter_ = 0; | 370 navigation_entry_committed_counter_ = 0; |
| 370 // Check that we can go to any valid offset into the history. | 371 // Check that we can go to any valid offset into the history. |
| 371 for (size_t j = 0; j < urls.size(); ++j) | 372 for (size_t j = 0; j < urls.size(); ++j) |
| 372 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 373 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
| 373 // Check that we can't go beyond the beginning or end of the history. | 374 // Check that we can't go beyond the beginning or end of the history. |
| 374 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 375 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
| 375 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 376 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
| 376 } | 377 } |
| 377 } | 378 } |
| 378 | 379 |
| 379 TEST_F(NavigationControllerTest, LoadURL) { | 380 TEST_F(NavigationControllerTest, LoadURL) { |
| 380 NavigationControllerImpl& controller = controller_impl(); | 381 NavigationControllerImpl& controller = controller_impl(); |
| 381 TestNotificationTracker notifications; | 382 TestNotificationTracker notifications; |
| 382 RegisterForAllNavNotifications(¬ifications, &controller); | 383 RegisterForAllNavNotifications(¬ifications, &controller); |
| 383 | 384 |
| 384 const GURL url1("http://foo1"); | 385 const GURL url1("http://foo1"); |
| 385 const GURL url2("http://foo2"); | 386 const GURL url2("http://foo2"); |
| 386 | 387 |
| 387 controller.LoadURL( | 388 controller.LoadURL( |
| 388 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 389 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 390 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 389 // Creating a pending notification should not have issued any of the | 391 // Creating a pending notification should not have issued any of the |
| 390 // notifications we're listening for. | 392 // notifications we're listening for. |
| 391 EXPECT_EQ(0U, notifications.size()); | 393 EXPECT_EQ(0U, notifications.size()); |
| 392 | 394 |
| 393 // The load should now be pending. | 395 // The load should now be pending. |
| 394 EXPECT_EQ(controller.GetEntryCount(), 0); | 396 EXPECT_EQ(controller.GetEntryCount(), 0); |
| 395 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | 397 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); |
| 396 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 398 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 397 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 399 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
| 398 ASSERT_TRUE(controller.GetPendingEntry()); | 400 ASSERT_TRUE(controller.GetPendingEntry()); |
| 399 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 401 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 400 EXPECT_FALSE(controller.CanGoBack()); | 402 EXPECT_FALSE(controller.CanGoBack()); |
| 401 EXPECT_FALSE(controller.CanGoForward()); | 403 EXPECT_FALSE(controller.CanGoForward()); |
| 402 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 404 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
| 403 | 405 |
| 404 // Neither the timestamp nor the status code should have been set yet. | 406 // Neither the timestamp nor the status code should have been set yet. |
| 405 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 407 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 406 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 408 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
| 407 | 409 |
| 408 // We should have gotten no notifications from the preceeding checks. | 410 // We should have gotten no notifications from the preceeding checks. |
| 409 EXPECT_EQ(0U, notifications.size()); | 411 EXPECT_EQ(0U, notifications.size()); |
| 410 | 412 |
| 411 main_test_rfh()->PrepareForCommit(); | 413 main_test_rfh()->PrepareForCommit(); |
| 412 main_test_rfh()->SendNavigate(0, url1); | 414 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 413 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 415 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 414 navigation_entry_committed_counter_ = 0; | 416 navigation_entry_committed_counter_ = 0; |
| 415 | 417 |
| 416 // The load should now be committed. | 418 // The load should now be committed. |
| 417 EXPECT_EQ(controller.GetEntryCount(), 1); | 419 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 418 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 420 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 419 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 421 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 420 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 422 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 421 EXPECT_FALSE(controller.GetPendingEntry()); | 423 EXPECT_FALSE(controller.GetPendingEntry()); |
| 422 ASSERT_TRUE(controller.GetVisibleEntry()); | 424 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 423 EXPECT_FALSE(controller.CanGoBack()); | 425 EXPECT_FALSE(controller.CanGoBack()); |
| 424 EXPECT_FALSE(controller.CanGoForward()); | 426 EXPECT_FALSE(controller.CanGoForward()); |
| 425 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 427 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 426 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 428 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 427 | 429 |
| 428 // The timestamp should have been set. | 430 // The timestamp should have been set. |
| 429 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); | 431 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); |
| 430 | 432 |
| 431 // Load another... | 433 // Load another... |
| 432 controller.LoadURL( | 434 controller.LoadURL( |
| 433 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 435 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 436 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 434 | 437 |
| 435 // The load should now be pending. | 438 // The load should now be pending. |
| 436 EXPECT_EQ(controller.GetEntryCount(), 1); | 439 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 437 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 440 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 438 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 441 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 439 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 442 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 440 ASSERT_TRUE(controller.GetPendingEntry()); | 443 ASSERT_TRUE(controller.GetPendingEntry()); |
| 441 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 444 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 442 // TODO(darin): maybe this should really be true? | 445 // TODO(darin): maybe this should really be true? |
| 443 EXPECT_FALSE(controller.CanGoBack()); | 446 EXPECT_FALSE(controller.CanGoBack()); |
| 444 EXPECT_FALSE(controller.CanGoForward()); | 447 EXPECT_FALSE(controller.CanGoForward()); |
| 445 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 448 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 446 | 449 |
| 447 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 450 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 448 | 451 |
| 449 // Simulate the beforeunload ack for the cross-site transition, and then the | 452 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 450 // commit. | 453 // commit. |
| 451 main_test_rfh()->PrepareForCommit(); | 454 main_test_rfh()->PrepareForCommit(); |
| 452 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 455 contents()->GetPendingMainFrame()->SendNavigate(1, entry_id, true, url2); |
| 453 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 456 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 454 navigation_entry_committed_counter_ = 0; | 457 navigation_entry_committed_counter_ = 0; |
| 455 | 458 |
| 456 // The load should now be committed. | 459 // The load should now be committed. |
| 457 EXPECT_EQ(controller.GetEntryCount(), 2); | 460 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 458 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 461 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 459 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 462 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 460 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 463 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 461 EXPECT_FALSE(controller.GetPendingEntry()); | 464 EXPECT_FALSE(controller.GetPendingEntry()); |
| 462 ASSERT_TRUE(controller.GetVisibleEntry()); | 465 ASSERT_TRUE(controller.GetVisibleEntry()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 482 | 485 |
| 483 // Set the clock to always return a timestamp of 1. | 486 // Set the clock to always return a timestamp of 1. |
| 484 controller.SetGetTimestampCallbackForTest( | 487 controller.SetGetTimestampCallbackForTest( |
| 485 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 488 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
| 486 | 489 |
| 487 const GURL url1("http://foo1"); | 490 const GURL url1("http://foo1"); |
| 488 const GURL url2("http://foo2"); | 491 const GURL url2("http://foo2"); |
| 489 | 492 |
| 490 controller.LoadURL( | 493 controller.LoadURL( |
| 491 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 494 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 495 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 492 | 496 |
| 493 main_test_rfh()->PrepareForCommit(); | 497 main_test_rfh()->PrepareForCommit(); |
| 494 main_test_rfh()->SendNavigate(0, url1); | 498 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 495 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 499 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 496 navigation_entry_committed_counter_ = 0; | 500 navigation_entry_committed_counter_ = 0; |
| 497 | 501 |
| 498 // Load another... | 502 // Load another... |
| 499 controller.LoadURL( | 503 controller.LoadURL( |
| 500 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 504 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 505 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 501 | 506 |
| 502 // Simulate the beforeunload ack for the cross-site transition, and then the | 507 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 503 // commit. | 508 // commit. |
| 504 main_test_rfh()->PrepareForCommit(); | 509 main_test_rfh()->PrepareForCommit(); |
| 505 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 510 contents()->GetPendingMainFrame()->SendNavigate(1, entry_id, true, url2); |
| 506 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 511 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 507 navigation_entry_committed_counter_ = 0; | 512 navigation_entry_committed_counter_ = 0; |
| 508 | 513 |
| 509 // The two loads should now be committed. | 514 // The two loads should now be committed. |
| 510 ASSERT_EQ(controller.GetEntryCount(), 2); | 515 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 511 | 516 |
| 512 // Timestamps should be distinct despite the clock returning the | 517 // Timestamps should be distinct despite the clock returning the |
| 513 // same value. | 518 // same value. |
| 514 EXPECT_EQ(1u, | 519 EXPECT_EQ(1u, |
| 515 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); | 520 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 // the load commits (because WebCore didn't actually make a new entry). | 617 // the load commits (because WebCore didn't actually make a new entry). |
| 613 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 618 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
| 614 NavigationControllerImpl& controller = controller_impl(); | 619 NavigationControllerImpl& controller = controller_impl(); |
| 615 TestNotificationTracker notifications; | 620 TestNotificationTracker notifications; |
| 616 RegisterForAllNavNotifications(¬ifications, &controller); | 621 RegisterForAllNavNotifications(¬ifications, &controller); |
| 617 | 622 |
| 618 const GURL url1("http://foo1"); | 623 const GURL url1("http://foo1"); |
| 619 | 624 |
| 620 controller.LoadURL( | 625 controller.LoadURL( |
| 621 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 626 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 627 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 622 EXPECT_EQ(0U, notifications.size()); | 628 EXPECT_EQ(0U, notifications.size()); |
| 623 main_test_rfh()->PrepareForCommit(); | 629 main_test_rfh()->PrepareForCommit(); |
| 624 main_test_rfh()->SendNavigate(0, url1); | 630 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 625 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 631 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 626 navigation_entry_committed_counter_ = 0; | 632 navigation_entry_committed_counter_ = 0; |
| 627 | 633 |
| 628 ASSERT_TRUE(controller.GetVisibleEntry()); | 634 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 629 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 635 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 630 EXPECT_FALSE(timestamp.is_null()); | 636 EXPECT_FALSE(timestamp.is_null()); |
| 631 | 637 |
| 632 controller.LoadURL( | 638 controller.LoadURL( |
| 633 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 639 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 640 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 634 EXPECT_EQ(0U, notifications.size()); | 641 EXPECT_EQ(0U, notifications.size()); |
| 635 main_test_rfh()->PrepareForCommit(); | 642 main_test_rfh()->PrepareForCommit(); |
| 636 main_test_rfh()->SendNavigate(0, url1); | 643 main_test_rfh()->SendNavigate(0, entry_id, false, url1); |
| 637 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 644 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 638 navigation_entry_committed_counter_ = 0; | 645 navigation_entry_committed_counter_ = 0; |
| 639 | 646 |
| 640 // We should not have produced a new session history entry. | 647 // We should not have produced a new session history entry. |
| 641 EXPECT_EQ(controller.GetEntryCount(), 1); | 648 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 642 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 649 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 643 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 650 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 644 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 651 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 645 EXPECT_FALSE(controller.GetPendingEntry()); | 652 EXPECT_FALSE(controller.GetPendingEntry()); |
| 646 ASSERT_TRUE(controller.GetVisibleEntry()); | 653 ASSERT_TRUE(controller.GetVisibleEntry()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 660 NavigationControllerImpl& controller = controller_impl(); | 667 NavigationControllerImpl& controller = controller_impl(); |
| 661 TestNotificationTracker notifications; | 668 TestNotificationTracker notifications; |
| 662 RegisterForAllNavNotifications(¬ifications, &controller); | 669 RegisterForAllNavNotifications(¬ifications, &controller); |
| 663 | 670 |
| 664 const GURL url1("http://foo1"); | 671 const GURL url1("http://foo1"); |
| 665 | 672 |
| 666 controller.LoadURL( | 673 controller.LoadURL( |
| 667 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 674 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 668 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 675 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 669 params.page_id = 0; | 676 params.page_id = 0; |
| 677 params.nav_entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 678 params.did_create_new_entry = true; |
| 670 params.url = url1; | 679 params.url = url1; |
| 671 params.transition = ui::PAGE_TRANSITION_TYPED; | 680 params.transition = ui::PAGE_TRANSITION_TYPED; |
| 672 params.is_post = true; | 681 params.is_post = true; |
| 673 params.post_id = 123; | 682 params.post_id = 123; |
| 674 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 683 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
| 675 main_test_rfh()->PrepareForCommit(); | 684 main_test_rfh()->PrepareForCommit(); |
| 676 main_test_rfh()->SendNavigateWithParams(¶ms); | 685 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 677 | 686 |
| 678 // The post data should be visible. | 687 // The post data should be visible. |
| 679 NavigationEntry* entry = controller.GetVisibleEntry(); | 688 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 680 ASSERT_TRUE(entry); | 689 ASSERT_TRUE(entry); |
| 681 EXPECT_TRUE(entry->GetHasPostData()); | 690 EXPECT_TRUE(entry->GetHasPostData()); |
| 682 EXPECT_EQ(entry->GetPostID(), 123); | 691 EXPECT_EQ(entry->GetPostID(), 123); |
| 683 | 692 |
| 684 controller.LoadURL( | 693 controller.LoadURL( |
| 685 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 694 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 686 main_test_rfh()->PrepareForCommit(); | 695 main_test_rfh()->PrepareForCommit(); |
| 687 main_test_rfh()->SendNavigate(0, url1); | 696 main_test_rfh()->SendNavigate(0, controller.GetPendingEntry()->GetUniqueID(), |
| 697 false, url1); |
| 688 | 698 |
| 689 // We should not have produced a new session history entry. | 699 // We should not have produced a new session history entry. |
| 690 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 700 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
| 691 | 701 |
| 692 // The post data should have been cleared due to the GET. | 702 // The post data should have been cleared due to the GET. |
| 693 EXPECT_FALSE(entry->GetHasPostData()); | 703 EXPECT_FALSE(entry->GetHasPostData()); |
| 694 EXPECT_EQ(entry->GetPostID(), 0); | 704 EXPECT_EQ(entry->GetPostID(), 0); |
| 695 } | 705 } |
| 696 | 706 |
| 697 // Tests loading a URL but discarding it before the load commits. | 707 // Tests loading a URL but discarding it before the load commits. |
| 698 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 708 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
| 699 NavigationControllerImpl& controller = controller_impl(); | 709 NavigationControllerImpl& controller = controller_impl(); |
| 700 TestNotificationTracker notifications; | 710 TestNotificationTracker notifications; |
| 701 RegisterForAllNavNotifications(¬ifications, &controller); | 711 RegisterForAllNavNotifications(¬ifications, &controller); |
| 702 | 712 |
| 703 const GURL url1("http://foo1"); | 713 const GURL url1("http://foo1"); |
| 704 const GURL url2("http://foo2"); | 714 const GURL url2("http://foo2"); |
| 705 | 715 |
| 706 controller.LoadURL( | 716 controller.LoadURL( |
| 707 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 717 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 718 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 708 EXPECT_EQ(0U, notifications.size()); | 719 EXPECT_EQ(0U, notifications.size()); |
| 709 main_test_rfh()->PrepareForCommit(); | 720 main_test_rfh()->PrepareForCommit(); |
| 710 main_test_rfh()->SendNavigate(0, url1); | 721 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 711 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 722 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 712 navigation_entry_committed_counter_ = 0; | 723 navigation_entry_committed_counter_ = 0; |
| 713 | 724 |
| 714 ASSERT_TRUE(controller.GetVisibleEntry()); | 725 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 715 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 726 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 716 EXPECT_FALSE(timestamp.is_null()); | 727 EXPECT_FALSE(timestamp.is_null()); |
| 717 | 728 |
| 718 controller.LoadURL( | 729 controller.LoadURL( |
| 719 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 730 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 720 controller.DiscardNonCommittedEntries(); | 731 controller.DiscardNonCommittedEntries(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 738 // navigates from the web page, and here we test that there is no pending entry. | 749 // navigates from the web page, and here we test that there is no pending entry. |
| 739 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 750 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
| 740 NavigationControllerImpl& controller = controller_impl(); | 751 NavigationControllerImpl& controller = controller_impl(); |
| 741 TestNotificationTracker notifications; | 752 TestNotificationTracker notifications; |
| 742 RegisterForAllNavNotifications(¬ifications, &controller); | 753 RegisterForAllNavNotifications(¬ifications, &controller); |
| 743 | 754 |
| 744 // First make an existing committed entry. | 755 // First make an existing committed entry. |
| 745 const GURL kExistingURL1("http://eh"); | 756 const GURL kExistingURL1("http://eh"); |
| 746 controller.LoadURL( | 757 controller.LoadURL( |
| 747 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 758 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 759 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 748 main_test_rfh()->PrepareForCommit(); | 760 main_test_rfh()->PrepareForCommit(); |
| 749 main_test_rfh()->SendNavigate(0, kExistingURL1); | 761 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
| 750 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 762 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 751 navigation_entry_committed_counter_ = 0; | 763 navigation_entry_committed_counter_ = 0; |
| 752 | 764 |
| 753 // Do a new navigation without making a pending one. | 765 // Do a new navigation without making a pending one. |
| 754 const GURL kNewURL("http://see"); | 766 const GURL kNewURL("http://see"); |
| 755 main_test_rfh()->NavigateAndCommitRendererInitiated(99, kNewURL); | 767 main_test_rfh()->NavigateAndCommitRendererInitiated(99, true, kNewURL); |
| 756 | 768 |
| 757 // There should no longer be any pending entry, and the third navigation we | 769 // There should no longer be any pending entry, and the second navigation we |
| 758 // just made should be committed. | 770 // just made should be committed. |
| 759 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 771 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 760 navigation_entry_committed_counter_ = 0; | 772 navigation_entry_committed_counter_ = 0; |
| 761 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 773 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 762 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 774 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 763 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 775 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 764 } | 776 } |
| 765 | 777 |
| 766 // Tests navigating to a new URL when there is a new pending navigation that is | 778 // Tests navigating to a new URL when there is a new pending navigation that is |
| 767 // not the one that just loaded. This will happen if the user types in a URL to | 779 // not the one that just loaded. This will happen if the user types in a URL to |
| 768 // somewhere slow, and then navigates the current page before the typed URL | 780 // somewhere slow, and then navigates the current page before the typed URL |
| 769 // commits. | 781 // commits. |
| 770 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 782 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 771 NavigationControllerImpl& controller = controller_impl(); | 783 NavigationControllerImpl& controller = controller_impl(); |
| 772 TestNotificationTracker notifications; | 784 TestNotificationTracker notifications; |
| 773 RegisterForAllNavNotifications(¬ifications, &controller); | 785 RegisterForAllNavNotifications(¬ifications, &controller); |
| 774 | 786 |
| 775 // First make an existing committed entry. | 787 // First make an existing committed entry. |
| 776 const GURL kExistingURL1("http://eh"); | 788 const GURL kExistingURL1("http://eh"); |
| 777 controller.LoadURL( | 789 controller.LoadURL( |
| 778 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 790 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 791 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 779 main_test_rfh()->PrepareForCommit(); | 792 main_test_rfh()->PrepareForCommit(); |
| 780 main_test_rfh()->SendNavigate(0, kExistingURL1); | 793 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
| 781 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 794 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 782 navigation_entry_committed_counter_ = 0; | 795 navigation_entry_committed_counter_ = 0; |
| 783 | 796 |
| 784 // Make a pending entry to somewhere new. | 797 // Make a pending entry to somewhere new. |
| 785 const GURL kExistingURL2("http://bee"); | 798 const GURL kExistingURL2("http://bee"); |
| 786 controller.LoadURL( | 799 controller.LoadURL( |
| 787 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 800 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 788 EXPECT_EQ(0U, notifications.size()); | 801 EXPECT_EQ(0U, notifications.size()); |
| 789 | 802 |
| 790 // After the beforeunload but before it commits... | 803 // After the beforeunload but before it commits... |
| 791 main_test_rfh()->PrepareForCommit(); | 804 main_test_rfh()->PrepareForCommit(); |
| 792 | 805 |
| 793 // ... Do a new navigation. | 806 // ... Do a new navigation. |
| 794 const GURL kNewURL("http://see"); | 807 const GURL kNewURL("http://see"); |
| 795 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); | 808 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 796 main_test_rfh()->PrepareForCommit(); | 809 main_test_rfh()->PrepareForCommit(); |
| 797 contents()->GetMainFrame()->SendNavigate(3, kNewURL); | 810 contents()->GetMainFrame()->SendNavigate(3, 0, true, kNewURL); |
| 798 | 811 |
| 799 // There should no longer be any pending entry, and the third navigation we | 812 // There should no longer be any pending entry, and the third navigation we |
| 800 // just made should be committed. | 813 // just made should be committed. |
| 801 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 814 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 802 navigation_entry_committed_counter_ = 0; | 815 navigation_entry_committed_counter_ = 0; |
| 803 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 816 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 804 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 817 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 805 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 818 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 806 } | 819 } |
| 807 | 820 |
| 808 // Tests navigating to a new URL when there is a pending back/forward | 821 // Tests navigating to a new URL when there is a pending back/forward |
| 809 // navigation. This will happen if the user hits back, but before that commits, | 822 // navigation. This will happen if the user hits back, but before that commits, |
| 810 // they navigate somewhere new. | 823 // they navigate somewhere new. |
| 811 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 824 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 812 NavigationControllerImpl& controller = controller_impl(); | 825 NavigationControllerImpl& controller = controller_impl(); |
| 813 TestNotificationTracker notifications; | 826 TestNotificationTracker notifications; |
| 814 RegisterForAllNavNotifications(¬ifications, &controller); | 827 RegisterForAllNavNotifications(¬ifications, &controller); |
| 815 | 828 |
| 816 // First make some history. | 829 // First make some history. |
| 817 const GURL kExistingURL1("http://foo/eh"); | 830 const GURL kExistingURL1("http://foo/eh"); |
| 818 controller.LoadURL( | 831 controller.LoadURL( |
| 819 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 832 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 833 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 820 main_test_rfh()->PrepareForCommit(); | 834 main_test_rfh()->PrepareForCommit(); |
| 821 main_test_rfh()->SendNavigate(0, kExistingURL1); | 835 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
| 822 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 836 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 823 navigation_entry_committed_counter_ = 0; | 837 navigation_entry_committed_counter_ = 0; |
| 824 | 838 |
| 825 const GURL kExistingURL2("http://foo/bee"); | 839 const GURL kExistingURL2("http://foo/bee"); |
| 826 controller.LoadURL( | 840 controller.LoadURL( |
| 827 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 841 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 842 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 828 main_test_rfh()->PrepareForCommit(); | 843 main_test_rfh()->PrepareForCommit(); |
| 829 main_test_rfh()->SendNavigate(1, kExistingURL2); | 844 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL2); |
| 830 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 845 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 831 navigation_entry_committed_counter_ = 0; | 846 navigation_entry_committed_counter_ = 0; |
| 832 | 847 |
| 833 // Now make a pending back/forward navigation. The zeroth entry should be | 848 // Now make a pending back/forward navigation. The zeroth entry should be |
| 834 // pending. | 849 // pending. |
| 835 controller.GoBack(); | 850 controller.GoBack(); |
| 836 EXPECT_EQ(0U, notifications.size()); | 851 EXPECT_EQ(0U, notifications.size()); |
| 837 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 852 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 838 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 853 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 839 | 854 |
| 840 // Before that commits, do a new navigation. | 855 // Before that commits, do a new navigation. |
| 841 const GURL kNewURL("http://foo/see"); | 856 const GURL kNewURL("http://foo/see"); |
| 842 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); | 857 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 843 main_test_rfh()->PrepareForCommit(); | 858 main_test_rfh()->PrepareForCommit(); |
| 844 main_test_rfh()->SendNavigate(3, kNewURL); | 859 main_test_rfh()->SendNavigate(3, 0, true, kNewURL); |
| 845 | 860 |
| 846 // There should no longer be any pending entry, and the third navigation we | 861 // There should no longer be any pending entry, and the new navigation we |
| 847 // just made should be committed. | 862 // just made should be committed. |
| 848 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 863 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 849 navigation_entry_committed_counter_ = 0; | 864 navigation_entry_committed_counter_ = 0; |
| 850 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 865 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 851 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 866 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 852 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 867 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 853 } | 868 } |
| 854 | 869 |
| 855 // Tests navigating to a new URL when there is a pending back/forward | 870 // Tests navigating to a new URL when there is a pending back/forward |
| 856 // navigation to a cross-process, privileged URL. This will happen if the user | 871 // navigation to a cross-process, privileged URL. This will happen if the user |
| 857 // hits back, but before that commits, they navigate somewhere new. | 872 // hits back, but before that commits, they navigate somewhere new. |
| 858 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 873 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
| 859 NavigationControllerImpl& controller = controller_impl(); | 874 NavigationControllerImpl& controller = controller_impl(); |
| 860 TestNotificationTracker notifications; | 875 TestNotificationTracker notifications; |
| 861 RegisterForAllNavNotifications(¬ifications, &controller); | 876 RegisterForAllNavNotifications(¬ifications, &controller); |
| 862 | 877 |
| 863 // First make some history, starting with a privileged URL. | 878 // First make some history, starting with a privileged URL. |
| 864 const GURL kExistingURL1("http://privileged"); | 879 const GURL kExistingURL1("http://privileged"); |
| 865 controller.LoadURL( | 880 controller.LoadURL( |
| 866 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 881 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 882 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 867 // Pretend it has bindings so we can tell if we incorrectly copy it. | 883 // Pretend it has bindings so we can tell if we incorrectly copy it. |
| 868 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); | 884 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); |
| 869 main_test_rfh()->PrepareForCommit(); | 885 main_test_rfh()->PrepareForCommit(); |
| 870 main_test_rfh()->SendNavigate(0, kExistingURL1); | 886 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
| 871 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 887 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 872 navigation_entry_committed_counter_ = 0; | 888 navigation_entry_committed_counter_ = 0; |
| 873 | 889 |
| 874 // Navigate cross-process to a second URL. | 890 // Navigate cross-process to a second URL. |
| 875 const GURL kExistingURL2("http://foo/eh"); | 891 const GURL kExistingURL2("http://foo/eh"); |
| 876 controller.LoadURL( | 892 controller.LoadURL( |
| 877 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 893 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 894 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 878 main_test_rfh()->PrepareForCommit(); | 895 main_test_rfh()->PrepareForCommit(); |
| 879 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); | 896 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); |
| 880 foo_rfh->SendNavigate(1, kExistingURL2); | 897 foo_rfh->SendNavigate(1, entry_id, true, kExistingURL2); |
| 881 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 898 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 882 navigation_entry_committed_counter_ = 0; | 899 navigation_entry_committed_counter_ = 0; |
| 883 | 900 |
| 884 // Now make a pending back/forward navigation to a privileged entry. | 901 // Now make a pending back/forward navigation to a privileged entry. |
| 885 // The zeroth entry should be pending. | 902 // The zeroth entry should be pending. |
| 886 controller.GoBack(); | 903 controller.GoBack(); |
| 887 foo_rfh->SendBeforeUnloadACK(true); | 904 foo_rfh->SendBeforeUnloadACK(true); |
| 888 EXPECT_EQ(0U, notifications.size()); | 905 EXPECT_EQ(0U, notifications.size()); |
| 889 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 906 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 890 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 907 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 891 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); | 908 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); |
| 892 | 909 |
| 893 // Before that commits, do a new navigation. | 910 // Before that commits, do a new navigation. |
| 894 const GURL kNewURL("http://foo/bee"); | 911 const GURL kNewURL("http://foo/bee"); |
| 895 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); | 912 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 896 foo_rfh->PrepareForCommit(); | 913 foo_rfh->PrepareForCommit(); |
| 897 foo_rfh->SendNavigate(3, kNewURL); | 914 foo_rfh->SendNavigate(3, 0, true, kNewURL); |
| 898 | 915 |
| 899 // There should no longer be any pending entry, and the third navigation we | 916 // There should no longer be any pending entry, and the new navigation we |
| 900 // just made should be committed. | 917 // just made should be committed. |
| 901 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 918 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 902 navigation_entry_committed_counter_ = 0; | 919 navigation_entry_committed_counter_ = 0; |
| 903 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 920 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 904 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 921 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 905 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 922 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 906 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 923 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 907 } | 924 } |
| 908 | 925 |
| 909 // Tests navigating to an existing URL when there is a pending new navigation. | 926 // Tests navigating to an existing URL when there is a pending new navigation. |
| 910 // This will happen if the user enters a URL, but before that commits, the | 927 // This will happen if the user enters a URL, but before that commits, the |
| 911 // current page fires history.back(). | 928 // current page fires history.back(). |
| 912 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 929 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 913 NavigationControllerImpl& controller = controller_impl(); | 930 NavigationControllerImpl& controller = controller_impl(); |
| 914 TestNotificationTracker notifications; | 931 TestNotificationTracker notifications; |
| 915 RegisterForAllNavNotifications(¬ifications, &controller); | 932 RegisterForAllNavNotifications(¬ifications, &controller); |
| 916 | 933 |
| 917 // First make some history. | 934 // First make some history. |
| 918 const GURL kExistingURL1("http://foo/eh"); | 935 const GURL kExistingURL1("http://foo/eh"); |
| 919 controller.LoadURL( | 936 controller.LoadURL( |
| 920 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 937 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 938 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 921 main_test_rfh()->PrepareForCommit(); | 939 main_test_rfh()->PrepareForCommit(); |
| 922 main_test_rfh()->SendNavigate(0, kExistingURL1); | 940 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
| 923 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 941 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 924 navigation_entry_committed_counter_ = 0; | 942 navigation_entry_committed_counter_ = 0; |
| 925 | 943 |
| 926 const GURL kExistingURL2("http://foo/bee"); | 944 const GURL kExistingURL2("http://foo/bee"); |
| 927 controller.LoadURL( | 945 controller.LoadURL( |
| 928 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 946 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 947 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 929 main_test_rfh()->PrepareForCommit(); | 948 main_test_rfh()->PrepareForCommit(); |
| 930 main_test_rfh()->SendNavigate(1, kExistingURL2); | 949 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL2); |
| 931 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 950 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 932 navigation_entry_committed_counter_ = 0; | 951 navigation_entry_committed_counter_ = 0; |
| 933 | 952 |
| 934 // A back navigation comes in from the renderer... | 953 // A back navigation comes in from the renderer... |
| 935 controller.GoToOffset(-1); | 954 controller.GoToOffset(-1); |
| 955 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 936 | 956 |
| 937 // ...while the user tries to navigate to a new page... | 957 // ...while the user tries to navigate to a new page... |
| 938 const GURL kNewURL("http://foo/see"); | 958 const GURL kNewURL("http://foo/see"); |
| 939 controller.LoadURL( | 959 controller.LoadURL( |
| 940 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 960 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 941 EXPECT_EQ(0U, notifications.size()); | 961 EXPECT_EQ(0U, notifications.size()); |
| 942 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 962 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 943 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 963 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 944 | 964 |
| 945 // ...and the back navigation commits. | 965 // ...and the back navigation commits. |
| 946 main_test_rfh()->PrepareForCommit(); | 966 main_test_rfh()->PrepareForCommit(); |
| 947 main_test_rfh()->SendNavigate(0, kExistingURL1); | 967 main_test_rfh()->SendNavigate(0, entry_id, false, kExistingURL1); |
| 948 | 968 |
| 949 // There should no longer be any pending entry, and the back navigation should | 969 // There should no longer be any pending entry, and the back navigation should |
| 950 // be committed. | 970 // be committed. |
| 951 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 971 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 952 navigation_entry_committed_counter_ = 0; | 972 navigation_entry_committed_counter_ = 0; |
| 953 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 973 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 954 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 974 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 955 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 975 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
| 956 } | 976 } |
| 957 | 977 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 975 const GURL kNewURL("http://eh"); | 995 const GURL kNewURL("http://eh"); |
| 976 controller.LoadURL( | 996 controller.LoadURL( |
| 977 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 997 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 978 EXPECT_EQ(0U, notifications.size()); | 998 EXPECT_EQ(0U, notifications.size()); |
| 979 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 999 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 980 EXPECT_TRUE(controller.GetPendingEntry()); | 1000 EXPECT_TRUE(controller.GetPendingEntry()); |
| 981 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1001 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 982 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1002 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 983 | 1003 |
| 984 // Before that commits, a document.write and location.reload can cause the | 1004 // Before that commits, a document.write and location.reload can cause the |
| 985 // renderer to send a FrameNavigate with page_id -1. | 1005 // renderer to send a FrameNavigate with page_id -1 and nav_entry_id 0. |
| 986 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); | 1006 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); |
| 987 main_test_rfh()->PrepareForCommit(); | 1007 main_test_rfh()->PrepareForCommit(); |
| 988 main_test_rfh()->SendNavigate(-1, kExistingURL); | 1008 main_test_rfh()->SendNavigate(-1, 0, false, kExistingURL); |
| 989 | 1009 |
| 990 // This should clear the pending entry and notify of a navigation state | 1010 // This should clear the pending entry and notify of a navigation state |
| 991 // change, so that we do not keep displaying kNewURL. | 1011 // change, so that we do not keep displaying kNewURL. |
| 992 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1012 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 993 EXPECT_FALSE(controller.GetPendingEntry()); | 1013 EXPECT_FALSE(controller.GetPendingEntry()); |
| 994 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1014 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 995 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 1015 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
| 996 | 1016 |
| 997 contents()->SetDelegate(NULL); | 1017 contents()->SetDelegate(NULL); |
| 998 } | 1018 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 // redirect and abort. See http://crbug.com/83031. | 1074 // redirect and abort. See http://crbug.com/83031. |
| 1055 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { | 1075 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { |
| 1056 NavigationControllerImpl& controller = controller_impl(); | 1076 NavigationControllerImpl& controller = controller_impl(); |
| 1057 TestNotificationTracker notifications; | 1077 TestNotificationTracker notifications; |
| 1058 RegisterForAllNavNotifications(¬ifications, &controller); | 1078 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1059 | 1079 |
| 1060 // First make an existing committed entry. | 1080 // First make an existing committed entry. |
| 1061 const GURL kExistingURL("http://foo/eh"); | 1081 const GURL kExistingURL("http://foo/eh"); |
| 1062 controller.LoadURL(kExistingURL, content::Referrer(), | 1082 controller.LoadURL(kExistingURL, content::Referrer(), |
| 1063 ui::PAGE_TRANSITION_TYPED, std::string()); | 1083 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1084 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1064 main_test_rfh()->PrepareForCommit(); | 1085 main_test_rfh()->PrepareForCommit(); |
| 1065 main_test_rfh()->SendNavigate(1, kExistingURL); | 1086 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL); |
| 1066 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1087 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1067 navigation_entry_committed_counter_ = 0; | 1088 navigation_entry_committed_counter_ = 0; |
| 1068 | 1089 |
| 1069 // Set a WebContentsDelegate to listen for state changes. | 1090 // Set a WebContentsDelegate to listen for state changes. |
| 1070 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 1091 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
| 1071 EXPECT_FALSE(contents()->GetDelegate()); | 1092 EXPECT_FALSE(contents()->GetDelegate()); |
| 1072 contents()->SetDelegate(delegate.get()); | 1093 contents()->SetDelegate(delegate.get()); |
| 1073 | 1094 |
| 1074 // Now make a pending new navigation, initiated by the renderer. | 1095 // Now make a pending new navigation, initiated by the renderer. |
| 1075 const GURL kNewURL("http://foo/bee"); | 1096 const GURL kNewURL("http://foo/bee"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 std::vector<GURL> url_chain; | 1148 std::vector<GURL> url_chain; |
| 1128 | 1149 |
| 1129 const GURL url1("http://foo1"); | 1150 const GURL url1("http://foo1"); |
| 1130 const GURL url2("http://foo2"); | 1151 const GURL url2("http://foo2"); |
| 1131 | 1152 |
| 1132 // Navigate to a first, unprivileged URL. | 1153 // Navigate to a first, unprivileged URL. |
| 1133 controller.LoadURL( | 1154 controller.LoadURL( |
| 1134 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1155 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1135 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1156 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
| 1136 controller.GetPendingEntry()->bindings()); | 1157 controller.GetPendingEntry()->bindings()); |
| 1158 int entry1_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1137 | 1159 |
| 1138 // Commit. | 1160 // Commit. |
| 1139 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1161 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
| 1140 orig_rfh->PrepareForCommit(); | 1162 orig_rfh->PrepareForCommit(); |
| 1141 orig_rfh->SendNavigate(0, url1); | 1163 orig_rfh->SendNavigate(0, entry1_id, true, url1); |
| 1142 EXPECT_EQ(controller.GetEntryCount(), 1); | 1164 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1143 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1165 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1144 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1166 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 1167 entry1_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1145 | 1168 |
| 1146 // Manually increase the number of active frames in the SiteInstance | 1169 // Manually increase the number of active frames in the SiteInstance |
| 1147 // that orig_rfh belongs to, to prevent it from being destroyed when | 1170 // that orig_rfh belongs to, to prevent it from being destroyed when |
| 1148 // it gets swapped out, so that we can reuse orig_rfh when the | 1171 // it gets swapped out, so that we can reuse orig_rfh when the |
| 1149 // controller goes back. | 1172 // controller goes back. |
| 1150 orig_rfh->GetSiteInstance()->increment_active_frame_count(); | 1173 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1151 | 1174 |
| 1152 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1175 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
| 1153 // transition, and set bindings on the pending RenderViewHost to simulate a | 1176 // transition, and set bindings on the pending RenderViewHost to simulate a |
| 1154 // privileged url. | 1177 // privileged url. |
| 1155 controller.LoadURL( | 1178 controller.LoadURL( |
| 1156 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1179 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1180 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1157 orig_rfh->PrepareForCommit(); | 1181 orig_rfh->PrepareForCommit(); |
| 1158 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1182 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
| 1159 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1183 new_rfh->GetRenderViewHost()->AllowBindings(1); |
| 1160 new_rfh->SendNavigate(1, url2); | 1184 new_rfh->SendNavigate(1, entry_id, true, url2); |
| 1161 | 1185 |
| 1162 // The second load should be committed, and bindings should be remembered. | 1186 // The second load should be committed, and bindings should be remembered. |
| 1163 EXPECT_EQ(controller.GetEntryCount(), 2); | 1187 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1164 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1188 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1165 EXPECT_TRUE(controller.CanGoBack()); | 1189 EXPECT_TRUE(controller.CanGoBack()); |
| 1166 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); | 1190 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); |
| 1167 | 1191 |
| 1168 // Going back, the first entry should still appear unprivileged. | 1192 // Going back, the first entry should still appear unprivileged. |
| 1169 controller.GoBack(); | 1193 controller.GoBack(); |
| 1170 new_rfh->PrepareForCommit(); | 1194 new_rfh->PrepareForCommit(); |
| 1171 orig_rfh->SendNavigate(0, url1); | 1195 orig_rfh->SendNavigate(0, entry1_id, false, url1); |
| 1172 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1196 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1173 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1197 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 1174 } | 1198 } |
| 1175 | 1199 |
| 1176 TEST_F(NavigationControllerTest, Reload) { | 1200 TEST_F(NavigationControllerTest, Reload) { |
| 1177 NavigationControllerImpl& controller = controller_impl(); | 1201 NavigationControllerImpl& controller = controller_impl(); |
| 1178 TestNotificationTracker notifications; | 1202 TestNotificationTracker notifications; |
| 1179 RegisterForAllNavNotifications(¬ifications, &controller); | 1203 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1180 | 1204 |
| 1181 const GURL url1("http://foo1"); | 1205 const GURL url1("http://foo1"); |
| 1182 | 1206 |
| 1183 controller.LoadURL( | 1207 controller.LoadURL( |
| 1184 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1208 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1209 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1185 EXPECT_EQ(0U, notifications.size()); | 1210 EXPECT_EQ(0U, notifications.size()); |
| 1186 main_test_rfh()->PrepareForCommit(); | 1211 main_test_rfh()->PrepareForCommit(); |
| 1187 main_test_rfh()->SendNavigate(0, url1); | 1212 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 1188 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1213 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1189 navigation_entry_committed_counter_ = 0; | 1214 navigation_entry_committed_counter_ = 0; |
| 1190 ASSERT_TRUE(controller.GetVisibleEntry()); | 1215 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1191 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1216 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1217 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1218 |
| 1192 controller.Reload(true); | 1219 controller.Reload(true); |
| 1193 EXPECT_EQ(0U, notifications.size()); | 1220 EXPECT_EQ(0U, notifications.size()); |
| 1194 | 1221 |
| 1195 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1222 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 1196 EXPECT_FALSE(timestamp.is_null()); | 1223 EXPECT_FALSE(timestamp.is_null()); |
| 1197 | 1224 |
| 1198 // The reload is pending. | 1225 // The reload is pending. |
| 1199 EXPECT_EQ(controller.GetEntryCount(), 1); | 1226 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1200 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1227 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1201 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1228 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1202 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1229 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1203 EXPECT_TRUE(controller.GetPendingEntry()); | 1230 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1204 EXPECT_FALSE(controller.CanGoBack()); | 1231 EXPECT_FALSE(controller.CanGoBack()); |
| 1205 EXPECT_FALSE(controller.CanGoForward()); | 1232 EXPECT_FALSE(controller.CanGoForward()); |
| 1206 // Make sure the title has been cleared (will be redrawn just after reload). | 1233 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1207 // Avoids a stale cached title when the new page being reloaded has no title. | 1234 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1208 // See http://crbug.com/96041. | 1235 // See http://crbug.com/96041. |
| 1209 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1236 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1210 | 1237 |
| 1211 main_test_rfh()->PrepareForCommit(); | 1238 main_test_rfh()->PrepareForCommit(); |
| 1212 main_test_rfh()->SendNavigate(0, url1); | 1239 main_test_rfh()->SendNavigate(0, entry_id, false, url1); |
| 1213 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1240 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1214 navigation_entry_committed_counter_ = 0; | 1241 navigation_entry_committed_counter_ = 0; |
| 1215 | 1242 |
| 1216 // Now the reload is committed. | 1243 // Now the reload is committed. |
| 1217 EXPECT_EQ(controller.GetEntryCount(), 1); | 1244 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1218 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1245 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1219 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1246 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1220 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1247 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1221 EXPECT_FALSE(controller.GetPendingEntry()); | 1248 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1222 EXPECT_FALSE(controller.CanGoBack()); | 1249 EXPECT_FALSE(controller.CanGoBack()); |
| 1223 EXPECT_FALSE(controller.CanGoForward()); | 1250 EXPECT_FALSE(controller.CanGoForward()); |
| 1224 | 1251 |
| 1225 // The timestamp should have been updated. | 1252 // The timestamp should have been updated. |
| 1226 ASSERT_TRUE(controller.GetVisibleEntry()); | 1253 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1227 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1254 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
| 1228 } | 1255 } |
| 1229 | 1256 |
| 1230 // Tests what happens when a reload navigation produces a new page. | 1257 // Tests what happens when a reload navigation produces a new page. |
| 1231 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1258 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 1232 NavigationControllerImpl& controller = controller_impl(); | 1259 NavigationControllerImpl& controller = controller_impl(); |
| 1233 TestNotificationTracker notifications; | 1260 TestNotificationTracker notifications; |
| 1234 RegisterForAllNavNotifications(¬ifications, &controller); | 1261 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1235 | 1262 |
| 1236 const GURL url1("http://foo1"); | 1263 const GURL url1("http://foo1"); |
| 1237 const GURL url2("http://foo2"); | 1264 const GURL url2("http://foo2"); |
| 1238 | 1265 |
| 1239 controller.LoadURL( | 1266 controller.LoadURL( |
| 1240 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1267 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1268 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1241 main_test_rfh()->PrepareForCommit(); | 1269 main_test_rfh()->PrepareForCommit(); |
| 1242 main_test_rfh()->SendNavigate(0, url1); | 1270 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 1243 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1271 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1244 navigation_entry_committed_counter_ = 0; | 1272 navigation_entry_committed_counter_ = 0; |
| 1273 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1245 | 1274 |
| 1246 controller.Reload(true); | 1275 controller.Reload(true); |
| 1247 EXPECT_EQ(0U, notifications.size()); | 1276 EXPECT_EQ(0U, notifications.size()); |
| 1248 | 1277 |
| 1249 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); | 1278 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
| 1250 main_test_rfh()->SendNavigate(1, url2); | 1279 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
| 1251 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1280 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1252 navigation_entry_committed_counter_ = 0; | 1281 navigation_entry_committed_counter_ = 0; |
| 1253 | 1282 |
| 1254 // Now the reload is committed. | 1283 // Now the reload is committed. |
| 1255 EXPECT_EQ(controller.GetEntryCount(), 2); | 1284 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1256 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1285 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1257 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1286 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1258 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1287 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1259 EXPECT_FALSE(controller.GetPendingEntry()); | 1288 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1260 EXPECT_TRUE(controller.CanGoBack()); | 1289 EXPECT_TRUE(controller.CanGoBack()); |
| 1261 EXPECT_FALSE(controller.CanGoForward()); | 1290 EXPECT_FALSE(controller.CanGoForward()); |
| 1262 } | 1291 } |
| 1263 | 1292 |
| 1264 // This test ensures that when a guest renderer reloads, the reload goes through | 1293 // This test ensures that when a guest renderer reloads, the reload goes through |
| 1265 // without ending up in the "we have a wrong process for the URL" branch in | 1294 // without ending up in the "we have a wrong process for the URL" branch in |
| 1266 // NavigationControllerImpl::ReloadInternal. | 1295 // NavigationControllerImpl::ReloadInternal. |
| 1267 TEST_F(NavigationControllerTest, ReloadWithGuest) { | 1296 TEST_F(NavigationControllerTest, ReloadWithGuest) { |
| 1268 NavigationControllerImpl& controller = controller_impl(); | 1297 NavigationControllerImpl& controller = controller_impl(); |
| 1269 | 1298 |
| 1270 const GURL url1("http://foo1"); | 1299 const GURL url1("http://foo1"); |
| 1271 controller.LoadURL( | 1300 controller.LoadURL( |
| 1272 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1301 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1302 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1273 main_test_rfh()->PrepareForCommit(); | 1303 main_test_rfh()->PrepareForCommit(); |
| 1274 main_test_rfh()->SendNavigate(0, url1); | 1304 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 1275 ASSERT_TRUE(controller.GetVisibleEntry()); | 1305 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1276 | 1306 |
| 1277 // Make the entry believe its RenderProcessHost is a guest. | 1307 // Make the entry believe its RenderProcessHost is a guest. |
| 1278 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); | 1308 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); |
| 1279 reinterpret_cast<MockRenderProcessHost*>( | 1309 reinterpret_cast<MockRenderProcessHost*>( |
| 1280 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); | 1310 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); |
| 1281 | 1311 |
| 1282 // And reload. | 1312 // And reload. |
| 1283 controller.Reload(true); | 1313 controller.Reload(true); |
| 1284 | 1314 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1297 NavigationControllerImpl& controller = controller_impl(); | 1327 NavigationControllerImpl& controller = controller_impl(); |
| 1298 TestNotificationTracker notifications; | 1328 TestNotificationTracker notifications; |
| 1299 RegisterForAllNavNotifications(¬ifications, &controller); | 1329 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1300 | 1330 |
| 1301 const GURL original_url("http://foo1"); | 1331 const GURL original_url("http://foo1"); |
| 1302 const GURL final_url("http://foo2"); | 1332 const GURL final_url("http://foo2"); |
| 1303 | 1333 |
| 1304 // Load up the original URL, but get redirected. | 1334 // Load up the original URL, but get redirected. |
| 1305 controller.LoadURL( | 1335 controller.LoadURL( |
| 1306 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1336 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1337 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1307 EXPECT_EQ(0U, notifications.size()); | 1338 EXPECT_EQ(0U, notifications.size()); |
| 1308 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); | 1339 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
| 1309 main_test_rfh()->SendNavigateWithOriginalRequestURL( | 1340 main_test_rfh()->SendNavigateWithOriginalRequestURL(0, entry_id, true, |
| 1310 0, final_url, original_url); | 1341 final_url, original_url); |
| 1311 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1342 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1312 navigation_entry_committed_counter_ = 0; | 1343 navigation_entry_committed_counter_ = 0; |
| 1344 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1313 | 1345 |
| 1314 // The NavigationEntry should save both the original URL and the final | 1346 // The NavigationEntry should save both the original URL and the final |
| 1315 // redirected URL. | 1347 // redirected URL. |
| 1316 EXPECT_EQ( | 1348 EXPECT_EQ( |
| 1317 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1349 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
| 1318 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1350 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
| 1319 | 1351 |
| 1320 // Reload using the original URL. | 1352 // Reload using the original URL. |
| 1321 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1353 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1322 controller.ReloadOriginalRequestURL(false); | 1354 controller.ReloadOriginalRequestURL(false); |
| 1323 EXPECT_EQ(0U, notifications.size()); | 1355 EXPECT_EQ(0U, notifications.size()); |
| 1324 | 1356 |
| 1325 // The reload is pending. The request should point to the original URL. | 1357 // The reload is pending. The request should point to the original URL. |
| 1326 EXPECT_EQ(original_url, navigated_url()); | 1358 EXPECT_EQ(original_url, navigated_url()); |
| 1327 EXPECT_EQ(controller.GetEntryCount(), 1); | 1359 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1328 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1360 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1329 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1361 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1330 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1362 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1331 EXPECT_TRUE(controller.GetPendingEntry()); | 1363 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1332 EXPECT_FALSE(controller.CanGoBack()); | 1364 EXPECT_FALSE(controller.CanGoBack()); |
| 1333 EXPECT_FALSE(controller.CanGoForward()); | 1365 EXPECT_FALSE(controller.CanGoForward()); |
| 1334 | 1366 |
| 1335 // Make sure the title has been cleared (will be redrawn just after reload). | 1367 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1336 // Avoids a stale cached title when the new page being reloaded has no title. | 1368 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1337 // See http://crbug.com/96041. | 1369 // See http://crbug.com/96041. |
| 1338 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1370 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1339 | 1371 |
| 1340 // Send that the navigation has proceeded; say it got redirected again. | 1372 // Send that the navigation has proceeded; say it got redirected again. |
| 1341 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); | 1373 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
| 1342 main_test_rfh()->SendNavigate(0, final_url); | 1374 main_test_rfh()->SendNavigate(0, entry_id, false, final_url); |
| 1343 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1375 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1344 navigation_entry_committed_counter_ = 0; | 1376 navigation_entry_committed_counter_ = 0; |
| 1345 | 1377 |
| 1346 // Now the reload is committed. | 1378 // Now the reload is committed. |
| 1347 EXPECT_EQ(controller.GetEntryCount(), 1); | 1379 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1348 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1380 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1349 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1381 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1350 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1382 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1351 EXPECT_FALSE(controller.GetPendingEntry()); | 1383 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1352 EXPECT_FALSE(controller.CanGoBack()); | 1384 EXPECT_FALSE(controller.CanGoBack()); |
| 1353 EXPECT_FALSE(controller.CanGoForward()); | 1385 EXPECT_FALSE(controller.CanGoForward()); |
| 1354 } | 1386 } |
| 1355 | 1387 |
| 1356 #endif // !defined(OS_ANDROID) | 1388 #endif // !defined(OS_ANDROID) |
| 1357 | 1389 |
| 1358 // Test that certain non-persisted NavigationEntryImpl values get reset after | 1390 // Test that certain non-persisted NavigationEntryImpl values get reset after |
| 1359 // commit. | 1391 // commit. |
| 1360 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { | 1392 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { |
| 1361 NavigationControllerImpl& controller = controller_impl(); | 1393 NavigationControllerImpl& controller = controller_impl(); |
| 1362 | 1394 |
| 1363 // The value of "should replace entry" will be tested, but it's an error to | 1395 // The value of "should replace entry" will be tested, but it's an error to |
| 1364 // specify it when there are no entries. Create a simple entry to be replaced. | 1396 // specify it when there are no entries. Create a simple entry to be replaced. |
| 1365 const GURL url0("http://foo/0"); | 1397 const GURL url0("http://foo/0"); |
| 1366 controller.LoadURL( | 1398 controller.LoadURL( |
| 1367 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1399 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1400 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1368 main_test_rfh()->PrepareForCommit(); | 1401 main_test_rfh()->PrepareForCommit(); |
| 1369 main_test_rfh()->SendNavigate(0, url0); | 1402 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
| 1370 | 1403 |
| 1371 // Set up the pending entry. | 1404 // Set up the pending entry. |
| 1372 const GURL url1("http://foo/1"); | 1405 const GURL url1("http://foo/1"); |
| 1373 controller.LoadURL( | 1406 controller.LoadURL( |
| 1374 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1407 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1408 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1375 | 1409 |
| 1376 // Set up some sample values. | 1410 // Set up some sample values. |
| 1377 const unsigned char* raw_data = | 1411 const unsigned char* raw_data = |
| 1378 reinterpret_cast<const unsigned char*>("post\n\n\0data"); | 1412 reinterpret_cast<const unsigned char*>("post\n\n\0data"); |
| 1379 const int length = 11; | 1413 const int length = 11; |
| 1380 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 1414 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); |
| 1381 scoped_refptr<base::RefCountedBytes> post_data = | 1415 scoped_refptr<base::RefCountedBytes> post_data = |
| 1382 base::RefCountedBytes::TakeVector(&post_data_vector); | 1416 base::RefCountedBytes::TakeVector(&post_data_vector); |
| 1383 GlobalRequestID transfer_id(3, 4); | 1417 GlobalRequestID transfer_id(3, 4); |
| 1384 | 1418 |
| 1385 // Set non-persisted values on the pending entry. | 1419 // Set non-persisted values on the pending entry. |
| 1386 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | 1420 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
| 1387 pending_entry->SetBrowserInitiatedPostData(post_data.get()); | 1421 pending_entry->SetBrowserInitiatedPostData(post_data.get()); |
| 1388 pending_entry->set_is_renderer_initiated(true); | 1422 pending_entry->set_is_renderer_initiated(true); |
| 1389 pending_entry->set_transferred_global_request_id(transfer_id); | 1423 pending_entry->set_transferred_global_request_id(transfer_id); |
| 1390 pending_entry->set_should_replace_entry(true); | 1424 pending_entry->set_should_replace_entry(true); |
| 1391 pending_entry->set_should_clear_history_list(true); | 1425 pending_entry->set_should_clear_history_list(true); |
| 1392 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1426 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); |
| 1393 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1427 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
| 1394 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1428 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
| 1395 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1429 EXPECT_TRUE(pending_entry->should_replace_entry()); |
| 1396 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1430 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
| 1397 | 1431 |
| 1398 // Fake a commit response. | 1432 // Fake a commit response. |
| 1399 main_test_rfh()->PrepareForCommit(); | 1433 main_test_rfh()->PrepareForCommit(); |
| 1400 main_test_rfh()->SendNavigate(1, url1); | 1434 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
| 1401 | 1435 |
| 1402 // Certain values that are only used for pending entries get reset after | 1436 // Certain values that are only used for pending entries get reset after |
| 1403 // commit. | 1437 // commit. |
| 1404 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); | 1438 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
| 1405 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1439 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); |
| 1406 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1440 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
| 1407 EXPECT_EQ(GlobalRequestID(-1, -1), | 1441 EXPECT_EQ(GlobalRequestID(-1, -1), |
| 1408 committed_entry->transferred_global_request_id()); | 1442 committed_entry->transferred_global_request_id()); |
| 1409 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1443 EXPECT_FALSE(committed_entry->should_replace_entry()); |
| 1410 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1444 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
| 1411 } | 1445 } |
| 1412 | 1446 |
| 1413 // Test that Redirects are preserved after a commit. | 1447 // Test that Redirects are preserved after a commit. |
| 1414 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { | 1448 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { |
| 1415 NavigationControllerImpl& controller = controller_impl(); | 1449 NavigationControllerImpl& controller = controller_impl(); |
| 1416 const GURL url1("http://foo1"); | 1450 const GURL url1("http://foo1"); |
| 1417 const GURL url2("http://foo2"); | 1451 const GURL url2("http://foo2"); |
| 1418 controller.LoadURL( | 1452 controller.LoadURL( |
| 1419 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1453 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1454 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1420 | 1455 |
| 1421 // Set up some redirect values. | 1456 // Set up some redirect values. |
| 1422 std::vector<GURL> redirects; | 1457 std::vector<GURL> redirects; |
| 1423 redirects.push_back(url2); | 1458 redirects.push_back(url2); |
| 1424 | 1459 |
| 1425 // Set redirects on the pending entry. | 1460 // Set redirects on the pending entry. |
| 1426 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | 1461 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
| 1427 pending_entry->SetRedirectChain(redirects); | 1462 pending_entry->SetRedirectChain(redirects); |
| 1428 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); | 1463 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); |
| 1429 EXPECT_EQ(url2, pending_entry->GetRedirectChain()[0]); | 1464 EXPECT_EQ(url2, pending_entry->GetRedirectChain()[0]); |
| 1430 | 1465 |
| 1431 // Normal navigation will preserve redirects in the committed entry. | 1466 // Normal navigation will preserve redirects in the committed entry. |
| 1432 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); | 1467 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
| 1433 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); | 1468 main_test_rfh()->SendNavigateWithRedirects(0, entry_id, true, url1, |
| 1469 redirects); |
| 1434 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); | 1470 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
| 1435 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); | 1471 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); |
| 1436 EXPECT_EQ(url2, committed_entry->GetRedirectChain()[0]); | 1472 EXPECT_EQ(url2, committed_entry->GetRedirectChain()[0]); |
| 1437 } | 1473 } |
| 1438 | 1474 |
| 1439 // Tests what happens when we navigate back successfully | 1475 // Tests what happens when we navigate back successfully |
| 1440 TEST_F(NavigationControllerTest, Back) { | 1476 TEST_F(NavigationControllerTest, Back) { |
| 1441 NavigationControllerImpl& controller = controller_impl(); | 1477 NavigationControllerImpl& controller = controller_impl(); |
| 1442 TestNotificationTracker notifications; | 1478 TestNotificationTracker notifications; |
| 1443 RegisterForAllNavNotifications(¬ifications, &controller); | 1479 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1444 | 1480 |
| 1445 const GURL url1("http://foo1"); | 1481 const GURL url1("http://foo1"); |
| 1446 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 1482 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 1447 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1483 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1448 navigation_entry_committed_counter_ = 0; | 1484 navigation_entry_committed_counter_ = 0; |
| 1449 | 1485 |
| 1450 const GURL url2("http://foo2"); | 1486 const GURL url2("http://foo2"); |
| 1451 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); | 1487 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url2); |
| 1452 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1488 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1453 navigation_entry_committed_counter_ = 0; | 1489 navigation_entry_committed_counter_ = 0; |
| 1454 | 1490 |
| 1455 controller.GoBack(); | 1491 controller.GoBack(); |
| 1492 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1456 EXPECT_EQ(0U, notifications.size()); | 1493 EXPECT_EQ(0U, notifications.size()); |
| 1457 | 1494 |
| 1458 // We should now have a pending navigation to go back. | 1495 // We should now have a pending navigation to go back. |
| 1459 EXPECT_EQ(controller.GetEntryCount(), 2); | 1496 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1460 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1497 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1461 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1498 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1462 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1499 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1463 EXPECT_TRUE(controller.GetPendingEntry()); | 1500 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1464 EXPECT_FALSE(controller.CanGoBack()); | 1501 EXPECT_FALSE(controller.CanGoBack()); |
| 1465 EXPECT_FALSE(controller.CanGoToOffset(-1)); | 1502 EXPECT_FALSE(controller.CanGoToOffset(-1)); |
| 1466 EXPECT_TRUE(controller.CanGoForward()); | 1503 EXPECT_TRUE(controller.CanGoForward()); |
| 1467 EXPECT_TRUE(controller.CanGoToOffset(1)); | 1504 EXPECT_TRUE(controller.CanGoToOffset(1)); |
| 1468 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. | 1505 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go forward 2 steps. |
| 1469 | 1506 |
| 1470 // Timestamp for entry 1 should be on or after that of entry 0. | 1507 // Timestamp for entry 1 should be on or after that of entry 0. |
| 1471 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1508 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
| 1472 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), | 1509 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), |
| 1473 controller.GetEntryAtIndex(0)->GetTimestamp()); | 1510 controller.GetEntryAtIndex(0)->GetTimestamp()); |
| 1474 | 1511 |
| 1475 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url2); | 1512 main_test_rfh()->SendNavigate(0, entry_id, false, url2); |
| 1476 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1513 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1477 navigation_entry_committed_counter_ = 0; | 1514 navigation_entry_committed_counter_ = 0; |
| 1478 | 1515 |
| 1479 // The back navigation completed successfully. | 1516 // The back navigation completed successfully. |
| 1480 EXPECT_EQ(controller.GetEntryCount(), 2); | 1517 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1481 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1518 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1482 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1519 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1483 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1520 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1484 EXPECT_FALSE(controller.GetPendingEntry()); | 1521 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1485 EXPECT_FALSE(controller.CanGoBack()); | 1522 EXPECT_FALSE(controller.CanGoBack()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1499 NavigationControllerImpl& controller = controller_impl(); | 1536 NavigationControllerImpl& controller = controller_impl(); |
| 1500 TestNotificationTracker notifications; | 1537 TestNotificationTracker notifications; |
| 1501 RegisterForAllNavNotifications(¬ifications, &controller); | 1538 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1502 | 1539 |
| 1503 const GURL url1("http://foo/1"); | 1540 const GURL url1("http://foo/1"); |
| 1504 const GURL url2("http://foo/2"); | 1541 const GURL url2("http://foo/2"); |
| 1505 const GURL url3("http://foo/3"); | 1542 const GURL url3("http://foo/3"); |
| 1506 | 1543 |
| 1507 controller.LoadURL( | 1544 controller.LoadURL( |
| 1508 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1545 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1546 int entry1_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1509 main_test_rfh()->PrepareForCommit(); | 1547 main_test_rfh()->PrepareForCommit(); |
| 1510 main_test_rfh()->SendNavigate(0, url1); | 1548 main_test_rfh()->SendNavigate(0, entry1_id, true, url1); |
| 1549 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1550 navigation_entry_committed_counter_ = 0; |
| 1551 entry1_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1552 |
| 1553 controller.LoadURL( |
| 1554 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1555 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1556 main_test_rfh()->PrepareForCommit(); |
| 1557 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
| 1511 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1558 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1512 navigation_entry_committed_counter_ = 0; | 1559 navigation_entry_committed_counter_ = 0; |
| 1513 | 1560 |
| 1514 controller.LoadURL( | |
| 1515 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | |
| 1516 main_test_rfh()->PrepareForCommit(); | |
| 1517 main_test_rfh()->SendNavigate(1, url2); | |
| 1518 EXPECT_EQ(1U, navigation_entry_committed_counter_); | |
| 1519 navigation_entry_committed_counter_ = 0; | |
| 1520 | |
| 1521 controller.GoBack(); | 1561 controller.GoBack(); |
| 1522 EXPECT_EQ(0U, notifications.size()); | 1562 EXPECT_EQ(0U, notifications.size()); |
| 1523 | 1563 |
| 1524 // We should now have a pending navigation to go back. | 1564 // We should now have a pending navigation to go back. |
| 1525 EXPECT_EQ(controller.GetEntryCount(), 2); | 1565 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1526 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1566 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1527 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1567 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1528 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1568 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1529 EXPECT_TRUE(controller.GetPendingEntry()); | 1569 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1530 EXPECT_FALSE(controller.CanGoBack()); | 1570 EXPECT_FALSE(controller.CanGoBack()); |
| 1531 EXPECT_TRUE(controller.CanGoForward()); | 1571 EXPECT_TRUE(controller.CanGoForward()); |
| 1532 | 1572 |
| 1533 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); | 1573 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); |
| 1534 main_test_rfh()->SendNavigate(2, url3); | 1574 main_test_rfh()->SendNavigate(2, entry1_id, true, url3); |
| 1535 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1575 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1536 navigation_entry_committed_counter_ = 0; | 1576 navigation_entry_committed_counter_ = 0; |
| 1537 | 1577 |
| 1538 // The back navigation resulted in a completely new navigation. | 1578 // The back navigation resulted in a completely new navigation. |
| 1539 // TODO(darin): perhaps this behavior will be confusing to users? | 1579 // TODO(darin): perhaps this behavior will be confusing to users? |
| 1540 EXPECT_EQ(controller.GetEntryCount(), 3); | 1580 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 1541 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1581 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
| 1542 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1582 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1543 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1583 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1544 EXPECT_FALSE(controller.GetPendingEntry()); | 1584 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1545 EXPECT_TRUE(controller.CanGoBack()); | 1585 EXPECT_TRUE(controller.CanGoBack()); |
| 1546 EXPECT_FALSE(controller.CanGoForward()); | 1586 EXPECT_FALSE(controller.CanGoForward()); |
| 1547 } | 1587 } |
| 1548 | 1588 |
| 1549 // Receives a back message when there is a new pending navigation entry. | 1589 // Receives a back message when there is a new pending navigation entry. |
| 1550 TEST_F(NavigationControllerTest, Back_NewPending) { | 1590 TEST_F(NavigationControllerTest, Back_NewPending) { |
| 1551 NavigationControllerImpl& controller = controller_impl(); | 1591 NavigationControllerImpl& controller = controller_impl(); |
| 1552 TestNotificationTracker notifications; | 1592 TestNotificationTracker notifications; |
| 1553 RegisterForAllNavNotifications(¬ifications, &controller); | 1593 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1554 | 1594 |
| 1555 const GURL kUrl1("http://foo1"); | 1595 const GURL kUrl1("http://foo1"); |
| 1556 const GURL kUrl2("http://foo2"); | 1596 const GURL kUrl2("http://foo2"); |
| 1557 const GURL kUrl3("http://foo3"); | 1597 const GURL kUrl3("http://foo3"); |
| 1558 | 1598 |
| 1559 // First navigate two places so we have some back history. | 1599 // First navigate two places so we have some back history. |
| 1560 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); | 1600 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, kUrl1); |
| 1561 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1601 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1562 navigation_entry_committed_counter_ = 0; | 1602 navigation_entry_committed_counter_ = 0; |
| 1563 | 1603 |
| 1564 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); | 1604 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1565 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); | 1605 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, kUrl2); |
| 1566 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1606 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1567 navigation_entry_committed_counter_ = 0; | 1607 navigation_entry_committed_counter_ = 0; |
| 1568 | 1608 |
| 1569 // Now start a new pending navigation and go back before it commits. | 1609 // Now start a new pending navigation and go back before it commits. |
| 1570 controller.LoadURL( | 1610 controller.LoadURL( |
| 1571 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1611 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1572 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1612 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1573 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); | 1613 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); |
| 1574 controller.GoBack(); | 1614 controller.GoBack(); |
| 1575 | 1615 |
| 1576 // The pending navigation should now be the "back" item and the new one | 1616 // The pending navigation should now be the "back" item and the new one |
| 1577 // should be gone. | 1617 // should be gone. |
| 1578 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 1618 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 1579 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); | 1619 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); |
| 1580 } | 1620 } |
| 1581 | 1621 |
| 1582 // Receives a back message when there is a different renavigation already | 1622 // Receives a back message when there is a different renavigation already |
| 1583 // pending. | 1623 // pending. |
| 1584 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1624 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
| 1585 NavigationControllerImpl& controller = controller_impl(); | 1625 NavigationControllerImpl& controller = controller_impl(); |
| 1586 const GURL kUrl1("http://foo/1"); | 1626 const GURL kUrl1("http://foo/1"); |
| 1587 const GURL kUrl2("http://foo/2"); | 1627 const GURL kUrl2("http://foo/2"); |
| 1588 const GURL kUrl3("http://foo/3"); | 1628 const GURL kUrl3("http://foo/3"); |
| 1589 | 1629 |
| 1590 // First navigate three places so we have some back history. | 1630 // First navigate three places so we have some back history. |
| 1591 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); | 1631 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
| 1592 main_test_rfh()->PrepareForCommit(); | 1632 main_test_rfh()->PrepareForCommit(); |
| 1593 main_test_rfh()->SendNavigate(0, kUrl1); | 1633 main_test_rfh()->SendNavigate(0, 0, true, kUrl1); |
| 1594 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); | 1634 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1595 main_test_rfh()->PrepareForCommit(); | 1635 main_test_rfh()->PrepareForCommit(); |
| 1596 main_test_rfh()->SendNavigate(1, kUrl2); | 1636 main_test_rfh()->SendNavigate(1, 0, true, kUrl2); |
| 1597 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); | 1637 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); |
| 1598 main_test_rfh()->PrepareForCommit(); | 1638 main_test_rfh()->PrepareForCommit(); |
| 1599 main_test_rfh()->SendNavigate(2, kUrl3); | 1639 main_test_rfh()->SendNavigate(2, 0, true, kUrl3); |
| 1600 | 1640 |
| 1601 // With nothing pending, say we get a renderer back navigation request to the | 1641 // With nothing pending, say we get a renderer back navigation request to the |
| 1602 // second entry. | 1642 // second entry. |
| 1603 controller.GoToOffset(-1); | 1643 controller.GoToOffset(-1); |
| 1644 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1604 main_test_rfh()->PrepareForCommit(); | 1645 main_test_rfh()->PrepareForCommit(); |
| 1605 main_test_rfh()->SendNavigate(1, kUrl2); | 1646 main_test_rfh()->SendNavigate(1, entry_id, false, kUrl2); |
| 1606 | 1647 |
| 1607 // We know all the entries have the same site instance, so we can just grab | 1648 // We know all the entries have the same site instance, so we can just grab |
| 1608 // a random one for looking up other entries. | 1649 // a random one for looking up other entries. |
| 1609 SiteInstance* site_instance = | 1650 SiteInstance* site_instance = |
| 1610 controller.GetLastCommittedEntry()->site_instance(); | 1651 controller.GetLastCommittedEntry()->site_instance(); |
| 1611 | 1652 |
| 1612 // That second URL should be the last committed and it should have gotten the | 1653 // That second URL should be the last committed and it should have gotten the |
| 1613 // new title. | 1654 // new title. |
| 1614 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1655 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
| 1615 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1656 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1616 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1657 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1617 | 1658 |
| 1618 // Now go forward to the last item again and say it was committed. | 1659 // Now go forward to the last item again and say it was committed. |
| 1619 controller.GoForward(); | 1660 controller.GoForward(); |
| 1661 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1620 main_test_rfh()->PrepareForCommit(); | 1662 main_test_rfh()->PrepareForCommit(); |
| 1621 main_test_rfh()->SendNavigate(2, kUrl3); | 1663 main_test_rfh()->SendNavigate(2, entry_id, false, kUrl3); |
| 1622 | 1664 |
| 1623 // Now start going back one to the second page. It will be pending. | 1665 // Now start going back one to the second page. It will be pending. |
| 1624 controller.GoBack(); | 1666 controller.GoBack(); |
| 1625 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1667 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
| 1626 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1668 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 1627 | 1669 |
| 1628 // Now have the renderer request a navigation back to the first page. This | 1670 // Now have the renderer request a navigation back to the first page. This |
| 1629 // will not match the pending one. | 1671 // will not match the pending one. |
| 1630 controller.GoToOffset(-2); | 1672 controller.GoToOffset(-2); |
| 1673 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1631 main_test_rfh()->PrepareForCommit(); | 1674 main_test_rfh()->PrepareForCommit(); |
| 1632 main_test_rfh()->SendNavigate(0, kUrl1); | 1675 main_test_rfh()->SendNavigate(0, entry_id, false, kUrl1); |
| 1633 | 1676 |
| 1634 // The committed navigation should clear the pending entry. | 1677 // The committed navigation should clear the pending entry. |
| 1635 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1678 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1636 | 1679 |
| 1637 // But the navigated entry should be the last committed. | 1680 // But the navigated entry should be the last committed. |
| 1638 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1681 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1639 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1682 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
| 1640 } | 1683 } |
| 1641 | 1684 |
| 1642 // Tests what happens when we navigate forward successfully. | 1685 // Tests what happens when we navigate forward successfully. |
| 1643 TEST_F(NavigationControllerTest, Forward) { | 1686 TEST_F(NavigationControllerTest, Forward) { |
| 1644 NavigationControllerImpl& controller = controller_impl(); | 1687 NavigationControllerImpl& controller = controller_impl(); |
| 1645 TestNotificationTracker notifications; | 1688 TestNotificationTracker notifications; |
| 1646 RegisterForAllNavNotifications(¬ifications, &controller); | 1689 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1647 | 1690 |
| 1648 const GURL url1("http://foo1"); | 1691 const GURL url1("http://foo1"); |
| 1649 const GURL url2("http://foo2"); | 1692 const GURL url2("http://foo2"); |
| 1650 | 1693 |
| 1651 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); | 1694 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); |
| 1652 main_test_rfh()->PrepareForCommit(); | 1695 main_test_rfh()->PrepareForCommit(); |
| 1653 main_test_rfh()->SendNavigate(0, url1); | 1696 main_test_rfh()->SendNavigate(0, 0, true, url1); |
| 1697 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| 1654 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1698 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1655 navigation_entry_committed_counter_ = 0; | 1699 navigation_entry_committed_counter_ = 0; |
| 1656 | 1700 |
| 1657 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); | 1701 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); |
| 1658 main_test_rfh()->PrepareForCommit(); | 1702 main_test_rfh()->PrepareForCommit(); |
| 1659 main_test_rfh()->SendNavigate(1, url2); | 1703 main_test_rfh()->SendNavigate(1, 0, true, url2); |
| 1704 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| 1660 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1705 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1661 navigation_entry_committed_counter_ = 0; | 1706 navigation_entry_committed_counter_ = 0; |
| 1662 | 1707 |
| 1663 controller.GoBack(); | 1708 controller.GoBack(); |
| 1664 main_test_rfh()->PrepareForCommit(); | 1709 main_test_rfh()->PrepareForCommit(); |
| 1665 main_test_rfh()->SendNavigate(0, url1); | 1710 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1); |
| 1666 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1711 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1667 navigation_entry_committed_counter_ = 0; | 1712 navigation_entry_committed_counter_ = 0; |
| 1668 | 1713 |
| 1669 controller.GoForward(); | 1714 controller.GoForward(); |
| 1670 | 1715 |
| 1671 // We should now have a pending navigation to go forward. | 1716 // We should now have a pending navigation to go forward. |
| 1672 EXPECT_EQ(controller.GetEntryCount(), 2); | 1717 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1673 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1718 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1674 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1719 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1675 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1720 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1676 EXPECT_TRUE(controller.GetPendingEntry()); | 1721 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1677 EXPECT_TRUE(controller.CanGoBack()); | 1722 EXPECT_TRUE(controller.CanGoBack()); |
| 1678 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1723 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
| 1679 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1724 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
| 1680 EXPECT_FALSE(controller.CanGoForward()); | 1725 EXPECT_FALSE(controller.CanGoForward()); |
| 1681 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1726 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 1682 | 1727 |
| 1683 // Timestamp for entry 0 should be on or after that of entry 1 | 1728 // Timestamp for entry 0 should be on or after that of entry 1 |
| 1684 // (since we went back to it). | 1729 // (since we went back to it). |
| 1685 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1730 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
| 1686 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1731 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
| 1687 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1732 controller.GetEntryAtIndex(1)->GetTimestamp()); |
| 1688 | 1733 |
| 1689 main_test_rfh()->PrepareForCommit(); | 1734 main_test_rfh()->PrepareForCommit(); |
| 1690 main_test_rfh()->SendNavigate(1, url2); | 1735 main_test_rfh()->SendNavigate(1, entry2->GetUniqueID(), false, url2); |
| 1691 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1736 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1692 navigation_entry_committed_counter_ = 0; | 1737 navigation_entry_committed_counter_ = 0; |
| 1693 | 1738 |
| 1694 // The forward navigation completed successfully. | 1739 // The forward navigation completed successfully. |
| 1695 EXPECT_EQ(controller.GetEntryCount(), 2); | 1740 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1696 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1741 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1697 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1742 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1698 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1743 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1699 EXPECT_FALSE(controller.GetPendingEntry()); | 1744 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1700 EXPECT_TRUE(controller.CanGoBack()); | 1745 EXPECT_TRUE(controller.CanGoBack()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1714 NavigationControllerImpl& controller = controller_impl(); | 1759 NavigationControllerImpl& controller = controller_impl(); |
| 1715 TestNotificationTracker notifications; | 1760 TestNotificationTracker notifications; |
| 1716 RegisterForAllNavNotifications(¬ifications, &controller); | 1761 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1717 | 1762 |
| 1718 const GURL url1("http://foo1"); | 1763 const GURL url1("http://foo1"); |
| 1719 const GURL url2("http://foo2"); | 1764 const GURL url2("http://foo2"); |
| 1720 const GURL url3("http://foo3"); | 1765 const GURL url3("http://foo3"); |
| 1721 | 1766 |
| 1722 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); | 1767 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); |
| 1723 main_test_rfh()->PrepareForCommit(); | 1768 main_test_rfh()->PrepareForCommit(); |
| 1724 main_test_rfh()->SendNavigate(0, url1); | 1769 main_test_rfh()->SendNavigate(0, 0, true, url1); |
| 1725 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1770 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1771 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| 1726 navigation_entry_committed_counter_ = 0; | 1772 navigation_entry_committed_counter_ = 0; |
| 1727 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); | 1773 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); |
| 1728 main_test_rfh()->PrepareForCommit(); | 1774 main_test_rfh()->PrepareForCommit(); |
| 1729 main_test_rfh()->SendNavigate(1, url2); | 1775 main_test_rfh()->SendNavigate(1, 0, true, url2); |
| 1730 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1776 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1777 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| 1731 navigation_entry_committed_counter_ = 0; | 1778 navigation_entry_committed_counter_ = 0; |
| 1732 | 1779 |
| 1733 controller.GoBack(); | 1780 controller.GoBack(); |
| 1734 main_test_rfh()->PrepareForCommit(); | 1781 main_test_rfh()->PrepareForCommit(); |
| 1735 main_test_rfh()->SendNavigate(0, url1); | 1782 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1); |
| 1736 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1783 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1737 navigation_entry_committed_counter_ = 0; | 1784 navigation_entry_committed_counter_ = 0; |
| 1738 | 1785 |
| 1739 controller.GoForward(); | 1786 controller.GoForward(); |
| 1740 EXPECT_EQ(0U, notifications.size()); | 1787 EXPECT_EQ(0U, notifications.size()); |
| 1741 | 1788 |
| 1742 // Should now have a pending navigation to go forward. | 1789 // Should now have a pending navigation to go forward. |
| 1743 EXPECT_EQ(controller.GetEntryCount(), 2); | 1790 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1744 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1791 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1745 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1792 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1746 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1793 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1747 EXPECT_TRUE(controller.GetPendingEntry()); | 1794 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1748 EXPECT_TRUE(controller.CanGoBack()); | 1795 EXPECT_TRUE(controller.CanGoBack()); |
| 1749 EXPECT_FALSE(controller.CanGoForward()); | 1796 EXPECT_FALSE(controller.CanGoForward()); |
| 1750 | 1797 |
| 1751 main_test_rfh()->PrepareForCommit(); | 1798 main_test_rfh()->PrepareForCommit(); |
| 1752 main_test_rfh()->SendNavigate(2, url3); | 1799 main_test_rfh()->SendNavigate(2, entry2->GetUniqueID(), true, url3); |
| 1753 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1800 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1754 navigation_entry_committed_counter_ = 0; | 1801 navigation_entry_committed_counter_ = 0; |
| 1755 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1802 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
| 1756 | 1803 |
| 1757 EXPECT_EQ(controller.GetEntryCount(), 2); | 1804 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1758 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1805 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1759 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1806 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1760 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1807 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1761 EXPECT_FALSE(controller.GetPendingEntry()); | 1808 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1762 EXPECT_TRUE(controller.CanGoBack()); | 1809 EXPECT_TRUE(controller.CanGoBack()); |
| 1763 EXPECT_FALSE(controller.CanGoForward()); | 1810 EXPECT_FALSE(controller.CanGoForward()); |
| 1764 } | 1811 } |
| 1765 | 1812 |
| 1766 // Two consecutive navigations for the same URL entered in should be considered | 1813 // Two consecutive navigations for the same URL entered in should be considered |
| 1767 // as SAME_PAGE navigation even when we are redirected to some other page. | 1814 // as SAME_PAGE navigation even when we are redirected to some other page. |
| 1768 TEST_F(NavigationControllerTest, Redirect) { | 1815 TEST_F(NavigationControllerTest, Redirect) { |
| 1769 NavigationControllerImpl& controller = controller_impl(); | 1816 NavigationControllerImpl& controller = controller_impl(); |
| 1770 TestNotificationTracker notifications; | 1817 TestNotificationTracker notifications; |
| 1771 RegisterForAllNavNotifications(¬ifications, &controller); | 1818 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1772 | 1819 |
| 1773 const GURL url1("http://foo1"); | 1820 const GURL url1("http://foo1"); |
| 1774 const GURL url2("http://foo2"); // Redirection target | 1821 const GURL url2("http://foo2"); // Redirection target |
| 1775 | 1822 |
| 1776 // First request. | 1823 // First request. |
| 1777 controller.LoadURL( | 1824 controller.LoadURL( |
| 1778 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1825 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1826 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1779 | 1827 |
| 1780 EXPECT_EQ(0U, notifications.size()); | 1828 EXPECT_EQ(0U, notifications.size()); |
| 1781 | 1829 |
| 1782 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1830 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 1783 params.page_id = 0; | 1831 params.page_id = 0; |
| 1832 params.nav_entry_id = entry_id; |
| 1833 params.did_create_new_entry = true; |
| 1784 params.url = url2; | 1834 params.url = url2; |
| 1785 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1835 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
| 1786 params.redirects.push_back(GURL("http://foo1")); | 1836 params.redirects.push_back(GURL("http://foo1")); |
| 1787 params.redirects.push_back(GURL("http://foo2")); | 1837 params.redirects.push_back(GURL("http://foo2")); |
| 1788 params.should_update_history = false; | 1838 params.should_update_history = false; |
| 1789 params.gesture = NavigationGestureAuto; | 1839 params.gesture = NavigationGestureAuto; |
| 1790 params.is_post = false; | 1840 params.is_post = false; |
| 1791 params.page_state = PageState::CreateFromURL(url2); | 1841 params.page_state = PageState::CreateFromURL(url2); |
| 1792 | 1842 |
| 1793 LoadCommittedDetails details; | 1843 LoadCommittedDetails details; |
| 1794 | 1844 |
| 1795 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1845 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 1796 &details)); | 1846 &details)); |
| 1797 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1847 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1798 navigation_entry_committed_counter_ = 0; | 1848 navigation_entry_committed_counter_ = 0; |
| 1799 | 1849 |
| 1800 // Second request. | 1850 // Second request. |
| 1801 controller.LoadURL( | 1851 controller.LoadURL( |
| 1802 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1852 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1853 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1803 | 1854 |
| 1804 EXPECT_TRUE(controller.GetPendingEntry()); | 1855 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1805 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1856 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1806 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1857 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1858 |
| 1859 params.nav_entry_id = entry_id; |
| 1860 params.did_create_new_entry = false; |
| 1861 |
| 1807 EXPECT_EQ(0U, notifications.size()); | 1862 EXPECT_EQ(0U, notifications.size()); |
| 1808 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1863 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 1809 &details)); | 1864 &details)); |
| 1810 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1865 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1811 navigation_entry_committed_counter_ = 0; | 1866 navigation_entry_committed_counter_ = 0; |
| 1812 | 1867 |
| 1813 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1868 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
| 1814 EXPECT_EQ(controller.GetEntryCount(), 1); | 1869 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1815 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1870 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1816 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1871 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1829 NavigationControllerImpl& controller = controller_impl(); | 1884 NavigationControllerImpl& controller = controller_impl(); |
| 1830 TestNotificationTracker notifications; | 1885 TestNotificationTracker notifications; |
| 1831 RegisterForAllNavNotifications(¬ifications, &controller); | 1886 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1832 | 1887 |
| 1833 const GURL url1("http://foo1"); | 1888 const GURL url1("http://foo1"); |
| 1834 const GURL url2("http://foo2"); // Redirection target | 1889 const GURL url2("http://foo2"); // Redirection target |
| 1835 | 1890 |
| 1836 // First request as POST. | 1891 // First request as POST. |
| 1837 controller.LoadURL( | 1892 controller.LoadURL( |
| 1838 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1893 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1894 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1839 controller.GetVisibleEntry()->SetHasPostData(true); | 1895 controller.GetVisibleEntry()->SetHasPostData(true); |
| 1840 | 1896 |
| 1841 EXPECT_EQ(0U, notifications.size()); | 1897 EXPECT_EQ(0U, notifications.size()); |
| 1842 | 1898 |
| 1843 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1899 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 1844 params.page_id = 0; | 1900 params.page_id = 0; |
| 1901 params.nav_entry_id = entry_id; |
| 1902 params.did_create_new_entry = true; |
| 1845 params.url = url2; | 1903 params.url = url2; |
| 1846 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1904 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
| 1847 params.redirects.push_back(GURL("http://foo1")); | 1905 params.redirects.push_back(GURL("http://foo1")); |
| 1848 params.redirects.push_back(GURL("http://foo2")); | 1906 params.redirects.push_back(GURL("http://foo2")); |
| 1849 params.should_update_history = false; | 1907 params.should_update_history = false; |
| 1850 params.gesture = NavigationGestureAuto; | 1908 params.gesture = NavigationGestureAuto; |
| 1851 params.is_post = true; | 1909 params.is_post = true; |
| 1852 params.page_state = PageState::CreateFromURL(url2); | 1910 params.page_state = PageState::CreateFromURL(url2); |
| 1853 | 1911 |
| 1854 LoadCommittedDetails details; | 1912 LoadCommittedDetails details; |
| 1855 | 1913 |
| 1856 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1914 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 1857 &details)); | 1915 &details)); |
| 1858 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1916 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1859 navigation_entry_committed_counter_ = 0; | 1917 navigation_entry_committed_counter_ = 0; |
| 1860 | 1918 |
| 1861 // Second request. | 1919 // Second request. |
| 1862 controller.LoadURL( | 1920 controller.LoadURL( |
| 1863 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1921 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1922 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1864 | 1923 |
| 1865 EXPECT_TRUE(controller.GetPendingEntry()); | 1924 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1866 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1925 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1867 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1926 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1868 | 1927 |
| 1928 params.nav_entry_id = entry_id; |
| 1929 params.did_create_new_entry = false; |
| 1869 params.is_post = false; | 1930 params.is_post = false; |
| 1870 | 1931 |
| 1871 EXPECT_EQ(0U, notifications.size()); | 1932 EXPECT_EQ(0U, notifications.size()); |
| 1872 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1933 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 1873 &details)); | 1934 &details)); |
| 1874 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1935 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1875 navigation_entry_committed_counter_ = 0; | 1936 navigation_entry_committed_counter_ = 0; |
| 1876 | 1937 |
| 1877 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1938 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
| 1878 EXPECT_EQ(controller.GetEntryCount(), 1); | 1939 EXPECT_EQ(controller.GetEntryCount(), 1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1892 NavigationControllerImpl& controller = controller_impl(); | 1953 NavigationControllerImpl& controller = controller_impl(); |
| 1893 TestNotificationTracker notifications; | 1954 TestNotificationTracker notifications; |
| 1894 RegisterForAllNavNotifications(¬ifications, &controller); | 1955 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1895 | 1956 |
| 1896 const GURL url1("http://foo1"); | 1957 const GURL url1("http://foo1"); |
| 1897 const GURL url2("http://foo2"); // Redirection target | 1958 const GURL url2("http://foo2"); // Redirection target |
| 1898 | 1959 |
| 1899 // First request | 1960 // First request |
| 1900 controller.LoadURL( | 1961 controller.LoadURL( |
| 1901 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1962 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1963 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1902 | 1964 |
| 1903 EXPECT_TRUE(controller.GetPendingEntry()); | 1965 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1904 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1966 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1905 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1967 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1906 | 1968 |
| 1907 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1969 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 1908 params.page_id = 0; | 1970 params.page_id = 0; |
| 1971 params.nav_entry_id = entry_id; |
| 1972 params.did_create_new_entry = true; |
| 1909 params.url = url2; | 1973 params.url = url2; |
| 1910 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1974 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
| 1911 params.redirects.push_back(GURL("http://foo1")); | 1975 params.redirects.push_back(GURL("http://foo1")); |
| 1912 params.redirects.push_back(GURL("http://foo2")); | 1976 params.redirects.push_back(GURL("http://foo2")); |
| 1913 params.should_update_history = false; | 1977 params.should_update_history = false; |
| 1914 params.gesture = NavigationGestureAuto; | 1978 params.gesture = NavigationGestureAuto; |
| 1915 params.is_post = false; | 1979 params.is_post = false; |
| 1916 params.page_state = PageState::CreateFromURL(url2); | 1980 params.page_state = PageState::CreateFromURL(url2); |
| 1917 | 1981 |
| 1918 LoadCommittedDetails details; | 1982 LoadCommittedDetails details; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1936 } | 2000 } |
| 1937 | 2001 |
| 1938 // Tests navigation via link click within a subframe. A new navigation entry | 2002 // Tests navigation via link click within a subframe. A new navigation entry |
| 1939 // should be created. | 2003 // should be created. |
| 1940 TEST_F(NavigationControllerTest, NewSubframe) { | 2004 TEST_F(NavigationControllerTest, NewSubframe) { |
| 1941 NavigationControllerImpl& controller = controller_impl(); | 2005 NavigationControllerImpl& controller = controller_impl(); |
| 1942 TestNotificationTracker notifications; | 2006 TestNotificationTracker notifications; |
| 1943 RegisterForAllNavNotifications(¬ifications, &controller); | 2007 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1944 | 2008 |
| 1945 const GURL url1("http://foo1"); | 2009 const GURL url1("http://foo1"); |
| 1946 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2010 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 1947 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2011 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1948 navigation_entry_committed_counter_ = 0; | 2012 navigation_entry_committed_counter_ = 0; |
| 1949 | 2013 |
| 1950 const GURL url2("http://foo2"); | 2014 const GURL url2("http://foo2"); |
| 1951 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2015 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 1952 params.page_id = 1; | 2016 params.page_id = 1; |
| 2017 params.nav_entry_id = 0; |
| 2018 params.did_create_new_entry = true; |
| 1953 params.url = url2; | 2019 params.url = url2; |
| 1954 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2020 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
| 1955 params.should_update_history = false; | 2021 params.should_update_history = false; |
| 1956 params.gesture = NavigationGestureUser; | 2022 params.gesture = NavigationGestureUser; |
| 1957 params.is_post = false; | 2023 params.is_post = false; |
| 1958 params.page_state = PageState::CreateFromURL(url2); | 2024 params.page_state = PageState::CreateFromURL(url2); |
| 1959 | 2025 |
| 1960 LoadCommittedDetails details; | 2026 LoadCommittedDetails details; |
| 1961 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2027 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 1962 &details)); | 2028 &details)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1978 // Auto subframes are ones the page loads automatically like ads. They should | 2044 // Auto subframes are ones the page loads automatically like ads. They should |
| 1979 // not create new navigation entries. | 2045 // not create new navigation entries. |
| 1980 // TODO(creis): Test cross-site and nested iframes. | 2046 // TODO(creis): Test cross-site and nested iframes. |
| 1981 // TODO(creis): Test updating entries for history auto subframe navigations. | 2047 // TODO(creis): Test updating entries for history auto subframe navigations. |
| 1982 TEST_F(NavigationControllerTest, AutoSubframe) { | 2048 TEST_F(NavigationControllerTest, AutoSubframe) { |
| 1983 NavigationControllerImpl& controller = controller_impl(); | 2049 NavigationControllerImpl& controller = controller_impl(); |
| 1984 TestNotificationTracker notifications; | 2050 TestNotificationTracker notifications; |
| 1985 RegisterForAllNavNotifications(¬ifications, &controller); | 2051 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1986 | 2052 |
| 1987 const GURL url1("http://foo/1"); | 2053 const GURL url1("http://foo/1"); |
| 1988 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url1); | 2054 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); |
| 1989 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2055 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1990 navigation_entry_committed_counter_ = 0; | 2056 navigation_entry_committed_counter_ = 0; |
| 1991 | 2057 |
| 1992 // Add a subframe and navigate it. | 2058 // Add a subframe and navigate it. |
| 1993 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), | 2059 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
| 1994 SandboxFlags::NONE); | 2060 SandboxFlags::NONE); |
| 1995 RenderFrameHostImpl* subframe = | 2061 RenderFrameHostImpl* subframe = |
| 1996 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); | 2062 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
| 1997 const GURL url2("http://foo/2"); | 2063 const GURL url2("http://foo/2"); |
| 1998 { | 2064 { |
| 1999 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2065 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2000 params.page_id = 1; | 2066 params.page_id = 1; |
| 2067 params.nav_entry_id = 0; |
| 2068 params.did_create_new_entry = false; |
| 2001 params.url = url2; | 2069 params.url = url2; |
| 2002 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2070 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 2003 params.should_update_history = false; | 2071 params.should_update_history = false; |
| 2004 params.gesture = NavigationGestureUser; | 2072 params.gesture = NavigationGestureUser; |
| 2005 params.is_post = false; | 2073 params.is_post = false; |
| 2006 params.page_state = PageState::CreateFromURL(url2); | 2074 params.page_state = PageState::CreateFromURL(url2); |
| 2007 | 2075 |
| 2008 // Navigating should do nothing. | 2076 // Navigating should do nothing. |
| 2009 LoadCommittedDetails details; | 2077 LoadCommittedDetails details; |
| 2010 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); | 2078 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 } | 2145 } |
| 2078 | 2146 |
| 2079 // Tests navigation and then going back to a subframe navigation. | 2147 // Tests navigation and then going back to a subframe navigation. |
| 2080 TEST_F(NavigationControllerTest, BackSubframe) { | 2148 TEST_F(NavigationControllerTest, BackSubframe) { |
| 2081 NavigationControllerImpl& controller = controller_impl(); | 2149 NavigationControllerImpl& controller = controller_impl(); |
| 2082 TestNotificationTracker notifications; | 2150 TestNotificationTracker notifications; |
| 2083 RegisterForAllNavNotifications(¬ifications, &controller); | 2151 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2084 | 2152 |
| 2085 // Main page. | 2153 // Main page. |
| 2086 const GURL url1("http://foo1"); | 2154 const GURL url1("http://foo1"); |
| 2087 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2155 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 2088 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2156 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2157 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| 2089 navigation_entry_committed_counter_ = 0; | 2158 navigation_entry_committed_counter_ = 0; |
| 2090 | 2159 |
| 2091 // First manual subframe navigation. | 2160 // First manual subframe navigation. |
| 2092 const GURL url2("http://foo2"); | 2161 const GURL url2("http://foo2"); |
| 2093 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2162 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2094 params.page_id = 1; | 2163 params.page_id = 1; |
| 2164 params.nav_entry_id = 0; |
| 2165 params.did_create_new_entry = true; |
| 2095 params.url = url2; | 2166 params.url = url2; |
| 2096 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2167 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
| 2097 params.should_update_history = false; | 2168 params.should_update_history = false; |
| 2098 params.gesture = NavigationGestureUser; | 2169 params.gesture = NavigationGestureUser; |
| 2099 params.is_post = false; | 2170 params.is_post = false; |
| 2100 params.page_state = PageState::CreateFromURL(url2); | 2171 params.page_state = PageState::CreateFromURL(url2); |
| 2101 | 2172 |
| 2102 // This should generate a new entry. | 2173 // This should generate a new entry. |
| 2103 LoadCommittedDetails details; | 2174 LoadCommittedDetails details; |
| 2104 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2175 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2105 &details)); | 2176 &details)); |
| 2177 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| 2106 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2178 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2107 navigation_entry_committed_counter_ = 0; | 2179 navigation_entry_committed_counter_ = 0; |
| 2108 EXPECT_EQ(2, controller.GetEntryCount()); | 2180 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2109 | 2181 |
| 2110 // Second manual subframe navigation should also make a new entry. | 2182 // Second manual subframe navigation should also make a new entry. |
| 2111 const GURL url3("http://foo3"); | 2183 const GURL url3("http://foo3"); |
| 2112 params.page_id = 2; | 2184 params.page_id = 2; |
| 2185 params.nav_entry_id = 0; |
| 2186 params.did_create_new_entry = true; |
| 2113 params.url = url3; | 2187 params.url = url3; |
| 2114 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2188 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
| 2115 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2189 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2116 &details)); | 2190 &details)); |
| 2117 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2191 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2118 navigation_entry_committed_counter_ = 0; | 2192 navigation_entry_committed_counter_ = 0; |
| 2119 EXPECT_EQ(3, controller.GetEntryCount()); | 2193 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2120 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2194 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 2121 | 2195 |
| 2122 // Go back one. | 2196 // Go back one. |
| 2123 controller.GoBack(); | 2197 controller.GoBack(); |
| 2124 params.page_id = 1; | 2198 params.page_id = 1; |
| 2199 params.nav_entry_id = entry2->GetUniqueID(); |
| 2200 params.did_create_new_entry = false; |
| 2125 params.url = url2; | 2201 params.url = url2; |
| 2126 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2202 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 2127 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2203 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2128 &details)); | 2204 &details)); |
| 2129 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2205 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2130 navigation_entry_committed_counter_ = 0; | 2206 navigation_entry_committed_counter_ = 0; |
| 2131 EXPECT_EQ(3, controller.GetEntryCount()); | 2207 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2132 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2208 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 2133 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2209 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 2134 EXPECT_FALSE(controller.GetPendingEntry()); | 2210 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2135 | 2211 |
| 2136 // Go back one more. | 2212 // Go back one more. |
| 2137 controller.GoBack(); | 2213 controller.GoBack(); |
| 2138 params.page_id = 0; | 2214 params.page_id = 0; |
| 2215 params.nav_entry_id = entry1->GetUniqueID(); |
| 2216 params.did_create_new_entry = false; |
| 2139 params.url = url1; | 2217 params.url = url1; |
| 2140 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2218 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 2141 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2219 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2142 &details)); | 2220 &details)); |
| 2143 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2221 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2144 navigation_entry_committed_counter_ = 0; | 2222 navigation_entry_committed_counter_ = 0; |
| 2145 EXPECT_EQ(3, controller.GetEntryCount()); | 2223 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2146 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2224 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 2147 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2225 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 2148 EXPECT_FALSE(controller.GetPendingEntry()); | 2226 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2149 } | 2227 } |
| 2150 | 2228 |
| 2151 TEST_F(NavigationControllerTest, LinkClick) { | 2229 TEST_F(NavigationControllerTest, LinkClick) { |
| 2152 NavigationControllerImpl& controller = controller_impl(); | 2230 NavigationControllerImpl& controller = controller_impl(); |
| 2153 TestNotificationTracker notifications; | 2231 TestNotificationTracker notifications; |
| 2154 RegisterForAllNavNotifications(¬ifications, &controller); | 2232 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2155 | 2233 |
| 2156 const GURL url1("http://foo1"); | 2234 const GURL url1("http://foo1"); |
| 2157 const GURL url2("http://foo2"); | 2235 const GURL url2("http://foo2"); |
| 2158 | 2236 |
| 2159 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2237 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 2160 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2238 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2161 navigation_entry_committed_counter_ = 0; | 2239 navigation_entry_committed_counter_ = 0; |
| 2162 | 2240 |
| 2163 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); | 2241 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url2); |
| 2164 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2242 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2165 navigation_entry_committed_counter_ = 0; | 2243 navigation_entry_committed_counter_ = 0; |
| 2166 | 2244 |
| 2167 // Should not have produced a new session history entry. | 2245 // Should have produced a new session history entry. |
| 2168 EXPECT_EQ(controller.GetEntryCount(), 2); | 2246 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 2169 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2247 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2170 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2248 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2171 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2249 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2172 EXPECT_FALSE(controller.GetPendingEntry()); | 2250 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2173 EXPECT_TRUE(controller.CanGoBack()); | 2251 EXPECT_TRUE(controller.CanGoBack()); |
| 2174 EXPECT_FALSE(controller.CanGoForward()); | 2252 EXPECT_FALSE(controller.CanGoForward()); |
| 2175 } | 2253 } |
| 2176 | 2254 |
| 2177 TEST_F(NavigationControllerTest, InPage) { | 2255 TEST_F(NavigationControllerTest, InPage) { |
| 2178 NavigationControllerImpl& controller = controller_impl(); | 2256 NavigationControllerImpl& controller = controller_impl(); |
| 2179 TestNotificationTracker notifications; | 2257 TestNotificationTracker notifications; |
| 2180 RegisterForAllNavNotifications(¬ifications, &controller); | 2258 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2181 | 2259 |
| 2182 // Main page. | 2260 // Main page. |
| 2183 const GURL url1("http://foo"); | 2261 const GURL url1("http://foo"); |
| 2184 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2262 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 2185 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2263 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2186 navigation_entry_committed_counter_ = 0; | 2264 navigation_entry_committed_counter_ = 0; |
| 2187 | 2265 |
| 2188 // Ensure main page navigation to same url respects the was_within_same_page | 2266 // Ensure main page navigation to same url respects the was_within_same_page |
| 2189 // hint provided in the params. | 2267 // hint provided in the params. |
| 2190 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; | 2268 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; |
| 2191 self_params.page_id = 0; | 2269 self_params.page_id = 0; |
| 2270 self_params.nav_entry_id = 0; |
| 2271 self_params.did_create_new_entry = false; |
| 2192 self_params.url = url1; | 2272 self_params.url = url1; |
| 2193 self_params.transition = ui::PAGE_TRANSITION_LINK; | 2273 self_params.transition = ui::PAGE_TRANSITION_LINK; |
| 2194 self_params.should_update_history = false; | 2274 self_params.should_update_history = false; |
| 2195 self_params.gesture = NavigationGestureUser; | 2275 self_params.gesture = NavigationGestureUser; |
| 2196 self_params.is_post = false; | 2276 self_params.is_post = false; |
| 2197 self_params.page_state = PageState::CreateFromURL(url1); | 2277 self_params.page_state = PageState::CreateFromURL(url1); |
| 2198 self_params.was_within_same_page = true; | 2278 self_params.was_within_same_page = true; |
| 2199 | 2279 |
| 2200 LoadCommittedDetails details; | 2280 LoadCommittedDetails details; |
| 2201 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, | 2281 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, |
| 2202 &details)); | 2282 &details)); |
| 2283 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| 2203 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2284 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2204 navigation_entry_committed_counter_ = 0; | 2285 navigation_entry_committed_counter_ = 0; |
| 2205 EXPECT_TRUE(details.is_in_page); | 2286 EXPECT_TRUE(details.is_in_page); |
| 2206 EXPECT_TRUE(details.did_replace_entry); | 2287 EXPECT_TRUE(details.did_replace_entry); |
| 2207 EXPECT_EQ(1, controller.GetEntryCount()); | 2288 EXPECT_EQ(1, controller.GetEntryCount()); |
| 2208 | 2289 |
| 2209 // Fragment navigation to a new page_id. | 2290 // Fragment navigation to a new page_id. |
| 2210 const GURL url2("http://foo#a"); | 2291 const GURL url2("http://foo#a"); |
| 2211 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2292 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2212 params.page_id = 1; | 2293 params.page_id = 1; |
| 2294 params.nav_entry_id = 0; |
| 2295 params.did_create_new_entry = true; |
| 2213 params.url = url2; | 2296 params.url = url2; |
| 2214 params.transition = ui::PAGE_TRANSITION_LINK; | 2297 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2215 params.should_update_history = false; | 2298 params.should_update_history = false; |
| 2216 params.gesture = NavigationGestureUser; | 2299 params.gesture = NavigationGestureUser; |
| 2217 params.is_post = false; | 2300 params.is_post = false; |
| 2218 params.page_state = PageState::CreateFromURL(url2); | 2301 params.page_state = PageState::CreateFromURL(url2); |
| 2219 params.was_within_same_page = true; | 2302 params.was_within_same_page = true; |
| 2220 | 2303 |
| 2221 // This should generate a new entry. | 2304 // This should generate a new entry. |
| 2222 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2305 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2223 &details)); | 2306 &details)); |
| 2307 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| 2224 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2308 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2225 navigation_entry_committed_counter_ = 0; | 2309 navigation_entry_committed_counter_ = 0; |
| 2226 EXPECT_TRUE(details.is_in_page); | 2310 EXPECT_TRUE(details.is_in_page); |
| 2227 EXPECT_FALSE(details.did_replace_entry); | 2311 EXPECT_FALSE(details.did_replace_entry); |
| 2228 EXPECT_EQ(2, controller.GetEntryCount()); | 2312 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2229 | 2313 |
| 2230 // Go back one. | 2314 // Go back one. |
| 2231 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); | 2315 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); |
| 2232 controller.GoBack(); | 2316 controller.GoBack(); |
| 2233 back_params.url = url1; | 2317 back_params.url = url1; |
| 2234 back_params.page_id = 0; | 2318 back_params.page_id = 0; |
| 2319 back_params.nav_entry_id = entry1->GetUniqueID(); |
| 2320 back_params.did_create_new_entry = false; |
| 2235 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2321 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
| 2236 &details)); | 2322 &details)); |
| 2237 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2323 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2238 navigation_entry_committed_counter_ = 0; | 2324 navigation_entry_committed_counter_ = 0; |
| 2239 EXPECT_TRUE(details.is_in_page); | 2325 EXPECT_TRUE(details.is_in_page); |
| 2240 EXPECT_EQ(2, controller.GetEntryCount()); | 2326 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2241 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2327 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 2242 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); | 2328 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
| 2243 | 2329 |
| 2244 // Go forward | 2330 // Go forward. |
| 2245 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); | 2331 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); |
| 2246 controller.GoForward(); | 2332 controller.GoForward(); |
| 2247 forward_params.url = url2; | 2333 forward_params.url = url2; |
| 2248 forward_params.page_id = 1; | 2334 forward_params.page_id = 1; |
| 2335 forward_params.nav_entry_id = entry2->GetUniqueID(); |
| 2336 forward_params.did_create_new_entry = false; |
| 2249 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2337 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
| 2250 &details)); | 2338 &details)); |
| 2251 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2339 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2252 navigation_entry_committed_counter_ = 0; | 2340 navigation_entry_committed_counter_ = 0; |
| 2253 EXPECT_TRUE(details.is_in_page); | 2341 EXPECT_TRUE(details.is_in_page); |
| 2254 EXPECT_EQ(2, controller.GetEntryCount()); | 2342 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2255 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2343 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 2256 EXPECT_EQ(forward_params.url, | 2344 EXPECT_EQ(forward_params.url, |
| 2257 controller.GetVisibleEntry()->GetURL()); | 2345 controller.GetVisibleEntry()->GetURL()); |
| 2258 | 2346 |
| 2259 // Now go back and forward again. This is to work around a bug where we would | 2347 // Now go back and forward again. This is to work around a bug where we would |
| 2260 // compare the incoming URL with the last committed entry rather than the | 2348 // compare the incoming URL with the last committed entry rather than the |
| 2261 // one identified by an existing page ID. This would result in the second URL | 2349 // one identified by an existing page ID. This would result in the second URL |
| 2262 // losing the reference fragment when you navigate away from it and then back. | 2350 // losing the reference fragment when you navigate away from it and then back. |
| 2263 controller.GoBack(); | 2351 controller.GoBack(); |
| 2264 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2352 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
| 2265 &details)); | 2353 &details)); |
| 2266 controller.GoForward(); | 2354 controller.GoForward(); |
| 2267 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2355 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
| 2268 &details)); | 2356 &details)); |
| 2269 EXPECT_EQ(forward_params.url, | 2357 EXPECT_EQ(forward_params.url, |
| 2270 controller.GetVisibleEntry()->GetURL()); | 2358 controller.GetVisibleEntry()->GetURL()); |
| 2271 | 2359 |
| 2272 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 2360 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
| 2273 const GURL url3("http://bar"); | 2361 const GURL url3("http://bar"); |
| 2274 params.page_id = 2; | 2362 params.page_id = 2; |
| 2363 params.nav_entry_id = 0; |
| 2364 params.did_create_new_entry = true; |
| 2275 params.url = url3; | 2365 params.url = url3; |
| 2276 navigation_entry_committed_counter_ = 0; | 2366 navigation_entry_committed_counter_ = 0; |
| 2277 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2367 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2278 &details)); | 2368 &details)); |
| 2279 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2369 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2280 navigation_entry_committed_counter_ = 0; | 2370 navigation_entry_committed_counter_ = 0; |
| 2281 EXPECT_FALSE(details.is_in_page); | 2371 EXPECT_FALSE(details.is_in_page); |
| 2282 EXPECT_EQ(3, controller.GetEntryCount()); | 2372 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2283 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2373 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 2284 } | 2374 } |
| 2285 | 2375 |
| 2286 TEST_F(NavigationControllerTest, InPage_Replace) { | 2376 TEST_F(NavigationControllerTest, InPage_Replace) { |
| 2287 NavigationControllerImpl& controller = controller_impl(); | 2377 NavigationControllerImpl& controller = controller_impl(); |
| 2288 TestNotificationTracker notifications; | 2378 TestNotificationTracker notifications; |
| 2289 RegisterForAllNavNotifications(¬ifications, &controller); | 2379 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2290 | 2380 |
| 2291 // Main page. | 2381 // Main page. |
| 2292 const GURL url1("http://foo"); | 2382 const GURL url1("http://foo"); |
| 2293 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2383 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 2294 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2384 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2295 navigation_entry_committed_counter_ = 0; | 2385 navigation_entry_committed_counter_ = 0; |
| 2296 | 2386 |
| 2297 // First navigation. | 2387 // First navigation. |
| 2298 const GURL url2("http://foo#a"); | 2388 const GURL url2("http://foo#a"); |
| 2299 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2389 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2300 params.page_id = 0; // Same page_id | 2390 params.page_id = 0; // Same page_id |
| 2391 params.nav_entry_id = 0; |
| 2392 params.did_create_new_entry = false; |
| 2301 params.url = url2; | 2393 params.url = url2; |
| 2302 params.transition = ui::PAGE_TRANSITION_LINK; | 2394 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2303 params.should_update_history = false; | 2395 params.should_update_history = false; |
| 2304 params.gesture = NavigationGestureUser; | 2396 params.gesture = NavigationGestureUser; |
| 2305 params.is_post = false; | 2397 params.is_post = false; |
| 2306 params.page_state = PageState::CreateFromURL(url2); | 2398 params.page_state = PageState::CreateFromURL(url2); |
| 2307 params.was_within_same_page = true; | 2399 params.was_within_same_page = true; |
| 2308 | 2400 |
| 2309 // This should NOT generate a new entry, nor prune the list. | 2401 // This should NOT generate a new entry, nor prune the list. |
| 2310 LoadCommittedDetails details; | 2402 LoadCommittedDetails details; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2324 // window.location='http://foo3/'; | 2416 // window.location='http://foo3/'; |
| 2325 // </script> | 2417 // </script> |
| 2326 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 2418 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
| 2327 NavigationControllerImpl& controller = controller_impl(); | 2419 NavigationControllerImpl& controller = controller_impl(); |
| 2328 TestNotificationTracker notifications; | 2420 TestNotificationTracker notifications; |
| 2329 RegisterForAllNavNotifications(¬ifications, &controller); | 2421 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2330 | 2422 |
| 2331 // Load an initial page. | 2423 // Load an initial page. |
| 2332 { | 2424 { |
| 2333 const GURL url("http://foo/"); | 2425 const GURL url("http://foo/"); |
| 2334 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 2426 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); |
| 2335 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2427 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2336 navigation_entry_committed_counter_ = 0; | 2428 navigation_entry_committed_counter_ = 0; |
| 2337 } | 2429 } |
| 2338 | 2430 |
| 2339 // Navigate to a new page. | 2431 // Navigate to a new page. |
| 2340 { | 2432 { |
| 2341 const GURL url("http://foo2/"); | 2433 const GURL url("http://foo2/"); |
| 2342 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url); | 2434 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url); |
| 2343 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2435 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2344 navigation_entry_committed_counter_ = 0; | 2436 navigation_entry_committed_counter_ = 0; |
| 2345 } | 2437 } |
| 2346 | 2438 |
| 2347 // Navigate within the page. | 2439 // Navigate within the page. |
| 2348 { | 2440 { |
| 2349 const GURL url("http://foo2/#a"); | 2441 const GURL url("http://foo2/#a"); |
| 2350 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2442 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2351 params.page_id = 1; // Same page_id | 2443 params.page_id = 1; // Same page_id |
| 2444 params.nav_entry_id = 0; |
| 2445 params.did_create_new_entry = false; |
| 2352 params.url = url; | 2446 params.url = url; |
| 2353 params.transition = ui::PAGE_TRANSITION_LINK; | 2447 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2354 params.redirects.push_back(url); | 2448 params.redirects.push_back(url); |
| 2355 params.should_update_history = true; | 2449 params.should_update_history = true; |
| 2356 params.gesture = NavigationGestureUnknown; | 2450 params.gesture = NavigationGestureUnknown; |
| 2357 params.is_post = false; | 2451 params.is_post = false; |
| 2358 params.page_state = PageState::CreateFromURL(url); | 2452 params.page_state = PageState::CreateFromURL(url); |
| 2359 params.was_within_same_page = true; | 2453 params.was_within_same_page = true; |
| 2360 | 2454 |
| 2361 // This should NOT generate a new entry, nor prune the list. | 2455 // This should NOT generate a new entry, nor prune the list. |
| 2362 LoadCommittedDetails details; | 2456 LoadCommittedDetails details; |
| 2363 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2457 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2364 &details)); | 2458 &details)); |
| 2365 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2459 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2366 navigation_entry_committed_counter_ = 0; | 2460 navigation_entry_committed_counter_ = 0; |
| 2367 EXPECT_TRUE(details.is_in_page); | 2461 EXPECT_TRUE(details.is_in_page); |
| 2368 EXPECT_TRUE(details.did_replace_entry); | 2462 EXPECT_TRUE(details.did_replace_entry); |
| 2369 EXPECT_EQ(2, controller.GetEntryCount()); | 2463 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2370 } | 2464 } |
| 2371 | 2465 |
| 2372 // Perform a client redirect to a new page. | 2466 // Perform a client redirect to a new page. |
| 2373 { | 2467 { |
| 2374 const GURL url("http://foo3/"); | 2468 const GURL url("http://foo3/"); |
| 2375 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2469 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2376 params.page_id = 2; // New page_id | 2470 params.page_id = 2; // New page_id |
| 2471 params.nav_entry_id = 0; |
| 2472 params.did_create_new_entry = true; |
| 2377 params.url = url; | 2473 params.url = url; |
| 2378 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 2474 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 2379 params.redirects.push_back(GURL("http://foo2/#a")); | 2475 params.redirects.push_back(GURL("http://foo2/#a")); |
| 2380 params.redirects.push_back(url); | 2476 params.redirects.push_back(url); |
| 2381 params.should_update_history = true; | 2477 params.should_update_history = true; |
| 2382 params.gesture = NavigationGestureUnknown; | 2478 params.gesture = NavigationGestureUnknown; |
| 2383 params.is_post = false; | 2479 params.is_post = false; |
| 2384 params.page_state = PageState::CreateFromURL(url); | 2480 params.page_state = PageState::CreateFromURL(url); |
| 2385 | 2481 |
| 2386 // This SHOULD generate a new entry. | 2482 // This SHOULD generate a new entry. |
| 2387 LoadCommittedDetails details; | 2483 LoadCommittedDetails details; |
| 2388 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2484 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 2389 &details)); | 2485 &details)); |
| 2390 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2486 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2391 navigation_entry_committed_counter_ = 0; | 2487 navigation_entry_committed_counter_ = 0; |
| 2392 EXPECT_FALSE(details.is_in_page); | 2488 EXPECT_FALSE(details.is_in_page); |
| 2393 EXPECT_EQ(3, controller.GetEntryCount()); | 2489 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2394 } | 2490 } |
| 2395 | 2491 |
| 2396 // Verify that BACK brings us back to http://foo2/. | 2492 // Verify that BACK brings us back to http://foo2/. |
| 2397 { | 2493 { |
| 2398 const GURL url("http://foo2/"); | 2494 const GURL url("http://foo2/"); |
| 2399 controller.GoBack(); | 2495 controller.GoBack(); |
| 2496 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2400 main_test_rfh()->PrepareForCommit(); | 2497 main_test_rfh()->PrepareForCommit(); |
| 2401 main_test_rfh()->SendNavigate(1, url); | 2498 main_test_rfh()->SendNavigate(1, entry_id, false, url); |
| 2402 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2499 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2403 navigation_entry_committed_counter_ = 0; | 2500 navigation_entry_committed_counter_ = 0; |
| 2404 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2501 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2405 } | 2502 } |
| 2406 } | 2503 } |
| 2407 | 2504 |
| 2408 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) | 2505 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) |
| 2409 { | 2506 { |
| 2410 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); | 2507 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); |
| 2411 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2508 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2412 GURL url("http://foo"); | 2509 GURL url("http://foo"); |
| 2413 params.page_id = 1; | 2510 params.page_id = 1; |
| 2511 params.nav_entry_id = 0; |
| 2512 params.did_create_new_entry = true; |
| 2414 params.url = url; | 2513 params.url = url; |
| 2415 params.page_state = PageState::CreateFromURL(url); | 2514 params.page_state = PageState::CreateFromURL(url); |
| 2416 params.was_within_same_page = true; | 2515 params.was_within_same_page = true; |
| 2417 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 2516 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
| 2418 main_test_rfh()->PrepareForCommit(); | 2517 main_test_rfh()->PrepareForCommit(); |
| 2419 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 2518 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
| 2420 // We pass if we don't crash. | 2519 // We pass if we don't crash. |
| 2421 } | 2520 } |
| 2422 | 2521 |
| 2423 // NotificationObserver implementation used in verifying we've received the | 2522 // NotificationObserver implementation used in verifying we've received the |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2458 const int kMaxEntryCount = 5; | 2557 const int kMaxEntryCount = 5; |
| 2459 | 2558 |
| 2460 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2559 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
| 2461 | 2560 |
| 2462 int url_index; | 2561 int url_index; |
| 2463 // Load up to the max count, all entries should be there. | 2562 // Load up to the max count, all entries should be there. |
| 2464 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2563 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
| 2465 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2564 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2466 controller.LoadURL( | 2565 controller.LoadURL( |
| 2467 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2566 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2567 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2468 main_test_rfh()->PrepareForCommit(); | 2568 main_test_rfh()->PrepareForCommit(); |
| 2469 main_test_rfh()->SendNavigate(url_index, url); | 2569 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
| 2470 } | 2570 } |
| 2471 | 2571 |
| 2472 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2572 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2473 | 2573 |
| 2474 // Created a PrunedListener to observe prune notifications. | 2574 // Created a PrunedListener to observe prune notifications. |
| 2475 PrunedListener listener(&controller); | 2575 PrunedListener listener(&controller); |
| 2476 | 2576 |
| 2477 // Navigate some more. | 2577 // Navigate some more. |
| 2478 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2578 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2479 controller.LoadURL( | 2579 controller.LoadURL( |
| 2480 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2580 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2581 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2481 main_test_rfh()->PrepareForCommit(); | 2582 main_test_rfh()->PrepareForCommit(); |
| 2482 main_test_rfh()->SendNavigate(url_index, url); | 2583 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
| 2483 url_index++; | 2584 url_index++; |
| 2484 | 2585 |
| 2485 // We should have got a pruned navigation. | 2586 // We should have got a pruned navigation. |
| 2486 EXPECT_EQ(1, listener.notification_count_); | 2587 EXPECT_EQ(1, listener.notification_count_); |
| 2487 EXPECT_TRUE(listener.details_.from_front); | 2588 EXPECT_TRUE(listener.details_.from_front); |
| 2488 EXPECT_EQ(1, listener.details_.count); | 2589 EXPECT_EQ(1, listener.details_.count); |
| 2489 | 2590 |
| 2490 // We expect http://www.a.com/0 to be gone. | 2591 // We expect http://www.a.com/0 to be gone. |
| 2491 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2592 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2492 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2593 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2493 GURL("http:////www.a.com/1")); | 2594 GURL("http://www.a.com/1")); |
| 2494 | 2595 |
| 2495 // More navigations. | 2596 // More navigations. |
| 2496 for (int i = 0; i < 3; i++) { | 2597 for (int i = 0; i < 3; i++) { |
| 2497 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2598 url = GURL(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2498 controller.LoadURL( | 2599 controller.LoadURL( |
| 2499 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2600 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2601 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2500 main_test_rfh()->PrepareForCommit(); | 2602 main_test_rfh()->PrepareForCommit(); |
| 2501 main_test_rfh()->SendNavigate(url_index, url); | 2603 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
| 2502 url_index++; | 2604 url_index++; |
| 2503 } | 2605 } |
| 2504 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2606 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2505 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2607 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2506 GURL("http:////www.a.com/4")); | 2608 GURL("http://www.a.com/4")); |
| 2507 | 2609 |
| 2508 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2610 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
| 2509 } | 2611 } |
| 2510 | 2612 |
| 2511 // Tests that we can do a restore and navigate to the restored entries and | 2613 // Tests that we can do a restore and navigate to the restored entries and |
| 2512 // everything is updated properly. This can be tricky since there is no | 2614 // everything is updated properly. This can be tricky since there is no |
| 2513 // SiteInstance for the entries created initially. | 2615 // SiteInstance for the entries created initially. |
| 2514 TEST_F(NavigationControllerTest, RestoreNavigate) { | 2616 TEST_F(NavigationControllerTest, RestoreNavigate) { |
| 2515 // Create a NavigationController with a restored set of tabs. | 2617 // Create a NavigationController with a restored set of tabs. |
| 2516 GURL url("http://foo"); | 2618 GURL url("http://foo"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2652 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
| 2551 our_controller.GetEntryAtIndex(0)->restore_type()); | 2653 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 2552 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2654 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 2553 | 2655 |
| 2554 // Timestamp should remain the same before the navigation finishes. | 2656 // Timestamp should remain the same before the navigation finishes. |
| 2555 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 2657 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
| 2556 | 2658 |
| 2557 // Say we navigated to that entry. | 2659 // Say we navigated to that entry. |
| 2558 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2660 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2559 params.page_id = 0; | 2661 params.page_id = 0; |
| 2662 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID(); |
| 2663 params.did_create_new_entry = false; |
| 2560 params.url = url; | 2664 params.url = url; |
| 2561 params.transition = ui::PAGE_TRANSITION_LINK; | 2665 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2562 params.should_update_history = false; | 2666 params.should_update_history = false; |
| 2563 params.gesture = NavigationGestureUser; | 2667 params.gesture = NavigationGestureUser; |
| 2564 params.is_post = false; | 2668 params.is_post = false; |
| 2565 params.page_state = PageState::CreateFromURL(url); | 2669 params.page_state = PageState::CreateFromURL(url); |
| 2566 LoadCommittedDetails details; | 2670 LoadCommittedDetails details; |
| 2567 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2671 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
| 2568 &details); | 2672 &details); |
| 2569 | 2673 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2598 entries.push_back(entry); | 2702 entries.push_back(entry); |
| 2599 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2703 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
| 2600 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2704 WebContents::Create(WebContents::CreateParams(browser_context())))); |
| 2601 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2705 NavigationControllerImpl& our_controller = our_contents->GetController(); |
| 2602 our_controller.Restore( | 2706 our_controller.Restore( |
| 2603 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 2707 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
| 2604 ASSERT_EQ(0u, entries.size()); | 2708 ASSERT_EQ(0u, entries.size()); |
| 2605 | 2709 |
| 2606 // Before navigating to the restored entry, it should have a restore_type | 2710 // Before navigating to the restored entry, it should have a restore_type |
| 2607 // and no SiteInstance. | 2711 // and no SiteInstance. |
| 2712 entry = our_controller.GetEntryAtIndex(0); |
| 2608 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2713 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| 2609 our_controller.GetEntryAtIndex(0)->restore_type()); | 2714 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 2610 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2715 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 2611 | 2716 |
| 2612 // After navigating, we should have one entry, and it should be "pending". | 2717 // After navigating, we should have one entry, and it should be "pending". |
| 2613 // It should now have a SiteInstance and no restore_type. | 2718 // It should now have a SiteInstance and no restore_type. |
| 2614 our_controller.GoToIndex(0); | 2719 our_controller.GoToIndex(0); |
| 2615 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2720 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 2616 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 2721 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 2617 our_controller.GetPendingEntry()); | 2722 our_controller.GetPendingEntry()); |
| 2618 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 2723 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
| 2619 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2724 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
| 2620 our_controller.GetEntryAtIndex(0)->restore_type()); | 2725 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 2621 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2726 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 2622 | 2727 |
| 2623 // This pending navigation may have caused a different navigation to fail, | 2728 // This pending navigation may have caused a different navigation to fail, |
| 2624 // which causes the pending entry to be cleared. | 2729 // which causes the pending entry to be cleared. |
| 2625 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; | 2730 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; |
| 2626 fail_load_params.error_code = net::ERR_ABORTED; | 2731 fail_load_params.error_code = net::ERR_ABORTED; |
| 2627 fail_load_params.error_description = base::string16(); | 2732 fail_load_params.error_description = base::string16(); |
| 2628 fail_load_params.url = url; | 2733 fail_load_params.url = url; |
| 2629 fail_load_params.showing_repost_interstitial = false; | 2734 fail_load_params.showing_repost_interstitial = false; |
| 2630 main_test_rfh()->OnMessageReceived( | 2735 main_test_rfh()->OnMessageReceived( |
| 2631 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2736 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
| 2632 fail_load_params)); | 2737 fail_load_params)); |
| 2633 | 2738 |
| 2634 // Now the pending restored entry commits. | 2739 // Now the pending restored entry commits. |
| 2635 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2740 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2636 params.page_id = 0; | 2741 params.page_id = 0; |
| 2742 params.nav_entry_id = entry->GetUniqueID(); |
| 2743 params.did_create_new_entry = false; |
| 2637 params.url = url; | 2744 params.url = url; |
| 2638 params.transition = ui::PAGE_TRANSITION_LINK; | 2745 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2639 params.should_update_history = false; | 2746 params.should_update_history = false; |
| 2640 params.gesture = NavigationGestureUser; | 2747 params.gesture = NavigationGestureUser; |
| 2641 params.is_post = false; | 2748 params.is_post = false; |
| 2642 params.page_state = PageState::CreateFromURL(url); | 2749 params.page_state = PageState::CreateFromURL(url); |
| 2643 LoadCommittedDetails details; | 2750 LoadCommittedDetails details; |
| 2644 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2751 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
| 2645 &details); | 2752 &details); |
| 2646 | 2753 |
| 2647 // There should be no pending entry and one committed one. | 2754 // There should be no pending entry and one committed one. |
| 2648 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2755 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 2649 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2756 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
| 2650 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2757 EXPECT_FALSE(our_controller.GetPendingEntry()); |
| 2651 EXPECT_EQ( | 2758 EXPECT_EQ( |
| 2652 url, | 2759 url, |
| 2653 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 2760 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
| 2654 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2761 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
| 2655 our_controller.GetEntryAtIndex(0)->restore_type()); | 2762 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 2656 } | 2763 } |
| 2657 | 2764 |
| 2658 // Make sure that the page type and stuff is correct after an interstitial. | 2765 // Make sure that the page type and stuff is correct after an interstitial. |
| 2659 TEST_F(NavigationControllerTest, Interstitial) { | 2766 TEST_F(NavigationControllerTest, Interstitial) { |
| 2660 NavigationControllerImpl& controller = controller_impl(); | 2767 NavigationControllerImpl& controller = controller_impl(); |
| 2661 // First navigate somewhere normal. | 2768 // First navigate somewhere normal. |
| 2662 const GURL url1("http://foo"); | 2769 const GURL url1("http://foo"); |
| 2663 controller.LoadURL( | 2770 controller.LoadURL( |
| 2664 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2771 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2772 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2665 main_test_rfh()->PrepareForCommit(); | 2773 main_test_rfh()->PrepareForCommit(); |
| 2666 main_test_rfh()->SendNavigate(0, url1); | 2774 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 2667 | 2775 |
| 2668 // Now navigate somewhere with an interstitial. | 2776 // Now navigate somewhere with an interstitial. |
| 2669 const GURL url2("http://bar"); | 2777 const GURL url2("http://bar"); |
| 2670 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, | 2778 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 2671 std::string()); | 2779 std::string()); |
| 2780 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2672 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); | 2781 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
| 2673 | 2782 |
| 2674 // At this point the interstitial will be displayed and the load will still | 2783 // At this point the interstitial will be displayed and the load will still |
| 2675 // be pending. If the user continues, the load will commit. | 2784 // be pending. If the user continues, the load will commit. |
| 2676 main_test_rfh()->PrepareForCommit(); | 2785 main_test_rfh()->PrepareForCommit(); |
| 2677 main_test_rfh()->SendNavigate(1, url2); | 2786 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
| 2678 | 2787 |
| 2679 // The page should be a normal page again. | 2788 // The page should be a normal page again. |
| 2680 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2789 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 2681 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2790 EXPECT_EQ(PAGE_TYPE_NORMAL, |
| 2682 controller.GetLastCommittedEntry()->GetPageType()); | 2791 controller.GetLastCommittedEntry()->GetPageType()); |
| 2683 } | 2792 } |
| 2684 | 2793 |
| 2685 TEST_F(NavigationControllerTest, RemoveEntry) { | 2794 TEST_F(NavigationControllerTest, RemoveEntry) { |
| 2686 NavigationControllerImpl& controller = controller_impl(); | 2795 NavigationControllerImpl& controller = controller_impl(); |
| 2687 const GURL url1("http://foo/1"); | 2796 const GURL url1("http://foo/1"); |
| 2688 const GURL url2("http://foo/2"); | 2797 const GURL url2("http://foo/2"); |
| 2689 const GURL url3("http://foo/3"); | 2798 const GURL url3("http://foo/3"); |
| 2690 const GURL url4("http://foo/4"); | 2799 const GURL url4("http://foo/4"); |
| 2691 const GURL url5("http://foo/5"); | 2800 const GURL url5("http://foo/5"); |
| 2692 const GURL pending_url("http://foo/pending"); | 2801 const GURL pending_url("http://foo/pending"); |
| 2693 const GURL default_url("http://foo/default"); | 2802 const GURL default_url("http://foo/default"); |
| 2694 | 2803 |
| 2695 controller.LoadURL( | 2804 controller.LoadURL( |
| 2696 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2805 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2806 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2697 main_test_rfh()->PrepareForCommit(); | 2807 main_test_rfh()->PrepareForCommit(); |
| 2698 main_test_rfh()->SendNavigate(0, url1); | 2808 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 2699 controller.LoadURL( | 2809 controller.LoadURL( |
| 2700 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2810 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2811 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2701 main_test_rfh()->PrepareForCommit(); | 2812 main_test_rfh()->PrepareForCommit(); |
| 2702 main_test_rfh()->SendNavigate(1, url2); | 2813 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
| 2703 controller.LoadURL( | 2814 controller.LoadURL( |
| 2704 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2815 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2816 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2705 main_test_rfh()->PrepareForCommit(); | 2817 main_test_rfh()->PrepareForCommit(); |
| 2706 main_test_rfh()->SendNavigate(2, url3); | 2818 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
| 2707 controller.LoadURL( | 2819 controller.LoadURL( |
| 2708 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2820 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2821 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2709 main_test_rfh()->PrepareForCommit(); | 2822 main_test_rfh()->PrepareForCommit(); |
| 2710 main_test_rfh()->SendNavigate(3, url4); | 2823 main_test_rfh()->SendNavigate(3, entry_id, true, url4); |
| 2711 controller.LoadURL( | 2824 controller.LoadURL( |
| 2712 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2825 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2826 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2713 main_test_rfh()->PrepareForCommit(); | 2827 main_test_rfh()->PrepareForCommit(); |
| 2714 main_test_rfh()->SendNavigate(4, url5); | 2828 main_test_rfh()->SendNavigate(4, entry_id, true, url5); |
| 2715 | 2829 |
| 2716 // Try to remove the last entry. Will fail because it is the current entry. | 2830 // Try to remove the last entry. Will fail because it is the current entry. |
| 2717 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2831 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2718 EXPECT_EQ(5, controller.GetEntryCount()); | 2832 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2719 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2833 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
| 2720 | 2834 |
| 2721 // Go back, but don't commit yet. Check that we can't delete the current | 2835 // Go back, but don't commit yet. Check that we can't delete the current |
| 2722 // and pending entries. | 2836 // and pending entries. |
| 2723 controller.GoBack(); | 2837 controller.GoBack(); |
| 2838 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2724 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2839 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2725 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2840 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
| 2726 | 2841 |
| 2727 // Now commit and delete the last entry. | 2842 // Now commit and delete the last entry. |
| 2728 main_test_rfh()->PrepareForCommit(); | 2843 main_test_rfh()->PrepareForCommit(); |
| 2729 main_test_rfh()->SendNavigate(3, url4); | 2844 main_test_rfh()->SendNavigate(3, entry_id, false, url4); |
| 2730 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2845 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2731 EXPECT_EQ(4, controller.GetEntryCount()); | 2846 EXPECT_EQ(4, controller.GetEntryCount()); |
| 2732 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2847 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| 2733 EXPECT_FALSE(controller.GetPendingEntry()); | 2848 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2734 | 2849 |
| 2735 // Remove an entry which is not the last committed one. | 2850 // Remove an entry which is not the last committed one. |
| 2736 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2851 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2737 EXPECT_EQ(3, controller.GetEntryCount()); | 2852 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2738 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2853 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 2739 EXPECT_FALSE(controller.GetPendingEntry()); | 2854 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2740 | 2855 |
| 2741 // Remove the 2 remaining entries. | 2856 // Remove the 2 remaining entries. |
| 2742 controller.RemoveEntryAtIndex(1); | 2857 controller.RemoveEntryAtIndex(1); |
| 2743 controller.RemoveEntryAtIndex(0); | 2858 controller.RemoveEntryAtIndex(0); |
| 2744 | 2859 |
| 2745 // This should leave us with only the last committed entry. | 2860 // This should leave us with only the last committed entry. |
| 2746 EXPECT_EQ(1, controller.GetEntryCount()); | 2861 EXPECT_EQ(1, controller.GetEntryCount()); |
| 2747 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2862 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2748 } | 2863 } |
| 2749 | 2864 |
| 2750 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2865 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
| 2751 NavigationControllerImpl& controller = controller_impl(); | 2866 NavigationControllerImpl& controller = controller_impl(); |
| 2752 const GURL url1("http://foo/1"); | 2867 const GURL url1("http://foo/1"); |
| 2753 const GURL url2("http://foo/2"); | 2868 const GURL url2("http://foo/2"); |
| 2754 const GURL url3("http://foo/3"); | 2869 const GURL url3("http://foo/3"); |
| 2755 const GURL default_url("http://foo/default"); | 2870 const GURL default_url("http://foo/default"); |
| 2756 | 2871 |
| 2757 controller.LoadURL( | 2872 controller.LoadURL( |
| 2758 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2873 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2874 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2759 main_test_rfh()->PrepareForCommit(); | 2875 main_test_rfh()->PrepareForCommit(); |
| 2760 main_test_rfh()->SendNavigate(0, url1); | 2876 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 2761 controller.LoadURL( | 2877 controller.LoadURL( |
| 2762 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2878 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2879 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2763 main_test_rfh()->PrepareForCommit(); | 2880 main_test_rfh()->PrepareForCommit(); |
| 2764 main_test_rfh()->SendNavigate(1, url2); | 2881 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
| 2765 controller.LoadURL( | 2882 controller.LoadURL( |
| 2766 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2883 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2884 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2767 main_test_rfh()->PrepareForCommit(); | 2885 main_test_rfh()->PrepareForCommit(); |
| 2768 main_test_rfh()->SendNavigate(2, url3); | 2886 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
| 2769 | 2887 |
| 2770 // Go back, but don't commit yet. Check that we can't delete the current | 2888 // Go back, but don't commit yet. Check that we can't delete the current |
| 2771 // and pending entries. | 2889 // and pending entries. |
| 2772 controller.GoBack(); | 2890 controller.GoBack(); |
| 2891 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2773 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2892 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
| 2774 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2893 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
| 2775 | 2894 |
| 2776 // Remove the first entry, while there is a pending entry. This is expected | 2895 // Remove the first entry, while there is a pending entry. This is expected |
| 2777 // to discard the pending entry. | 2896 // to discard the pending entry. |
| 2778 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2897 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2779 EXPECT_FALSE(controller.GetPendingEntry()); | 2898 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2780 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2899 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 2781 | 2900 |
| 2782 // We should update the last committed entry index. | 2901 // We should update the last committed entry index. |
| 2783 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2902 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2784 | 2903 |
| 2785 // Now commit and ensure we land on the right entry. | 2904 // Now commit and ensure we land on the right entry. |
| 2786 main_test_rfh()->PrepareForCommit(); | 2905 main_test_rfh()->PrepareForCommit(); |
| 2787 main_test_rfh()->SendNavigate(1, url2); | 2906 main_test_rfh()->SendNavigate(1, entry_id, false, url2); |
| 2788 EXPECT_EQ(2, controller.GetEntryCount()); | 2907 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2789 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2908 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2790 EXPECT_FALSE(controller.GetPendingEntry()); | 2909 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2791 } | 2910 } |
| 2792 | 2911 |
| 2793 // Tests the transient entry, making sure it goes away with all navigations. | 2912 // Tests the transient entry, making sure it goes away with all navigations. |
| 2794 TEST_F(NavigationControllerTest, TransientEntry) { | 2913 TEST_F(NavigationControllerTest, TransientEntry) { |
| 2795 NavigationControllerImpl& controller = controller_impl(); | 2914 NavigationControllerImpl& controller = controller_impl(); |
| 2796 TestNotificationTracker notifications; | 2915 TestNotificationTracker notifications; |
| 2797 RegisterForAllNavNotifications(¬ifications, &controller); | 2916 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2798 | 2917 |
| 2799 const GURL url0("http://foo/0"); | 2918 const GURL url0("http://foo/0"); |
| 2800 const GURL url1("http://foo/1"); | 2919 const GURL url1("http://foo/1"); |
| 2801 const GURL url2("http://foo/2"); | 2920 const GURL url2("http://foo/2"); |
| 2802 const GURL url3("http://foo/3"); | 2921 const GURL url3("http://foo/3"); |
| 2803 const GURL url3_ref("http://foo/3#bar"); | 2922 const GURL url3_ref("http://foo/3#bar"); |
| 2804 const GURL url4("http://foo/4"); | 2923 const GURL url4("http://foo/4"); |
| 2805 const GURL transient_url("http://foo/transient"); | 2924 const GURL transient_url("http://foo/transient"); |
| 2806 | 2925 |
| 2807 controller.LoadURL( | 2926 controller.LoadURL( |
| 2808 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2927 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2928 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2809 main_test_rfh()->PrepareForCommit(); | 2929 main_test_rfh()->PrepareForCommit(); |
| 2810 main_test_rfh()->SendNavigate(0, url0); | 2930 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
| 2811 controller.LoadURL( | 2931 controller.LoadURL( |
| 2812 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2932 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2933 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2813 main_test_rfh()->PrepareForCommit(); | 2934 main_test_rfh()->PrepareForCommit(); |
| 2814 main_test_rfh()->SendNavigate(1, url1); | 2935 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
| 2815 | 2936 |
| 2816 notifications.Reset(); | 2937 notifications.Reset(); |
| 2817 | 2938 |
| 2818 // Adding a transient with no pending entry. | 2939 // Adding a transient with no pending entry. |
| 2819 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2940 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2820 transient_entry->SetURL(transient_url); | 2941 transient_entry->SetURL(transient_url); |
| 2821 controller.SetTransientEntry(transient_entry); | 2942 controller.SetTransientEntry(transient_entry); |
| 2822 | 2943 |
| 2823 // We should not have received any notifications. | 2944 // We should not have received any notifications. |
| 2824 EXPECT_EQ(0U, notifications.size()); | 2945 EXPECT_EQ(0U, notifications.size()); |
| 2825 | 2946 |
| 2826 // Check our state. | 2947 // Check our state. |
| 2827 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2948 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2828 EXPECT_EQ(controller.GetEntryCount(), 3); | 2949 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2829 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2950 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2830 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2951 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2831 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2952 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2832 EXPECT_FALSE(controller.GetPendingEntry()); | 2953 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2833 EXPECT_TRUE(controller.CanGoBack()); | 2954 EXPECT_TRUE(controller.CanGoBack()); |
| 2834 EXPECT_FALSE(controller.CanGoForward()); | 2955 EXPECT_FALSE(controller.CanGoForward()); |
| 2835 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2956 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 2836 | 2957 |
| 2837 // Navigate. | 2958 // Navigate. |
| 2838 controller.LoadURL( | 2959 controller.LoadURL( |
| 2839 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2960 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2961 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2840 main_test_rfh()->PrepareForCommit(); | 2962 main_test_rfh()->PrepareForCommit(); |
| 2841 main_test_rfh()->SendNavigate(2, url2); | 2963 main_test_rfh()->SendNavigate(2, entry_id, true, url2); |
| 2842 | 2964 |
| 2843 // We should have navigated, transient entry should be gone. | 2965 // We should have navigated, transient entry should be gone. |
| 2844 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2966 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2845 EXPECT_EQ(controller.GetEntryCount(), 3); | 2967 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2846 | 2968 |
| 2847 // Add a transient again, then navigate with no pending entry this time. | 2969 // Add a transient again, then navigate with no pending entry this time. |
| 2848 transient_entry = new NavigationEntryImpl; | 2970 transient_entry = new NavigationEntryImpl; |
| 2849 transient_entry->SetURL(transient_url); | 2971 transient_entry->SetURL(transient_url); |
| 2850 controller.SetTransientEntry(transient_entry); | 2972 controller.SetTransientEntry(transient_entry); |
| 2851 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2973 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2852 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); | 2974 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); |
| 2853 main_test_rfh()->PrepareForCommit(); | 2975 main_test_rfh()->PrepareForCommit(); |
| 2854 main_test_rfh()->SendNavigate(3, url3); | 2976 main_test_rfh()->SendNavigate(3, 0, true, url3); |
| 2855 // Transient entry should be gone. | 2977 // Transient entry should be gone. |
| 2856 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2978 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2857 EXPECT_EQ(controller.GetEntryCount(), 4); | 2979 EXPECT_EQ(controller.GetEntryCount(), 4); |
| 2858 | 2980 |
| 2859 // Initiate a navigation, add a transient then commit navigation. | 2981 // Initiate a navigation, add a transient then commit navigation. |
| 2860 controller.LoadURL( | 2982 controller.LoadURL( |
| 2861 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2983 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2984 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2862 transient_entry = new NavigationEntryImpl; | 2985 transient_entry = new NavigationEntryImpl; |
| 2863 transient_entry->SetURL(transient_url); | 2986 transient_entry->SetURL(transient_url); |
| 2864 controller.SetTransientEntry(transient_entry); | 2987 controller.SetTransientEntry(transient_entry); |
| 2865 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2988 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2866 main_test_rfh()->PrepareForCommit(); | 2989 main_test_rfh()->PrepareForCommit(); |
| 2867 main_test_rfh()->SendNavigate(4, url4); | 2990 main_test_rfh()->SendNavigate(4, entry_id, true, url4); |
| 2868 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2991 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2869 EXPECT_EQ(controller.GetEntryCount(), 5); | 2992 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2870 | 2993 |
| 2871 // Add a transient and go back. This should simply remove the transient. | 2994 // Add a transient and go back. This should simply remove the transient. |
| 2872 transient_entry = new NavigationEntryImpl; | 2995 transient_entry = new NavigationEntryImpl; |
| 2873 transient_entry->SetURL(transient_url); | 2996 transient_entry->SetURL(transient_url); |
| 2874 controller.SetTransientEntry(transient_entry); | 2997 controller.SetTransientEntry(transient_entry); |
| 2875 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2998 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2876 EXPECT_TRUE(controller.CanGoBack()); | 2999 EXPECT_TRUE(controller.CanGoBack()); |
| 2877 EXPECT_FALSE(controller.CanGoForward()); | 3000 EXPECT_FALSE(controller.CanGoForward()); |
| 2878 controller.GoBack(); | 3001 controller.GoBack(); |
| 2879 // Transient entry should be gone. | 3002 // Transient entry should be gone. |
| 2880 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 3003 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2881 EXPECT_EQ(controller.GetEntryCount(), 5); | 3004 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2882 | 3005 |
| 2883 // Suppose the page requested a history navigation backward. | 3006 // Suppose the page requested a history navigation backward. |
| 2884 controller.GoToOffset(-1); | 3007 controller.GoToOffset(-1); |
| 3008 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2885 main_test_rfh()->PrepareForCommit(); | 3009 main_test_rfh()->PrepareForCommit(); |
| 2886 main_test_rfh()->SendNavigate(3, url3); | 3010 main_test_rfh()->SendNavigate(3, entry_id, false, url3); |
| 2887 | 3011 |
| 2888 // Add a transient and go to an entry before the current one. | 3012 // Add a transient and go to an entry before the current one. |
| 2889 transient_entry = new NavigationEntryImpl; | 3013 transient_entry = new NavigationEntryImpl; |
| 2890 transient_entry->SetURL(transient_url); | 3014 transient_entry->SetURL(transient_url); |
| 2891 controller.SetTransientEntry(transient_entry); | 3015 controller.SetTransientEntry(transient_entry); |
| 2892 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3016 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2893 controller.GoToIndex(1); | 3017 controller.GoToIndex(1); |
| 3018 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2894 // The navigation should have been initiated, transient entry should be gone. | 3019 // The navigation should have been initiated, transient entry should be gone. |
| 2895 EXPECT_FALSE(controller.GetTransientEntry()); | 3020 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2896 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3021 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2897 // Visible entry does not update for history navigations until commit. | 3022 // Visible entry does not update for history navigations until commit. |
| 2898 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 3023 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2899 main_test_rfh()->PrepareForCommit(); | 3024 main_test_rfh()->PrepareForCommit(); |
| 2900 main_test_rfh()->SendNavigate(1, url1); | 3025 main_test_rfh()->SendNavigate(1, entry_id, false, url1); |
| 2901 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3026 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2902 | 3027 |
| 2903 // Add a transient and go to an entry after the current one. | 3028 // Add a transient and go to an entry after the current one. |
| 2904 transient_entry = new NavigationEntryImpl; | 3029 transient_entry = new NavigationEntryImpl; |
| 2905 transient_entry->SetURL(transient_url); | 3030 transient_entry->SetURL(transient_url); |
| 2906 controller.SetTransientEntry(transient_entry); | 3031 controller.SetTransientEntry(transient_entry); |
| 2907 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3032 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2908 controller.GoToIndex(3); | 3033 controller.GoToIndex(3); |
| 3034 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2909 // The navigation should have been initiated, transient entry should be gone. | 3035 // The navigation should have been initiated, transient entry should be gone. |
| 2910 // Because of the transient entry that is removed, going to index 3 makes us | 3036 // Because of the transient entry that is removed, going to index 3 makes us |
| 2911 // land on url2 (which is visible after the commit). | 3037 // land on url2 (which is visible after the commit). |
| 2912 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3038 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 2913 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3039 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2914 main_test_rfh()->PrepareForCommit(); | 3040 main_test_rfh()->PrepareForCommit(); |
| 2915 main_test_rfh()->SendNavigate(2, url2); | 3041 main_test_rfh()->SendNavigate(2, entry_id, false, url2); |
| 2916 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 3042 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2917 | 3043 |
| 2918 // Add a transient and go forward. | 3044 // Add a transient and go forward. |
| 2919 transient_entry = new NavigationEntryImpl; | 3045 transient_entry = new NavigationEntryImpl; |
| 2920 transient_entry->SetURL(transient_url); | 3046 transient_entry->SetURL(transient_url); |
| 2921 controller.SetTransientEntry(transient_entry); | 3047 controller.SetTransientEntry(transient_entry); |
| 2922 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3048 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2923 EXPECT_TRUE(controller.CanGoForward()); | 3049 EXPECT_TRUE(controller.CanGoForward()); |
| 2924 controller.GoForward(); | 3050 controller.GoForward(); |
| 3051 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2925 // We should have navigated, transient entry should be gone. | 3052 // We should have navigated, transient entry should be gone. |
| 2926 EXPECT_FALSE(controller.GetTransientEntry()); | 3053 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2927 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 3054 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
| 2928 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 3055 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2929 main_test_rfh()->PrepareForCommit(); | 3056 main_test_rfh()->PrepareForCommit(); |
| 2930 main_test_rfh()->SendNavigate(3, url3); | 3057 main_test_rfh()->SendNavigate(3, entry_id, false, url3); |
| 2931 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 3058 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2932 | 3059 |
| 2933 // Add a transient and do an in-page navigation, replacing the current entry. | 3060 // Add a transient and do an in-page navigation, replacing the current entry. |
| 2934 transient_entry = new NavigationEntryImpl; | 3061 transient_entry = new NavigationEntryImpl; |
| 2935 transient_entry->SetURL(transient_url); | 3062 transient_entry->SetURL(transient_url); |
| 2936 controller.SetTransientEntry(transient_entry); | 3063 controller.SetTransientEntry(transient_entry); |
| 2937 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3064 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2938 | 3065 |
| 2939 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); | 3066 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); |
| 2940 main_test_rfh()->PrepareForCommit(); | 3067 main_test_rfh()->PrepareForCommit(); |
| 2941 main_test_rfh()->SendNavigate(3, url3_ref); | 3068 main_test_rfh()->SendNavigate(3, 0, false, url3_ref); |
| 2942 // Transient entry should be gone. | 3069 // Transient entry should be gone. |
| 2943 EXPECT_FALSE(controller.GetTransientEntry()); | 3070 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2944 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 3071 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
| 2945 | 3072 |
| 2946 // Ensure the URLs are correct. | 3073 // Ensure the URLs are correct. |
| 2947 EXPECT_EQ(controller.GetEntryCount(), 5); | 3074 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2948 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3075 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2949 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 3076 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
| 2950 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 3077 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
| 2951 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 3078 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
| 2952 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 3079 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
| 2953 } | 3080 } |
| 2954 | 3081 |
| 2955 // Test that Reload initiates a new navigation to a transient entry's URL. | 3082 // Test that Reload initiates a new navigation to a transient entry's URL. |
| 2956 TEST_F(NavigationControllerTest, ReloadTransient) { | 3083 TEST_F(NavigationControllerTest, ReloadTransient) { |
| 2957 NavigationControllerImpl& controller = controller_impl(); | 3084 NavigationControllerImpl& controller = controller_impl(); |
| 2958 const GURL url0("http://foo/0"); | 3085 const GURL url0("http://foo/0"); |
| 2959 const GURL url1("http://foo/1"); | 3086 const GURL url1("http://foo/1"); |
| 2960 const GURL transient_url("http://foo/transient"); | 3087 const GURL transient_url("http://foo/transient"); |
| 2961 | 3088 |
| 2962 // Load |url0|, and start a pending navigation to |url1|. | 3089 // Load |url0|, and start a pending navigation to |url1|. |
| 2963 controller.LoadURL( | 3090 controller.LoadURL( |
| 2964 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3091 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3092 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2965 main_test_rfh()->PrepareForCommit(); | 3093 main_test_rfh()->PrepareForCommit(); |
| 2966 main_test_rfh()->SendNavigate(0, url0); | 3094 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
| 2967 controller.LoadURL( | 3095 controller.LoadURL( |
| 2968 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3096 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2969 | 3097 |
| 2970 // A transient entry is added, interrupting the navigation. | 3098 // A transient entry is added, interrupting the navigation. |
| 2971 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 3099 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2972 transient_entry->SetURL(transient_url); | 3100 transient_entry->SetURL(transient_url); |
| 2973 controller.SetTransientEntry(transient_entry); | 3101 controller.SetTransientEntry(transient_entry); |
| 2974 EXPECT_TRUE(controller.GetTransientEntry()); | 3102 EXPECT_TRUE(controller.GetTransientEntry()); |
| 2975 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3103 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2976 | 3104 |
| 2977 // The page is reloaded, which should remove the pending entry for |url1| and | 3105 // The page is reloaded, which should remove the pending entry for |url1| and |
| 2978 // the transient entry for |transient_url|, and start a navigation to | 3106 // the transient entry for |transient_url|, and start a navigation to |
| 2979 // |transient_url|. | 3107 // |transient_url|. |
| 2980 controller.Reload(true); | 3108 controller.Reload(true); |
| 3109 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2981 EXPECT_FALSE(controller.GetTransientEntry()); | 3110 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2982 EXPECT_TRUE(controller.GetPendingEntry()); | 3111 EXPECT_TRUE(controller.GetPendingEntry()); |
| 2983 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3112 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2984 ASSERT_EQ(controller.GetEntryCount(), 1); | 3113 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2985 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3114 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2986 | 3115 |
| 2987 // Load of |transient_url| completes. | 3116 // Load of |transient_url| completes. |
| 2988 main_test_rfh()->PrepareForCommit(); | 3117 main_test_rfh()->PrepareForCommit(); |
| 2989 main_test_rfh()->SendNavigate(1, transient_url); | 3118 main_test_rfh()->SendNavigate(1, entry_id, true, transient_url); |
| 2990 ASSERT_EQ(controller.GetEntryCount(), 2); | 3119 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2991 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3120 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2992 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 3121 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2993 } | 3122 } |
| 2994 | 3123 |
| 2995 // Ensure that renderer initiated pending entries get replaced, so that we | 3124 // Ensure that renderer initiated pending entries get replaced, so that we |
| 2996 // don't show a stale virtual URL when a navigation commits. | 3125 // don't show a stale virtual URL when a navigation commits. |
| 2997 // See http://crbug.com/266922. | 3126 // See http://crbug.com/266922. |
| 2998 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 3127 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
| 2999 NavigationControllerImpl& controller = controller_impl(); | 3128 NavigationControllerImpl& controller = controller_impl(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3018 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3147 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 3019 | 3148 |
| 3020 // If the user clicks another link, we should replace the pending entry. | 3149 // If the user clicks another link, we should replace the pending entry. |
| 3021 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3150 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3022 main_test_rfh()->PrepareForCommit(); | 3151 main_test_rfh()->PrepareForCommit(); |
| 3023 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3152 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
| 3024 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3153 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 3025 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3154 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
| 3026 | 3155 |
| 3027 // Once it commits, the URL and virtual URL should reflect the actual page. | 3156 // Once it commits, the URL and virtual URL should reflect the actual page. |
| 3028 main_test_rfh()->SendNavigate(0, url2); | 3157 main_test_rfh()->SendNavigate(0, 0, true, url2); |
| 3029 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3158 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3030 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3159 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
| 3031 | 3160 |
| 3032 // We should not replace the pending entry for an error URL. | 3161 // We should not replace the pending entry for an error URL. |
| 3033 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3162 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
| 3034 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3163 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3035 navigator->DidStartProvisionalLoad(main_test_rfh(), | 3164 navigator->DidStartProvisionalLoad(main_test_rfh(), |
| 3036 GURL(kUnreachableWebDataURL), false); | 3165 GURL(kUnreachableWebDataURL), false); |
| 3037 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3166 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3038 | 3167 |
| 3039 // We should remember if the pending entry will replace the current one. | 3168 // We should remember if the pending entry will replace the current one. |
| 3040 // http://crbug.com/308444. | 3169 // http://crbug.com/308444. |
| 3041 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3170 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
| 3042 controller.GetPendingEntry()->set_should_replace_entry(true); | 3171 controller.GetPendingEntry()->set_should_replace_entry(true); |
| 3043 | 3172 |
| 3044 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3173 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3045 main_test_rfh()->PrepareForCommit(); | 3174 main_test_rfh()->PrepareForCommit(); |
| 3046 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3175 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
| 3047 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3176 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
| 3048 main_test_rfh()->SendNavigate(0, url2); | 3177 main_test_rfh()->SendNavigate(0, 0, false, url2); |
| 3049 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3178 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3050 } | 3179 } |
| 3051 | 3180 |
| 3052 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3181 // Tests that the URLs for renderer-initiated navigations are not displayed to |
| 3053 // the user until the navigation commits, to prevent URL spoof attacks. | 3182 // the user until the navigation commits, to prevent URL spoof attacks. |
| 3054 // See http://crbug.com/99016. | 3183 // See http://crbug.com/99016. |
| 3055 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3184 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 3056 NavigationControllerImpl& controller = controller_impl(); | 3185 NavigationControllerImpl& controller = controller_impl(); |
| 3057 TestNotificationTracker notifications; | 3186 TestNotificationTracker notifications; |
| 3058 RegisterForAllNavNotifications(¬ifications, &controller); | 3187 RegisterForAllNavNotifications(¬ifications, &controller); |
| 3059 | 3188 |
| 3060 const GURL url0("http://foo/0"); | 3189 const GURL url0("http://foo/0"); |
| 3061 const GURL url1("http://foo/1"); | 3190 const GURL url1("http://foo/1"); |
| 3062 | 3191 |
| 3063 // For typed navigations (browser-initiated), both pending and visible entries | 3192 // For typed navigations (browser-initiated), both pending and visible entries |
| 3064 // should update before commit. | 3193 // should update before commit. |
| 3065 controller.LoadURL( | 3194 controller.LoadURL( |
| 3066 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3195 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3196 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 3067 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 3197 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
| 3068 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3198 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 3069 main_test_rfh()->PrepareForCommit(); | 3199 main_test_rfh()->PrepareForCommit(); |
| 3070 main_test_rfh()->SendNavigate(0, url0); | 3200 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
| 3071 | 3201 |
| 3072 // For link clicks (renderer-initiated navigations), the pending entry should | 3202 // For link clicks (renderer-initiated navigations), the pending entry should |
| 3073 // update before commit but the visible should not. | 3203 // update before commit but the visible should not. |
| 3074 NavigationController::LoadURLParams load_url_params(url1); | 3204 NavigationController::LoadURLParams load_url_params(url1); |
| 3075 load_url_params.is_renderer_initiated = true; | 3205 load_url_params.is_renderer_initiated = true; |
| 3076 controller.LoadURLWithParams(load_url_params); | 3206 controller.LoadURLWithParams(load_url_params); |
| 3207 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 3077 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3208 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 3078 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3209 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3079 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3210 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 3080 | 3211 |
| 3081 // After commit, both visible should be updated, there should be no pending | 3212 // After commit, both visible should be updated, there should be no pending |
| 3082 // entry, and we should no longer treat the entry as renderer-initiated. | 3213 // entry, and we should no longer treat the entry as renderer-initiated. |
| 3083 main_test_rfh()->PrepareForCommit(); | 3214 main_test_rfh()->PrepareForCommit(); |
| 3084 main_test_rfh()->SendNavigate(1, url1); | 3215 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
| 3085 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3216 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 3086 EXPECT_FALSE(controller.GetPendingEntry()); | 3217 EXPECT_FALSE(controller.GetPendingEntry()); |
| 3087 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); | 3218 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
| 3088 | 3219 |
| 3089 notifications.Reset(); | 3220 notifications.Reset(); |
| 3090 } | 3221 } |
| 3091 | 3222 |
| 3092 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3223 // Tests that the URLs for renderer-initiated navigations in new tabs are |
| 3093 // displayed to the user before commit, as long as the initial about:blank | 3224 // displayed to the user before commit, as long as the initial about:blank |
| 3094 // page has not been modified. If so, we must revert to showing about:blank. | 3225 // page has not been modified. If so, we must revert to showing about:blank. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3232 const GURL url1("http://foo/eh"); | 3363 const GURL url1("http://foo/eh"); |
| 3233 const GURL url2("http://foo/bee"); | 3364 const GURL url2("http://foo/bee"); |
| 3234 | 3365 |
| 3235 // For renderer-initiated navigations in new tabs (with no committed entries), | 3366 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 3236 // we show the pending entry's URL as long as the about:blank page is not | 3367 // we show the pending entry's URL as long as the about:blank page is not |
| 3237 // modified. | 3368 // modified. |
| 3238 NavigationController::LoadURLParams load_url_params(url1); | 3369 NavigationController::LoadURLParams load_url_params(url1); |
| 3239 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3370 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 3240 load_url_params.is_renderer_initiated = true; | 3371 load_url_params.is_renderer_initiated = true; |
| 3241 controller.LoadURLWithParams(load_url_params); | 3372 controller.LoadURLWithParams(load_url_params); |
| 3373 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 3242 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3374 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 3243 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3375 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 3244 EXPECT_TRUE(controller.IsInitialNavigation()); | 3376 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 3245 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3377 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 3246 | 3378 |
| 3247 // Simulate a commit and then starting a new pending navigation. | 3379 // Simulate a commit and then starting a new pending navigation. |
| 3248 main_test_rfh()->PrepareForCommit(); | 3380 main_test_rfh()->PrepareForCommit(); |
| 3249 main_test_rfh()->SendNavigate(0, url1); | 3381 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
| 3250 NavigationController::LoadURLParams load_url2_params(url2); | 3382 NavigationController::LoadURLParams load_url2_params(url2); |
| 3251 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3383 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 3252 load_url2_params.is_renderer_initiated = true; | 3384 load_url2_params.is_renderer_initiated = true; |
| 3253 controller.LoadURLWithParams(load_url2_params); | 3385 controller.LoadURLWithParams(load_url2_params); |
| 3254 | 3386 |
| 3255 // We should not consider this an initial navigation, and thus should | 3387 // We should not consider this an initial navigation, and thus should |
| 3256 // not show the pending URL. | 3388 // not show the pending URL. |
| 3257 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3389 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 3258 EXPECT_FALSE(controller.IsInitialNavigation()); | 3390 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 3259 EXPECT_TRUE(controller.GetVisibleEntry()); | 3391 EXPECT_TRUE(controller.GetVisibleEntry()); |
| 3260 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3392 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 3261 | 3393 |
| 3262 notifications.Reset(); | 3394 notifications.Reset(); |
| 3263 } | 3395 } |
| 3264 | 3396 |
| 3265 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3397 // Tests that IsInPageNavigation returns appropriate results. Prevents |
| 3266 // regression for bug 1126349. | 3398 // regression for bug 1126349. |
| 3267 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3399 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
| 3268 NavigationControllerImpl& controller = controller_impl(); | 3400 NavigationControllerImpl& controller = controller_impl(); |
| 3269 const GURL url("http://www.google.com/home.html"); | 3401 const GURL url("http://www.google.com/home.html"); |
| 3270 | 3402 |
| 3271 // If the renderer claims it performed an in-page navigation from | 3403 // If the renderer claims it performed an in-page navigation from |
| 3272 // about:blank, trust the renderer. | 3404 // about:blank, trust the renderer. |
| 3273 // This can happen when an iframe is created and populated via | 3405 // This can happen when an iframe is created and populated via |
| 3274 // document.write(), then tries to perform a fragment navigation. | 3406 // document.write(), then tries to perform a fragment navigation. |
| 3275 // TODO(japhet): We should only trust the renderer if the about:blank | 3407 // TODO(japhet): We should only trust the renderer if the about:blank |
| 3276 // was the first document in the given frame, but we don't have enough | 3408 // was the first document in the given frame, but we don't have enough |
| 3277 // information to identify that case currently. | 3409 // information to identify that case currently. |
| 3278 const GURL blank_url(url::kAboutBlankURL); | 3410 const GURL blank_url(url::kAboutBlankURL); |
| 3279 main_test_rfh()->NavigateAndCommitRendererInitiated(0, blank_url); | 3411 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); |
| 3280 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3412 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
| 3281 main_test_rfh())); | 3413 main_test_rfh())); |
| 3282 | 3414 |
| 3283 // Navigate to URL with no refs. | 3415 // Navigate to URL with no refs. |
| 3284 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3416 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); |
| 3285 | 3417 |
| 3286 // Reloading the page is not an in-page navigation. | 3418 // Reloading the page is not an in-page navigation. |
| 3287 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3419 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh())); |
| 3288 main_test_rfh())); | |
| 3289 const GURL other_url("http://www.google.com/add.html"); | 3420 const GURL other_url("http://www.google.com/add.html"); |
| 3290 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3421 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3291 main_test_rfh())); | 3422 main_test_rfh())); |
| 3292 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3423 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
| 3293 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3424 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
| 3294 main_test_rfh())); | 3425 main_test_rfh())); |
| 3295 | 3426 |
| 3296 // Navigate to URL with refs. | 3427 // Navigate to URL with refs. |
| 3297 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url_with_ref); | 3428 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url_with_ref); |
| 3298 | 3429 |
| 3299 // Reloading the page is not an in-page navigation. | 3430 // Reloading the page is not an in-page navigation. |
| 3300 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, | 3431 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
| 3301 main_test_rfh())); | 3432 main_test_rfh())); |
| 3302 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3433 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3303 main_test_rfh())); | 3434 main_test_rfh())); |
| 3304 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3435 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3305 main_test_rfh())); | 3436 main_test_rfh())); |
| 3306 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3437 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
| 3307 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, | 3438 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3325 // Test allow_universal_access_from_file_urls flag. | 3456 // Test allow_universal_access_from_file_urls flag. |
| 3326 const GURL different_origin_url("http://www.example.com"); | 3457 const GURL different_origin_url("http://www.example.com"); |
| 3327 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); | 3458 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); |
| 3328 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); | 3459 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); |
| 3329 prefs.allow_universal_access_from_file_urls = true; | 3460 prefs.allow_universal_access_from_file_urls = true; |
| 3330 test_rvh()->UpdateWebkitPreferences(prefs); | 3461 test_rvh()->UpdateWebkitPreferences(prefs); |
| 3331 prefs = test_rvh()->GetWebkitPreferences(); | 3462 prefs = test_rvh()->GetWebkitPreferences(); |
| 3332 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); | 3463 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); |
| 3333 // Allow in page navigation if existing URL is file scheme. | 3464 // Allow in page navigation if existing URL is file scheme. |
| 3334 const GURL file_url("file:///foo/index.html"); | 3465 const GURL file_url("file:///foo/index.html"); |
| 3335 main_test_rfh()->NavigateAndCommitRendererInitiated(0, file_url); | 3466 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, file_url); |
| 3336 EXPECT_EQ(0, rph->bad_msg_count()); | 3467 EXPECT_EQ(0, rph->bad_msg_count()); |
| 3337 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, | 3468 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, |
| 3338 main_test_rfh())); | 3469 main_test_rfh())); |
| 3339 EXPECT_EQ(0, rph->bad_msg_count()); | 3470 EXPECT_EQ(0, rph->bad_msg_count()); |
| 3340 // Don't honor allow_universal_access_from_file_urls if existing URL is | 3471 // Don't honor allow_universal_access_from_file_urls if existing URL is |
| 3341 // not file scheme. | 3472 // not file scheme. |
| 3342 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3473 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); |
| 3343 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3474 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
| 3344 main_test_rfh())); | 3475 main_test_rfh())); |
| 3345 EXPECT_EQ(1, rph->bad_msg_count()); | 3476 EXPECT_EQ(1, rph->bad_msg_count()); |
| 3346 | 3477 |
| 3347 // Remove allow_universal_access_from_file_urls flag. | 3478 // Remove allow_universal_access_from_file_urls flag. |
| 3348 prefs.allow_universal_access_from_file_urls = false; | 3479 prefs.allow_universal_access_from_file_urls = false; |
| 3349 test_rvh()->UpdateWebkitPreferences(prefs); | 3480 test_rvh()->UpdateWebkitPreferences(prefs); |
| 3350 prefs = test_rvh()->GetWebkitPreferences(); | 3481 prefs = test_rvh()->GetWebkitPreferences(); |
| 3351 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); | 3482 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); |
| 3352 | 3483 |
| 3353 // Don't believe the renderer if it claims a cross-origin navigation is | 3484 // Don't believe the renderer if it claims a cross-origin navigation is |
| 3354 // in-page. | 3485 // in-page. |
| 3355 EXPECT_EQ(1, rph->bad_msg_count()); | 3486 EXPECT_EQ(1, rph->bad_msg_count()); |
| 3356 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3487 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
| 3357 main_test_rfh())); | 3488 main_test_rfh())); |
| 3358 EXPECT_EQ(2, rph->bad_msg_count()); | 3489 EXPECT_EQ(2, rph->bad_msg_count()); |
| 3359 } | 3490 } |
| 3360 | 3491 |
| 3361 // Some pages can have subframes with the same base URL (minus the reference) as | 3492 // Some pages can have subframes with the same base URL (minus the reference) as |
| 3362 // the main page. Even though this is hard, it can happen, and we don't want | 3493 // the main page. Even though this is hard, it can happen, and we don't want |
| 3363 // these subframe navigations to affect the toplevel document. They should | 3494 // these subframe navigations to affect the toplevel document. They should |
| 3364 // instead be ignored. http://crbug.com/5585 | 3495 // instead be ignored. http://crbug.com/5585 |
| 3365 TEST_F(NavigationControllerTest, SameSubframe) { | 3496 TEST_F(NavigationControllerTest, SameSubframe) { |
| 3366 NavigationControllerImpl& controller = controller_impl(); | 3497 NavigationControllerImpl& controller = controller_impl(); |
| 3367 // Navigate the main frame. | 3498 // Navigate the main frame. |
| 3368 const GURL url("http://www.google.com/"); | 3499 const GURL url("http://www.google.com/"); |
| 3369 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3500 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); |
| 3370 | 3501 |
| 3371 // We should be at the first navigation entry. | 3502 // We should be at the first navigation entry. |
| 3372 EXPECT_EQ(controller.GetEntryCount(), 1); | 3503 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 3373 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 3504 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 3374 | 3505 |
| 3375 // Navigate a subframe that would normally count as in-page. | 3506 // Navigate a subframe that would normally count as in-page. |
| 3376 const GURL subframe("http://www.google.com/#"); | 3507 const GURL subframe("http://www.google.com/#"); |
| 3377 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3508 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 3378 params.page_id = 0; | 3509 params.page_id = 0; |
| 3510 params.nav_entry_id = 0; |
| 3511 params.did_create_new_entry = false; |
| 3379 params.url = subframe; | 3512 params.url = subframe; |
| 3380 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3513 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 3381 params.should_update_history = false; | 3514 params.should_update_history = false; |
| 3382 params.gesture = NavigationGestureAuto; | 3515 params.gesture = NavigationGestureAuto; |
| 3383 params.is_post = false; | 3516 params.is_post = false; |
| 3384 params.page_state = PageState::CreateFromURL(subframe); | 3517 params.page_state = PageState::CreateFromURL(subframe); |
| 3385 LoadCommittedDetails details; | 3518 LoadCommittedDetails details; |
| 3386 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3519 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
| 3387 &details)); | 3520 &details)); |
| 3388 | 3521 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3514 // Now start a pending load to a totally different page, but don't commit it. | 3647 // Now start a pending load to a totally different page, but don't commit it. |
| 3515 const GURL url2("http://bar/"); | 3648 const GURL url2("http://bar/"); |
| 3516 controller.LoadURL( | 3649 controller.LoadURL( |
| 3517 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3650 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3518 | 3651 |
| 3519 // Send a subframe update from the first page, as if one had just | 3652 // Send a subframe update from the first page, as if one had just |
| 3520 // automatically loaded. Auto subframes don't increment the page ID. | 3653 // automatically loaded. Auto subframes don't increment the page ID. |
| 3521 const GURL url1_sub("http://foo/subframe"); | 3654 const GURL url1_sub("http://foo/subframe"); |
| 3522 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3655 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 3523 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); | 3656 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); |
| 3657 params.nav_entry_id = 0; |
| 3658 params.did_create_new_entry = false; |
| 3524 params.url = url1_sub; | 3659 params.url = url1_sub; |
| 3525 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3660 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 3526 params.should_update_history = false; | 3661 params.should_update_history = false; |
| 3527 params.gesture = NavigationGestureAuto; | 3662 params.gesture = NavigationGestureAuto; |
| 3528 params.is_post = false; | 3663 params.is_post = false; |
| 3529 params.page_state = PageState::CreateFromURL(url1_sub); | 3664 params.page_state = PageState::CreateFromURL(url1_sub); |
| 3530 LoadCommittedDetails details; | 3665 LoadCommittedDetails details; |
| 3531 | 3666 |
| 3532 // This should return false meaning that nothing was actually updated. | 3667 // This should return false meaning that nothing was actually updated. |
| 3533 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3668 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3811 | 3946 |
| 3812 NavigateAndCommit(url1); | 3947 NavigateAndCommit(url1); |
| 3813 | 3948 |
| 3814 scoped_ptr<TestWebContents> other_contents( | 3949 scoped_ptr<TestWebContents> other_contents( |
| 3815 static_cast<TestWebContents*>(CreateTestWebContents())); | 3950 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 3816 NavigationControllerImpl& other_controller = other_contents->GetController(); | 3951 NavigationControllerImpl& other_controller = other_contents->GetController(); |
| 3817 other_contents->NavigateAndCommit(url2a); | 3952 other_contents->NavigateAndCommit(url2a); |
| 3818 // Simulate a client redirect, which has the same page ID as entry 2a. | 3953 // Simulate a client redirect, which has the same page ID as entry 2a. |
| 3819 other_controller.LoadURL( | 3954 other_controller.LoadURL( |
| 3820 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 3955 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 3821 other_controller.GetPendingEntry()->SetPageID( | 3956 NavigationEntry* entry = other_controller.GetPendingEntry(); |
| 3822 other_controller.GetLastCommittedEntry()->GetPageID()); | 3957 entry->SetPageID(other_controller.GetLastCommittedEntry()->GetPageID()); |
| 3823 | 3958 |
| 3824 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); | 3959 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); |
| 3825 other_controller.CopyStateFromAndPrune(&controller, false); | 3960 other_controller.CopyStateFromAndPrune(&controller, false); |
| 3826 | 3961 |
| 3827 // other_controller should now contain url1, url2a, and a pending entry | 3962 // other_controller should now contain url1, url2a, and a pending entry |
| 3828 // for url2b. | 3963 // for url2b. |
| 3829 | 3964 |
| 3830 ASSERT_EQ(2, other_controller.GetEntryCount()); | 3965 ASSERT_EQ(2, other_controller.GetEntryCount()); |
| 3831 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 3966 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
| 3832 | 3967 |
| 3833 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3968 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
| 3834 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); | 3969 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 3835 | 3970 |
| 3836 // And there should be a pending entry for url4. | 3971 // And there should be a pending entry for url4. |
| 3837 ASSERT_TRUE(other_controller.GetPendingEntry()); | 3972 ASSERT_TRUE(other_controller.GetPendingEntry()); |
| 3838 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); | 3973 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); |
| 3839 | 3974 |
| 3840 // Let the pending entry commit. | 3975 // Let the pending entry commit. |
| 3841 other_contents->CommitPendingNavigation(); | 3976 other_contents->TestDidNavigate(other_contents->GetMainFrame(), |
| 3977 entry->GetPageID(), 0, false, url2b, |
| 3978 ui::PAGE_TRANSITION_LINK); |
| 3842 | 3979 |
| 3843 // The max page ID map should be copied over and updated with the max page ID | 3980 // The max page ID map should be copied over and updated with the max page ID |
| 3844 // from the current tab. | 3981 // from the current tab. |
| 3845 SiteInstance* instance1 = | 3982 SiteInstance* instance1 = |
| 3846 other_controller.GetEntryAtIndex(1)->site_instance(); | 3983 other_controller.GetEntryAtIndex(1)->site_instance(); |
| 3847 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3984 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
| 3848 } | 3985 } |
| 3849 | 3986 |
| 3850 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the | 3987 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the |
| 3851 // source, and 1 entry in the target. The back pending entry should be ignored. | 3988 // source, and 1 entry in the target. The back pending entry should be ignored. |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4192 const GURL url1("http://foo/1"); | 4329 const GURL url1("http://foo/1"); |
| 4193 const GURL url2("http://foo/2"); | 4330 const GURL url2("http://foo/2"); |
| 4194 const GURL url3("http://foo/3"); | 4331 const GURL url3("http://foo/3"); |
| 4195 | 4332 |
| 4196 NavigateAndCommit(url1); | 4333 NavigateAndCommit(url1); |
| 4197 NavigateAndCommit(url2); | 4334 NavigateAndCommit(url2); |
| 4198 | 4335 |
| 4199 // Create a pending entry that is not in the entry list. | 4336 // Create a pending entry that is not in the entry list. |
| 4200 controller.LoadURL( | 4337 controller.LoadURL( |
| 4201 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4338 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4339 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 4202 EXPECT_TRUE(controller.GetPendingEntry()); | 4340 EXPECT_TRUE(controller.GetPendingEntry()); |
| 4203 EXPECT_EQ(2, controller.GetEntryCount()); | 4341 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4204 | 4342 |
| 4205 contents()->ExpectSetHistoryOffsetAndLength(0, 1); | 4343 contents()->ExpectSetHistoryOffsetAndLength(0, 1); |
| 4206 controller.PruneAllButLastCommitted(); | 4344 controller.PruneAllButLastCommitted(); |
| 4207 | 4345 |
| 4208 // We should only have the last committed and pending entries at this point, | 4346 // We should only have the last committed and pending entries at this point, |
| 4209 // and the pending entry should still not be in the entry list. | 4347 // and the pending entry should still not be in the entry list. |
| 4210 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4348 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4211 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4349 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
| 4212 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4350 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4213 EXPECT_TRUE(controller.GetPendingEntry()); | 4351 EXPECT_TRUE(controller.GetPendingEntry()); |
| 4214 EXPECT_EQ(1, controller.GetEntryCount()); | 4352 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4215 | 4353 |
| 4216 // Try to commit the pending entry. | 4354 // Try to commit the pending entry. |
| 4217 main_test_rfh()->PrepareForCommit(); | 4355 main_test_rfh()->PrepareForCommit(); |
| 4218 main_test_rfh()->SendNavigate(2, url3); | 4356 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
| 4219 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4357 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4220 EXPECT_FALSE(controller.GetPendingEntry()); | 4358 EXPECT_FALSE(controller.GetPendingEntry()); |
| 4221 EXPECT_EQ(2, controller.GetEntryCount()); | 4359 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4222 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4360 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
| 4223 } | 4361 } |
| 4224 | 4362 |
| 4225 // Test to ensure that when we do a history navigation back to the current | 4363 // Test to ensure that when we do a history navigation back to the current |
| 4226 // committed page (e.g., going forward to a slow-loading page, then pressing | 4364 // committed page (e.g., going forward to a slow-loading page, then pressing |
| 4227 // the back button), we just stop the navigation to prevent the throbber from | 4365 // the back button), we just stop the navigation to prevent the throbber from |
| 4228 // running continuously. Otherwise, the RenderViewHost forces the throbber to | 4366 // running continuously. Otherwise, the RenderViewHost forces the throbber to |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4250 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 4388 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
| 4251 NavigationControllerImpl& controller = controller_impl(); | 4389 NavigationControllerImpl& controller = controller_impl(); |
| 4252 TestNotificationTracker notifications; | 4390 TestNotificationTracker notifications; |
| 4253 RegisterForAllNavNotifications(¬ifications, &controller); | 4391 RegisterForAllNavNotifications(¬ifications, &controller); |
| 4254 | 4392 |
| 4255 // Initial state. | 4393 // Initial state. |
| 4256 EXPECT_TRUE(controller.IsInitialNavigation()); | 4394 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 4257 | 4395 |
| 4258 // After commit, it stays false. | 4396 // After commit, it stays false. |
| 4259 const GURL url1("http://foo1"); | 4397 const GURL url1("http://foo1"); |
| 4260 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 4398 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
| 4261 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4399 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4262 navigation_entry_committed_counter_ = 0; | 4400 navigation_entry_committed_counter_ = 0; |
| 4263 EXPECT_FALSE(controller.IsInitialNavigation()); | 4401 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 4264 | 4402 |
| 4265 // After starting a new navigation, it stays false. | 4403 // After starting a new navigation, it stays false. |
| 4266 const GURL url2("http://foo2"); | 4404 const GURL url2("http://foo2"); |
| 4267 controller.LoadURL( | 4405 controller.LoadURL( |
| 4268 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4406 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4269 } | 4407 } |
| 4270 | 4408 |
| 4271 // Check that the favicon is not reused across a client redirect. | 4409 // Check that the favicon is not reused across a client redirect. |
| 4272 // (crbug.com/28515) | 4410 // (crbug.com/28515) |
| 4273 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 4411 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
| 4274 const GURL kPageWithFavicon("http://withfavicon.html"); | 4412 const GURL kPageWithFavicon("http://withfavicon.html"); |
| 4275 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 4413 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
| 4276 const GURL kIconURL("http://withfavicon.ico"); | 4414 const GURL kIconURL("http://withfavicon.ico"); |
| 4277 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 4415 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
| 4278 | 4416 |
| 4279 NavigationControllerImpl& controller = controller_impl(); | 4417 NavigationControllerImpl& controller = controller_impl(); |
| 4280 TestNotificationTracker notifications; | 4418 TestNotificationTracker notifications; |
| 4281 RegisterForAllNavNotifications(¬ifications, &controller); | 4419 RegisterForAllNavNotifications(¬ifications, &controller); |
| 4282 | 4420 |
| 4283 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kPageWithFavicon); | 4421 main_test_rfh()->NavigateAndCommitRendererInitiated( |
| 4422 0, true, kPageWithFavicon); |
| 4284 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4423 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4285 navigation_entry_committed_counter_ = 0; | 4424 navigation_entry_committed_counter_ = 0; |
| 4286 | 4425 |
| 4287 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4426 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 4288 EXPECT_TRUE(entry); | 4427 EXPECT_TRUE(entry); |
| 4289 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 4428 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
| 4290 | 4429 |
| 4291 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 4430 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
| 4292 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4431 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
| 4293 favicon_status.image = CreateImage(SK_ColorWHITE); | 4432 favicon_status.image = CreateImage(SK_ColorWHITE); |
| 4294 favicon_status.url = kIconURL; | 4433 favicon_status.url = kIconURL; |
| 4295 favicon_status.valid = true; | 4434 favicon_status.valid = true; |
| 4296 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4435 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
| 4297 | 4436 |
| 4298 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, | 4437 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, |
| 4299 false); | 4438 false); |
| 4300 main_test_rfh()->PrepareForCommit(); | 4439 main_test_rfh()->PrepareForCommit(); |
| 4301 main_test_rfh()->SendNavigateWithTransition( | 4440 main_test_rfh()->SendNavigateWithTransition( |
| 4302 0, // same page ID. | 4441 0, // same page ID. |
| 4303 kPageWithoutFavicon, | 4442 0, // nav_entry_id |
| 4304 ui::PAGE_TRANSITION_CLIENT_REDIRECT); | 4443 false, // no new entry |
| 4444 kPageWithoutFavicon, ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
| 4305 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4445 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4306 navigation_entry_committed_counter_ = 0; | 4446 navigation_entry_committed_counter_ = 0; |
| 4307 | 4447 |
| 4308 entry = controller.GetLastCommittedEntry(); | 4448 entry = controller.GetLastCommittedEntry(); |
| 4309 EXPECT_TRUE(entry); | 4449 EXPECT_TRUE(entry); |
| 4310 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 4450 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
| 4311 | 4451 |
| 4312 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4452 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
| 4313 } | 4453 } |
| 4314 | 4454 |
| 4315 // Check that the favicon is not cleared for NavigationEntries which were | 4455 // Check that the favicon is not cleared for NavigationEntries which were |
| 4316 // previously navigated to. | 4456 // previously navigated to. |
| 4317 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 4457 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
| 4318 const GURL kUrl1("http://www.a.com/1"); | 4458 const GURL kUrl1("http://www.a.com/1"); |
| 4319 const GURL kUrl2("http://www.a.com/2"); | 4459 const GURL kUrl2("http://www.a.com/2"); |
| 4320 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 4460 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
| 4321 | 4461 |
| 4322 NavigationControllerImpl& controller = controller_impl(); | 4462 NavigationControllerImpl& controller = controller_impl(); |
| 4323 TestNotificationTracker notifications; | 4463 TestNotificationTracker notifications; |
| 4324 RegisterForAllNavNotifications(¬ifications, &controller); | 4464 RegisterForAllNavNotifications(¬ifications, &controller); |
| 4325 | 4465 |
| 4326 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); | 4466 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, kUrl1); |
| 4327 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4467 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4328 navigation_entry_committed_counter_ = 0; | 4468 navigation_entry_committed_counter_ = 0; |
| 4329 | 4469 |
| 4330 // Simulate Chromium having set the favicon for |kUrl1|. | 4470 // Simulate Chromium having set the favicon for |kUrl1|. |
| 4331 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); | 4471 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); |
| 4332 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4472 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 4333 EXPECT_TRUE(entry); | 4473 EXPECT_TRUE(entry); |
| 4334 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4474 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
| 4335 favicon_status.image = favicon_image; | 4475 favicon_status.image = favicon_image; |
| 4336 favicon_status.url = kIconURL; | 4476 favicon_status.url = kIconURL; |
| 4337 favicon_status.valid = true; | 4477 favicon_status.valid = true; |
| 4338 | 4478 |
| 4339 // Navigate to another page and go back to the original page. | 4479 // Navigate to another page and go back to the original page. |
| 4340 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); | 4480 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, kUrl2); |
| 4341 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4481 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4342 navigation_entry_committed_counter_ = 0; | 4482 navigation_entry_committed_counter_ = 0; |
| 4343 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); | 4483 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); |
| 4344 main_test_rfh()->PrepareForCommit(); | 4484 main_test_rfh()->PrepareForCommit(); |
| 4345 main_test_rfh()->SendNavigateWithTransition( | 4485 main_test_rfh()->SendNavigateWithTransition( |
| 4346 0, | 4486 0, controller.GetEntryAtIndex(0)->GetUniqueID(), false, kUrl1, |
| 4347 kUrl1, | |
| 4348 ui::PAGE_TRANSITION_FORWARD_BACK); | 4487 ui::PAGE_TRANSITION_FORWARD_BACK); |
| 4349 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4488 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 4350 navigation_entry_committed_counter_ = 0; | 4489 navigation_entry_committed_counter_ = 0; |
| 4351 | 4490 |
| 4352 // Verify that the favicon for the page at |kUrl1| was not cleared. | 4491 // Verify that the favicon for the page at |kUrl1| was not cleared. |
| 4353 entry = controller.GetEntryAtIndex(0); | 4492 entry = controller.GetEntryAtIndex(0); |
| 4354 EXPECT_TRUE(entry); | 4493 EXPECT_TRUE(entry); |
| 4355 EXPECT_EQ(kUrl1, entry->GetURL()); | 4494 EXPECT_EQ(kUrl1, entry->GetURL()); |
| 4356 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); | 4495 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); |
| 4357 } | 4496 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4438 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); | 4577 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); |
| 4439 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4578 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
| 4440 entry = controller.GetEntryAtIndex(i); | 4579 entry = controller.GetEntryAtIndex(i); |
| 4441 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4580 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
| 4442 << " not cleared"; | 4581 << " not cleared"; |
| 4443 } | 4582 } |
| 4444 } | 4583 } |
| 4445 | 4584 |
| 4446 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { | 4585 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { |
| 4447 // Navigate. | 4586 // Navigate. |
| 4448 main_test_rfh()->NavigateAndCommitRendererInitiated(1, GURL("http://foo")); | 4587 main_test_rfh()->NavigateAndCommitRendererInitiated( |
| 4588 1, true, GURL("http://foo")); |
| 4449 | 4589 |
| 4450 // Set title and favicon. | 4590 // Set title and favicon. |
| 4451 base::string16 title(base::ASCIIToUTF16("Title")); | 4591 base::string16 title(base::ASCIIToUTF16("Title")); |
| 4452 FaviconStatus favicon; | 4592 FaviconStatus favicon; |
| 4453 favicon.valid = true; | 4593 favicon.valid = true; |
| 4454 favicon.url = GURL("http://foo/favicon.ico"); | 4594 favicon.url = GURL("http://foo/favicon.ico"); |
| 4455 controller().GetLastCommittedEntry()->SetTitle(title); | 4595 controller().GetLastCommittedEntry()->SetTitle(title); |
| 4456 controller().GetLastCommittedEntry()->GetFavicon() = favicon; | 4596 controller().GetLastCommittedEntry()->GetFavicon() = favicon; |
| 4457 | 4597 |
| 4458 // history.pushState() is called. | 4598 // history.pushState() is called. |
| 4459 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4599 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 4460 GURL kUrl2("http://foo#foo"); | 4600 GURL kUrl2("http://foo#foo"); |
| 4461 params.page_id = 2; | 4601 params.page_id = 2; |
| 4602 params.nav_entry_id = 0; |
| 4603 params.did_create_new_entry = true; |
| 4462 params.url = kUrl2; | 4604 params.url = kUrl2; |
| 4463 params.page_state = PageState::CreateFromURL(kUrl2); | 4605 params.page_state = PageState::CreateFromURL(kUrl2); |
| 4464 params.was_within_same_page = true; | 4606 params.was_within_same_page = true; |
| 4465 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); | 4607 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); |
| 4466 main_test_rfh()->PrepareForCommit(); | 4608 main_test_rfh()->PrepareForCommit(); |
| 4467 main_test_rfh()->SendNavigateWithParams(¶ms); | 4609 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 4468 | 4610 |
| 4469 // The title should immediately be visible on the new NavigationEntry. | 4611 // The title should immediately be visible on the new NavigationEntry. |
| 4470 base::string16 new_title = | 4612 base::string16 new_title = |
| 4471 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); | 4613 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4530 | 4672 |
| 4531 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { | 4673 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { |
| 4532 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 4674 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
| 4533 EXPECT_FALSE(contents()->GetDelegate()); | 4675 EXPECT_FALSE(contents()->GetDelegate()); |
| 4534 contents()->SetDelegate(delegate.get()); | 4676 contents()->SetDelegate(delegate.get()); |
| 4535 | 4677 |
| 4536 // Submit a form. | 4678 // Submit a form. |
| 4537 GURL url("http://foo"); | 4679 GURL url("http://foo"); |
| 4538 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4680 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 4539 params.page_id = 1; | 4681 params.page_id = 1; |
| 4682 params.nav_entry_id = 0; |
| 4683 params.did_create_new_entry = true; |
| 4540 params.url = url; | 4684 params.url = url; |
| 4541 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; | 4685 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; |
| 4542 params.gesture = NavigationGestureUser; | 4686 params.gesture = NavigationGestureUser; |
| 4543 params.page_state = PageState::CreateFromURL(url); | 4687 params.page_state = PageState::CreateFromURL(url); |
| 4544 params.was_within_same_page = false; | 4688 params.was_within_same_page = false; |
| 4545 params.is_post = true; | 4689 params.is_post = true; |
| 4546 params.post_id = 2; | 4690 params.post_id = 2; |
| 4547 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 4691 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
| 4548 main_test_rfh()->PrepareForCommit(); | 4692 main_test_rfh()->PrepareForCommit(); |
| 4549 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4693 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
| 4550 | 4694 |
| 4551 // history.replaceState() is called. | 4695 // history.replaceState() is called. |
| 4552 GURL replace_url("http://foo#foo"); | 4696 GURL replace_url("http://foo#foo"); |
| 4553 params.page_id = 1; | 4697 params.page_id = 1; |
| 4698 params.nav_entry_id = 0; |
| 4699 params.did_create_new_entry = false; |
| 4554 params.url = replace_url; | 4700 params.url = replace_url; |
| 4555 params.transition = ui::PAGE_TRANSITION_LINK; | 4701 params.transition = ui::PAGE_TRANSITION_LINK; |
| 4556 params.gesture = NavigationGestureUser; | 4702 params.gesture = NavigationGestureUser; |
| 4557 params.page_state = PageState::CreateFromURL(replace_url); | 4703 params.page_state = PageState::CreateFromURL(replace_url); |
| 4558 params.was_within_same_page = true; | 4704 params.was_within_same_page = true; |
| 4559 params.is_post = false; | 4705 params.is_post = false; |
| 4560 params.post_id = -1; | 4706 params.post_id = -1; |
| 4561 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); | 4707 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); |
| 4562 main_test_rfh()->PrepareForCommit(); | 4708 main_test_rfh()->PrepareForCommit(); |
| 4563 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4709 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
| 4564 | 4710 |
| 4565 // Now reload. replaceState overrides the POST, so we should not show a | 4711 // Now reload. replaceState overrides the POST, so we should not show a |
| 4566 // repost warning dialog. | 4712 // repost warning dialog. |
| 4567 controller_impl().Reload(true); | 4713 controller_impl().Reload(true); |
| 4568 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4714 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
| 4569 } | 4715 } |
| 4570 | 4716 |
| 4571 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { | 4717 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| 4572 GURL url("http://foo"); | 4718 GURL url("http://foo"); |
| 4573 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4719 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 4574 params.page_id = 1; | 4720 params.page_id = 1; |
| 4721 params.nav_entry_id = 0; |
| 4722 params.did_create_new_entry = true; |
| 4575 params.url = url; | 4723 params.url = url; |
| 4576 params.transition = ui::PAGE_TRANSITION_LINK; | 4724 params.transition = ui::PAGE_TRANSITION_LINK; |
| 4577 params.gesture = NavigationGestureUser; | 4725 params.gesture = NavigationGestureUser; |
| 4578 params.page_state = PageState::CreateFromURL(url); | 4726 params.page_state = PageState::CreateFromURL(url); |
| 4579 params.was_within_same_page = false; | 4727 params.was_within_same_page = false; |
| 4580 params.is_post = true; | 4728 params.is_post = true; |
| 4581 params.post_id = 2; | 4729 params.post_id = 2; |
| 4582 params.url_is_unreachable = true; | 4730 params.url_is_unreachable = true; |
| 4583 // Navigate to new page | 4731 |
| 4732 // Navigate to new page. |
| 4584 { | 4733 { |
| 4585 LoadCommittedDetails details; | 4734 LoadCommittedDetails details; |
| 4586 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4735 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4587 EXPECT_EQ(PAGE_TYPE_ERROR, | 4736 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4588 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4737 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4589 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); | 4738 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); |
| 4590 } | 4739 } |
| 4591 | 4740 |
| 4592 // Navigate to existing page. | 4741 // Navigate to existing page. |
| 4593 { | 4742 { |
| 4743 params.did_create_new_entry = false; |
| 4594 LoadCommittedDetails details; | 4744 LoadCommittedDetails details; |
| 4595 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4745 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4596 EXPECT_EQ(PAGE_TYPE_ERROR, | 4746 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4597 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4747 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4598 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); | 4748 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); |
| 4599 } | 4749 } |
| 4600 | 4750 |
| 4601 // Navigate to same page. | 4751 // Navigate to same page. |
| 4602 // Note: The call to LoadURL() creates a pending entry in order to trigger the | 4752 // Note: The call to LoadURL() creates a pending entry in order to trigger the |
| 4603 // same-page transition. | 4753 // same-page transition. |
| 4604 controller_impl().LoadURL( | 4754 controller_impl().LoadURL( |
| 4605 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4755 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4756 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); |
| 4606 params.transition = ui::PAGE_TRANSITION_TYPED; | 4757 params.transition = ui::PAGE_TRANSITION_TYPED; |
| 4607 { | 4758 { |
| 4608 LoadCommittedDetails details; | 4759 LoadCommittedDetails details; |
| 4609 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4760 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4610 EXPECT_EQ(PAGE_TYPE_ERROR, | 4761 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4611 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4762 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4612 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); | 4763 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); |
| 4613 } | 4764 } |
| 4614 | 4765 |
| 4615 // Navigate in page. | 4766 // Navigate in page. |
| 4616 params.url = GURL("http://foo#foo"); | 4767 params.url = GURL("http://foo#foo"); |
| 4617 params.transition = ui::PAGE_TRANSITION_LINK; | 4768 params.transition = ui::PAGE_TRANSITION_LINK; |
| 4618 params.was_within_same_page = true; | 4769 params.was_within_same_page = true; |
| 4619 { | 4770 { |
| 4620 LoadCommittedDetails details; | 4771 LoadCommittedDetails details; |
| 4621 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4772 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4622 EXPECT_EQ(PAGE_TYPE_ERROR, | 4773 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4623 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4774 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4624 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4775 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
| 4625 } | 4776 } |
| 4626 } | 4777 } |
| 4627 | 4778 |
| 4628 } // namespace content | 4779 } // namespace content |
| OLD | NEW |