| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SetUp() override { | 211 void SetUp() override { |
| 212 RenderViewHostImplTestHarness::SetUp(); | 212 RenderViewHostImplTestHarness::SetUp(); |
| 213 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); | 213 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); |
| 214 ASSERT_TRUE(web_contents); // The WebContents should be created by now. | 214 ASSERT_TRUE(web_contents); // The WebContents should be created by now. |
| 215 WebContentsObserver::Observe(web_contents); | 215 WebContentsObserver::Observe(web_contents); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // WebContentsObserver: | 218 // WebContentsObserver: |
| 219 void DidStartNavigationToPendingEntry( | 219 void DidStartNavigationToPendingEntry(const GURL& url, |
| 220 const GURL& url, | 220 ReloadType reload_type) override { |
| 221 NavigationController::ReloadType reload_type) override { | |
| 222 navigated_url_ = url; | 221 navigated_url_ = url; |
| 223 } | 222 } |
| 224 | 223 |
| 225 void NavigationEntryCommitted( | 224 void NavigationEntryCommitted( |
| 226 const LoadCommittedDetails& load_details) override { | 225 const LoadCommittedDetails& load_details) override { |
| 227 navigation_entry_committed_counter_++; | 226 navigation_entry_committed_counter_++; |
| 228 } | 227 } |
| 229 | 228 |
| 230 const GURL& navigated_url() const { | 229 const GURL& navigated_url() const { |
| 231 return navigated_url_; | 230 return navigated_url_; |
| (...skipping 2784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3016 browser_context()); | 3015 browser_context()); |
| 3017 entry->SetPageID(0); | 3016 entry->SetPageID(0); |
| 3018 entry->SetTitle(base::ASCIIToUTF16("Title")); | 3017 entry->SetTitle(base::ASCIIToUTF16("Title")); |
| 3019 entry->SetPageState(PageState::CreateFromEncodedData("state")); | 3018 entry->SetPageState(PageState::CreateFromEncodedData("state")); |
| 3020 const base::Time timestamp = base::Time::Now(); | 3019 const base::Time timestamp = base::Time::Now(); |
| 3021 entry->SetTimestamp(timestamp); | 3020 entry->SetTimestamp(timestamp); |
| 3022 entries.push_back(std::move(entry)); | 3021 entries.push_back(std::move(entry)); |
| 3023 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 3022 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
| 3024 WebContents::Create(WebContents::CreateParams(browser_context())))); | 3023 WebContents::Create(WebContents::CreateParams(browser_context())))); |
| 3025 NavigationControllerImpl& our_controller = our_contents->GetController(); | 3024 NavigationControllerImpl& our_controller = our_contents->GetController(); |
| 3026 our_controller.Restore( | 3025 our_controller.Restore(0, RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 3027 0, | |
| 3028 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | |
| 3029 &entries); | |
| 3030 ASSERT_EQ(0u, entries.size()); | 3026 ASSERT_EQ(0u, entries.size()); |
| 3031 | 3027 |
| 3032 // Before navigating to the restored entry, it should have a restore_type | 3028 // Before navigating to the restored entry, it should have a restore_type |
| 3033 // and no SiteInstance. | 3029 // and no SiteInstance. |
| 3034 ASSERT_EQ(1, our_controller.GetEntryCount()); | 3030 ASSERT_EQ(1, our_controller.GetEntryCount()); |
| 3035 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 3031 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, |
| 3036 our_controller.GetEntryAtIndex(0)->restore_type()); | 3032 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3037 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 3033 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 3038 | 3034 |
| 3039 // After navigating, we should have one entry, and it should be "pending". | 3035 // After navigating, we should have one entry, and it should be "pending". |
| 3040 our_controller.GoToIndex(0); | 3036 our_controller.GoToIndex(0); |
| 3041 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3037 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3042 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 3038 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 3043 our_controller.GetPendingEntry()); | 3039 our_controller.GetPendingEntry()); |
| 3044 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 3040 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
| 3045 | 3041 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3064 | 3060 |
| 3065 // There should be no longer any pending entry and one committed one. This | 3061 // There should be no longer any pending entry and one committed one. This |
| 3066 // means that we were able to locate the entry, assign its site instance, and | 3062 // means that we were able to locate the entry, assign its site instance, and |
| 3067 // commit it properly. | 3063 // commit it properly. |
| 3068 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3064 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3069 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 3065 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
| 3070 EXPECT_FALSE(our_controller.GetPendingEntry()); | 3066 EXPECT_FALSE(our_controller.GetPendingEntry()); |
| 3071 EXPECT_EQ( | 3067 EXPECT_EQ( |
| 3072 url, | 3068 url, |
| 3073 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 3069 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
| 3074 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 3070 EXPECT_EQ(RestoreType::NONE, |
| 3075 our_controller.GetEntryAtIndex(0)->restore_type()); | 3071 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3076 | 3072 |
| 3077 // Timestamp should have been updated. | 3073 // Timestamp should have been updated. |
| 3078 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); | 3074 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); |
| 3079 } | 3075 } |
| 3080 | 3076 |
| 3081 // Tests that we can still navigate to a restored entry after a different | 3077 // Tests that we can still navigate to a restored entry after a different |
| 3082 // navigation fails and clears the pending entry. http://crbug.com/90085 | 3078 // navigation fails and clears the pending entry. http://crbug.com/90085 |
| 3083 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 3079 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
| 3084 // Create a NavigationController with a restored set of tabs. | 3080 // Create a NavigationController with a restored set of tabs. |
| 3085 GURL url("http://foo"); | 3081 GURL url("http://foo"); |
| 3086 std::vector<std::unique_ptr<NavigationEntry>> entries; | 3082 std::vector<std::unique_ptr<NavigationEntry>> entries; |
| 3087 std::unique_ptr<NavigationEntry> new_entry = | 3083 std::unique_ptr<NavigationEntry> new_entry = |
| 3088 NavigationControllerImpl::CreateNavigationEntry( | 3084 NavigationControllerImpl::CreateNavigationEntry( |
| 3089 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), | 3085 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), |
| 3090 browser_context()); | 3086 browser_context()); |
| 3091 new_entry->SetPageID(0); | 3087 new_entry->SetPageID(0); |
| 3092 new_entry->SetTitle(base::ASCIIToUTF16("Title")); | 3088 new_entry->SetTitle(base::ASCIIToUTF16("Title")); |
| 3093 new_entry->SetPageState(PageState::CreateFromEncodedData("state")); | 3089 new_entry->SetPageState(PageState::CreateFromEncodedData("state")); |
| 3094 entries.push_back(std::move(new_entry)); | 3090 entries.push_back(std::move(new_entry)); |
| 3095 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 3091 std::unique_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
| 3096 WebContents::Create(WebContents::CreateParams(browser_context())))); | 3092 WebContents::Create(WebContents::CreateParams(browser_context())))); |
| 3097 NavigationControllerImpl& our_controller = our_contents->GetController(); | 3093 NavigationControllerImpl& our_controller = our_contents->GetController(); |
| 3098 our_controller.Restore( | 3094 our_controller.Restore(0, RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 3099 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | |
| 3100 ASSERT_EQ(0u, entries.size()); | 3095 ASSERT_EQ(0u, entries.size()); |
| 3101 | 3096 |
| 3102 // Ensure the RenderFrame is initialized before simulating events coming from | 3097 // Ensure the RenderFrame is initialized before simulating events coming from |
| 3103 // it. | 3098 // it. |
| 3104 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 3099 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 3105 | 3100 |
| 3106 // Before navigating to the restored entry, it should have a restore_type | 3101 // Before navigating to the restored entry, it should have a restore_type |
| 3107 // and no SiteInstance. | 3102 // and no SiteInstance. |
| 3108 NavigationEntry* entry = our_controller.GetEntryAtIndex(0); | 3103 NavigationEntry* entry = our_controller.GetEntryAtIndex(0); |
| 3109 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 3104 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, |
| 3110 our_controller.GetEntryAtIndex(0)->restore_type()); | 3105 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3111 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 3106 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
| 3112 | 3107 |
| 3113 // After navigating, we should have one entry, and it should be "pending". | 3108 // After navigating, we should have one entry, and it should be "pending". |
| 3114 our_controller.GoToIndex(0); | 3109 our_controller.GoToIndex(0); |
| 3115 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3110 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3116 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 3111 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
| 3117 our_controller.GetPendingEntry()); | 3112 our_controller.GetPendingEntry()); |
| 3118 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 3113 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
| 3119 | 3114 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3145 main_rfh->PrepareForCommit(); | 3140 main_rfh->PrepareForCommit(); |
| 3146 main_rfh->SendNavigateWithParams(¶ms); | 3141 main_rfh->SendNavigateWithParams(¶ms); |
| 3147 | 3142 |
| 3148 // There should be no pending entry and one committed one. | 3143 // There should be no pending entry and one committed one. |
| 3149 EXPECT_EQ(1, our_controller.GetEntryCount()); | 3144 EXPECT_EQ(1, our_controller.GetEntryCount()); |
| 3150 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 3145 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
| 3151 EXPECT_FALSE(our_controller.GetPendingEntry()); | 3146 EXPECT_FALSE(our_controller.GetPendingEntry()); |
| 3152 EXPECT_EQ( | 3147 EXPECT_EQ( |
| 3153 url, | 3148 url, |
| 3154 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 3149 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
| 3155 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 3150 EXPECT_EQ(RestoreType::NONE, |
| 3156 our_controller.GetEntryAtIndex(0)->restore_type()); | 3151 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 3157 } | 3152 } |
| 3158 | 3153 |
| 3159 // Make sure that the page type and stuff is correct after an interstitial. | 3154 // Make sure that the page type and stuff is correct after an interstitial. |
| 3160 TEST_F(NavigationControllerTest, Interstitial) { | 3155 TEST_F(NavigationControllerTest, Interstitial) { |
| 3161 NavigationControllerImpl& controller = controller_impl(); | 3156 NavigationControllerImpl& controller = controller_impl(); |
| 3162 // First navigate somewhere normal. | 3157 // First navigate somewhere normal. |
| 3163 const GURL url1("http://foo"); | 3158 const GURL url1("http://foo"); |
| 3164 controller.LoadURL( | 3159 controller.LoadURL( |
| 3165 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3160 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4668 std::string(), browser_context()); | 4663 std::string(), browser_context()); |
| 4669 entry->SetPageID(static_cast<int>(i)); | 4664 entry->SetPageID(static_cast<int>(i)); |
| 4670 entries.push_back(std::move(entry)); | 4665 entries.push_back(std::move(entry)); |
| 4671 } | 4666 } |
| 4672 | 4667 |
| 4673 // Create a WebContents with restored entries. | 4668 // Create a WebContents with restored entries. |
| 4674 std::unique_ptr<TestWebContents> source_contents( | 4669 std::unique_ptr<TestWebContents> source_contents( |
| 4675 static_cast<TestWebContents*>(CreateTestWebContents())); | 4670 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 4676 NavigationControllerImpl& source_controller = | 4671 NavigationControllerImpl& source_controller = |
| 4677 source_contents->GetController(); | 4672 source_contents->GetController(); |
| 4678 source_controller.Restore( | 4673 source_controller.Restore(entries.size() - 1, |
| 4679 entries.size() - 1, | 4674 RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); |
| 4680 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | |
| 4681 &entries); | |
| 4682 ASSERT_EQ(0u, entries.size()); | 4675 ASSERT_EQ(0u, entries.size()); |
| 4683 source_controller.LoadIfNecessary(); | 4676 source_controller.LoadIfNecessary(); |
| 4684 source_contents->CommitPendingNavigation(); | 4677 source_contents->CommitPendingNavigation(); |
| 4685 | 4678 |
| 4686 // Load a page, then copy state from |source_contents|. | 4679 // Load a page, then copy state from |source_contents|. |
| 4687 NavigateAndCommit(kInitialUrl); | 4680 NavigateAndCommit(kInitialUrl); |
| 4688 contents()->ExpectSetHistoryOffsetAndLength(2, 3); | 4681 contents()->ExpectSetHistoryOffsetAndLength(2, 3); |
| 4689 controller_impl().CopyStateFromAndPrune(&source_controller, false); | 4682 controller_impl().CopyStateFromAndPrune(&source_controller, false); |
| 4690 ASSERT_EQ(3, controller_impl().GetEntryCount()); | 4683 ASSERT_EQ(3, controller_impl().GetEntryCount()); |
| 4691 | 4684 |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5337 // means that occasionally a navigation conflict will end up with one entry | 5330 // means that occasionally a navigation conflict will end up with one entry |
| 5338 // bubbling to the end of the entry list, but that's the least-bad option. | 5331 // bubbling to the end of the entry list, but that's the least-bad option. |
| 5339 EXPECT_EQ(3, controller.GetEntryCount()); | 5332 EXPECT_EQ(3, controller.GetEntryCount()); |
| 5340 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 5333 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 5341 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); | 5334 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); |
| 5342 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); | 5335 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); |
| 5343 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); | 5336 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); |
| 5344 } | 5337 } |
| 5345 | 5338 |
| 5346 } // namespace content | 5339 } // namespace content |
| OLD | NEW |