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

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: content::kAboutBlankURL 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());
3107 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); 3107 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3108 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); 3108 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID());
3109 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3109 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3110 3110
3111 // A new SiteInstance should be used for the new tab. 3111 // A new SiteInstance in a different BrowsingInstance should be used for the
3112 // new tab.
3112 SiteInstance* instance3 = 3113 SiteInstance* instance3 =
3113 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); 3114 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2));
3114 EXPECT_NE(instance3, instance1); 3115 EXPECT_NE(instance3, instance1);
3116 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1));
3115 3117
3116 // The max page ID map should be copied over and updated with the max page ID 3118 // The max page ID map should be copied over and updated with the max page ID
3117 // from the current tab. 3119 // from the current tab.
3118 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); 3120 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1));
3119 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); 3121 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3));
3120 } 3122 }
3121 3123
3122 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in 3124 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in
3123 // the target. 3125 // the target.
3124 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { 3126 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
3125 NavigationControllerImpl& controller = controller_impl(); 3127 NavigationControllerImpl& controller = controller_impl();
3126 const GURL url1("http://foo1"); 3128 const GURL url1("http://foo1");
3127 const GURL url2("http://foo2"); 3129 const GURL url2("http://foo2");
3128 const GURL url3("http://foo3"); 3130 const GURL url3("http://foo3");
3129 3131
3130 NavigateAndCommit(url1); 3132 NavigateAndCommit(url1);
3131 NavigateAndCommit(url2); 3133 NavigateAndCommit(url2);
3132 controller.GoBack(); 3134 controller.GoBack();
3133 contents()->CommitPendingNavigation(); 3135 contents()->CommitPendingNavigation();
3134 3136
3135 scoped_ptr<TestWebContents> other_contents( 3137 scoped_ptr<TestWebContents> other_contents(
3136 static_cast<TestWebContents*>(CreateTestWebContents())); 3138 static_cast<TestWebContents*>(CreateTestWebContents()));
3137 NavigationControllerImpl& other_controller = other_contents->GetController(); 3139 NavigationControllerImpl& other_controller = other_contents->GetController();
3138 other_contents->NavigateAndCommit(url3); 3140 other_contents->NavigateAndCommit(url3);
3139 other_contents->ExpectSetHistoryLengthAndPrune( 3141 other_contents->ExpectSetHistoryLengthAndPrune(
3140 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3142 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3141 other_controller.GetEntryAtIndex(0)->GetPageID()); 3143 other_controller.GetEntryAtIndex(0)->GetPageID());
3142 other_controller.CopyStateFromAndPrune(&controller); 3144 other_controller.CopyStateFromAndPrune(&controller, false);
3143 3145
3144 // other_controller should now contain: url1, url3 3146 // other_controller should now contain: url1, url3
3145 3147
3146 ASSERT_EQ(2, other_controller.GetEntryCount()); 3148 ASSERT_EQ(2, other_controller.GetEntryCount());
3147 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); 3149 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
3148 3150
3149 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3151 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3150 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3152 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3151 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); 3153 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID());
3152 3154
(...skipping 17 matching lines...) Expand all
3170 NavigateAndCommit(url2); 3172 NavigateAndCommit(url2);
3171 3173
3172 scoped_ptr<TestWebContents> other_contents( 3174 scoped_ptr<TestWebContents> other_contents(
3173 static_cast<TestWebContents*>(CreateTestWebContents())); 3175 static_cast<TestWebContents*>(CreateTestWebContents()));
3174 NavigationControllerImpl& other_controller = other_contents->GetController(); 3176 NavigationControllerImpl& other_controller = other_contents->GetController();
3175 other_contents->NavigateAndCommit(url3); 3177 other_contents->NavigateAndCommit(url3);
3176 other_contents->NavigateAndCommit(url4); 3178 other_contents->NavigateAndCommit(url4);
3177 other_contents->ExpectSetHistoryLengthAndPrune( 3179 other_contents->ExpectSetHistoryLengthAndPrune(
3178 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)), 2, 3180 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)), 2,
3179 other_controller.GetEntryAtIndex(0)->GetPageID()); 3181 other_controller.GetEntryAtIndex(0)->GetPageID());
3180 other_controller.CopyStateFromAndPrune(&controller); 3182 other_controller.CopyStateFromAndPrune(&controller, false);
3181 3183
3182 // other_controller should now contain: url1, url2, url4 3184 // other_controller should now contain: url1, url2, url4
3183 3185
3184 ASSERT_EQ(3, other_controller.GetEntryCount()); 3186 ASSERT_EQ(3, other_controller.GetEntryCount());
3185 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3187 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3186 3188
3187 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3189 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3188 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3190 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3189 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); 3191 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3190 3192
(...skipping 19 matching lines...) Expand all
3210 scoped_ptr<TestWebContents> other_contents( 3212 scoped_ptr<TestWebContents> other_contents(
3211 static_cast<TestWebContents*>(CreateTestWebContents())); 3213 static_cast<TestWebContents*>(CreateTestWebContents()));
3212 NavigationControllerImpl& other_controller = other_contents->GetController(); 3214 NavigationControllerImpl& other_controller = other_contents->GetController();
3213 other_contents->NavigateAndCommit(url3); 3215 other_contents->NavigateAndCommit(url3);
3214 other_contents->NavigateAndCommit(url4); 3216 other_contents->NavigateAndCommit(url4);
3215 other_controller.GoBack(); 3217 other_controller.GoBack();
3216 other_contents->CommitPendingNavigation(); 3218 other_contents->CommitPendingNavigation();
3217 other_contents->ExpectSetHistoryLengthAndPrune( 3219 other_contents->ExpectSetHistoryLengthAndPrune(
3218 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3220 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3219 other_controller.GetEntryAtIndex(0)->GetPageID()); 3221 other_controller.GetEntryAtIndex(0)->GetPageID());
3220 other_controller.CopyStateFromAndPrune(&controller); 3222 other_controller.CopyStateFromAndPrune(&controller, false);
3221 3223
3222 // other_controller should now contain: url1, url2, url3 3224 // other_controller should now contain: url1, url2, url3
3223 3225
3224 ASSERT_EQ(3, other_controller.GetEntryCount()); 3226 ASSERT_EQ(3, other_controller.GetEntryCount());
3225 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3227 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3226 3228
3227 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3229 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3228 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3230 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3229 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 3231 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
3230 3232
(...skipping 20 matching lines...) Expand all
3251 3253
3252 scoped_ptr<TestWebContents> other_contents( 3254 scoped_ptr<TestWebContents> other_contents(
3253 static_cast<TestWebContents*>(CreateTestWebContents())); 3255 static_cast<TestWebContents*>(CreateTestWebContents()));
3254 NavigationControllerImpl& other_controller = other_contents->GetController(); 3256 NavigationControllerImpl& other_controller = other_contents->GetController();
3255 other_contents->NavigateAndCommit(url3); 3257 other_contents->NavigateAndCommit(url3);
3256 other_controller.LoadURL( 3258 other_controller.LoadURL(
3257 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 3259 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3258 other_contents->ExpectSetHistoryLengthAndPrune( 3260 other_contents->ExpectSetHistoryLengthAndPrune(
3259 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3261 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3260 other_controller.GetEntryAtIndex(0)->GetPageID()); 3262 other_controller.GetEntryAtIndex(0)->GetPageID());
3261 other_controller.CopyStateFromAndPrune(&controller); 3263 other_controller.CopyStateFromAndPrune(&controller, false);
3262 3264
3263 // other_controller should now contain url1, url3, and a pending entry 3265 // other_controller should now contain url1, url3, and a pending entry
3264 // for url4. 3266 // for url4.
3265 3267
3266 ASSERT_EQ(2, other_controller.GetEntryCount()); 3268 ASSERT_EQ(2, other_controller.GetEntryCount());
3267 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 3269 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
3268 3270
3269 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3271 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3270 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3272 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3271 3273
(...skipping 26 matching lines...) Expand all
3298 other_contents->NavigateAndCommit(url2a); 3300 other_contents->NavigateAndCommit(url2a);
3299 // Simulate a client redirect, which has the same page ID as entry 2a. 3301 // Simulate a client redirect, which has the same page ID as entry 2a.
3300 other_controller.LoadURL( 3302 other_controller.LoadURL(
3301 url2b, Referrer(), PAGE_TRANSITION_LINK, std::string()); 3303 url2b, Referrer(), PAGE_TRANSITION_LINK, std::string());
3302 other_controller.GetPendingEntry()->SetPageID( 3304 other_controller.GetPendingEntry()->SetPageID(
3303 other_controller.GetLastCommittedEntry()->GetPageID()); 3305 other_controller.GetLastCommittedEntry()->GetPageID());
3304 3306
3305 other_contents->ExpectSetHistoryLengthAndPrune( 3307 other_contents->ExpectSetHistoryLengthAndPrune(
3306 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, 3308 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3307 other_controller.GetEntryAtIndex(0)->GetPageID()); 3309 other_controller.GetEntryAtIndex(0)->GetPageID());
3308 other_controller.CopyStateFromAndPrune(&controller); 3310 other_controller.CopyStateFromAndPrune(&controller, false);
3309 3311
3310 // other_controller should now contain url1, url2a, and a pending entry 3312 // other_controller should now contain url1, url2a, and a pending entry
3311 // for url2b. 3313 // for url2b.
3312 3314
3313 ASSERT_EQ(2, other_controller.GetEntryCount()); 3315 ASSERT_EQ(2, other_controller.GetEntryCount());
3314 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 3316 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
3315 3317
3316 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3318 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3317 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); 3319 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL());
3318 3320
(...skipping 23 matching lines...) Expand all
3342 NavigateAndCommit(url2); 3344 NavigateAndCommit(url2);
3343 controller.GoBack(); 3345 controller.GoBack();
3344 3346
3345 scoped_ptr<TestWebContents> other_contents( 3347 scoped_ptr<TestWebContents> other_contents(
3346 static_cast<TestWebContents*>(CreateTestWebContents())); 3348 static_cast<TestWebContents*>(CreateTestWebContents()));
3347 NavigationControllerImpl& other_controller = other_contents->GetController(); 3349 NavigationControllerImpl& other_controller = other_contents->GetController();
3348 other_contents->NavigateAndCommit(url3); 3350 other_contents->NavigateAndCommit(url3);
3349 other_contents->ExpectSetHistoryLengthAndPrune( 3351 other_contents->ExpectSetHistoryLengthAndPrune(
3350 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3352 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3351 other_controller.GetEntryAtIndex(0)->GetPageID()); 3353 other_controller.GetEntryAtIndex(0)->GetPageID());
3352 other_controller.CopyStateFromAndPrune(&controller); 3354 other_controller.CopyStateFromAndPrune(&controller, false);
3353 3355
3354 // other_controller should now contain: url1, url2, url3 3356 // other_controller should now contain: url1, url2, url3
3355 3357
3356 ASSERT_EQ(3, other_controller.GetEntryCount()); 3358 ASSERT_EQ(3, other_controller.GetEntryCount());
3357 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3359 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3358 3360
3359 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3361 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3360 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3362 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3361 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 3363 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
3362 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3364 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
(...skipping 26 matching lines...) Expand all
3389 NavigateAndCommit(url2); 3391 NavigateAndCommit(url2);
3390 NavigateAndCommit(url3); 3392 NavigateAndCommit(url3);
3391 3393
3392 scoped_ptr<TestWebContents> other_contents( 3394 scoped_ptr<TestWebContents> other_contents(
3393 static_cast<TestWebContents*>(CreateTestWebContents())); 3395 static_cast<TestWebContents*>(CreateTestWebContents()));
3394 NavigationControllerImpl& other_controller = other_contents->GetController(); 3396 NavigationControllerImpl& other_controller = other_contents->GetController();
3395 other_contents->NavigateAndCommit(url4); 3397 other_contents->NavigateAndCommit(url4);
3396 other_contents->ExpectSetHistoryLengthAndPrune( 3398 other_contents->ExpectSetHistoryLengthAndPrune(
3397 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 3399 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3398 other_controller.GetEntryAtIndex(0)->GetPageID()); 3400 other_controller.GetEntryAtIndex(0)->GetPageID());
3399 other_controller.CopyStateFromAndPrune(&controller); 3401 other_controller.CopyStateFromAndPrune(&controller, false);
3400 3402
3401 // We should have received a pruned notification. 3403 // We should have received a pruned notification.
3402 EXPECT_EQ(1, listener.notification_count_); 3404 EXPECT_EQ(1, listener.notification_count_);
3403 EXPECT_TRUE(listener.details_.from_front); 3405 EXPECT_TRUE(listener.details_.from_front);
3404 EXPECT_EQ(1, listener.details_.count); 3406 EXPECT_EQ(1, listener.details_.count);
3405 3407
3406 // other_controller should now contain only 3 urls: url2, url3 and url4. 3408 // other_controller should now contain only 3 urls: url2, url3 and url4.
3407 3409
3408 ASSERT_EQ(3, other_controller.GetEntryCount()); 3410 ASSERT_EQ(3, other_controller.GetEntryCount());
3409 3411
3410 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 3412 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3411 3413
3412 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL()); 3414 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL());
3413 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 3415 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3414 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); 3416 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3415 EXPECT_EQ(1, other_controller.GetEntryAtIndex(0)->GetPageID()); 3417 EXPECT_EQ(1, other_controller.GetEntryAtIndex(0)->GetPageID());
3416 EXPECT_EQ(2, other_controller.GetEntryAtIndex(1)->GetPageID()); 3418 EXPECT_EQ(2, other_controller.GetEntryAtIndex(1)->GetPageID());
3417 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3419 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3418 3420
3419 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); 3421 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
3420 } 3422 }
3421 3423
3424 // Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest, with
3425 // replace_entry set to true.
3426 TEST_F(NavigationControllerTest, CopyStateFromAndPruneReplaceEntry) {
3427 NavigationControllerImpl& controller = controller_impl();
3428 const GURL url1("http://foo/1");
3429 const GURL url2("http://foo/2");
3430 const GURL url3("http://foo/3");
3431
3432 NavigateAndCommit(url1);
3433 NavigateAndCommit(url2);
3434
3435 // First two entries should have the same SiteInstance.
3436 SiteInstance* instance1 =
3437 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0));
3438 SiteInstance* instance2 =
3439 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1));
3440 EXPECT_EQ(instance1, instance2);
3441 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID());
3442 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID());
3443 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1));
3444
3445 scoped_ptr<TestWebContents> other_contents(
3446 static_cast<TestWebContents*>(CreateTestWebContents()));
3447 NavigationControllerImpl& other_controller = other_contents->GetController();
3448 other_contents->NavigateAndCommit(url3);
3449 other_contents->ExpectSetHistoryLengthAndPrune(
3450 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
3451 other_controller.GetEntryAtIndex(0)->GetPageID());
3452 other_controller.CopyStateFromAndPrune(&controller, true);
3453
3454 // other_controller should now contain the 2 urls: url1 and url3.
3455
3456 ASSERT_EQ(2, other_controller.GetEntryCount());
3457
3458 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
3459
3460 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3461 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
3462 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3463 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID());
3464
3465 // A new SiteInstance in a different BrowsingInstance should be used for the
3466 // new tab.
3467 SiteInstance* instance3 =
3468 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1));
3469 EXPECT_NE(instance3, instance1);
3470 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1));
3471
3472 // The max page ID map should be copied over and updated with the max page ID
3473 // from the current tab.
3474 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1));
3475 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3));
3476 }
3477
3478 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, when the max
3479 // entry count is 3 and replace_entry is true. We should not prune entries.
3480 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) {
3481 NavigationControllerImpl& controller = controller_impl();
3482 size_t original_count = NavigationControllerImpl::max_entry_count();
3483 const int kMaxEntryCount = 3;
3484
3485 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
3486
3487 const GURL url1("http://foo/1");
3488 const GURL url2("http://foo/2");
3489 const GURL url3("http://foo/3");
3490 const GURL url4("http://foo/4");
3491
3492 // Create a PrunedListener to observe prune notifications.
3493 PrunedListener listener(&controller);
3494
3495 NavigateAndCommit(url1);
3496 NavigateAndCommit(url2);
3497 NavigateAndCommit(url3);
3498
3499 scoped_ptr<TestWebContents> other_contents(
3500 static_cast<TestWebContents*>(CreateTestWebContents()));
3501 NavigationControllerImpl& other_controller = other_contents->GetController();
3502 other_contents->NavigateAndCommit(url4);
3503 other_contents->ExpectSetHistoryLengthAndPrune(
3504 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
3505 other_controller.GetEntryAtIndex(0)->GetPageID());
3506 other_controller.CopyStateFromAndPrune(&controller, true);
3507
3508 // We should have received no pruned notification.
3509 EXPECT_EQ(0, listener.notification_count_);
3510
3511 // other_controller should now contain only 3 urls: url1, url2 and url4.
3512
3513 ASSERT_EQ(3, other_controller.GetEntryCount());
3514
3515 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
3516
3517 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3518 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3519 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3520 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3521 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID());
3522 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3523
3524 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
3525 }
3526
3422 // Tests that navigations initiated from the page (with the history object) 3527 // Tests that navigations initiated from the page (with the history object)
3423 // work as expected without navigation entries. 3528 // work as expected without navigation entries.
3424 TEST_F(NavigationControllerTest, HistoryNavigate) { 3529 TEST_F(NavigationControllerTest, HistoryNavigate) {
3425 NavigationControllerImpl& controller = controller_impl(); 3530 NavigationControllerImpl& controller = controller_impl();
3426 const GURL url1("http://foo/1"); 3531 const GURL url1("http://foo/1");
3427 const GURL url2("http://foo/2"); 3532 const GURL url2("http://foo/2");
3428 const GURL url3("http://foo/3"); 3533 const GURL url3("http://foo/3");
3429 3534
3430 NavigateAndCommit(url1); 3535 NavigateAndCommit(url1);
3431 NavigateAndCommit(url2); 3536 NavigateAndCommit(url2);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 EXPECT_EQ(1, controller.GetEntryCount()); 3941 EXPECT_EQ(1, controller.GetEntryCount());
3837 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 3942 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
3838 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3943 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3839 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3944 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3840 EXPECT_FALSE(controller.CanGoBack()); 3945 EXPECT_FALSE(controller.CanGoBack());
3841 EXPECT_FALSE(controller.CanGoForward()); 3946 EXPECT_FALSE(controller.CanGoForward());
3842 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 3947 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
3843 } 3948 }
3844 3949
3845 } // namespace content 3950 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698