| 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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 int repost_form_warning_count_; | 300 int repost_form_warning_count_; |
| 301 }; | 301 }; |
| 302 | 302 |
| 303 // Observer that records the LoadCommittedDetails from the most recent commit. | 303 // Observer that records the LoadCommittedDetails from the most recent commit. |
| 304 class LoadCommittedDetailsObserver : public WebContentsObserver { | 304 class LoadCommittedDetailsObserver : public WebContentsObserver { |
| 305 public: | 305 public: |
| 306 // Observes navigation for the specified |web_contents|. | 306 // Observes navigation for the specified |web_contents|. |
| 307 explicit LoadCommittedDetailsObserver(WebContents* web_contents) | 307 explicit LoadCommittedDetailsObserver(WebContents* web_contents) |
| 308 : WebContentsObserver(web_contents), | 308 : WebContentsObserver(web_contents), |
| 309 navigation_type_(NAVIGATION_TYPE_UNKNOWN), | 309 navigation_type_(NAVIGATION_TYPE_UNKNOWN), |
| 310 is_in_page_(false), | 310 is_same_document_(false), |
| 311 is_main_frame_(false), | 311 is_main_frame_(false), |
| 312 did_replace_entry_(false) {} | 312 did_replace_entry_(false) {} |
| 313 | 313 |
| 314 NavigationType navigation_type() { return navigation_type_; } | 314 NavigationType navigation_type() { return navigation_type_; } |
| 315 const GURL& previous_url() { return previous_url_; } | 315 const GURL& previous_url() { return previous_url_; } |
| 316 bool is_in_page() { return is_in_page_; } | 316 bool is_same_document() { return is_same_document_; } |
| 317 bool is_main_frame() { return is_main_frame_; } | 317 bool is_main_frame() { return is_main_frame_; } |
| 318 bool did_replace_entry() { return did_replace_entry_; } | 318 bool did_replace_entry() { return did_replace_entry_; } |
| 319 | 319 |
| 320 private: | 320 private: |
| 321 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 321 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| 322 if (!navigation_handle->HasCommitted()) | 322 if (!navigation_handle->HasCommitted()) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 navigation_type_ = static_cast<NavigationHandleImpl*>(navigation_handle) | 325 navigation_type_ = static_cast<NavigationHandleImpl*>(navigation_handle) |
| 326 ->navigation_type(); | 326 ->navigation_type(); |
| 327 previous_url_ = navigation_handle->GetPreviousURL(); | 327 previous_url_ = navigation_handle->GetPreviousURL(); |
| 328 is_in_page_ = navigation_handle->IsSameDocument(); | 328 is_same_document_ = navigation_handle->IsSameDocument(); |
| 329 is_main_frame_ = navigation_handle->IsInMainFrame(); | 329 is_main_frame_ = navigation_handle->IsInMainFrame(); |
| 330 did_replace_entry_ = navigation_handle->DidReplaceEntry(); | 330 did_replace_entry_ = navigation_handle->DidReplaceEntry(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 NavigationType navigation_type_; | 333 NavigationType navigation_type_; |
| 334 GURL previous_url_; | 334 GURL previous_url_; |
| 335 bool is_in_page_; | 335 bool is_same_document_; |
| 336 bool is_main_frame_; | 336 bool is_main_frame_; |
| 337 bool did_replace_entry_; | 337 bool did_replace_entry_; |
| 338 }; | 338 }; |
| 339 | 339 |
| 340 // PlzNavigate | 340 // PlzNavigate |
| 341 // A NavigationControllerTest run with --enable-browser-side-navigation. | 341 // A NavigationControllerTest run with --enable-browser-side-navigation. |
| 342 class NavigationControllerTestWithBrowserSideNavigation | 342 class NavigationControllerTestWithBrowserSideNavigation |
| 343 : public NavigationControllerTest { | 343 : public NavigationControllerTest { |
| 344 public: | 344 public: |
| 345 void SetUp() override { | 345 void SetUp() override { |
| (...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 params.method = "GET"; | 2268 params.method = "GET"; |
| 2269 params.page_state = PageState::CreateFromURL(url2); | 2269 params.page_state = PageState::CreateFromURL(url2); |
| 2270 | 2270 |
| 2271 LoadCommittedDetailsObserver observer(contents()); | 2271 LoadCommittedDetailsObserver observer(contents()); |
| 2272 subframe->SendRendererInitiatedNavigationRequest(url2, true); | 2272 subframe->SendRendererInitiatedNavigationRequest(url2, true); |
| 2273 subframe->PrepareForCommit(); | 2273 subframe->PrepareForCommit(); |
| 2274 subframe->SendNavigateWithParams(¶ms); | 2274 subframe->SendNavigateWithParams(¶ms); |
| 2275 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2275 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2276 navigation_entry_committed_counter_ = 0; | 2276 navigation_entry_committed_counter_ = 0; |
| 2277 EXPECT_EQ(url1, observer.previous_url()); | 2277 EXPECT_EQ(url1, observer.previous_url()); |
| 2278 EXPECT_FALSE(observer.is_in_page()); | 2278 EXPECT_FALSE(observer.is_same_document()); |
| 2279 EXPECT_FALSE(observer.is_main_frame()); | 2279 EXPECT_FALSE(observer.is_main_frame()); |
| 2280 | 2280 |
| 2281 // The new entry should be appended. | 2281 // The new entry should be appended. |
| 2282 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 2282 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 2283 EXPECT_EQ(2, controller.GetEntryCount()); | 2283 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2284 | 2284 |
| 2285 // New entry should refer to the new page, but the old URL (entries only | 2285 // New entry should refer to the new page, but the old URL (entries only |
| 2286 // reflect the toplevel URL). | 2286 // reflect the toplevel URL). |
| 2287 EXPECT_EQ(url1, entry->GetURL()); | 2287 EXPECT_EQ(url1, entry->GetURL()); |
| 2288 | 2288 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2614 // Should have produced a new session history entry. | 2614 // Should have produced a new session history entry. |
| 2615 EXPECT_EQ(controller.GetEntryCount(), 2); | 2615 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 2616 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2616 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2617 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2617 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2618 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2618 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2619 EXPECT_FALSE(controller.GetPendingEntry()); | 2619 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2620 EXPECT_TRUE(controller.CanGoBack()); | 2620 EXPECT_TRUE(controller.CanGoBack()); |
| 2621 EXPECT_FALSE(controller.CanGoForward()); | 2621 EXPECT_FALSE(controller.CanGoForward()); |
| 2622 } | 2622 } |
| 2623 | 2623 |
| 2624 TEST_F(NavigationControllerTest, InPage) { | 2624 TEST_F(NavigationControllerTest, SameDocument) { |
| 2625 NavigationControllerImpl& controller = controller_impl(); | 2625 NavigationControllerImpl& controller = controller_impl(); |
| 2626 TestNotificationTracker notifications; | 2626 TestNotificationTracker notifications; |
| 2627 RegisterForAllNavNotifications(¬ifications, &controller); | 2627 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2628 | 2628 |
| 2629 // Main page. | 2629 // Main page. |
| 2630 const GURL url1("http://foo"); | 2630 const GURL url1("http://foo"); |
| 2631 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); | 2631 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); |
| 2632 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2632 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2633 navigation_entry_committed_counter_ = 0; | 2633 navigation_entry_committed_counter_ = 0; |
| 2634 | 2634 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2649 self_params.document_sequence_number); | 2649 self_params.document_sequence_number); |
| 2650 self_params.was_within_same_document = true; | 2650 self_params.was_within_same_document = true; |
| 2651 | 2651 |
| 2652 LoadCommittedDetailsObserver observer(contents()); | 2652 LoadCommittedDetailsObserver observer(contents()); |
| 2653 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); | 2653 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); |
| 2654 main_test_rfh()->PrepareForCommit(); | 2654 main_test_rfh()->PrepareForCommit(); |
| 2655 main_test_rfh()->SendNavigateWithParams(&self_params); | 2655 main_test_rfh()->SendNavigateWithParams(&self_params); |
| 2656 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); | 2656 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| 2657 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2657 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2658 navigation_entry_committed_counter_ = 0; | 2658 navigation_entry_committed_counter_ = 0; |
| 2659 EXPECT_TRUE(observer.is_in_page()); | 2659 EXPECT_TRUE(observer.is_same_document()); |
| 2660 EXPECT_TRUE(observer.did_replace_entry()); | 2660 EXPECT_TRUE(observer.did_replace_entry()); |
| 2661 EXPECT_EQ(1, controller.GetEntryCount()); | 2661 EXPECT_EQ(1, controller.GetEntryCount()); |
| 2662 | 2662 |
| 2663 // Fragment navigation to a new page. | 2663 // Fragment navigation to a new page. |
| 2664 const GURL url2("http://foo#a"); | 2664 const GURL url2("http://foo#a"); |
| 2665 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2665 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2666 params.nav_entry_id = 0; | 2666 params.nav_entry_id = 0; |
| 2667 params.did_create_new_entry = true; | 2667 params.did_create_new_entry = true; |
| 2668 params.url = url2; | 2668 params.url = url2; |
| 2669 params.transition = ui::PAGE_TRANSITION_LINK; | 2669 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2670 params.should_update_history = false; | 2670 params.should_update_history = false; |
| 2671 params.gesture = NavigationGestureUser; | 2671 params.gesture = NavigationGestureUser; |
| 2672 params.method = "GET"; | 2672 params.method = "GET"; |
| 2673 params.item_sequence_number = GenerateSequenceNumber(); | 2673 params.item_sequence_number = GenerateSequenceNumber(); |
| 2674 params.document_sequence_number = self_params.document_sequence_number; | 2674 params.document_sequence_number = self_params.document_sequence_number; |
| 2675 params.page_state = PageState::CreateForTestingWithSequenceNumbers( | 2675 params.page_state = PageState::CreateForTestingWithSequenceNumbers( |
| 2676 url2, params.item_sequence_number, params.document_sequence_number); | 2676 url2, params.item_sequence_number, params.document_sequence_number); |
| 2677 params.was_within_same_document = true; | 2677 params.was_within_same_document = true; |
| 2678 | 2678 |
| 2679 // This should generate a new entry. | 2679 // This should generate a new entry. |
| 2680 main_test_rfh()->SendNavigateWithParams(¶ms); | 2680 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 2681 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); | 2681 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| 2682 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2682 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2683 navigation_entry_committed_counter_ = 0; | 2683 navigation_entry_committed_counter_ = 0; |
| 2684 EXPECT_TRUE(observer.is_in_page()); | 2684 EXPECT_TRUE(observer.is_same_document()); |
| 2685 EXPECT_FALSE(observer.did_replace_entry()); | 2685 EXPECT_FALSE(observer.did_replace_entry()); |
| 2686 EXPECT_EQ(2, controller.GetEntryCount()); | 2686 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2687 | 2687 |
| 2688 // Go back one. | 2688 // Go back one. |
| 2689 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(self_params); | 2689 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(self_params); |
| 2690 controller.GoBack(); | 2690 controller.GoBack(); |
| 2691 back_params.nav_entry_id = entry1->GetUniqueID(); | 2691 back_params.nav_entry_id = entry1->GetUniqueID(); |
| 2692 back_params.did_create_new_entry = false; | 2692 back_params.did_create_new_entry = false; |
| 2693 main_test_rfh()->SendNavigateWithParams(&back_params); | 2693 main_test_rfh()->SendNavigateWithParams(&back_params); |
| 2694 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2694 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2695 navigation_entry_committed_counter_ = 0; | 2695 navigation_entry_committed_counter_ = 0; |
| 2696 EXPECT_TRUE(observer.is_in_page()); | 2696 EXPECT_TRUE(observer.is_same_document()); |
| 2697 EXPECT_EQ(2, controller.GetEntryCount()); | 2697 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2698 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2698 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 2699 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); | 2699 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
| 2700 | 2700 |
| 2701 // Go forward. | 2701 // Go forward. |
| 2702 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); | 2702 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); |
| 2703 controller.GoForward(); | 2703 controller.GoForward(); |
| 2704 forward_params.nav_entry_id = entry2->GetUniqueID(); | 2704 forward_params.nav_entry_id = entry2->GetUniqueID(); |
| 2705 forward_params.did_create_new_entry = false; | 2705 forward_params.did_create_new_entry = false; |
| 2706 main_test_rfh()->SendNavigateWithParams(&forward_params); | 2706 main_test_rfh()->SendNavigateWithParams(&forward_params); |
| 2707 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2707 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2708 navigation_entry_committed_counter_ = 0; | 2708 navigation_entry_committed_counter_ = 0; |
| 2709 EXPECT_TRUE(observer.is_in_page()); | 2709 EXPECT_TRUE(observer.is_same_document()); |
| 2710 EXPECT_EQ(2, controller.GetEntryCount()); | 2710 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2711 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2711 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 2712 EXPECT_EQ(forward_params.url, | 2712 EXPECT_EQ(forward_params.url, |
| 2713 controller.GetVisibleEntry()->GetURL()); | 2713 controller.GetVisibleEntry()->GetURL()); |
| 2714 | 2714 |
| 2715 // Now go back and forward again. This is to work around a bug where we would | 2715 // Now go back and forward again. This is to work around a bug where we would |
| 2716 // compare the incoming URL with the last committed entry rather than the | 2716 // compare the incoming URL with the last committed entry rather than the |
| 2717 // one identified by an existing page ID. This would result in the second URL | 2717 // one identified by an existing page ID. This would result in the second URL |
| 2718 // losing the reference fragment when you navigate away from it and then back. | 2718 // losing the reference fragment when you navigate away from it and then back. |
| 2719 controller.GoBack(); | 2719 controller.GoBack(); |
| 2720 main_test_rfh()->SendNavigateWithParams(&back_params); | 2720 main_test_rfh()->SendNavigateWithParams(&back_params); |
| 2721 controller.GoForward(); | 2721 controller.GoForward(); |
| 2722 main_test_rfh()->SendNavigateWithParams(&forward_params); | 2722 main_test_rfh()->SendNavigateWithParams(&forward_params); |
| 2723 EXPECT_EQ(forward_params.url, | 2723 EXPECT_EQ(forward_params.url, |
| 2724 controller.GetVisibleEntry()->GetURL()); | 2724 controller.GetVisibleEntry()->GetURL()); |
| 2725 | 2725 |
| 2726 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 2726 // Finally, navigate to an unrelated URL to make sure same_document is not |
| 2727 // sticky. |
| 2727 const GURL url3("http://bar"); | 2728 const GURL url3("http://bar"); |
| 2728 params.nav_entry_id = 0; | 2729 params.nav_entry_id = 0; |
| 2729 params.did_create_new_entry = true; | 2730 params.did_create_new_entry = true; |
| 2730 params.url = url3; | 2731 params.url = url3; |
| 2731 params.item_sequence_number = 0; | 2732 params.item_sequence_number = 0; |
| 2732 params.document_sequence_number = 0; | 2733 params.document_sequence_number = 0; |
| 2733 params.page_state = PageState::CreateFromURL(url3); | 2734 params.page_state = PageState::CreateFromURL(url3); |
| 2734 params.was_within_same_document = false; | 2735 params.was_within_same_document = false; |
| 2735 navigation_entry_committed_counter_ = 0; | 2736 navigation_entry_committed_counter_ = 0; |
| 2736 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); | 2737 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); |
| 2737 main_test_rfh()->PrepareForCommit(); | 2738 main_test_rfh()->PrepareForCommit(); |
| 2738 main_test_rfh()->SendNavigateWithParams(¶ms); | 2739 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 2739 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2740 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2740 navigation_entry_committed_counter_ = 0; | 2741 navigation_entry_committed_counter_ = 0; |
| 2741 EXPECT_FALSE(observer.is_in_page()); | 2742 EXPECT_FALSE(observer.is_same_document()); |
| 2742 EXPECT_EQ(3, controller.GetEntryCount()); | 2743 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2743 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2744 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 2744 } | 2745 } |
| 2745 | 2746 |
| 2746 TEST_F(NavigationControllerTest, InPage_Replace) { | 2747 TEST_F(NavigationControllerTest, SameDocument_Replace) { |
| 2747 NavigationControllerImpl& controller = controller_impl(); | 2748 NavigationControllerImpl& controller = controller_impl(); |
| 2748 TestNotificationTracker notifications; | 2749 TestNotificationTracker notifications; |
| 2749 RegisterForAllNavNotifications(¬ifications, &controller); | 2750 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2750 | 2751 |
| 2751 // Main page. | 2752 // Main page. |
| 2752 const GURL url1("http://foo"); | 2753 const GURL url1("http://foo"); |
| 2753 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); | 2754 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); |
| 2754 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2755 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2755 navigation_entry_committed_counter_ = 0; | 2756 navigation_entry_committed_counter_ = 0; |
| 2756 | 2757 |
| 2757 // First navigation. | 2758 // First navigation. |
| 2758 const GURL url2("http://foo#a"); | 2759 const GURL url2("http://foo#a"); |
| 2759 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2760 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2760 params.nav_entry_id = 0; | 2761 params.nav_entry_id = 0; |
| 2761 params.did_create_new_entry = false; | 2762 params.did_create_new_entry = false; |
| 2762 params.url = url2; | 2763 params.url = url2; |
| 2763 params.transition = ui::PAGE_TRANSITION_LINK; | 2764 params.transition = ui::PAGE_TRANSITION_LINK; |
| 2764 params.should_update_history = false; | 2765 params.should_update_history = false; |
| 2765 params.gesture = NavigationGestureUser; | 2766 params.gesture = NavigationGestureUser; |
| 2766 params.method = "GET"; | 2767 params.method = "GET"; |
| 2767 params.page_state = PageState::CreateFromURL(url2); | 2768 params.page_state = PageState::CreateFromURL(url2); |
| 2768 params.was_within_same_document = true; | 2769 params.was_within_same_document = true; |
| 2769 | 2770 |
| 2770 // This should NOT generate a new entry, nor prune the list. | 2771 // This should NOT generate a new entry, nor prune the list. |
| 2771 LoadCommittedDetailsObserver observer(contents()); | 2772 LoadCommittedDetailsObserver observer(contents()); |
| 2772 main_test_rfh()->SendNavigateWithParams(¶ms); | 2773 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 2773 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2774 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2774 navigation_entry_committed_counter_ = 0; | 2775 navigation_entry_committed_counter_ = 0; |
| 2775 EXPECT_TRUE(observer.is_in_page()); | 2776 EXPECT_TRUE(observer.is_same_document()); |
| 2776 EXPECT_TRUE(observer.did_replace_entry()); | 2777 EXPECT_TRUE(observer.did_replace_entry()); |
| 2777 EXPECT_EQ(1, controller.GetEntryCount()); | 2778 EXPECT_EQ(1, controller.GetEntryCount()); |
| 2778 } | 2779 } |
| 2779 | 2780 |
| 2780 // Tests for http://crbug.com/40395 | 2781 // Tests for http://crbug.com/40395 |
| 2781 // Simulates this: | 2782 // Simulates this: |
| 2782 // <script> | 2783 // <script> |
| 2783 // window.location.replace("#a"); | 2784 // window.location.replace("#a"); |
| 2784 // window.location='http://foo3/'; | 2785 // window.location='http://foo3/'; |
| 2785 // </script> | 2786 // </script> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2817 params.gesture = NavigationGestureUnknown; | 2818 params.gesture = NavigationGestureUnknown; |
| 2818 params.method = "GET"; | 2819 params.method = "GET"; |
| 2819 params.page_state = PageState::CreateFromURL(url); | 2820 params.page_state = PageState::CreateFromURL(url); |
| 2820 params.was_within_same_document = true; | 2821 params.was_within_same_document = true; |
| 2821 | 2822 |
| 2822 // This should NOT generate a new entry, nor prune the list. | 2823 // This should NOT generate a new entry, nor prune the list. |
| 2823 LoadCommittedDetailsObserver observer(contents()); | 2824 LoadCommittedDetailsObserver observer(contents()); |
| 2824 main_test_rfh()->SendNavigateWithParams(¶ms); | 2825 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 2825 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2826 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2826 navigation_entry_committed_counter_ = 0; | 2827 navigation_entry_committed_counter_ = 0; |
| 2827 EXPECT_TRUE(observer.is_in_page()); | 2828 EXPECT_TRUE(observer.is_same_document()); |
| 2828 EXPECT_TRUE(observer.did_replace_entry()); | 2829 EXPECT_TRUE(observer.did_replace_entry()); |
| 2829 EXPECT_EQ(2, controller.GetEntryCount()); | 2830 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2830 } | 2831 } |
| 2831 | 2832 |
| 2832 // Perform a client redirect to a new page. | 2833 // Perform a client redirect to a new page. |
| 2833 { | 2834 { |
| 2834 const GURL url("http://foo3/"); | 2835 const GURL url("http://foo3/"); |
| 2835 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2836 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 2836 params.nav_entry_id = 0; | 2837 params.nav_entry_id = 0; |
| 2837 params.did_create_new_entry = true; | 2838 params.did_create_new_entry = true; |
| 2838 params.url = url; | 2839 params.url = url; |
| 2839 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 2840 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 2840 params.redirects.push_back(GURL("http://foo2/#a")); | 2841 params.redirects.push_back(GURL("http://foo2/#a")); |
| 2841 params.redirects.push_back(url); | 2842 params.redirects.push_back(url); |
| 2842 params.should_update_history = true; | 2843 params.should_update_history = true; |
| 2843 params.gesture = NavigationGestureUnknown; | 2844 params.gesture = NavigationGestureUnknown; |
| 2844 params.method = "GET"; | 2845 params.method = "GET"; |
| 2845 params.page_state = PageState::CreateFromURL(url); | 2846 params.page_state = PageState::CreateFromURL(url); |
| 2846 | 2847 |
| 2847 // This SHOULD generate a new entry. | 2848 // This SHOULD generate a new entry. |
| 2848 LoadCommittedDetailsObserver observer(contents()); | 2849 LoadCommittedDetailsObserver observer(contents()); |
| 2849 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 2850 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
| 2850 main_test_rfh()->PrepareForCommit(); | 2851 main_test_rfh()->PrepareForCommit(); |
| 2851 main_test_rfh()->SendNavigateWithParams(¶ms); | 2852 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 2852 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2853 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2853 navigation_entry_committed_counter_ = 0; | 2854 navigation_entry_committed_counter_ = 0; |
| 2854 EXPECT_FALSE(observer.is_in_page()); | 2855 EXPECT_FALSE(observer.is_same_document()); |
| 2855 EXPECT_EQ(3, controller.GetEntryCount()); | 2856 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2856 } | 2857 } |
| 2857 | 2858 |
| 2858 // Verify that BACK brings us back to http://foo2/. | 2859 // Verify that BACK brings us back to http://foo2/. |
| 2859 { | 2860 { |
| 2860 const GURL url("http://foo2/"); | 2861 const GURL url("http://foo2/"); |
| 2861 controller.GoBack(); | 2862 controller.GoBack(); |
| 2862 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | 2863 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 2863 main_test_rfh()->PrepareForCommit(); | 2864 main_test_rfh()->PrepareForCommit(); |
| 2864 main_test_rfh()->SendNavigate(entry_id, false, url); | 2865 main_test_rfh()->SendNavigate(entry_id, false, url); |
| (...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 | 5134 |
| 5134 // Navigate without changing document. | 5135 // Navigate without changing document. |
| 5135 params.url = GURL("http://foo#foo"); | 5136 params.url = GURL("http://foo#foo"); |
| 5136 params.transition = ui::PAGE_TRANSITION_LINK; | 5137 params.transition = ui::PAGE_TRANSITION_LINK; |
| 5137 params.was_within_same_document = true; | 5138 params.was_within_same_document = true; |
| 5138 { | 5139 { |
| 5139 LoadCommittedDetailsObserver observer(contents()); | 5140 LoadCommittedDetailsObserver observer(contents()); |
| 5140 main_test_rfh()->SendNavigateWithParams(¶ms); | 5141 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 5141 EXPECT_EQ(PAGE_TYPE_ERROR, | 5142 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 5142 controller_impl().GetLastCommittedEntry()->GetPageType()); | 5143 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 5143 EXPECT_TRUE(observer.is_in_page()); | 5144 EXPECT_TRUE(observer.is_same_document()); |
| 5144 } | 5145 } |
| 5145 } | 5146 } |
| 5146 | 5147 |
| 5147 // Tests that if a stale navigation comes back from the renderer, it is properly | 5148 // Tests that if a stale navigation comes back from the renderer, it is properly |
| 5148 // resurrected. | 5149 // resurrected. |
| 5149 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { | 5150 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { |
| 5150 NavigationControllerImpl& controller = controller_impl(); | 5151 NavigationControllerImpl& controller = controller_impl(); |
| 5151 TestNotificationTracker notifications; | 5152 TestNotificationTracker notifications; |
| 5152 RegisterForAllNavNotifications(¬ifications, &controller); | 5153 RegisterForAllNavNotifications(¬ifications, &controller); |
| 5153 | 5154 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5360 ASSERT_EQ(2, controller.GetEntryCount()); | 5361 ASSERT_EQ(2, controller.GetEntryCount()); |
| 5361 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 5362 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5362 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 5363 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 5363 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 5364 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
| 5364 EXPECT_EQ(nullptr, controller.GetTransientEntry()); | 5365 EXPECT_EQ(nullptr, controller.GetTransientEntry()); |
| 5365 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); | 5366 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); |
| 5366 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL()); | 5367 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL()); |
| 5367 } | 5368 } |
| 5368 | 5369 |
| 5369 } // namespace content | 5370 } // namespace content |
| OLD | NEW |