Chromium Code Reviews| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/frame_host/cross_site_transferring_request.h" | 14 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 15 #include "content/browser/frame_host/navigation_controller_impl.h" | 15 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 16 #include "content/browser/frame_host/navigation_entry_impl.h" | 16 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| 18 #include "content/browser/frame_host/navigation_request.h" | |
| 18 #include "content/browser/frame_host/navigator.h" | 19 #include "content/browser/frame_host/navigator.h" |
| 20 #include "content/browser/frame_host/navigator_impl.h" | |
| 19 #include "content/browser/site_instance_impl.h" | 21 #include "content/browser/site_instance_impl.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/common/frame_messages.h" | 23 #include "content/common/frame_messages.h" |
| 22 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 23 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
| 25 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 208 } |
| 207 | 209 |
| 208 const GURL& navigated_url() const { | 210 const GURL& navigated_url() const { |
| 209 return navigated_url_; | 211 return navigated_url_; |
| 210 } | 212 } |
| 211 | 213 |
| 212 NavigationControllerImpl& controller_impl() { | 214 NavigationControllerImpl& controller_impl() { |
| 213 return static_cast<NavigationControllerImpl&>(controller()); | 215 return static_cast<NavigationControllerImpl&>(controller()); |
| 214 } | 216 } |
| 215 | 217 |
| 216 const IPC::Message* GetLastNavigationRequest() { | 218 const bool HasNavigationRequest() { |
| 217 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 219 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 218 switches::kEnableBrowserSideNavigation)) { | 220 switches::kEnableBrowserSideNavigation)) { |
| 219 return process()->sink().GetFirstMessageMatching( | 221 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 220 FrameMsg_RequestNavigation::ID); | 222 NavigationRequest* navigation_request = static_cast<NavigatorImpl*>( |
| 223 root->navigator())->GetNavigationRequestForNodeForTesting(root); | |
| 224 return navigation_request != nullptr; | |
| 221 } | 225 } |
| 222 return process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); | 226 return process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID) |
| 227 != nullptr; | |
| 223 } | 228 } |
| 224 | 229 |
| 225 const GURL GetNavigationURLFromIPC(const IPC::Message* message) { | 230 const GURL GetLastNavigationURL() { |
| 226 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 231 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 227 switches::kEnableBrowserSideNavigation)) { | 232 switches::kEnableBrowserSideNavigation)) { |
| 228 Tuple<CommonNavigationParams, RequestNavigationParams> nav_params; | 233 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 229 FrameMsg_RequestNavigation::Read(message, &nav_params); | 234 NavigationRequest* navigation_request = static_cast<NavigatorImpl*>( |
| 230 return get<0>(nav_params).url; | 235 root->navigator())->GetNavigationRequestForNodeForTesting(root); |
| 236 CHECK(navigation_request); | |
| 237 return navigation_request->common_params().url; | |
| 231 } | 238 } |
| 239 const IPC::Message* message = | |
| 240 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); | |
| 241 CHECK(message); | |
| 232 Tuple<FrameMsg_Navigate_Params> nav_params; | 242 Tuple<FrameMsg_Navigate_Params> nav_params; |
| 233 FrameMsg_Navigate::Read(message, &nav_params); | 243 FrameMsg_Navigate::Read(message, &nav_params); |
| 234 return get<0>(nav_params).common_params.url; | 244 return get<0>(nav_params).common_params.url; |
| 235 } | 245 } |
| 236 | 246 |
| 237 protected: | 247 protected: |
| 238 GURL navigated_url_; | 248 GURL navigated_url_; |
| 239 size_t navigation_entry_committed_counter_; | 249 size_t navigation_entry_committed_counter_; |
| 240 }; | 250 }; |
| 241 | 251 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 NavigationControllerImpl& controller = controller_impl(); | 312 NavigationControllerImpl& controller = controller_impl(); |
| 303 TestNotificationTracker notifications; | 313 TestNotificationTracker notifications; |
| 304 RegisterForAllNavNotifications(¬ifications, &controller); | 314 RegisterForAllNavNotifications(¬ifications, &controller); |
| 305 | 315 |
| 306 const int kNumUrls = 5; | 316 const int kNumUrls = 5; |
| 307 std::vector<GURL> urls(kNumUrls); | 317 std::vector<GURL> urls(kNumUrls); |
| 308 for (int i = 0; i < kNumUrls; ++i) { | 318 for (int i = 0; i < kNumUrls; ++i) { |
| 309 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 319 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
| 310 } | 320 } |
| 311 | 321 |
| 322 main_test_rfh()->PrepareForCommit(urls[0]); | |
|
carlosk
2015/02/03 16:06:02
As PrepareForCommit has ASSERTs in its implementat
clamy
2015/02/03 16:17:09
Interesting. I'm not planning to change that in th
| |
| 312 main_test_rfh()->SendNavigate(0, urls[0]); | 323 main_test_rfh()->SendNavigate(0, urls[0]); |
| 313 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 324 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 314 navigation_entry_committed_counter_ = 0; | 325 navigation_entry_committed_counter_ = 0; |
| 315 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 326 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
| 316 EXPECT_FALSE(controller.CanGoBack()); | 327 EXPECT_FALSE(controller.CanGoBack()); |
| 317 EXPECT_FALSE(controller.CanGoForward()); | 328 EXPECT_FALSE(controller.CanGoForward()); |
| 318 EXPECT_FALSE(controller.CanGoToOffset(1)); | 329 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 319 | 330 |
| 320 for (int i = 1; i <= 4; ++i) { | 331 for (int i = 1; i <= 4; ++i) { |
| 332 main_test_rfh()->PrepareForCommit(urls[i]); | |
| 321 main_test_rfh()->SendNavigate(i, urls[i]); | 333 main_test_rfh()->SendNavigate(i, urls[i]); |
| 322 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 334 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 323 navigation_entry_committed_counter_ = 0; | 335 navigation_entry_committed_counter_ = 0; |
| 324 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 336 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
| 325 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 337 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
| 326 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 338 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
| 327 EXPECT_FALSE(controller.CanGoToOffset(1)); | 339 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 328 } | 340 } |
| 329 | 341 |
| 330 // We have loaded 5 pages, and are currently at the last-loaded page. | 342 // We have loaded 5 pages, and are currently at the last-loaded page. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 346 GO_TO_BEGINNING, | 358 GO_TO_BEGINNING, |
| 347 GO_TO_END | 359 GO_TO_END |
| 348 }; | 360 }; |
| 349 | 361 |
| 350 for (int test = 0; test < NUM_TESTS; ++test) { | 362 for (int test = 0; test < NUM_TESTS; ++test) { |
| 351 int offset = test_offsets[test]; | 363 int offset = test_offsets[test]; |
| 352 controller.GoToOffset(offset); | 364 controller.GoToOffset(offset); |
| 353 url_index += offset; | 365 url_index += offset; |
| 354 // Check that the GoToOffset will land on the expected page. | 366 // Check that the GoToOffset will land on the expected page. |
| 355 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 367 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
| 368 main_test_rfh()->PrepareForCommit(urls[url_index]); | |
| 356 main_test_rfh()->SendNavigate(url_index, urls[url_index]); | 369 main_test_rfh()->SendNavigate(url_index, urls[url_index]); |
| 357 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 370 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 358 navigation_entry_committed_counter_ = 0; | 371 navigation_entry_committed_counter_ = 0; |
| 359 // Check that we can go to any valid offset into the history. | 372 // Check that we can go to any valid offset into the history. |
| 360 for (size_t j = 0; j < urls.size(); ++j) | 373 for (size_t j = 0; j < urls.size(); ++j) |
| 361 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 374 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
| 362 // Check that we can't go beyond the beginning or end of the history. | 375 // Check that we can't go beyond the beginning or end of the history. |
| 363 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 376 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
| 364 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 377 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
| 365 } | 378 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 // Set the clock to always return a timestamp of 1. | 486 // Set the clock to always return a timestamp of 1. |
| 474 controller.SetGetTimestampCallbackForTest( | 487 controller.SetGetTimestampCallbackForTest( |
| 475 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 488 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
| 476 | 489 |
| 477 const GURL url1("http://foo1"); | 490 const GURL url1("http://foo1"); |
| 478 const GURL url2("http://foo2"); | 491 const GURL url2("http://foo2"); |
| 479 | 492 |
| 480 controller.LoadURL( | 493 controller.LoadURL( |
| 481 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 494 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 482 | 495 |
| 496 main_test_rfh()->PrepareForCommit(url1); | |
| 483 main_test_rfh()->SendNavigate(0, url1); | 497 main_test_rfh()->SendNavigate(0, url1); |
| 484 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 498 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 485 navigation_entry_committed_counter_ = 0; | 499 navigation_entry_committed_counter_ = 0; |
| 486 | 500 |
| 487 // Load another... | 501 // Load another... |
| 488 controller.LoadURL( | 502 controller.LoadURL( |
| 489 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 503 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 490 | 504 |
| 491 // Simulate the beforeunload ack for the cross-site transition, and then the | 505 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 492 // commit. | 506 // commit. |
| 493 main_test_rfh()->SendBeforeUnloadACK(true); | 507 main_test_rfh()->PrepareForCommit(url2); |
| 494 main_test_rfh()->SendNavigate(1, url2); | 508 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
| 495 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 509 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 496 navigation_entry_committed_counter_ = 0; | 510 navigation_entry_committed_counter_ = 0; |
| 497 | 511 |
| 498 // The two loads should now be committed. | 512 // The two loads should now be committed. |
| 499 ASSERT_EQ(controller.GetEntryCount(), 2); | 513 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 500 | 514 |
| 501 // Timestamps should be distinct despite the clock returning the | 515 // Timestamps should be distinct despite the clock returning the |
| 502 // same value. | 516 // same value. |
| 503 EXPECT_EQ(1u, | 517 EXPECT_EQ(1u, |
| 504 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); | 518 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 622 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
| 609 NavigationControllerImpl& controller = controller_impl(); | 623 NavigationControllerImpl& controller = controller_impl(); |
| 610 TestNotificationTracker notifications; | 624 TestNotificationTracker notifications; |
| 611 RegisterForAllNavNotifications(¬ifications, &controller); | 625 RegisterForAllNavNotifications(¬ifications, &controller); |
| 612 | 626 |
| 613 const GURL url1("http://foo1"); | 627 const GURL url1("http://foo1"); |
| 614 | 628 |
| 615 controller.LoadURL( | 629 controller.LoadURL( |
| 616 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 630 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 617 EXPECT_EQ(0U, notifications.size()); | 631 EXPECT_EQ(0U, notifications.size()); |
| 632 main_test_rfh()->PrepareForCommit(url1); | |
| 618 main_test_rfh()->SendNavigate(0, url1); | 633 main_test_rfh()->SendNavigate(0, url1); |
| 619 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 634 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 620 navigation_entry_committed_counter_ = 0; | 635 navigation_entry_committed_counter_ = 0; |
| 621 | 636 |
| 622 ASSERT_TRUE(controller.GetVisibleEntry()); | 637 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 623 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 638 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 624 EXPECT_FALSE(timestamp.is_null()); | 639 EXPECT_FALSE(timestamp.is_null()); |
| 625 | 640 |
| 626 controller.LoadURL( | 641 controller.LoadURL( |
| 627 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 642 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 628 EXPECT_EQ(0U, notifications.size()); | 643 EXPECT_EQ(0U, notifications.size()); |
| 644 main_test_rfh()->PrepareForCommit(url1); | |
| 629 main_test_rfh()->SendNavigate(0, url1); | 645 main_test_rfh()->SendNavigate(0, url1); |
| 630 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 646 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 631 navigation_entry_committed_counter_ = 0; | 647 navigation_entry_committed_counter_ = 0; |
| 632 | 648 |
| 633 // We should not have produced a new session history entry. | 649 // We should not have produced a new session history entry. |
| 634 EXPECT_EQ(controller.GetEntryCount(), 1); | 650 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 635 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 651 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 636 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 652 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 637 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 653 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 638 EXPECT_FALSE(controller.GetPendingEntry()); | 654 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 658 | 674 |
| 659 controller.LoadURL( | 675 controller.LoadURL( |
| 660 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 676 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 661 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 677 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 662 params.page_id = 0; | 678 params.page_id = 0; |
| 663 params.url = url1; | 679 params.url = url1; |
| 664 params.transition = ui::PAGE_TRANSITION_TYPED; | 680 params.transition = ui::PAGE_TRANSITION_TYPED; |
| 665 params.is_post = true; | 681 params.is_post = true; |
| 666 params.post_id = 123; | 682 params.post_id = 123; |
| 667 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 683 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
| 684 main_test_rfh()->PrepareForCommit(url1); | |
| 668 main_test_rfh()->SendNavigateWithParams(¶ms); | 685 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 669 | 686 |
| 670 // The post data should be visible. | 687 // The post data should be visible. |
| 671 NavigationEntry* entry = controller.GetVisibleEntry(); | 688 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 672 ASSERT_TRUE(entry); | 689 ASSERT_TRUE(entry); |
| 673 EXPECT_TRUE(entry->GetHasPostData()); | 690 EXPECT_TRUE(entry->GetHasPostData()); |
| 674 EXPECT_EQ(entry->GetPostID(), 123); | 691 EXPECT_EQ(entry->GetPostID(), 123); |
| 675 | 692 |
| 676 controller.LoadURL( | 693 controller.LoadURL( |
| 677 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 694 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 695 main_test_rfh()->PrepareForCommit(url1); | |
| 678 main_test_rfh()->SendNavigate(0, url1); | 696 main_test_rfh()->SendNavigate(0, url1); |
| 679 | 697 |
| 680 // We should not have produced a new session history entry. | 698 // We should not have produced a new session history entry. |
| 681 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 699 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
| 682 | 700 |
| 683 // The post data should have been cleared due to the GET. | 701 // The post data should have been cleared due to the GET. |
| 684 EXPECT_FALSE(entry->GetHasPostData()); | 702 EXPECT_FALSE(entry->GetHasPostData()); |
| 685 EXPECT_EQ(entry->GetPostID(), 0); | 703 EXPECT_EQ(entry->GetPostID(), 0); |
| 686 } | 704 } |
| 687 | 705 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 // commits. | 776 // commits. |
| 759 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 777 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 760 NavigationControllerImpl& controller = controller_impl(); | 778 NavigationControllerImpl& controller = controller_impl(); |
| 761 TestNotificationTracker notifications; | 779 TestNotificationTracker notifications; |
| 762 RegisterForAllNavNotifications(¬ifications, &controller); | 780 RegisterForAllNavNotifications(¬ifications, &controller); |
| 763 | 781 |
| 764 // First make an existing committed entry. | 782 // First make an existing committed entry. |
| 765 const GURL kExistingURL1("http://eh"); | 783 const GURL kExistingURL1("http://eh"); |
| 766 controller.LoadURL( | 784 controller.LoadURL( |
| 767 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 785 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 786 main_test_rfh()->PrepareForCommit(kExistingURL1); | |
| 768 main_test_rfh()->SendNavigate(0, kExistingURL1); | 787 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 769 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 788 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 770 navigation_entry_committed_counter_ = 0; | 789 navigation_entry_committed_counter_ = 0; |
| 771 | 790 |
| 772 // Make a pending entry to somewhere new. | 791 // Make a pending entry to somewhere new. |
| 773 const GURL kExistingURL2("http://bee"); | 792 const GURL kExistingURL2("http://bee"); |
| 774 controller.LoadURL( | 793 controller.LoadURL( |
| 775 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 794 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 776 EXPECT_EQ(0U, notifications.size()); | 795 EXPECT_EQ(0U, notifications.size()); |
| 777 | 796 |
| 778 // After the beforeunload but before it commits, do a new navigation. | 797 // After the beforeunload but before it commits, do a new navigation. |
| 779 main_test_rfh()->PrepareForCommit(kExistingURL2); | 798 main_test_rfh()->PrepareForCommit(kExistingURL2); |
| 780 const GURL kNewURL("http://see"); | 799 const GURL kNewURL("http://see"); |
| 800 main_test_rfh()->PrepareForCommit(kNewURL); | |
| 781 contents()->GetMainFrame()->SendNavigate(3, kNewURL); | 801 contents()->GetMainFrame()->SendNavigate(3, kNewURL); |
| 782 | 802 |
| 783 // There should no longer be any pending entry, and the third navigation we | 803 // There should no longer be any pending entry, and the third navigation we |
| 784 // just made should be committed. | 804 // just made should be committed. |
| 785 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 805 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 786 navigation_entry_committed_counter_ = 0; | 806 navigation_entry_committed_counter_ = 0; |
| 787 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 807 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 788 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 808 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 789 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 809 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 790 } | 810 } |
| 791 | 811 |
| 792 // Tests navigating to a new URL when there is a pending back/forward | 812 // Tests navigating to a new URL when there is a pending back/forward |
| 793 // navigation. This will happen if the user hits back, but before that commits, | 813 // navigation. This will happen if the user hits back, but before that commits, |
| 794 // they navigate somewhere new. | 814 // they navigate somewhere new. |
| 795 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 815 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 796 NavigationControllerImpl& controller = controller_impl(); | 816 NavigationControllerImpl& controller = controller_impl(); |
| 797 TestNotificationTracker notifications; | 817 TestNotificationTracker notifications; |
| 798 RegisterForAllNavNotifications(¬ifications, &controller); | 818 RegisterForAllNavNotifications(¬ifications, &controller); |
| 799 | 819 |
| 800 // First make some history. | 820 // First make some history. |
| 801 const GURL kExistingURL1("http://foo/eh"); | 821 const GURL kExistingURL1("http://foo/eh"); |
| 802 controller.LoadURL( | 822 controller.LoadURL( |
| 803 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 823 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 824 main_test_rfh()->PrepareForCommit(kExistingURL1); | |
| 804 main_test_rfh()->SendNavigate(0, kExistingURL1); | 825 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 805 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 826 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 806 navigation_entry_committed_counter_ = 0; | 827 navigation_entry_committed_counter_ = 0; |
| 807 | 828 |
| 808 const GURL kExistingURL2("http://foo/bee"); | 829 const GURL kExistingURL2("http://foo/bee"); |
| 809 controller.LoadURL( | 830 controller.LoadURL( |
| 810 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 831 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 832 main_test_rfh()->PrepareForCommit(kExistingURL2); | |
| 811 main_test_rfh()->SendNavigate(1, kExistingURL2); | 833 main_test_rfh()->SendNavigate(1, kExistingURL2); |
| 812 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 834 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 813 navigation_entry_committed_counter_ = 0; | 835 navigation_entry_committed_counter_ = 0; |
| 814 | 836 |
| 815 // Now make a pending back/forward navigation. The zeroth entry should be | 837 // Now make a pending back/forward navigation. The zeroth entry should be |
| 816 // pending. | 838 // pending. |
| 817 controller.GoBack(); | 839 controller.GoBack(); |
| 818 EXPECT_EQ(0U, notifications.size()); | 840 EXPECT_EQ(0U, notifications.size()); |
| 819 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 841 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 820 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 842 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 821 | 843 |
| 822 // Before that commits, do a new navigation. | 844 // Before that commits, do a new navigation. |
| 823 const GURL kNewURL("http://foo/see"); | 845 const GURL kNewURL("http://foo/see"); |
| 846 main_test_rfh()->PrepareForCommit(kNewURL); | |
| 824 main_test_rfh()->SendNavigate(3, kNewURL); | 847 main_test_rfh()->SendNavigate(3, kNewURL); |
| 825 | 848 |
| 826 // There should no longer be any pending entry, and the third navigation we | 849 // There should no longer be any pending entry, and the third navigation we |
| 827 // just made should be committed. | 850 // just made should be committed. |
| 828 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 851 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 829 navigation_entry_committed_counter_ = 0; | 852 navigation_entry_committed_counter_ = 0; |
| 830 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 853 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 831 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 854 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 832 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 855 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 833 } | 856 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 controller.GoBack(); | 889 controller.GoBack(); |
| 867 foo_rfh->SendBeforeUnloadACK(true); | 890 foo_rfh->SendBeforeUnloadACK(true); |
| 868 EXPECT_EQ(0U, notifications.size()); | 891 EXPECT_EQ(0U, notifications.size()); |
| 869 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 892 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 870 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 893 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 871 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( | 894 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( |
| 872 controller.GetPendingEntry())->bindings()); | 895 controller.GetPendingEntry())->bindings()); |
| 873 | 896 |
| 874 // Before that commits, do a new navigation. | 897 // Before that commits, do a new navigation. |
| 875 const GURL kNewURL("http://foo/bee"); | 898 const GURL kNewURL("http://foo/bee"); |
| 899 foo_rfh->PrepareForCommit(kNewURL); | |
| 876 foo_rfh->SendNavigate(3, kNewURL); | 900 foo_rfh->SendNavigate(3, kNewURL); |
| 877 | 901 |
| 878 // There should no longer be any pending entry, and the third navigation we | 902 // There should no longer be any pending entry, and the third navigation we |
| 879 // just made should be committed. | 903 // just made should be committed. |
| 880 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 904 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 881 navigation_entry_committed_counter_ = 0; | 905 navigation_entry_committed_counter_ = 0; |
| 882 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 906 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 883 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 907 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 884 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 908 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 885 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 909 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 886 controller.GetLastCommittedEntry())->bindings()); | 910 controller.GetLastCommittedEntry())->bindings()); |
| 887 } | 911 } |
| 888 | 912 |
| 889 // Tests navigating to an existing URL when there is a pending new navigation. | 913 // Tests navigating to an existing URL when there is a pending new navigation. |
| 890 // This will happen if the user enters a URL, but before that commits, the | 914 // This will happen if the user enters a URL, but before that commits, the |
| 891 // current page fires history.back(). | 915 // current page fires history.back(). |
| 892 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 916 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 893 NavigationControllerImpl& controller = controller_impl(); | 917 NavigationControllerImpl& controller = controller_impl(); |
| 894 TestNotificationTracker notifications; | 918 TestNotificationTracker notifications; |
| 895 RegisterForAllNavNotifications(¬ifications, &controller); | 919 RegisterForAllNavNotifications(¬ifications, &controller); |
| 896 | 920 |
| 897 // First make some history. | 921 // First make some history. |
| 898 const GURL kExistingURL1("http://foo/eh"); | 922 const GURL kExistingURL1("http://foo/eh"); |
| 899 controller.LoadURL( | 923 controller.LoadURL( |
| 900 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 924 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 925 main_test_rfh()->PrepareForCommit(kExistingURL1); | |
| 901 main_test_rfh()->SendNavigate(0, kExistingURL1); | 926 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 902 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 927 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 903 navigation_entry_committed_counter_ = 0; | 928 navigation_entry_committed_counter_ = 0; |
| 904 | 929 |
| 905 const GURL kExistingURL2("http://foo/bee"); | 930 const GURL kExistingURL2("http://foo/bee"); |
| 906 controller.LoadURL( | 931 controller.LoadURL( |
| 907 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 932 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 933 main_test_rfh()->PrepareForCommit(kExistingURL2); | |
| 908 main_test_rfh()->SendNavigate(1, kExistingURL2); | 934 main_test_rfh()->SendNavigate(1, kExistingURL2); |
| 909 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 935 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 910 navigation_entry_committed_counter_ = 0; | 936 navigation_entry_committed_counter_ = 0; |
| 911 | 937 |
| 912 // Now make a pending new navigation. | 938 // Now make a pending new navigation. |
| 913 const GURL kNewURL("http://foo/see"); | 939 const GURL kNewURL("http://foo/see"); |
| 914 controller.LoadURL( | 940 controller.LoadURL( |
| 915 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 941 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 916 EXPECT_EQ(0U, notifications.size()); | 942 EXPECT_EQ(0U, notifications.size()); |
| 917 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 943 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 918 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 944 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 919 | 945 |
| 920 // Before that commits, a back navigation from the renderer commits. | 946 // Before that commits, a back navigation from the renderer commits. |
| 947 main_test_rfh()->PrepareForCommit(kExistingURL1); | |
| 921 main_test_rfh()->SendNavigate(0, kExistingURL1); | 948 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 922 | 949 |
| 923 // There should no longer be any pending entry, and the back navigation we | 950 // There should no longer be any pending entry, and the back navigation we |
| 924 // just made should be committed. | 951 // just made should be committed. |
| 925 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 952 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 926 navigation_entry_committed_counter_ = 0; | 953 navigation_entry_committed_counter_ = 0; |
| 927 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 954 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 928 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 955 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 929 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 956 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
| 930 } | 957 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 950 controller.LoadURL( | 977 controller.LoadURL( |
| 951 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 978 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 952 EXPECT_EQ(0U, notifications.size()); | 979 EXPECT_EQ(0U, notifications.size()); |
| 953 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 980 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 954 EXPECT_TRUE(controller.GetPendingEntry()); | 981 EXPECT_TRUE(controller.GetPendingEntry()); |
| 955 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 982 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 956 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 983 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 957 | 984 |
| 958 // Before that commits, a document.write and location.reload can cause the | 985 // Before that commits, a document.write and location.reload can cause the |
| 959 // renderer to send a FrameNavigate with page_id -1. | 986 // renderer to send a FrameNavigate with page_id -1. |
| 987 main_test_rfh()->PrepareForCommit(kExistingURL); | |
| 960 main_test_rfh()->SendNavigate(-1, kExistingURL); | 988 main_test_rfh()->SendNavigate(-1, kExistingURL); |
| 961 | 989 |
| 962 // This should clear the pending entry and notify of a navigation state | 990 // This should clear the pending entry and notify of a navigation state |
| 963 // change, so that we do not keep displaying kNewURL. | 991 // change, so that we do not keep displaying kNewURL. |
| 964 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 992 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 965 EXPECT_FALSE(controller.GetPendingEntry()); | 993 EXPECT_FALSE(controller.GetPendingEntry()); |
| 966 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 994 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 967 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 995 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
| 968 | 996 |
| 969 contents()->SetDelegate(NULL); | 997 contents()->SetDelegate(NULL); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 | 1161 |
| 1134 // The second load should be committed, and bindings should be remembered. | 1162 // The second load should be committed, and bindings should be remembered. |
| 1135 EXPECT_EQ(controller.GetEntryCount(), 2); | 1163 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1136 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1164 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1137 EXPECT_TRUE(controller.CanGoBack()); | 1165 EXPECT_TRUE(controller.CanGoBack()); |
| 1138 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( | 1166 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( |
| 1139 controller.GetLastCommittedEntry())->bindings()); | 1167 controller.GetLastCommittedEntry())->bindings()); |
| 1140 | 1168 |
| 1141 // Going back, the first entry should still appear unprivileged. | 1169 // Going back, the first entry should still appear unprivileged. |
| 1142 controller.GoBack(); | 1170 controller.GoBack(); |
| 1143 new_rfh->SendBeforeUnloadACK(true); | 1171 new_rfh->PrepareForCommit(url1); |
| 1144 orig_rfh->SendNavigate(0, url1); | 1172 orig_rfh->SendNavigate(0, url1); |
| 1145 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1173 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1146 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1174 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 1147 controller.GetLastCommittedEntry())->bindings()); | 1175 controller.GetLastCommittedEntry())->bindings()); |
| 1148 } | 1176 } |
| 1149 | 1177 |
| 1150 TEST_F(NavigationControllerTest, Reload) { | 1178 TEST_F(NavigationControllerTest, Reload) { |
| 1151 NavigationControllerImpl& controller = controller_impl(); | 1179 NavigationControllerImpl& controller = controller_impl(); |
| 1152 TestNotificationTracker notifications; | 1180 TestNotificationTracker notifications; |
| 1153 RegisterForAllNavNotifications(¬ifications, &controller); | 1181 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1154 | 1182 |
| 1155 const GURL url1("http://foo1"); | 1183 const GURL url1("http://foo1"); |
| 1156 | 1184 |
| 1157 controller.LoadURL( | 1185 controller.LoadURL( |
| 1158 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1186 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1159 EXPECT_EQ(0U, notifications.size()); | 1187 EXPECT_EQ(0U, notifications.size()); |
| 1188 main_test_rfh()->PrepareForCommit(url1); | |
| 1160 main_test_rfh()->SendNavigate(0, url1); | 1189 main_test_rfh()->SendNavigate(0, url1); |
| 1161 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1190 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1162 navigation_entry_committed_counter_ = 0; | 1191 navigation_entry_committed_counter_ = 0; |
| 1163 ASSERT_TRUE(controller.GetVisibleEntry()); | 1192 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1164 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1193 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1165 controller.Reload(true); | 1194 controller.Reload(true); |
| 1166 EXPECT_EQ(0U, notifications.size()); | 1195 EXPECT_EQ(0U, notifications.size()); |
| 1167 | 1196 |
| 1168 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1197 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 1169 EXPECT_FALSE(timestamp.is_null()); | 1198 EXPECT_FALSE(timestamp.is_null()); |
| 1170 | 1199 |
| 1171 // The reload is pending. | 1200 // The reload is pending. |
| 1172 EXPECT_EQ(controller.GetEntryCount(), 1); | 1201 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1173 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1202 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1174 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1203 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1175 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1204 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1176 EXPECT_TRUE(controller.GetPendingEntry()); | 1205 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1177 EXPECT_FALSE(controller.CanGoBack()); | 1206 EXPECT_FALSE(controller.CanGoBack()); |
| 1178 EXPECT_FALSE(controller.CanGoForward()); | 1207 EXPECT_FALSE(controller.CanGoForward()); |
| 1179 // Make sure the title has been cleared (will be redrawn just after reload). | 1208 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1180 // Avoids a stale cached title when the new page being reloaded has no title. | 1209 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1181 // See http://crbug.com/96041. | 1210 // See http://crbug.com/96041. |
| 1182 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1211 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1183 | 1212 |
| 1213 main_test_rfh()->PrepareForCommit(url1); | |
| 1184 main_test_rfh()->SendNavigate(0, url1); | 1214 main_test_rfh()->SendNavigate(0, url1); |
| 1185 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1215 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1186 navigation_entry_committed_counter_ = 0; | 1216 navigation_entry_committed_counter_ = 0; |
| 1187 | 1217 |
| 1188 // Now the reload is committed. | 1218 // Now the reload is committed. |
| 1189 EXPECT_EQ(controller.GetEntryCount(), 1); | 1219 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1190 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1220 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1191 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1221 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1192 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1222 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1193 EXPECT_FALSE(controller.GetPendingEntry()); | 1223 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1194 EXPECT_FALSE(controller.CanGoBack()); | 1224 EXPECT_FALSE(controller.CanGoBack()); |
| 1195 EXPECT_FALSE(controller.CanGoForward()); | 1225 EXPECT_FALSE(controller.CanGoForward()); |
| 1196 | 1226 |
| 1197 // The timestamp should have been updated. | 1227 // The timestamp should have been updated. |
| 1198 ASSERT_TRUE(controller.GetVisibleEntry()); | 1228 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1199 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1229 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
| 1200 } | 1230 } |
| 1201 | 1231 |
| 1202 // Tests what happens when a reload navigation produces a new page. | 1232 // Tests what happens when a reload navigation produces a new page. |
| 1203 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1233 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 1204 NavigationControllerImpl& controller = controller_impl(); | 1234 NavigationControllerImpl& controller = controller_impl(); |
| 1205 TestNotificationTracker notifications; | 1235 TestNotificationTracker notifications; |
| 1206 RegisterForAllNavNotifications(¬ifications, &controller); | 1236 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1207 | 1237 |
| 1208 const GURL url1("http://foo1"); | 1238 const GURL url1("http://foo1"); |
| 1209 const GURL url2("http://foo2"); | 1239 const GURL url2("http://foo2"); |
| 1210 | 1240 |
| 1211 controller.LoadURL( | 1241 controller.LoadURL( |
| 1212 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1242 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1243 main_test_rfh()->PrepareForCommit(url1); | |
| 1213 main_test_rfh()->SendNavigate(0, url1); | 1244 main_test_rfh()->SendNavigate(0, url1); |
| 1214 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1245 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1215 navigation_entry_committed_counter_ = 0; | 1246 navigation_entry_committed_counter_ = 0; |
| 1216 | 1247 |
| 1217 controller.Reload(true); | 1248 controller.Reload(true); |
| 1218 EXPECT_EQ(0U, notifications.size()); | 1249 EXPECT_EQ(0U, notifications.size()); |
| 1219 | 1250 |
| 1251 main_test_rfh()->PrepareForCommit(url2); | |
| 1220 main_test_rfh()->SendNavigate(1, url2); | 1252 main_test_rfh()->SendNavigate(1, url2); |
| 1221 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1253 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1222 navigation_entry_committed_counter_ = 0; | 1254 navigation_entry_committed_counter_ = 0; |
| 1223 | 1255 |
| 1224 // Now the reload is committed. | 1256 // Now the reload is committed. |
| 1225 EXPECT_EQ(controller.GetEntryCount(), 2); | 1257 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1226 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1258 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1227 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1259 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1228 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1260 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1229 EXPECT_FALSE(controller.GetPendingEntry()); | 1261 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 TestNotificationTracker notifications; | 1301 TestNotificationTracker notifications; |
| 1270 RegisterForAllNavNotifications(¬ifications, &controller); | 1302 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1271 | 1303 |
| 1272 const GURL original_url("http://foo1"); | 1304 const GURL original_url("http://foo1"); |
| 1273 const GURL final_url("http://foo2"); | 1305 const GURL final_url("http://foo2"); |
| 1274 | 1306 |
| 1275 // Load up the original URL, but get redirected. | 1307 // Load up the original URL, but get redirected. |
| 1276 controller.LoadURL( | 1308 controller.LoadURL( |
| 1277 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1309 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1278 EXPECT_EQ(0U, notifications.size()); | 1310 EXPECT_EQ(0U, notifications.size()); |
| 1311 main_test_rfh()->PrepareForCommit(final_url); | |
| 1279 main_test_rfh()->SendNavigateWithOriginalRequestURL( | 1312 main_test_rfh()->SendNavigateWithOriginalRequestURL( |
| 1280 0, final_url, original_url); | 1313 0, final_url, original_url); |
| 1281 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1314 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1282 navigation_entry_committed_counter_ = 0; | 1315 navigation_entry_committed_counter_ = 0; |
| 1283 | 1316 |
| 1284 // The NavigationEntry should save both the original URL and the final | 1317 // The NavigationEntry should save both the original URL and the final |
| 1285 // redirected URL. | 1318 // redirected URL. |
| 1286 EXPECT_EQ( | 1319 EXPECT_EQ( |
| 1287 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1320 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
| 1288 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1321 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1301 EXPECT_TRUE(controller.GetPendingEntry()); | 1334 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1302 EXPECT_FALSE(controller.CanGoBack()); | 1335 EXPECT_FALSE(controller.CanGoBack()); |
| 1303 EXPECT_FALSE(controller.CanGoForward()); | 1336 EXPECT_FALSE(controller.CanGoForward()); |
| 1304 | 1337 |
| 1305 // Make sure the title has been cleared (will be redrawn just after reload). | 1338 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1306 // Avoids a stale cached title when the new page being reloaded has no title. | 1339 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1307 // See http://crbug.com/96041. | 1340 // See http://crbug.com/96041. |
| 1308 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1341 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1309 | 1342 |
| 1310 // Send that the navigation has proceeded; say it got redirected again. | 1343 // Send that the navigation has proceeded; say it got redirected again. |
| 1344 main_test_rfh()->PrepareForCommit(final_url); | |
| 1311 main_test_rfh()->SendNavigate(0, final_url); | 1345 main_test_rfh()->SendNavigate(0, final_url); |
| 1312 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1346 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1313 navigation_entry_committed_counter_ = 0; | 1347 navigation_entry_committed_counter_ = 0; |
| 1314 | 1348 |
| 1315 // Now the reload is committed. | 1349 // Now the reload is committed. |
| 1316 EXPECT_EQ(controller.GetEntryCount(), 1); | 1350 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1317 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1351 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1318 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1352 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1319 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1353 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1320 EXPECT_FALSE(controller.GetPendingEntry()); | 1354 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 NavigationControllerImpl& controller = controller_impl(); | 1496 NavigationControllerImpl& controller = controller_impl(); |
| 1463 TestNotificationTracker notifications; | 1497 TestNotificationTracker notifications; |
| 1464 RegisterForAllNavNotifications(¬ifications, &controller); | 1498 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1465 | 1499 |
| 1466 const GURL url1("http://foo/1"); | 1500 const GURL url1("http://foo/1"); |
| 1467 const GURL url2("http://foo/2"); | 1501 const GURL url2("http://foo/2"); |
| 1468 const GURL url3("http://foo/3"); | 1502 const GURL url3("http://foo/3"); |
| 1469 | 1503 |
| 1470 controller.LoadURL( | 1504 controller.LoadURL( |
| 1471 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1505 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1506 main_test_rfh()->PrepareForCommit(url1); | |
| 1472 main_test_rfh()->SendNavigate(0, url1); | 1507 main_test_rfh()->SendNavigate(0, url1); |
| 1473 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1508 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1474 navigation_entry_committed_counter_ = 0; | 1509 navigation_entry_committed_counter_ = 0; |
| 1475 | 1510 |
| 1476 controller.LoadURL( | 1511 controller.LoadURL( |
| 1477 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1512 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1513 main_test_rfh()->PrepareForCommit(url2); | |
| 1478 main_test_rfh()->SendNavigate(1, url2); | 1514 main_test_rfh()->SendNavigate(1, url2); |
| 1479 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1515 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1480 navigation_entry_committed_counter_ = 0; | 1516 navigation_entry_committed_counter_ = 0; |
| 1481 | 1517 |
| 1482 controller.GoBack(); | 1518 controller.GoBack(); |
| 1483 EXPECT_EQ(0U, notifications.size()); | 1519 EXPECT_EQ(0U, notifications.size()); |
| 1484 | 1520 |
| 1485 // We should now have a pending navigation to go back. | 1521 // We should now have a pending navigation to go back. |
| 1486 EXPECT_EQ(controller.GetEntryCount(), 2); | 1522 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1487 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1523 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1488 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1524 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1489 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1525 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1490 EXPECT_TRUE(controller.GetPendingEntry()); | 1526 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1491 EXPECT_FALSE(controller.CanGoBack()); | 1527 EXPECT_FALSE(controller.CanGoBack()); |
| 1492 EXPECT_TRUE(controller.CanGoForward()); | 1528 EXPECT_TRUE(controller.CanGoForward()); |
| 1493 | 1529 |
| 1530 main_test_rfh()->PrepareForCommit(url3); | |
| 1494 main_test_rfh()->SendNavigate(2, url3); | 1531 main_test_rfh()->SendNavigate(2, url3); |
| 1495 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1532 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1496 navigation_entry_committed_counter_ = 0; | 1533 navigation_entry_committed_counter_ = 0; |
| 1497 | 1534 |
| 1498 // The back navigation resulted in a completely new navigation. | 1535 // The back navigation resulted in a completely new navigation. |
| 1499 // TODO(darin): perhaps this behavior will be confusing to users? | 1536 // TODO(darin): perhaps this behavior will be confusing to users? |
| 1500 EXPECT_EQ(controller.GetEntryCount(), 3); | 1537 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 1501 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1538 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
| 1502 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1539 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1503 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1540 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1541 | 1578 |
| 1542 // Receives a back message when there is a different renavigation already | 1579 // Receives a back message when there is a different renavigation already |
| 1543 // pending. | 1580 // pending. |
| 1544 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1581 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
| 1545 NavigationControllerImpl& controller = controller_impl(); | 1582 NavigationControllerImpl& controller = controller_impl(); |
| 1546 const GURL kUrl1("http://foo/1"); | 1583 const GURL kUrl1("http://foo/1"); |
| 1547 const GURL kUrl2("http://foo/2"); | 1584 const GURL kUrl2("http://foo/2"); |
| 1548 const GURL kUrl3("http://foo/3"); | 1585 const GURL kUrl3("http://foo/3"); |
| 1549 | 1586 |
| 1550 // First navigate three places so we have some back history. | 1587 // First navigate three places so we have some back history. |
| 1588 main_test_rfh()->PrepareForCommit(kUrl1); | |
| 1551 main_test_rfh()->SendNavigate(0, kUrl1); | 1589 main_test_rfh()->SendNavigate(0, kUrl1); |
| 1590 main_test_rfh()->PrepareForCommit(kUrl2); | |
| 1552 main_test_rfh()->SendNavigate(1, kUrl2); | 1591 main_test_rfh()->SendNavigate(1, kUrl2); |
| 1592 main_test_rfh()->PrepareForCommit(kUrl3); | |
| 1553 main_test_rfh()->SendNavigate(2, kUrl3); | 1593 main_test_rfh()->SendNavigate(2, kUrl3); |
| 1554 | 1594 |
| 1555 // With nothing pending, say we get a navigation to the second entry. | 1595 // With nothing pending, say we get a navigation to the second entry. |
| 1596 main_test_rfh()->PrepareForCommit(kUrl2); | |
| 1556 main_test_rfh()->SendNavigate(1, kUrl2); | 1597 main_test_rfh()->SendNavigate(1, kUrl2); |
| 1557 | 1598 |
| 1558 // We know all the entries have the same site instance, so we can just grab | 1599 // We know all the entries have the same site instance, so we can just grab |
| 1559 // a random one for looking up other entries. | 1600 // a random one for looking up other entries. |
| 1560 SiteInstance* site_instance = | 1601 SiteInstance* site_instance = |
| 1561 NavigationEntryImpl::FromNavigationEntry( | 1602 NavigationEntryImpl::FromNavigationEntry( |
| 1562 controller.GetLastCommittedEntry())->site_instance(); | 1603 controller.GetLastCommittedEntry())->site_instance(); |
| 1563 | 1604 |
| 1564 // That second URL should be the last committed and it should have gotten the | 1605 // That second URL should be the last committed and it should have gotten the |
| 1565 // new title. | 1606 // new title. |
| 1566 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1607 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
| 1567 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1608 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1568 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1609 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1569 | 1610 |
| 1570 // Now go forward to the last item again and say it was committed. | 1611 // Now go forward to the last item again and say it was committed. |
| 1571 controller.GoForward(); | 1612 controller.GoForward(); |
| 1613 main_test_rfh()->PrepareForCommit(kUrl3); | |
| 1572 main_test_rfh()->SendNavigate(2, kUrl3); | 1614 main_test_rfh()->SendNavigate(2, kUrl3); |
| 1573 | 1615 |
| 1574 // Now start going back one to the second page. It will be pending. | 1616 // Now start going back one to the second page. It will be pending. |
| 1575 controller.GoBack(); | 1617 controller.GoBack(); |
| 1576 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1618 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
| 1577 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1619 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 1578 | 1620 |
| 1579 // Not synthesize a totally new back event to the first page. This will not | 1621 // Not synthesize a totally new back event to the first page. This will not |
| 1580 // match the pending one. | 1622 // match the pending one. |
| 1623 main_test_rfh()->PrepareForCommit(kUrl1); | |
| 1581 main_test_rfh()->SendNavigate(0, kUrl1); | 1624 main_test_rfh()->SendNavigate(0, kUrl1); |
| 1582 | 1625 |
| 1583 // The committed navigation should clear the pending entry. | 1626 // The committed navigation should clear the pending entry. |
| 1584 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1627 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1585 | 1628 |
| 1586 // But the navigated entry should be the last committed. | 1629 // But the navigated entry should be the last committed. |
| 1587 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1630 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1588 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1631 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
| 1589 } | 1632 } |
| 1590 | 1633 |
| 1591 // Tests what happens when we navigate forward successfully. | 1634 // Tests what happens when we navigate forward successfully. |
| 1592 TEST_F(NavigationControllerTest, Forward) { | 1635 TEST_F(NavigationControllerTest, Forward) { |
| 1593 NavigationControllerImpl& controller = controller_impl(); | 1636 NavigationControllerImpl& controller = controller_impl(); |
| 1594 TestNotificationTracker notifications; | 1637 TestNotificationTracker notifications; |
| 1595 RegisterForAllNavNotifications(¬ifications, &controller); | 1638 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1596 | 1639 |
| 1597 const GURL url1("http://foo1"); | 1640 const GURL url1("http://foo1"); |
| 1598 const GURL url2("http://foo2"); | 1641 const GURL url2("http://foo2"); |
| 1599 | 1642 |
| 1643 main_test_rfh()->PrepareForCommit(url1); | |
| 1600 main_test_rfh()->SendNavigate(0, url1); | 1644 main_test_rfh()->SendNavigate(0, url1); |
| 1601 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1645 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1602 navigation_entry_committed_counter_ = 0; | 1646 navigation_entry_committed_counter_ = 0; |
| 1603 | 1647 |
| 1648 main_test_rfh()->PrepareForCommit(url2); | |
| 1604 main_test_rfh()->SendNavigate(1, url2); | 1649 main_test_rfh()->SendNavigate(1, url2); |
| 1605 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1650 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1606 navigation_entry_committed_counter_ = 0; | 1651 navigation_entry_committed_counter_ = 0; |
| 1607 | 1652 |
| 1608 controller.GoBack(); | 1653 controller.GoBack(); |
| 1654 main_test_rfh()->PrepareForCommit(url1); | |
| 1609 main_test_rfh()->SendNavigate(0, url1); | 1655 main_test_rfh()->SendNavigate(0, url1); |
| 1610 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1656 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1611 navigation_entry_committed_counter_ = 0; | 1657 navigation_entry_committed_counter_ = 0; |
| 1612 | 1658 |
| 1613 controller.GoForward(); | 1659 controller.GoForward(); |
| 1614 | 1660 |
| 1615 // We should now have a pending navigation to go forward. | 1661 // We should now have a pending navigation to go forward. |
| 1616 EXPECT_EQ(controller.GetEntryCount(), 2); | 1662 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1617 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1663 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1618 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1664 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1619 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1665 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1620 EXPECT_TRUE(controller.GetPendingEntry()); | 1666 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1621 EXPECT_TRUE(controller.CanGoBack()); | 1667 EXPECT_TRUE(controller.CanGoBack()); |
| 1622 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1668 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
| 1623 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1669 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
| 1624 EXPECT_FALSE(controller.CanGoForward()); | 1670 EXPECT_FALSE(controller.CanGoForward()); |
| 1625 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1671 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 1626 | 1672 |
| 1627 // Timestamp for entry 0 should be on or after that of entry 1 | 1673 // Timestamp for entry 0 should be on or after that of entry 1 |
| 1628 // (since we went back to it). | 1674 // (since we went back to it). |
| 1629 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1675 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
| 1630 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1676 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
| 1631 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1677 controller.GetEntryAtIndex(1)->GetTimestamp()); |
| 1632 | 1678 |
| 1679 main_test_rfh()->PrepareForCommit(url2); | |
| 1633 main_test_rfh()->SendNavigate(1, url2); | 1680 main_test_rfh()->SendNavigate(1, url2); |
| 1634 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1681 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1635 navigation_entry_committed_counter_ = 0; | 1682 navigation_entry_committed_counter_ = 0; |
| 1636 | 1683 |
| 1637 // The forward navigation completed successfully. | 1684 // The forward navigation completed successfully. |
| 1638 EXPECT_EQ(controller.GetEntryCount(), 2); | 1685 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1639 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1686 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1640 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1687 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1641 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1688 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1642 EXPECT_FALSE(controller.GetPendingEntry()); | 1689 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1655 // Tests what happens when a forward navigation produces a new page. | 1702 // Tests what happens when a forward navigation produces a new page. |
| 1656 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 1703 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
| 1657 NavigationControllerImpl& controller = controller_impl(); | 1704 NavigationControllerImpl& controller = controller_impl(); |
| 1658 TestNotificationTracker notifications; | 1705 TestNotificationTracker notifications; |
| 1659 RegisterForAllNavNotifications(¬ifications, &controller); | 1706 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1660 | 1707 |
| 1661 const GURL url1("http://foo1"); | 1708 const GURL url1("http://foo1"); |
| 1662 const GURL url2("http://foo2"); | 1709 const GURL url2("http://foo2"); |
| 1663 const GURL url3("http://foo3"); | 1710 const GURL url3("http://foo3"); |
| 1664 | 1711 |
| 1712 main_test_rfh()->PrepareForCommit(url1); | |
| 1665 main_test_rfh()->SendNavigate(0, url1); | 1713 main_test_rfh()->SendNavigate(0, url1); |
| 1666 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1714 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1667 navigation_entry_committed_counter_ = 0; | 1715 navigation_entry_committed_counter_ = 0; |
| 1716 main_test_rfh()->PrepareForCommit(url2); | |
| 1668 main_test_rfh()->SendNavigate(1, url2); | 1717 main_test_rfh()->SendNavigate(1, url2); |
| 1669 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1718 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1670 navigation_entry_committed_counter_ = 0; | 1719 navigation_entry_committed_counter_ = 0; |
| 1671 | 1720 |
| 1672 controller.GoBack(); | 1721 controller.GoBack(); |
| 1722 main_test_rfh()->PrepareForCommit(url1); | |
| 1673 main_test_rfh()->SendNavigate(0, url1); | 1723 main_test_rfh()->SendNavigate(0, url1); |
| 1674 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1724 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1675 navigation_entry_committed_counter_ = 0; | 1725 navigation_entry_committed_counter_ = 0; |
| 1676 | 1726 |
| 1677 controller.GoForward(); | 1727 controller.GoForward(); |
| 1678 EXPECT_EQ(0U, notifications.size()); | 1728 EXPECT_EQ(0U, notifications.size()); |
| 1679 | 1729 |
| 1680 // Should now have a pending navigation to go forward. | 1730 // Should now have a pending navigation to go forward. |
| 1681 EXPECT_EQ(controller.GetEntryCount(), 2); | 1731 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1682 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1732 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1683 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1733 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1684 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1734 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1685 EXPECT_TRUE(controller.GetPendingEntry()); | 1735 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1686 EXPECT_TRUE(controller.CanGoBack()); | 1736 EXPECT_TRUE(controller.CanGoBack()); |
| 1687 EXPECT_FALSE(controller.CanGoForward()); | 1737 EXPECT_FALSE(controller.CanGoForward()); |
| 1688 | 1738 |
| 1739 main_test_rfh()->PrepareForCommit(url3); | |
| 1689 main_test_rfh()->SendNavigate(2, url3); | 1740 main_test_rfh()->SendNavigate(2, url3); |
| 1690 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1741 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1691 navigation_entry_committed_counter_ = 0; | 1742 navigation_entry_committed_counter_ = 0; |
| 1692 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1743 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
| 1693 | 1744 |
| 1694 EXPECT_EQ(controller.GetEntryCount(), 2); | 1745 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1695 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1746 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1696 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1747 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1697 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1748 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1698 EXPECT_FALSE(controller.GetPendingEntry()); | 1749 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2340 const int kMaxEntryCount = 5; | 2391 const int kMaxEntryCount = 5; |
| 2341 | 2392 |
| 2342 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2393 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
| 2343 | 2394 |
| 2344 int url_index; | 2395 int url_index; |
| 2345 // Load up to the max count, all entries should be there. | 2396 // Load up to the max count, all entries should be there. |
| 2346 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2397 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
| 2347 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2398 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2348 controller.LoadURL( | 2399 controller.LoadURL( |
| 2349 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2400 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2401 main_test_rfh()->PrepareForCommit(url); | |
| 2350 main_test_rfh()->SendNavigate(url_index, url); | 2402 main_test_rfh()->SendNavigate(url_index, url); |
| 2351 } | 2403 } |
| 2352 | 2404 |
| 2353 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2405 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2354 | 2406 |
| 2355 // Created a PrunedListener to observe prune notifications. | 2407 // Created a PrunedListener to observe prune notifications. |
| 2356 PrunedListener listener(&controller); | 2408 PrunedListener listener(&controller); |
| 2357 | 2409 |
| 2358 // Navigate some more. | 2410 // Navigate some more. |
| 2359 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2411 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2360 controller.LoadURL( | 2412 controller.LoadURL( |
| 2361 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2413 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2414 main_test_rfh()->PrepareForCommit(url); | |
| 2362 main_test_rfh()->SendNavigate(url_index, url); | 2415 main_test_rfh()->SendNavigate(url_index, url); |
| 2363 url_index++; | 2416 url_index++; |
| 2364 | 2417 |
| 2365 // We should have got a pruned navigation. | 2418 // We should have got a pruned navigation. |
| 2366 EXPECT_EQ(1, listener.notification_count_); | 2419 EXPECT_EQ(1, listener.notification_count_); |
| 2367 EXPECT_TRUE(listener.details_.from_front); | 2420 EXPECT_TRUE(listener.details_.from_front); |
| 2368 EXPECT_EQ(1, listener.details_.count); | 2421 EXPECT_EQ(1, listener.details_.count); |
| 2369 | 2422 |
| 2370 // We expect http://www.a.com/0 to be gone. | 2423 // We expect http://www.a.com/0 to be gone. |
| 2371 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2424 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2372 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2425 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2373 GURL("http:////www.a.com/1")); | 2426 GURL("http:////www.a.com/1")); |
| 2374 | 2427 |
| 2375 // More navigations. | 2428 // More navigations. |
| 2376 for (int i = 0; i < 3; i++) { | 2429 for (int i = 0; i < 3; i++) { |
| 2377 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2430 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); |
| 2378 controller.LoadURL( | 2431 controller.LoadURL( |
| 2379 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2432 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2433 main_test_rfh()->PrepareForCommit(url); | |
| 2380 main_test_rfh()->SendNavigate(url_index, url); | 2434 main_test_rfh()->SendNavigate(url_index, url); |
| 2381 url_index++; | 2435 url_index++; |
| 2382 } | 2436 } |
| 2383 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2437 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2384 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2438 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2385 GURL("http:////www.a.com/4")); | 2439 GURL("http:////www.a.com/4")); |
| 2386 | 2440 |
| 2387 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2441 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
| 2388 } | 2442 } |
| 2389 | 2443 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2546 our_controller.GetEntryAtIndex(0))->restore_type()); | 2600 our_controller.GetEntryAtIndex(0))->restore_type()); |
| 2547 } | 2601 } |
| 2548 | 2602 |
| 2549 // Make sure that the page type and stuff is correct after an interstitial. | 2603 // Make sure that the page type and stuff is correct after an interstitial. |
| 2550 TEST_F(NavigationControllerTest, Interstitial) { | 2604 TEST_F(NavigationControllerTest, Interstitial) { |
| 2551 NavigationControllerImpl& controller = controller_impl(); | 2605 NavigationControllerImpl& controller = controller_impl(); |
| 2552 // First navigate somewhere normal. | 2606 // First navigate somewhere normal. |
| 2553 const GURL url1("http://foo"); | 2607 const GURL url1("http://foo"); |
| 2554 controller.LoadURL( | 2608 controller.LoadURL( |
| 2555 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2609 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2610 main_test_rfh()->PrepareForCommit(url1); | |
| 2556 main_test_rfh()->SendNavigate(0, url1); | 2611 main_test_rfh()->SendNavigate(0, url1); |
| 2557 | 2612 |
| 2558 // Now navigate somewhere with an interstitial. | 2613 // Now navigate somewhere with an interstitial. |
| 2559 const GURL url2("http://bar"); | 2614 const GURL url2("http://bar"); |
| 2560 controller.LoadURL( | 2615 controller.LoadURL( |
| 2561 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2616 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2562 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2617 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2563 set_page_type(PAGE_TYPE_INTERSTITIAL); | 2618 set_page_type(PAGE_TYPE_INTERSTITIAL); |
| 2564 | 2619 |
| 2565 // At this point the interstitial will be displayed and the load will still | 2620 // At this point the interstitial will be displayed and the load will still |
| 2566 // be pending. If the user continues, the load will commit. | 2621 // be pending. If the user continues, the load will commit. |
| 2622 main_test_rfh()->PrepareForCommit(url2); | |
| 2567 main_test_rfh()->SendNavigate(1, url2); | 2623 main_test_rfh()->SendNavigate(1, url2); |
| 2568 | 2624 |
| 2569 // The page should be a normal page again. | 2625 // The page should be a normal page again. |
| 2570 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2626 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 2571 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2627 EXPECT_EQ(PAGE_TYPE_NORMAL, |
| 2572 controller.GetLastCommittedEntry()->GetPageType()); | 2628 controller.GetLastCommittedEntry()->GetPageType()); |
| 2573 } | 2629 } |
| 2574 | 2630 |
| 2575 TEST_F(NavigationControllerTest, RemoveEntry) { | 2631 TEST_F(NavigationControllerTest, RemoveEntry) { |
| 2576 NavigationControllerImpl& controller = controller_impl(); | 2632 NavigationControllerImpl& controller = controller_impl(); |
| 2577 const GURL url1("http://foo/1"); | 2633 const GURL url1("http://foo/1"); |
| 2578 const GURL url2("http://foo/2"); | 2634 const GURL url2("http://foo/2"); |
| 2579 const GURL url3("http://foo/3"); | 2635 const GURL url3("http://foo/3"); |
| 2580 const GURL url4("http://foo/4"); | 2636 const GURL url4("http://foo/4"); |
| 2581 const GURL url5("http://foo/5"); | 2637 const GURL url5("http://foo/5"); |
| 2582 const GURL pending_url("http://foo/pending"); | 2638 const GURL pending_url("http://foo/pending"); |
| 2583 const GURL default_url("http://foo/default"); | 2639 const GURL default_url("http://foo/default"); |
| 2584 | 2640 |
| 2585 controller.LoadURL( | 2641 controller.LoadURL( |
| 2586 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2642 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2643 main_test_rfh()->PrepareForCommit(url1); | |
| 2587 main_test_rfh()->SendNavigate(0, url1); | 2644 main_test_rfh()->SendNavigate(0, url1); |
| 2588 controller.LoadURL( | 2645 controller.LoadURL( |
| 2589 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2646 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2647 main_test_rfh()->PrepareForCommit(url2); | |
| 2590 main_test_rfh()->SendNavigate(1, url2); | 2648 main_test_rfh()->SendNavigate(1, url2); |
| 2591 controller.LoadURL( | 2649 controller.LoadURL( |
| 2592 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2650 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2651 main_test_rfh()->PrepareForCommit(url3); | |
| 2593 main_test_rfh()->SendNavigate(2, url3); | 2652 main_test_rfh()->SendNavigate(2, url3); |
| 2594 controller.LoadURL( | 2653 controller.LoadURL( |
| 2595 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2654 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2655 main_test_rfh()->PrepareForCommit(url4); | |
| 2596 main_test_rfh()->SendNavigate(3, url4); | 2656 main_test_rfh()->SendNavigate(3, url4); |
| 2597 controller.LoadURL( | 2657 controller.LoadURL( |
| 2598 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2658 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2659 main_test_rfh()->PrepareForCommit(url5); | |
| 2599 main_test_rfh()->SendNavigate(4, url5); | 2660 main_test_rfh()->SendNavigate(4, url5); |
| 2600 | 2661 |
| 2601 // Try to remove the last entry. Will fail because it is the current entry. | 2662 // Try to remove the last entry. Will fail because it is the current entry. |
| 2602 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2663 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2603 EXPECT_EQ(5, controller.GetEntryCount()); | 2664 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2604 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2665 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
| 2605 | 2666 |
| 2606 // Go back, but don't commit yet. Check that we can't delete the current | 2667 // Go back, but don't commit yet. Check that we can't delete the current |
| 2607 // and pending entries. | 2668 // and pending entries. |
| 2608 controller.GoBack(); | 2669 controller.GoBack(); |
| 2609 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2670 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2610 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2671 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
| 2611 | 2672 |
| 2612 // Now commit and delete the last entry. | 2673 // Now commit and delete the last entry. |
| 2674 main_test_rfh()->PrepareForCommit(url4); | |
| 2613 main_test_rfh()->SendNavigate(3, url4); | 2675 main_test_rfh()->SendNavigate(3, url4); |
| 2614 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2676 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2615 EXPECT_EQ(4, controller.GetEntryCount()); | 2677 EXPECT_EQ(4, controller.GetEntryCount()); |
| 2616 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2678 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| 2617 EXPECT_FALSE(controller.GetPendingEntry()); | 2679 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2618 | 2680 |
| 2619 // Remove an entry which is not the last committed one. | 2681 // Remove an entry which is not the last committed one. |
| 2620 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2682 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2621 EXPECT_EQ(3, controller.GetEntryCount()); | 2683 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2622 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2684 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2633 | 2695 |
| 2634 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2696 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
| 2635 NavigationControllerImpl& controller = controller_impl(); | 2697 NavigationControllerImpl& controller = controller_impl(); |
| 2636 const GURL url1("http://foo/1"); | 2698 const GURL url1("http://foo/1"); |
| 2637 const GURL url2("http://foo/2"); | 2699 const GURL url2("http://foo/2"); |
| 2638 const GURL url3("http://foo/3"); | 2700 const GURL url3("http://foo/3"); |
| 2639 const GURL default_url("http://foo/default"); | 2701 const GURL default_url("http://foo/default"); |
| 2640 | 2702 |
| 2641 controller.LoadURL( | 2703 controller.LoadURL( |
| 2642 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2704 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2705 main_test_rfh()->PrepareForCommit(url1); | |
| 2643 main_test_rfh()->SendNavigate(0, url1); | 2706 main_test_rfh()->SendNavigate(0, url1); |
| 2644 controller.LoadURL( | 2707 controller.LoadURL( |
| 2645 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2708 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2709 main_test_rfh()->PrepareForCommit(url2); | |
| 2646 main_test_rfh()->SendNavigate(1, url2); | 2710 main_test_rfh()->SendNavigate(1, url2); |
| 2647 controller.LoadURL( | 2711 controller.LoadURL( |
| 2648 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2712 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2713 main_test_rfh()->PrepareForCommit(url3); | |
| 2649 main_test_rfh()->SendNavigate(2, url3); | 2714 main_test_rfh()->SendNavigate(2, url3); |
| 2650 | 2715 |
| 2651 // Go back, but don't commit yet. Check that we can't delete the current | 2716 // Go back, but don't commit yet. Check that we can't delete the current |
| 2652 // and pending entries. | 2717 // and pending entries. |
| 2653 controller.GoBack(); | 2718 controller.GoBack(); |
| 2654 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2719 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
| 2655 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2720 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
| 2656 | 2721 |
| 2657 // Remove the first entry, while there is a pending entry. This is expected | 2722 // Remove the first entry, while there is a pending entry. This is expected |
| 2658 // to discard the pending entry. | 2723 // to discard the pending entry. |
| 2659 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2724 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2660 EXPECT_FALSE(controller.GetPendingEntry()); | 2725 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2661 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2726 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 2662 | 2727 |
| 2663 // We should update the last committed entry index. | 2728 // We should update the last committed entry index. |
| 2664 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2729 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2665 | 2730 |
| 2666 // Now commit and ensure we land on the right entry. | 2731 // Now commit and ensure we land on the right entry. |
| 2732 main_test_rfh()->PrepareForCommit(url2); | |
| 2667 main_test_rfh()->SendNavigate(1, url2); | 2733 main_test_rfh()->SendNavigate(1, url2); |
| 2668 EXPECT_EQ(2, controller.GetEntryCount()); | 2734 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2669 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2735 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2670 EXPECT_FALSE(controller.GetPendingEntry()); | 2736 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2671 } | 2737 } |
| 2672 | 2738 |
| 2673 // Tests the transient entry, making sure it goes away with all navigations. | 2739 // Tests the transient entry, making sure it goes away with all navigations. |
| 2674 TEST_F(NavigationControllerTest, TransientEntry) { | 2740 TEST_F(NavigationControllerTest, TransientEntry) { |
| 2675 NavigationControllerImpl& controller = controller_impl(); | 2741 NavigationControllerImpl& controller = controller_impl(); |
| 2676 TestNotificationTracker notifications; | 2742 TestNotificationTracker notifications; |
| 2677 RegisterForAllNavNotifications(¬ifications, &controller); | 2743 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2678 | 2744 |
| 2679 const GURL url0("http://foo/0"); | 2745 const GURL url0("http://foo/0"); |
| 2680 const GURL url1("http://foo/1"); | 2746 const GURL url1("http://foo/1"); |
| 2681 const GURL url2("http://foo/2"); | 2747 const GURL url2("http://foo/2"); |
| 2682 const GURL url3("http://foo/3"); | 2748 const GURL url3("http://foo/3"); |
| 2683 const GURL url3_ref("http://foo/3#bar"); | 2749 const GURL url3_ref("http://foo/3#bar"); |
| 2684 const GURL url4("http://foo/4"); | 2750 const GURL url4("http://foo/4"); |
| 2685 const GURL transient_url("http://foo/transient"); | 2751 const GURL transient_url("http://foo/transient"); |
| 2686 | 2752 |
| 2687 controller.LoadURL( | 2753 controller.LoadURL( |
| 2688 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2754 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2755 main_test_rfh()->PrepareForCommit(url0); | |
| 2689 main_test_rfh()->SendNavigate(0, url0); | 2756 main_test_rfh()->SendNavigate(0, url0); |
| 2690 controller.LoadURL( | 2757 controller.LoadURL( |
| 2691 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2758 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2759 main_test_rfh()->PrepareForCommit(url1); | |
| 2692 main_test_rfh()->SendNavigate(1, url1); | 2760 main_test_rfh()->SendNavigate(1, url1); |
| 2693 | 2761 |
| 2694 notifications.Reset(); | 2762 notifications.Reset(); |
| 2695 | 2763 |
| 2696 // Adding a transient with no pending entry. | 2764 // Adding a transient with no pending entry. |
| 2697 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2765 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2698 transient_entry->SetURL(transient_url); | 2766 transient_entry->SetURL(transient_url); |
| 2699 controller.SetTransientEntry(transient_entry); | 2767 controller.SetTransientEntry(transient_entry); |
| 2700 | 2768 |
| 2701 // We should not have received any notifications. | 2769 // We should not have received any notifications. |
| 2702 EXPECT_EQ(0U, notifications.size()); | 2770 EXPECT_EQ(0U, notifications.size()); |
| 2703 | 2771 |
| 2704 // Check our state. | 2772 // Check our state. |
| 2705 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2773 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2706 EXPECT_EQ(controller.GetEntryCount(), 3); | 2774 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2707 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2775 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2708 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2776 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2709 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2777 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2710 EXPECT_FALSE(controller.GetPendingEntry()); | 2778 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2711 EXPECT_TRUE(controller.CanGoBack()); | 2779 EXPECT_TRUE(controller.CanGoBack()); |
| 2712 EXPECT_FALSE(controller.CanGoForward()); | 2780 EXPECT_FALSE(controller.CanGoForward()); |
| 2713 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2781 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 2714 | 2782 |
| 2715 // Navigate. | 2783 // Navigate. |
| 2716 controller.LoadURL( | 2784 controller.LoadURL( |
| 2717 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2785 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2786 main_test_rfh()->PrepareForCommit(url2); | |
| 2718 main_test_rfh()->SendNavigate(2, url2); | 2787 main_test_rfh()->SendNavigate(2, url2); |
| 2719 | 2788 |
| 2720 // We should have navigated, transient entry should be gone. | 2789 // We should have navigated, transient entry should be gone. |
| 2721 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2790 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2722 EXPECT_EQ(controller.GetEntryCount(), 3); | 2791 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2723 | 2792 |
| 2724 // Add a transient again, then navigate with no pending entry this time. | 2793 // Add a transient again, then navigate with no pending entry this time. |
| 2725 transient_entry = new NavigationEntryImpl; | 2794 transient_entry = new NavigationEntryImpl; |
| 2726 transient_entry->SetURL(transient_url); | 2795 transient_entry->SetURL(transient_url); |
| 2727 controller.SetTransientEntry(transient_entry); | 2796 controller.SetTransientEntry(transient_entry); |
| 2728 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2797 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2798 main_test_rfh()->PrepareForCommit(url3); | |
| 2729 main_test_rfh()->SendNavigate(3, url3); | 2799 main_test_rfh()->SendNavigate(3, url3); |
| 2730 // Transient entry should be gone. | 2800 // Transient entry should be gone. |
| 2731 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2801 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2732 EXPECT_EQ(controller.GetEntryCount(), 4); | 2802 EXPECT_EQ(controller.GetEntryCount(), 4); |
| 2733 | 2803 |
| 2734 // Initiate a navigation, add a transient then commit navigation. | 2804 // Initiate a navigation, add a transient then commit navigation. |
| 2735 controller.LoadURL( | 2805 controller.LoadURL( |
| 2736 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2806 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2737 transient_entry = new NavigationEntryImpl; | 2807 transient_entry = new NavigationEntryImpl; |
| 2738 transient_entry->SetURL(transient_url); | 2808 transient_entry->SetURL(transient_url); |
| 2739 controller.SetTransientEntry(transient_entry); | 2809 controller.SetTransientEntry(transient_entry); |
| 2740 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2810 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2811 main_test_rfh()->PrepareForCommit(url4); | |
| 2741 main_test_rfh()->SendNavigate(4, url4); | 2812 main_test_rfh()->SendNavigate(4, url4); |
| 2742 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2813 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2743 EXPECT_EQ(controller.GetEntryCount(), 5); | 2814 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2744 | 2815 |
| 2745 // Add a transient and go back. This should simply remove the transient. | 2816 // Add a transient and go back. This should simply remove the transient. |
| 2746 transient_entry = new NavigationEntryImpl; | 2817 transient_entry = new NavigationEntryImpl; |
| 2747 transient_entry->SetURL(transient_url); | 2818 transient_entry->SetURL(transient_url); |
| 2748 controller.SetTransientEntry(transient_entry); | 2819 controller.SetTransientEntry(transient_entry); |
| 2749 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2820 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2750 EXPECT_TRUE(controller.CanGoBack()); | 2821 EXPECT_TRUE(controller.CanGoBack()); |
| 2751 EXPECT_FALSE(controller.CanGoForward()); | 2822 EXPECT_FALSE(controller.CanGoForward()); |
| 2752 controller.GoBack(); | 2823 controller.GoBack(); |
| 2753 // Transient entry should be gone. | 2824 // Transient entry should be gone. |
| 2754 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2825 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2755 EXPECT_EQ(controller.GetEntryCount(), 5); | 2826 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2827 main_test_rfh()->PrepareForCommit(url3); | |
| 2756 main_test_rfh()->SendNavigate(3, url3); | 2828 main_test_rfh()->SendNavigate(3, url3); |
| 2757 | 2829 |
| 2758 // Add a transient and go to an entry before the current one. | 2830 // Add a transient and go to an entry before the current one. |
| 2759 transient_entry = new NavigationEntryImpl; | 2831 transient_entry = new NavigationEntryImpl; |
| 2760 transient_entry->SetURL(transient_url); | 2832 transient_entry->SetURL(transient_url); |
| 2761 controller.SetTransientEntry(transient_entry); | 2833 controller.SetTransientEntry(transient_entry); |
| 2762 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2834 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2763 controller.GoToIndex(1); | 2835 controller.GoToIndex(1); |
| 2764 // The navigation should have been initiated, transient entry should be gone. | 2836 // The navigation should have been initiated, transient entry should be gone. |
| 2765 EXPECT_FALSE(controller.GetTransientEntry()); | 2837 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2766 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2838 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2767 // Visible entry does not update for history navigations until commit. | 2839 // Visible entry does not update for history navigations until commit. |
| 2768 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2840 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2841 main_test_rfh()->PrepareForCommit(url1); | |
| 2769 main_test_rfh()->SendNavigate(1, url1); | 2842 main_test_rfh()->SendNavigate(1, url1); |
| 2770 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2843 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2771 | 2844 |
| 2772 // Add a transient and go to an entry after the current one. | 2845 // Add a transient and go to an entry after the current one. |
| 2773 transient_entry = new NavigationEntryImpl; | 2846 transient_entry = new NavigationEntryImpl; |
| 2774 transient_entry->SetURL(transient_url); | 2847 transient_entry->SetURL(transient_url); |
| 2775 controller.SetTransientEntry(transient_entry); | 2848 controller.SetTransientEntry(transient_entry); |
| 2776 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2849 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2777 controller.GoToIndex(3); | 2850 controller.GoToIndex(3); |
| 2778 // The navigation should have been initiated, transient entry should be gone. | 2851 // The navigation should have been initiated, transient entry should be gone. |
| 2779 // Because of the transient entry that is removed, going to index 3 makes us | 2852 // Because of the transient entry that is removed, going to index 3 makes us |
| 2780 // land on url2 (which is visible after the commit). | 2853 // land on url2 (which is visible after the commit). |
| 2781 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2854 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 2782 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2855 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2856 main_test_rfh()->PrepareForCommit(url2); | |
| 2783 main_test_rfh()->SendNavigate(2, url2); | 2857 main_test_rfh()->SendNavigate(2, url2); |
| 2784 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2858 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2785 | 2859 |
| 2786 // Add a transient and go forward. | 2860 // Add a transient and go forward. |
| 2787 transient_entry = new NavigationEntryImpl; | 2861 transient_entry = new NavigationEntryImpl; |
| 2788 transient_entry->SetURL(transient_url); | 2862 transient_entry->SetURL(transient_url); |
| 2789 controller.SetTransientEntry(transient_entry); | 2863 controller.SetTransientEntry(transient_entry); |
| 2790 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2864 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2791 EXPECT_TRUE(controller.CanGoForward()); | 2865 EXPECT_TRUE(controller.CanGoForward()); |
| 2792 controller.GoForward(); | 2866 controller.GoForward(); |
| 2793 // We should have navigated, transient entry should be gone. | 2867 // We should have navigated, transient entry should be gone. |
| 2794 EXPECT_FALSE(controller.GetTransientEntry()); | 2868 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2795 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 2869 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
| 2796 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2870 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2871 main_test_rfh()->PrepareForCommit(url3); | |
| 2797 main_test_rfh()->SendNavigate(3, url3); | 2872 main_test_rfh()->SendNavigate(3, url3); |
| 2798 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2873 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2799 | 2874 |
| 2800 // Add a transient and do an in-page navigation, replacing the current entry. | 2875 // Add a transient and do an in-page navigation, replacing the current entry. |
| 2801 transient_entry = new NavigationEntryImpl; | 2876 transient_entry = new NavigationEntryImpl; |
| 2802 transient_entry->SetURL(transient_url); | 2877 transient_entry->SetURL(transient_url); |
| 2803 controller.SetTransientEntry(transient_entry); | 2878 controller.SetTransientEntry(transient_entry); |
| 2804 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2879 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2880 main_test_rfh()->PrepareForCommit(url3_ref); | |
| 2805 main_test_rfh()->SendNavigate(3, url3_ref); | 2881 main_test_rfh()->SendNavigate(3, url3_ref); |
| 2806 // Transient entry should be gone. | 2882 // Transient entry should be gone. |
| 2807 EXPECT_FALSE(controller.GetTransientEntry()); | 2883 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2808 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 2884 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
| 2809 | 2885 |
| 2810 // Ensure the URLs are correct. | 2886 // Ensure the URLs are correct. |
| 2811 EXPECT_EQ(controller.GetEntryCount(), 5); | 2887 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2812 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2888 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2813 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2889 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
| 2814 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2890 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
| 2815 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2891 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
| 2816 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2892 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
| 2817 } | 2893 } |
| 2818 | 2894 |
| 2819 // Test that Reload initiates a new navigation to a transient entry's URL. | 2895 // Test that Reload initiates a new navigation to a transient entry's URL. |
| 2820 TEST_F(NavigationControllerTest, ReloadTransient) { | 2896 TEST_F(NavigationControllerTest, ReloadTransient) { |
| 2821 NavigationControllerImpl& controller = controller_impl(); | 2897 NavigationControllerImpl& controller = controller_impl(); |
| 2822 const GURL url0("http://foo/0"); | 2898 const GURL url0("http://foo/0"); |
| 2823 const GURL url1("http://foo/1"); | 2899 const GURL url1("http://foo/1"); |
| 2824 const GURL transient_url("http://foo/transient"); | 2900 const GURL transient_url("http://foo/transient"); |
| 2825 | 2901 |
| 2826 // Load |url0|, and start a pending navigation to |url1|. | 2902 // Load |url0|, and start a pending navigation to |url1|. |
| 2827 controller.LoadURL( | 2903 controller.LoadURL( |
| 2828 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2904 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2905 main_test_rfh()->PrepareForCommit(url0); | |
| 2829 main_test_rfh()->SendNavigate(0, url0); | 2906 main_test_rfh()->SendNavigate(0, url0); |
| 2830 controller.LoadURL( | 2907 controller.LoadURL( |
| 2831 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2908 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2832 | 2909 |
| 2833 // A transient entry is added, interrupting the navigation. | 2910 // A transient entry is added, interrupting the navigation. |
| 2834 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2911 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2835 transient_entry->SetURL(transient_url); | 2912 transient_entry->SetURL(transient_url); |
| 2836 controller.SetTransientEntry(transient_entry); | 2913 controller.SetTransientEntry(transient_entry); |
| 2837 EXPECT_TRUE(controller.GetTransientEntry()); | 2914 EXPECT_TRUE(controller.GetTransientEntry()); |
| 2838 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2915 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2839 | 2916 |
| 2840 // The page is reloaded, which should remove the pending entry for |url1| and | 2917 // The page is reloaded, which should remove the pending entry for |url1| and |
| 2841 // the transient entry for |transient_url|, and start a navigation to | 2918 // the transient entry for |transient_url|, and start a navigation to |
| 2842 // |transient_url|. | 2919 // |transient_url|. |
| 2843 controller.Reload(true); | 2920 controller.Reload(true); |
| 2844 EXPECT_FALSE(controller.GetTransientEntry()); | 2921 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2845 EXPECT_TRUE(controller.GetPendingEntry()); | 2922 EXPECT_TRUE(controller.GetPendingEntry()); |
| 2846 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2923 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2847 ASSERT_EQ(controller.GetEntryCount(), 1); | 2924 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2848 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2925 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2849 | 2926 |
| 2850 // Load of |transient_url| completes. | 2927 // Load of |transient_url| completes. |
| 2928 main_test_rfh()->PrepareForCommit(transient_url); | |
| 2851 main_test_rfh()->SendNavigate(1, transient_url); | 2929 main_test_rfh()->SendNavigate(1, transient_url); |
| 2852 ASSERT_EQ(controller.GetEntryCount(), 2); | 2930 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2853 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2931 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2854 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2932 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2855 } | 2933 } |
| 2856 | 2934 |
| 2857 // Ensure that renderer initiated pending entries get replaced, so that we | 2935 // Ensure that renderer initiated pending entries get replaced, so that we |
| 2858 // don't show a stale virtual URL when a navigation commits. | 2936 // don't show a stale virtual URL when a navigation commits. |
| 2859 // See http://crbug.com/266922. | 2937 // See http://crbug.com/266922. |
| 2860 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 2938 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2924 | 3002 |
| 2925 const GURL url0("http://foo/0"); | 3003 const GURL url0("http://foo/0"); |
| 2926 const GURL url1("http://foo/1"); | 3004 const GURL url1("http://foo/1"); |
| 2927 | 3005 |
| 2928 // For typed navigations (browser-initiated), both pending and visible entries | 3006 // For typed navigations (browser-initiated), both pending and visible entries |
| 2929 // should update before commit. | 3007 // should update before commit. |
| 2930 controller.LoadURL( | 3008 controller.LoadURL( |
| 2931 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3009 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2932 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 3010 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
| 2933 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3011 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 3012 main_test_rfh()->PrepareForCommit(url0); | |
| 2934 main_test_rfh()->SendNavigate(0, url0); | 3013 main_test_rfh()->SendNavigate(0, url0); |
| 2935 | 3014 |
| 2936 // For link clicks (renderer-initiated navigations), the pending entry should | 3015 // For link clicks (renderer-initiated navigations), the pending entry should |
| 2937 // update before commit but the visible should not. | 3016 // update before commit but the visible should not. |
| 2938 NavigationController::LoadURLParams load_url_params(url1); | 3017 NavigationController::LoadURLParams load_url_params(url1); |
| 2939 load_url_params.is_renderer_initiated = true; | 3018 load_url_params.is_renderer_initiated = true; |
| 2940 controller.LoadURLWithParams(load_url_params); | 3019 controller.LoadURLWithParams(load_url_params); |
| 2941 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3020 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 2942 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3021 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2943 EXPECT_TRUE( | 3022 EXPECT_TRUE( |
| 2944 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 3023 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2945 is_renderer_initiated()); | 3024 is_renderer_initiated()); |
| 2946 | 3025 |
| 2947 // After commit, both visible should be updated, there should be no pending | 3026 // After commit, both visible should be updated, there should be no pending |
| 2948 // entry, and we should no longer treat the entry as renderer-initiated. | 3027 // entry, and we should no longer treat the entry as renderer-initiated. |
| 3028 main_test_rfh()->PrepareForCommit(url1); | |
| 2949 main_test_rfh()->SendNavigate(1, url1); | 3029 main_test_rfh()->SendNavigate(1, url1); |
| 2950 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3030 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2951 EXPECT_FALSE(controller.GetPendingEntry()); | 3031 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2952 EXPECT_FALSE( | 3032 EXPECT_FALSE( |
| 2953 NavigationEntryImpl::FromNavigationEntry( | 3033 NavigationEntryImpl::FromNavigationEntry( |
| 2954 controller.GetLastCommittedEntry())->is_renderer_initiated()); | 3034 controller.GetLastCommittedEntry())->is_renderer_initiated()); |
| 2955 | 3035 |
| 2956 notifications.Reset(); | 3036 notifications.Reset(); |
| 2957 } | 3037 } |
| 2958 | 3038 |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3976 contents()->CommitPendingNavigation(); | 4056 contents()->CommitPendingNavigation(); |
| 3977 process()->sink().ClearMessages(); | 4057 process()->sink().ClearMessages(); |
| 3978 | 4058 |
| 3979 // Simulate the page calling history.back(). It should create a pending entry. | 4059 // Simulate the page calling history.back(). It should create a pending entry. |
| 3980 contents()->OnGoToEntryAtOffset(-1); | 4060 contents()->OnGoToEntryAtOffset(-1); |
| 3981 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 4061 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 3982 // The actual cross-navigation is suspended until the current RVH tells us | 4062 // The actual cross-navigation is suspended until the current RVH tells us |
| 3983 // it unloaded, simulate that. | 4063 // it unloaded, simulate that. |
| 3984 contents()->ProceedWithCrossSiteNavigation(); | 4064 contents()->ProceedWithCrossSiteNavigation(); |
| 3985 // Also make sure we told the page to navigate. | 4065 // Also make sure we told the page to navigate. |
| 3986 const IPC::Message* message = GetLastNavigationRequest(); | 4066 GURL nav_url = GetLastNavigationURL(); |
| 3987 ASSERT_TRUE(message != NULL); | |
| 3988 GURL nav_url = GetNavigationURLFromIPC(message); | |
| 3989 EXPECT_EQ(url1, nav_url); | 4067 EXPECT_EQ(url1, nav_url); |
| 4068 contents()->CommitPendingNavigation(); | |
| 3990 process()->sink().ClearMessages(); | 4069 process()->sink().ClearMessages(); |
| 3991 | 4070 |
| 3992 // Now test history.forward() | 4071 // Now test history.forward() |
| 3993 contents()->OnGoToEntryAtOffset(2); | 4072 contents()->OnGoToEntryAtOffset(2); |
| 3994 EXPECT_EQ(2, controller.GetPendingEntryIndex()); | 4073 EXPECT_EQ(2, controller.GetPendingEntryIndex()); |
| 3995 // The actual cross-navigation is suspended until the current RVH tells us | 4074 // The actual cross-navigation is suspended until the current RVH tells us |
| 3996 // it unloaded, simulate that. | 4075 // it unloaded, simulate that. |
| 3997 contents()->ProceedWithCrossSiteNavigation(); | 4076 contents()->ProceedWithCrossSiteNavigation(); |
| 3998 message = GetLastNavigationRequest(); | 4077 nav_url = GetLastNavigationURL(); |
| 3999 ASSERT_TRUE(message != NULL); | |
| 4000 nav_url = GetNavigationURLFromIPC(message); | |
| 4001 EXPECT_EQ(url3, nav_url); | 4078 EXPECT_EQ(url3, nav_url); |
| 4079 contents()->CommitPendingNavigation(); | |
| 4002 process()->sink().ClearMessages(); | 4080 process()->sink().ClearMessages(); |
| 4003 | 4081 |
| 4004 controller.DiscardNonCommittedEntries(); | 4082 controller.DiscardNonCommittedEntries(); |
| 4005 | 4083 |
| 4006 // Make sure an extravagant history.go() doesn't break. | 4084 // Make sure an extravagant history.go() doesn't break. |
| 4007 contents()->OnGoToEntryAtOffset(120); // Out of bounds. | 4085 contents()->OnGoToEntryAtOffset(120); // Out of bounds. |
| 4008 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4086 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4009 message = GetLastNavigationRequest(); | 4087 EXPECT_FALSE(HasNavigationRequest()); |
| 4010 EXPECT_TRUE(message == NULL); | |
| 4011 } | 4088 } |
| 4012 | 4089 |
| 4013 // Test call to PruneAllButLastCommitted for the only entry. | 4090 // Test call to PruneAllButLastCommitted for the only entry. |
| 4014 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { | 4091 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { |
| 4015 NavigationControllerImpl& controller = controller_impl(); | 4092 NavigationControllerImpl& controller = controller_impl(); |
| 4016 const GURL url1("http://foo1"); | 4093 const GURL url1("http://foo1"); |
| 4017 NavigateAndCommit(url1); | 4094 NavigateAndCommit(url1); |
| 4018 | 4095 |
| 4019 contents()->ExpectSetHistoryOffsetAndLength(0, 1); | 4096 contents()->ExpectSetHistoryOffsetAndLength(0, 1); |
| 4020 | 4097 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4089 | 4166 |
| 4090 // We should only have the last committed and pending entries at this point, | 4167 // We should only have the last committed and pending entries at this point, |
| 4091 // and the pending entry should still not be in the entry list. | 4168 // and the pending entry should still not be in the entry list. |
| 4092 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4169 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4093 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4170 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
| 4094 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4171 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4095 EXPECT_TRUE(controller.GetPendingEntry()); | 4172 EXPECT_TRUE(controller.GetPendingEntry()); |
| 4096 EXPECT_EQ(1, controller.GetEntryCount()); | 4173 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4097 | 4174 |
| 4098 // Try to commit the pending entry. | 4175 // Try to commit the pending entry. |
| 4176 main_test_rfh()->PrepareForCommit(url3); | |
| 4099 main_test_rfh()->SendNavigate(2, url3); | 4177 main_test_rfh()->SendNavigate(2, url3); |
| 4100 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4178 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4101 EXPECT_FALSE(controller.GetPendingEntry()); | 4179 EXPECT_FALSE(controller.GetPendingEntry()); |
| 4102 EXPECT_EQ(2, controller.GetEntryCount()); | 4180 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4103 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4181 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
| 4104 } | 4182 } |
| 4105 | 4183 |
| 4106 // Test to ensure that when we do a history navigation back to the current | 4184 // Test to ensure that when we do a history navigation back to the current |
| 4107 // committed page (e.g., going forward to a slow-loading page, then pressing | 4185 // committed page (e.g., going forward to a slow-loading page, then pressing |
| 4108 // the back button), we just stop the navigation to prevent the throbber from | 4186 // the back button), we just stop the navigation to prevent the throbber from |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4442 params.post_id = -1; | 4520 params.post_id = -1; |
| 4443 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4521 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
| 4444 | 4522 |
| 4445 // Now reload. replaceState overrides the POST, so we should not show a | 4523 // Now reload. replaceState overrides the POST, so we should not show a |
| 4446 // repost warning dialog. | 4524 // repost warning dialog. |
| 4447 controller_impl().Reload(true); | 4525 controller_impl().Reload(true); |
| 4448 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4526 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
| 4449 } | 4527 } |
| 4450 | 4528 |
| 4451 } // namespace content | 4529 } // namespace content |
| OLD | NEW |