| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SetUp() override { | 206 void SetUp() override { |
| 207 RenderViewHostImplTestHarness::SetUp(); | 207 RenderViewHostImplTestHarness::SetUp(); |
| 208 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); | 208 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); |
| 209 ASSERT_TRUE(web_contents); // The WebContents should be created by now. | 209 ASSERT_TRUE(web_contents); // The WebContents should be created by now. |
| 210 WebContentsObserver::Observe(web_contents); | 210 WebContentsObserver::Observe(web_contents); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // WebContentsObserver: | 213 // WebContentsObserver: |
| 214 void DidStartNavigationToPendingEntry( | 214 void DidStartNavigationToPendingEntry(const GURL& url, |
| 215 const GURL& url, | 215 ReloadType reload_type) override { |
| 216 NavigationController::ReloadType reload_type) override { | |
| 217 navigated_url_ = url; | 216 navigated_url_ = url; |
| 218 } | 217 } |
| 219 | 218 |
| 220 void NavigationEntryCommitted( | 219 void NavigationEntryCommitted( |
| 221 const LoadCommittedDetails& load_details) override { | 220 const LoadCommittedDetails& load_details) override { |
| 222 navigation_entry_committed_counter_++; | 221 navigation_entry_committed_counter_++; |
| 223 } | 222 } |
| 224 | 223 |
| 225 const GURL& navigated_url() const { | 224 const GURL& navigated_url() const { |
| 226 return navigated_url_; | 225 return navigated_url_; |
| (...skipping 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2997 browser_context()); | 2996 browser_context()); |
| 2998 entry->SetPageID(0); | 2997 entry->SetPageID(0); |
| 2999 entry->SetTitle(base::ASCIIToUTF16("Title")); | 2998 entry->SetTitle(base::ASCIIToUTF16("Title")); |
| 3000 entry->SetPageState(PageState::CreateFromEncodedData("state")); | 2999 entry->SetPageState(PageState::CreateFromEncodedData("state")); |
| 3001 const base::Time timestamp = base::Time::Now(); | 3000 const base::Time timestamp = base::Time::Now(); |
| 3002 entry->SetTimestamp(timestamp); | 3001 entry->SetTimestamp(timestamp); |
| 3003 entries.push_back(std::move(entry)); | 3002 entries.push_back(std::move(entry)); |
| 3004 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 3003 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
| 3005 WebContents::Create(WebContents::CreateParams(browser_context())))); | 3004 WebContents::Create(WebContents::CreateParams(browser_context())))); |
| 3006 NavigationControllerImpl& our_controller = our_contents->GetController(); | 3005 NavigationControllerImpl& our_controller = our_contents->GetController(); |
| 3007 our_controller.Restore( | 3006 our_controller.Restore(0, RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 3008 0, | |
| 3009 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | |
| 3010 &entries); | |
| 3011 ASSERT_EQ(0u, entries.size()); | 3007 ASSERT_EQ(0u, entries.size()); |
| 3012 | 3008 |
| 3013 // Before navigating to the restored entry, it should have a restore_type | 3009 // Before navigating to the restored entry, it should have a restore_type |
| 3014 // and no SiteInstance. | 3010 // and no SiteInstance. |
| 3015 ASSERT_EQ(1, our_controller.GetEntryCount()); | 3011 ASSERT_EQ(1, our_controller.GetEntryCount()); |
| 3016 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 3012 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, |
| 3017 our_controller.GetEntryAtIndex(0)->restore_type()); | 3013 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3018 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 3014 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 3019 | 3015 |
| 3020 // After navigating, we should have one entry, and it should be "pending". | 3016 // After navigating, we should have one entry, and it should be "pending". |
| 3021 our_controller.GoToIndex(0); | 3017 our_controller.GoToIndex(0); |
| 3022 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3018 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3023 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 3019 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 3024 our_controller.GetPendingEntry()); | 3020 our_controller.GetPendingEntry()); |
| 3025 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 3021 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
| 3026 | 3022 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3045 | 3041 |
| 3046 // There should be no longer any pending entry and one committed one. This | 3042 // There should be no longer any pending entry and one committed one. This |
| 3047 // means that we were able to locate the entry, assign its site instance, and | 3043 // means that we were able to locate the entry, assign its site instance, and |
| 3048 // commit it properly. | 3044 // commit it properly. |
| 3049 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3045 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3050 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 3046 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
| 3051 EXPECT_FALSE(our_controller.GetPendingEntry()); | 3047 EXPECT_FALSE(our_controller.GetPendingEntry()); |
| 3052 EXPECT_EQ( | 3048 EXPECT_EQ( |
| 3053 url, | 3049 url, |
| 3054 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 3050 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
| 3055 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 3051 EXPECT_EQ(RestoreType::NONE, |
| 3056 our_controller.GetEntryAtIndex(0)->restore_type()); | 3052 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3057 | 3053 |
| 3058 // Timestamp should have been updated. | 3054 // Timestamp should have been updated. |
| 3059 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); | 3055 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); |
| 3060 } | 3056 } |
| 3061 | 3057 |
| 3062 // Tests that we can still navigate to a restored entry after a different | 3058 // Tests that we can still navigate to a restored entry after a different |
| 3063 // navigation fails and clears the pending entry. http://crbug.com/90085 | 3059 // navigation fails and clears the pending entry. http://crbug.com/90085 |
| 3064 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 3060 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
| 3065 // Create a NavigationController with a restored set of tabs. | 3061 // Create a NavigationController with a restored set of tabs. |
| 3066 GURL url("http://foo"); | 3062 GURL url("http://foo"); |
| 3067 std::vector<std::unique_ptr<NavigationEntry>> entries; | 3063 std::vector<std::unique_ptr<NavigationEntry>> entries; |
| 3068 std::unique_ptr<NavigationEntry> new_entry = | 3064 std::unique_ptr<NavigationEntry> new_entry = |
| 3069 NavigationControllerImpl::CreateNavigationEntry( | 3065 NavigationControllerImpl::CreateNavigationEntry( |
| 3070 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), | 3066 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), |
| 3071 browser_context()); | 3067 browser_context()); |
| 3072 new_entry->SetPageID(0); | 3068 new_entry->SetPageID(0); |
| 3073 new_entry->SetTitle(base::ASCIIToUTF16("Title")); | 3069 new_entry->SetTitle(base::ASCIIToUTF16("Title")); |
| 3074 new_entry->SetPageState(PageState::CreateFromEncodedData("state")); | 3070 new_entry->SetPageState(PageState::CreateFromEncodedData("state")); |
| 3075 entries.push_back(std::move(new_entry)); | 3071 entries.push_back(std::move(new_entry)); |
| 3076 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 3072 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
| 3077 WebContents::Create(WebContents::CreateParams(browser_context())))); | 3073 WebContents::Create(WebContents::CreateParams(browser_context())))); |
| 3078 NavigationControllerImpl& our_controller = our_contents->GetController(); | 3074 NavigationControllerImpl& our_controller = our_contents->GetController(); |
| 3079 our_controller.Restore( | 3075 our_controller.Restore(0, RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 3080 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | |
| 3081 ASSERT_EQ(0u, entries.size()); | 3076 ASSERT_EQ(0u, entries.size()); |
| 3082 | 3077 |
| 3083 // Ensure the RenderFrame is initialized before simulating events coming from | 3078 // Ensure the RenderFrame is initialized before simulating events coming from |
| 3084 // it. | 3079 // it. |
| 3085 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 3080 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 3086 | 3081 |
| 3087 // Before navigating to the restored entry, it should have a restore_type | 3082 // Before navigating to the restored entry, it should have a restore_type |
| 3088 // and no SiteInstance. | 3083 // and no SiteInstance. |
| 3089 NavigationEntry* entry = our_controller.GetEntryAtIndex(0); | 3084 NavigationEntry* entry = our_controller.GetEntryAtIndex(0); |
| 3090 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 3085 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, |
| 3091 our_controller.GetEntryAtIndex(0)->restore_type()); | 3086 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3092 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 3087 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 3093 | 3088 |
| 3094 // After navigating, we should have one entry, and it should be "pending". | 3089 // After navigating, we should have one entry, and it should be "pending". |
| 3095 our_controller.GoToIndex(0); | 3090 our_controller.GoToIndex(0); |
| 3096 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3091 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3097 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 3092 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 3098 our_controller.GetPendingEntry()); | 3093 our_controller.GetPendingEntry()); |
| 3099 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 3094 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
| 3100 | 3095 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3126 main_rfh->PrepareForCommit(); | 3121 main_rfh->PrepareForCommit(); |
| 3127 main_rfh->SendNavigateWithParams(¶ms); | 3122 main_rfh->SendNavigateWithParams(¶ms); |
| 3128 | 3123 |
| 3129 // There should be no pending entry and one committed one. | 3124 // There should be no pending entry and one committed one. |
| 3130 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3125 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3131 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 3126 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
| 3132 EXPECT_FALSE(our_controller.GetPendingEntry()); | 3127 EXPECT_FALSE(our_controller.GetPendingEntry()); |
| 3133 EXPECT_EQ( | 3128 EXPECT_EQ( |
| 3134 url, | 3129 url, |
| 3135 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 3130 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
| 3136 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 3131 EXPECT_EQ(RestoreType::NONE, |
| 3137 our_controller.GetEntryAtIndex(0)->restore_type()); | 3132 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3138 } | 3133 } |
| 3139 | 3134 |
| 3140 // Make sure that the page type and stuff is correct after an interstitial. | 3135 // Make sure that the page type and stuff is correct after an interstitial. |
| 3141 TEST_F(NavigationControllerTest, Interstitial) { | 3136 TEST_F(NavigationControllerTest, Interstitial) { |
| 3142 NavigationControllerImpl& controller = controller_impl(); | 3137 NavigationControllerImpl& controller = controller_impl(); |
| 3143 // First navigate somewhere normal. | 3138 // First navigate somewhere normal. |
| 3144 const GURL url1("http://foo"); | 3139 const GURL url1("http://foo"); |
| 3145 controller.LoadURL( | 3140 controller.LoadURL( |
| 3146 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3141 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4649 std::string(), browser_context()); | 4644 std::string(), browser_context()); |
| 4650 entry->SetPageID(static_cast<int>(i)); | 4645 entry->SetPageID(static_cast<int>(i)); |
| 4651 entries.push_back(std::move(entry)); | 4646 entries.push_back(std::move(entry)); |
| 4652 } | 4647 } |
| 4653 | 4648 |
| 4654 // Create a WebContents with restored entries. | 4649 // Create a WebContents with restored entries. |
| 4655 std::unique_ptr<TestWebContents> source_contents( | 4650 std::unique_ptr<TestWebContents> source_contents( |
| 4656 static_cast<TestWebContents*>(CreateTestWebContents())); | 4651 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 4657 NavigationControllerImpl& source_controller = | 4652 NavigationControllerImpl& source_controller = |
| 4658 source_contents->GetController(); | 4653 source_contents->GetController(); |
| 4659 source_controller.Restore( | 4654 source_controller.Restore(entries.size() - 1, |
| 4660 entries.size() - 1, | 4655 RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 4661 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | |
| 4662 &entries); | |
| 4663 ASSERT_EQ(0u, entries.size()); | 4656 ASSERT_EQ(0u, entries.size()); |
| 4664 source_controller.LoadIfNecessary(); | 4657 source_controller.LoadIfNecessary(); |
| 4665 source_contents->CommitPendingNavigation(); | 4658 source_contents->CommitPendingNavigation(); |
| 4666 | 4659 |
| 4667 // Load a page, then copy state from |source_contents|. | 4660 // Load a page, then copy state from |source_contents|. |
| 4668 NavigateAndCommit(kInitialUrl); | 4661 NavigateAndCommit(kInitialUrl); |
| 4669 contents()->ExpectSetHistoryOffsetAndLength(2, 3); | 4662 contents()->ExpectSetHistoryOffsetAndLength(2, 3); |
| 4670 controller_impl().CopyStateFromAndPrune(&source_controller, false); | 4663 controller_impl().CopyStateFromAndPrune(&source_controller, false); |
| 4671 ASSERT_EQ(3, controller_impl().GetEntryCount()); | 4664 ASSERT_EQ(3, controller_impl().GetEntryCount()); |
| 4672 | 4665 |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5318 // means that occasionally a navigation conflict will end up with one entry | 5311 // means that occasionally a navigation conflict will end up with one entry |
| 5319 // bubbling to the end of the entry list, but that's the least-bad option. | 5312 // bubbling to the end of the entry list, but that's the least-bad option. |
| 5320 EXPECT_EQ(3, controller.GetEntryCount()); | 5313 EXPECT_EQ(3, controller.GetEntryCount()); |
| 5321 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 5314 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 5322 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); | 5315 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); |
| 5323 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); | 5316 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); |
| 5324 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); | 5317 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); |
| 5325 } | 5318 } |
| 5326 | 5319 |
| 5327 } // namespace content | 5320 } // namespace content |
| OLD | NEW |