Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 257463004: Copy max_restored_page_id_ when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 4154 matching lines...) Expand 10 before | Expand all | Expand 10 after
4165 // cleared. 4165 // cleared.
4166 EXPECT_EQ(1, controller.GetEntryCount()); 4166 EXPECT_EQ(1, controller.GetEntryCount());
4167 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4167 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4168 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4168 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4169 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4169 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4170 EXPECT_FALSE(controller.CanGoBack()); 4170 EXPECT_FALSE(controller.CanGoBack());
4171 EXPECT_FALSE(controller.CanGoForward()); 4171 EXPECT_FALSE(controller.CanGoForward());
4172 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4172 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4173 } 4173 }
4174 4174
4175 // Tests that we can navigate to the restored entries
4176 // imported by CopyStateFromAndPrune.
4177 TEST_F(NavigationControllerTest, CopyRestoredStateAndNavigate) {
Charlie Reis 2014/04/24 18:02:02 nit: Can you move this up near the other block of
Alexander Semashko 2014/04/24 21:40:37 Done.
4178 const GURL kRestoredUrls[] = {
4179 GURL("http://site1.com"),
4180 GURL("http://site2.com"),
4181 };
4182 const GURL kInitialUrl("http://site3.com");
4183
4184 std::vector<NavigationEntry*> entries;
4185 for (int i = 0; i < arraysize(kRestoredUrls); ++i) {
4186 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry(
4187 kRestoredUrls[i], Referrer(), PAGE_TRANSITION_RELOAD, false,
4188 std::string(), browser_context());
4189 entry->SetPageID(i);
4190 entries.push_back(entry);
4191 }
4192
4193 // Create a WebContents with restored entries.
4194 scoped_ptr<TestWebContents> source_contents(
4195 static_cast<TestWebContents*>(CreateTestWebContents()));
4196 NavigationControllerImpl& source_controller =
4197 source_contents->GetController();
4198 source_controller.Restore(
4199 entries.size() - 1,
4200 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
4201 &entries);
4202 ASSERT_EQ(0u, entries.size());
4203 source_controller.LoadIfNecessary();
4204 source_contents->CommitPendingNavigation();
4205
4206 // Load a page, then copy state from |source_contents|.
4207 NavigateAndCommit(kInitialUrl);
4208 contents()->ExpectSetHistoryLengthAndPrune(
4209 GetSiteInstanceFromEntry(controller_impl().GetEntryAtIndex(0)), 2,
4210 controller_impl().GetEntryAtIndex(0)->GetPageID());
4211 controller_impl().CopyStateFromAndPrune(&source_controller, false);
4212 ASSERT_EQ(3, controller_impl().GetEntryCount());
4213
4214 // Go back to the first entry one at a time and
4215 // verify that it works as expected.
4216 EXPECT_EQ(2, controller_impl().GetCurrentEntryIndex());
4217 EXPECT_EQ(kInitialUrl, controller_impl().GetActiveEntry()->GetURL());
4218
4219 controller_impl().GoBack();
4220 contents()->CommitPendingNavigation();
4221 EXPECT_EQ(1, controller_impl().GetCurrentEntryIndex());
4222 EXPECT_EQ(kRestoredUrls[1], controller_impl().GetActiveEntry()->GetURL());
4223
4224 controller_impl().GoBack();
4225 contents()->CommitPendingNavigation();
4226 EXPECT_EQ(0, controller_impl().GetCurrentEntryIndex());
4227 EXPECT_EQ(kRestoredUrls[0], controller_impl().GetActiveEntry()->GetURL());
4228 }
4229
4175 } // namespace content 4230 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698