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

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

Issue 49003011: Handle should_replace_current_entry in prerender. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years 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 3075 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); 3086 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID());
3087 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); 3087 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1));
3088 3088
3089 scoped_ptr<TestWebContents> other_contents( 3089 scoped_ptr<TestWebContents> other_contents(
3090 static_cast<TestWebContents*>(CreateTestWebContents())); 3090 static_cast<TestWebContents*>(CreateTestWebContents()));
3091 NavigationControllerImpl& other_controller = other_contents->GetController(); 3091 NavigationControllerImpl& other_controller = other_contents->GetController();
3092 other_contents->NavigateAndCommit(url3); 3092 other_contents->NavigateAndCommit(url3);
3093 other_contents->ExpectSetHistoryLengthAndPrune( 3093 other_contents->ExpectSetHistoryLengthAndPrune(
3094 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3094 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3095 other_controller.GetEntryAtIndex(0)->GetPageID()); 3095 other_controller.GetEntryAtIndex(0)->GetPageID());
3096 other_controller.CopyStateFromAndPrune(&controller); 3096 other_controller.CopyStateFromAndPrune(&controller, false);
3097 3097
3098 // other_controller should now contain the 3 urls: url1, url2 and url3. 3098 // other_controller should now contain the 3 urls: url1, url2 and url3.
3099 3099
3100 ASSERT_EQ(3, other_controller.GetEntryCount()); 3100 ASSERT_EQ(3, other_controller.GetEntryCount());
3101 3101
3102 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3102 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3103 3103
3104 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3104 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3105 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3105 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3106 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 3106 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
(...skipping 25 matching lines...) Expand all
3132 controller.GoBack(); 3132 controller.GoBack();
3133 contents()->CommitPendingNavigation(); 3133 contents()->CommitPendingNavigation();
3134 3134
3135 scoped_ptr<TestWebContents> other_contents( 3135 scoped_ptr<TestWebContents> other_contents(
3136 static_cast<TestWebContents*>(CreateTestWebContents())); 3136 static_cast<TestWebContents*>(CreateTestWebContents()));
3137 NavigationControllerImpl& other_controller = other_contents->GetController(); 3137 NavigationControllerImpl& other_controller = other_contents->GetController();
3138 other_contents->NavigateAndCommit(url3); 3138 other_contents->NavigateAndCommit(url3);
3139 other_contents->ExpectSetHistoryLengthAndPrune( 3139 other_contents->ExpectSetHistoryLengthAndPrune(
3140 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3140 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3141 other_controller.GetEntryAtIndex(0)->GetPageID()); 3141 other_controller.GetEntryAtIndex(0)->GetPageID());
3142 other_controller.CopyStateFromAndPrune(&controller); 3142 other_controller.CopyStateFromAndPrune(&controller, false);
3143 3143
3144 // other_controller should now contain: url1, url3 3144 // other_controller should now contain: url1, url3
3145 3145
3146 ASSERT_EQ(2, other_controller.GetEntryCount()); 3146 ASSERT_EQ(2, other_controller.GetEntryCount());
3147 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); 3147 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
3148 3148
3149 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3149 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3150 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3150 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3151 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); 3151 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID());
3152 3152
(...skipping 17 matching lines...) Expand all
3170 NavigateAndCommit(url2); 3170 NavigateAndCommit(url2);
3171 3171
3172 scoped_ptr<TestWebContents> other_contents( 3172 scoped_ptr<TestWebContents> other_contents(
3173 static_cast<TestWebContents*>(CreateTestWebContents())); 3173 static_cast<TestWebContents*>(CreateTestWebContents()));
3174 NavigationControllerImpl& other_controller = other_contents->GetController(); 3174 NavigationControllerImpl& other_controller = other_contents->GetController();
3175 other_contents->NavigateAndCommit(url3); 3175 other_contents->NavigateAndCommit(url3);
3176 other_contents->NavigateAndCommit(url4); 3176 other_contents->NavigateAndCommit(url4);
3177 other_contents->ExpectSetHistoryLengthAndPrune( 3177 other_contents->ExpectSetHistoryLengthAndPrune(
3178 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)), 2, 3178 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)), 2,
3179 other_controller.GetEntryAtIndex(0)->GetPageID()); 3179 other_controller.GetEntryAtIndex(0)->GetPageID());
3180 other_controller.CopyStateFromAndPrune(&controller); 3180 other_controller.CopyStateFromAndPrune(&controller, false);
3181 3181
3182 // other_controller should now contain: url1, url2, url4 3182 // other_controller should now contain: url1, url2, url4
3183 3183
3184 ASSERT_EQ(3, other_controller.GetEntryCount()); 3184 ASSERT_EQ(3, other_controller.GetEntryCount());
3185 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3185 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3186 3186
3187 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3187 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3188 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3188 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3189 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); 3189 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3190 3190
(...skipping 19 matching lines...) Expand all
3210 scoped_ptr<TestWebContents> other_contents( 3210 scoped_ptr<TestWebContents> other_contents(
3211 static_cast<TestWebContents*>(CreateTestWebContents())); 3211 static_cast<TestWebContents*>(CreateTestWebContents()));
3212 NavigationControllerImpl& other_controller = other_contents->GetController(); 3212 NavigationControllerImpl& other_controller = other_contents->GetController();
3213 other_contents->NavigateAndCommit(url3); 3213 other_contents->NavigateAndCommit(url3);
3214 other_contents->NavigateAndCommit(url4); 3214 other_contents->NavigateAndCommit(url4);
3215 other_controller.GoBack(); 3215 other_controller.GoBack();
3216 other_contents->CommitPendingNavigation(); 3216 other_contents->CommitPendingNavigation();
3217 other_contents->ExpectSetHistoryLengthAndPrune( 3217 other_contents->ExpectSetHistoryLengthAndPrune(
3218 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3218 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3219 other_controller.GetEntryAtIndex(0)->GetPageID()); 3219 other_controller.GetEntryAtIndex(0)->GetPageID());
3220 other_controller.CopyStateFromAndPrune(&controller); 3220 other_controller.CopyStateFromAndPrune(&controller, false);
3221 3221
3222 // other_controller should now contain: url1, url2, url3 3222 // other_controller should now contain: url1, url2, url3
3223 3223
3224 ASSERT_EQ(3, other_controller.GetEntryCount()); 3224 ASSERT_EQ(3, other_controller.GetEntryCount());
3225 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3225 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3226 3226
3227 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3227 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3228 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3228 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3229 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 3229 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
3230 3230
(...skipping 20 matching lines...) Expand all
3251 3251
3252 scoped_ptr<TestWebContents> other_contents( 3252 scoped_ptr<TestWebContents> other_contents(
3253 static_cast<TestWebContents*>(CreateTestWebContents())); 3253 static_cast<TestWebContents*>(CreateTestWebContents()));
3254 NavigationControllerImpl& other_controller = other_contents->GetController(); 3254 NavigationControllerImpl& other_controller = other_contents->GetController();
3255 other_contents->NavigateAndCommit(url3); 3255 other_contents->NavigateAndCommit(url3);
3256 other_controller.LoadURL( 3256 other_controller.LoadURL(
3257 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 3257 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3258 other_contents->ExpectSetHistoryLengthAndPrune( 3258 other_contents->ExpectSetHistoryLengthAndPrune(
3259 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3259 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3260 other_controller.GetEntryAtIndex(0)->GetPageID()); 3260 other_controller.GetEntryAtIndex(0)->GetPageID());
3261 other_controller.CopyStateFromAndPrune(&controller); 3261 other_controller.CopyStateFromAndPrune(&controller, false);
3262 3262
3263 // other_controller should now contain url1, url3, and a pending entry 3263 // other_controller should now contain url1, url3, and a pending entry
3264 // for url4. 3264 // for url4.
3265 3265
3266 ASSERT_EQ(2, other_controller.GetEntryCount()); 3266 ASSERT_EQ(2, other_controller.GetEntryCount());
3267 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 3267 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
3268 3268
3269 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3269 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3270 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3270 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3271 3271
(...skipping 26 matching lines...) Expand all
3298 other_contents->NavigateAndCommit(url2a); 3298 other_contents->NavigateAndCommit(url2a);
3299 // Simulate a client redirect, which has the same page ID as entry 2a. 3299 // Simulate a client redirect, which has the same page ID as entry 2a.
3300 other_controller.LoadURL( 3300 other_controller.LoadURL(
3301 url2b, Referrer(), PAGE_TRANSITION_LINK, std::string()); 3301 url2b, Referrer(), PAGE_TRANSITION_LINK, std::string());
3302 other_controller.GetPendingEntry()->SetPageID( 3302 other_controller.GetPendingEntry()->SetPageID(
3303 other_controller.GetLastCommittedEntry()->GetPageID()); 3303 other_controller.GetLastCommittedEntry()->GetPageID());
3304 3304
3305 other_contents->ExpectSetHistoryLengthAndPrune( 3305 other_contents->ExpectSetHistoryLengthAndPrune(
3306 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3306 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3307 other_controller.GetEntryAtIndex(0)->GetPageID()); 3307 other_controller.GetEntryAtIndex(0)->GetPageID());
3308 other_controller.CopyStateFromAndPrune(&controller); 3308 other_controller.CopyStateFromAndPrune(&controller, false);
3309 3309
3310 // other_controller should now contain url1, url2a, and a pending entry 3310 // other_controller should now contain url1, url2a, and a pending entry
3311 // for url2b. 3311 // for url2b.
3312 3312
3313 ASSERT_EQ(2, other_controller.GetEntryCount()); 3313 ASSERT_EQ(2, other_controller.GetEntryCount());
3314 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 3314 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
3315 3315
3316 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3316 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3317 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); 3317 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL());
3318 3318
(...skipping 23 matching lines...) Expand all
3342 NavigateAndCommit(url2); 3342 NavigateAndCommit(url2);
3343 controller.GoBack(); 3343 controller.GoBack();
3344 3344
3345 scoped_ptr<TestWebContents> other_contents( 3345 scoped_ptr<TestWebContents> other_contents(
3346 static_cast<TestWebContents*>(CreateTestWebContents())); 3346 static_cast<TestWebContents*>(CreateTestWebContents()));
3347 NavigationControllerImpl& other_controller = other_contents->GetController(); 3347 NavigationControllerImpl& other_controller = other_contents->GetController();
3348 other_contents->NavigateAndCommit(url3); 3348 other_contents->NavigateAndCommit(url3);
3349 other_contents->ExpectSetHistoryLengthAndPrune( 3349 other_contents->ExpectSetHistoryLengthAndPrune(
3350 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3350 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3351 other_controller.GetEntryAtIndex(0)->GetPageID()); 3351 other_controller.GetEntryAtIndex(0)->GetPageID());
3352 other_controller.CopyStateFromAndPrune(&controller); 3352 other_controller.CopyStateFromAndPrune(&controller, false);
3353 3353
3354 // other_controller should now contain: url1, url2, url3 3354 // other_controller should now contain: url1, url2, url3
3355 3355
3356 ASSERT_EQ(3, other_controller.GetEntryCount()); 3356 ASSERT_EQ(3, other_controller.GetEntryCount());
3357 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3357 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3358 3358
3359 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3359 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3360 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3360 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3361 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 3361 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
3362 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3362 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
(...skipping 26 matching lines...) Expand all
3389 NavigateAndCommit(url2); 3389 NavigateAndCommit(url2);
3390 NavigateAndCommit(url3); 3390 NavigateAndCommit(url3);
3391 3391
3392 scoped_ptr<TestWebContents> other_contents( 3392 scoped_ptr<TestWebContents> other_contents(
3393 static_cast<TestWebContents*>(CreateTestWebContents())); 3393 static_cast<TestWebContents*>(CreateTestWebContents()));
3394 NavigationControllerImpl& other_controller = other_contents->GetController(); 3394 NavigationControllerImpl& other_controller = other_contents->GetController();
3395 other_contents->NavigateAndCommit(url4); 3395 other_contents->NavigateAndCommit(url4);
3396 other_contents->ExpectSetHistoryLengthAndPrune( 3396 other_contents->ExpectSetHistoryLengthAndPrune(
3397 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3397 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3398 other_controller.GetEntryAtIndex(0)->GetPageID()); 3398 other_controller.GetEntryAtIndex(0)->GetPageID());
3399 other_controller.CopyStateFromAndPrune(&controller); 3399 other_controller.CopyStateFromAndPrune(&controller, false);
3400 3400
3401 // We should have received a pruned notification. 3401 // We should have received a pruned notification.
3402 EXPECT_EQ(1, listener.notification_count_); 3402 EXPECT_EQ(1, listener.notification_count_);
3403 EXPECT_TRUE(listener.details_.from_front); 3403 EXPECT_TRUE(listener.details_.from_front);
3404 EXPECT_EQ(1, listener.details_.count); 3404 EXPECT_EQ(1, listener.details_.count);
3405 3405
3406 // other_controller should now contain only 3 urls: url2, url3 and url4. 3406 // other_controller should now contain only 3 urls: url2, url3 and url4.
3407 3407
3408 ASSERT_EQ(3, other_controller.GetEntryCount()); 3408 ASSERT_EQ(3, other_controller.GetEntryCount());
3409 3409
3410 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3410 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3411 3411
3412 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL()); 3412 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL());
3413 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3413 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3414 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); 3414 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3415 EXPECT_EQ(1, other_controller.GetEntryAtIndex(0)->GetPageID()); 3415 EXPECT_EQ(1, other_controller.GetEntryAtIndex(0)->GetPageID());
3416 EXPECT_EQ(2, other_controller.GetEntryAtIndex(1)->GetPageID()); 3416 EXPECT_EQ(2, other_controller.GetEntryAtIndex(1)->GetPageID());
3417 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3417 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3418 3418
3419 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); 3419 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
3420 } 3420 }
3421 3421
3422 // Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest, with
3423 // replace_entry set to true.
3424 TEST_F(NavigationControllerTest, CopyStateFromAndPruneReplaceEntry) {
3425 NavigationControllerImpl& controller = controller_impl();
3426 const GURL url1("http://foo/1");
3427 const GURL url2("http://foo/2");
3428 const GURL url3("http://foo/3");
3429
3430 NavigateAndCommit(url1);
3431 NavigateAndCommit(url2);
3432
3433 // First two entries should have the same SiteInstance.
3434 SiteInstance* instance1 =
3435 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0));
3436 SiteInstance* instance2 =
3437 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1));
3438 EXPECT_EQ(instance1, instance2);
3439 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID());
3440 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID());
3441 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1));
3442
3443 scoped_ptr<TestWebContents> other_contents(
3444 static_cast<TestWebContents*>(CreateTestWebContents()));
3445 NavigationControllerImpl& other_controller = other_contents->GetController();
3446 other_contents->NavigateAndCommit(url3);
3447 other_contents->ExpectSetHistoryLengthAndPrune(
3448 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3449 other_controller.GetEntryAtIndex(0)->GetPageID());
3450 other_controller.CopyStateFromAndPrune(&controller, true);
3451
3452 // other_controller should now contain the 2 urls: url1 and url3.
3453
3454 ASSERT_EQ(2, other_controller.GetEntryCount());
3455
3456 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
3457
3458 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3459 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3460 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3461 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID());
3462
3463 // A new SiteInstance should be used for the new tab.
3464 SiteInstance* instance3 =
3465 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1));
3466 EXPECT_NE(instance3, instance1);
Charlie Reis 2013/12/11 02:57:39 Yikes, these are two different SiteInstances for t
davidben 2013/12/11 21:20:59 I just got that from the existing CopyStateFromAnd
3467
3468 // The max page ID map should be copied over and updated with the max page ID
3469 // from the current tab.
3470 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1));
3471 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3));
3472 }
3473
3474 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, when the max
3475 // entry count is 3 and replace_entry is true. We should not prune entries.
3476 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) {
3477 NavigationControllerImpl& controller = controller_impl();
3478 size_t original_count = NavigationControllerImpl::max_entry_count();
3479 const int kMaxEntryCount = 3;
3480
3481 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
3482
3483 const GURL url1("http://foo/1");
3484 const GURL url2("http://foo/2");
3485 const GURL url3("http://foo/3");
3486 const GURL url4("http://foo/4");
3487
3488 // Create a PrunedListener to observe prune notifications.
3489 PrunedListener listener(&controller);
3490
3491 NavigateAndCommit(url1);
3492 NavigateAndCommit(url2);
3493 NavigateAndCommit(url3);
3494
3495 scoped_ptr<TestWebContents> other_contents(
3496 static_cast<TestWebContents*>(CreateTestWebContents()));
3497 NavigationControllerImpl& other_controller = other_contents->GetController();
3498 other_contents->NavigateAndCommit(url4);
3499 other_contents->ExpectSetHistoryLengthAndPrune(
3500 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3501 other_controller.GetEntryAtIndex(0)->GetPageID());
3502 other_controller.CopyStateFromAndPrune(&controller, true);
3503
3504 // We should have received no pruned notification.
3505 EXPECT_EQ(0, listener.notification_count_);
3506
3507 // other_controller should now contain only 3 urls: url1, url2 and url4.
3508
3509 ASSERT_EQ(3, other_controller.GetEntryCount());
3510
3511 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3512
3513 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3514 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3515 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3516 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3517 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID());
3518 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3519
3520 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
3521 }
3522
3422 // Tests that navigations initiated from the page (with the history object) 3523 // Tests that navigations initiated from the page (with the history object)
3423 // work as expected without navigation entries. 3524 // work as expected without navigation entries.
3424 TEST_F(NavigationControllerTest, HistoryNavigate) { 3525 TEST_F(NavigationControllerTest, HistoryNavigate) {
3425 NavigationControllerImpl& controller = controller_impl(); 3526 NavigationControllerImpl& controller = controller_impl();
3426 const GURL url1("http://foo/1"); 3527 const GURL url1("http://foo/1");
3427 const GURL url2("http://foo/2"); 3528 const GURL url2("http://foo/2");
3428 const GURL url3("http://foo/3"); 3529 const GURL url3("http://foo/3");
3429 3530
3430 NavigateAndCommit(url1); 3531 NavigateAndCommit(url1);
3431 NavigateAndCommit(url2); 3532 NavigateAndCommit(url2);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 EXPECT_EQ(1, controller.GetEntryCount()); 3937 EXPECT_EQ(1, controller.GetEntryCount());
3837 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 3938 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
3838 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3939 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3839 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3940 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3840 EXPECT_FALSE(controller.CanGoBack()); 3941 EXPECT_FALSE(controller.CanGoBack());
3841 EXPECT_FALSE(controller.CanGoForward()); 3942 EXPECT_FALSE(controller.CanGoForward());
3842 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 3943 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
3843 } 3944 }
3844 3945
3845 } // namespace content 3946 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698