| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.h" |
| 8 #include "content/browser/renderer_host/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_view.h" | 9 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 10 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
| 11 #include "content/browser/site_instance.h" | 11 #include "content/browser/site_instance_impl.h" |
| 12 #include "content/browser/tab_contents/interstitial_page.h" | 12 #include "content/browser/tab_contents/interstitial_page.h" |
| 13 #include "content/browser/tab_contents/navigation_entry_impl.h" | 13 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 14 #include "content/browser/tab_contents/test_tab_contents.h" | 14 #include "content/browser/tab_contents/test_tab_contents.h" |
| 15 #include "content/browser/webui/empty_web_ui_factory.h" | 15 #include "content/browser/webui/empty_web_ui_factory.h" |
| 16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/browser/web_ui_controller.h" | 21 #include "content/public/browser/web_ui_controller.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 delegate_ = NULL; | 161 delegate_ = NULL; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void set_delegate(Delegate* delegate) { | 164 void set_delegate(Delegate* delegate) { |
| 165 delegate_ = delegate; | 165 delegate_ = delegate; |
| 166 } | 166 } |
| 167 | 167 |
| 168 protected: | 168 protected: |
| 169 virtual RenderViewHost* CreateRenderViewHost() { | 169 virtual RenderViewHost* CreateRenderViewHost() { |
| 170 return new TestRenderViewHost( | 170 return new TestRenderViewHost( |
| 171 SiteInstance::CreateSiteInstance(tab()->GetBrowserContext()), | 171 content::SiteInstance::CreateSiteInstance(tab()->GetBrowserContext()), |
| 172 this, MSG_ROUTING_NONE); | 172 this, MSG_ROUTING_NONE); |
| 173 } | 173 } |
| 174 | 174 |
| 175 virtual content::WebContentsView* CreateWebContentsView() { return NULL; } | 175 virtual content::WebContentsView* CreateWebContentsView() { return NULL; } |
| 176 | 176 |
| 177 | 177 |
| 178 virtual void CommandReceived(const std::string& command) { | 178 virtual void CommandReceived(const std::string& command) { |
| 179 command_received_count_++; | 179 command_received_count_++; |
| 180 } | 180 } |
| 181 | 181 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 ViewHostMsg_FrameNavigate_Params params; | 270 ViewHostMsg_FrameNavigate_Params params; |
| 271 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); | 271 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); |
| 272 content::LoadCommittedDetails details; | 272 content::LoadCommittedDetails details; |
| 273 cont.RendererDidNavigate(params, &details); | 273 cont.RendererDidNavigate(params, &details); |
| 274 // Also check title and url. | 274 // Also check title and url. |
| 275 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); | 275 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 // Test to ensure UpdateMaxPageID is working properly. | 278 // Test to ensure UpdateMaxPageID is working properly. |
| 279 TEST_F(TabContentsTest, UpdateMaxPageID) { | 279 TEST_F(TabContentsTest, UpdateMaxPageID) { |
| 280 SiteInstance* instance1 = contents()->GetSiteInstance(); | 280 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 281 scoped_refptr<SiteInstance> instance2(SiteInstance::CreateSiteInstance(NULL)); | 281 scoped_refptr<content::SiteInstance> instance2( |
| 282 content::SiteInstance::CreateSiteInstance(NULL)); |
| 282 | 283 |
| 283 // Starts at -1. | 284 // Starts at -1. |
| 284 EXPECT_EQ(-1, contents()->GetMaxPageID()); | 285 EXPECT_EQ(-1, contents()->GetMaxPageID()); |
| 285 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance1)); | 286 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance1)); |
| 286 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2)); | 287 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2)); |
| 287 | 288 |
| 288 // Make sure max_page_id_ is monotonically increasing per SiteInstance. | 289 // Make sure max_page_id_ is monotonically increasing per SiteInstance. |
| 289 contents()->UpdateMaxPageID(3); | 290 contents()->UpdateMaxPageID(3); |
| 290 contents()->UpdateMaxPageID(1); | 291 contents()->UpdateMaxPageID(1); |
| 291 EXPECT_EQ(3, contents()->GetMaxPageID()); | 292 EXPECT_EQ(3, contents()->GetMaxPageID()); |
| 292 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); | 293 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); |
| 293 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2)); | 294 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2)); |
| 294 | 295 |
| 295 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7); | 296 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7); |
| 296 EXPECT_EQ(3, contents()->GetMaxPageID()); | 297 EXPECT_EQ(3, contents()->GetMaxPageID()); |
| 297 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); | 298 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); |
| 298 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2)); | 299 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 // Test simple same-SiteInstance navigation. | 302 // Test simple same-SiteInstance navigation. |
| 302 TEST_F(TabContentsTest, SimpleNavigation) { | 303 TEST_F(TabContentsTest, SimpleNavigation) { |
| 303 TestRenderViewHost* orig_rvh = rvh(); | 304 TestRenderViewHost* orig_rvh = rvh(); |
| 304 SiteInstance* instance1 = contents()->GetSiteInstance(); | 305 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 305 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 306 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 306 | 307 |
| 307 // Navigate to URL | 308 // Navigate to URL |
| 308 const GURL url("http://www.google.com"); | 309 const GURL url("http://www.google.com"); |
| 309 controller().LoadURL( | 310 controller().LoadURL( |
| 310 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 311 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 311 EXPECT_FALSE(contents()->cross_navigation_pending()); | 312 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 312 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 313 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
| 313 // Controller's pending entry will have a NULL site instance until we assign | 314 // Controller's pending entry will have a NULL site instance until we assign |
| 314 // it in DidNavigate. | 315 // it in DidNavigate. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 341 EXPECT_TRUE(controller().GetActiveEntry() == NULL); | 342 EXPECT_TRUE(controller().GetActiveEntry() == NULL); |
| 342 } | 343 } |
| 343 | 344 |
| 344 // Test that navigating across a site boundary creates a new RenderViewHost | 345 // Test that navigating across a site boundary creates a new RenderViewHost |
| 345 // with a new SiteInstance. Going back should do the same. | 346 // with a new SiteInstance. Going back should do the same. |
| 346 TEST_F(TabContentsTest, CrossSiteBoundaries) { | 347 TEST_F(TabContentsTest, CrossSiteBoundaries) { |
| 347 contents()->transition_cross_site = true; | 348 contents()->transition_cross_site = true; |
| 348 TestRenderViewHost* orig_rvh = rvh(); | 349 TestRenderViewHost* orig_rvh = rvh(); |
| 349 int orig_rvh_delete_count = 0; | 350 int orig_rvh_delete_count = 0; |
| 350 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 351 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 351 SiteInstance* instance1 = contents()->GetSiteInstance(); | 352 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 352 | 353 |
| 353 // Navigate to URL. First URL should use first RenderViewHost. | 354 // Navigate to URL. First URL should use first RenderViewHost. |
| 354 const GURL url("http://www.google.com"); | 355 const GURL url("http://www.google.com"); |
| 355 controller().LoadURL( | 356 controller().LoadURL( |
| 356 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 357 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 357 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 358 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 358 | 359 |
| 359 EXPECT_FALSE(contents()->cross_navigation_pending()); | 360 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 360 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 361 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 361 | 362 |
| 362 // Navigate to new site | 363 // Navigate to new site |
| 363 const GURL url2("http://www.yahoo.com"); | 364 const GURL url2("http://www.yahoo.com"); |
| 364 controller().LoadURL( | 365 controller().LoadURL( |
| 365 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 366 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 366 EXPECT_TRUE(contents()->cross_navigation_pending()); | 367 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 367 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 368 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
| 368 int pending_rvh_delete_count = 0; | 369 int pending_rvh_delete_count = 0; |
| 369 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 370 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
| 370 | 371 |
| 371 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 372 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 372 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 373 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 373 orig_rvh->SendShouldCloseACK(true); | 374 orig_rvh->SendShouldCloseACK(true); |
| 374 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 375 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 375 | 376 |
| 376 // DidNavigate from the pending page | 377 // DidNavigate from the pending page |
| 377 contents()->TestDidNavigate( | 378 contents()->TestDidNavigate( |
| 378 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 379 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 379 SiteInstance* instance2 = contents()->GetSiteInstance(); | 380 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 380 | 381 |
| 381 EXPECT_FALSE(contents()->cross_navigation_pending()); | 382 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 382 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 383 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 383 EXPECT_NE(instance1, instance2); | 384 EXPECT_NE(instance1, instance2); |
| 384 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 385 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 385 // We keep the original RVH around, swapped out. | 386 // We keep the original RVH around, swapped out. |
| 386 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); | 387 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); |
| 387 EXPECT_EQ(orig_rvh_delete_count, 0); | 388 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 388 | 389 |
| 389 // Going back should switch SiteInstances again. The first SiteInstance is | 390 // Going back should switch SiteInstances again. The first SiteInstance is |
| (...skipping 26 matching lines...) Expand all Loading... |
| 416 EXPECT_EQ(pending_rvh_delete_count, 1); | 417 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Test that navigating across a site boundary after a crash creates a new | 420 // Test that navigating across a site boundary after a crash creates a new |
| 420 // RVH without requiring a cross-site transition (i.e., PENDING state). | 421 // RVH without requiring a cross-site transition (i.e., PENDING state). |
| 421 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 422 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
| 422 contents()->transition_cross_site = true; | 423 contents()->transition_cross_site = true; |
| 423 TestRenderViewHost* orig_rvh = rvh(); | 424 TestRenderViewHost* orig_rvh = rvh(); |
| 424 int orig_rvh_delete_count = 0; | 425 int orig_rvh_delete_count = 0; |
| 425 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 426 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 426 SiteInstance* instance1 = contents()->GetSiteInstance(); | 427 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 427 | 428 |
| 428 // Navigate to URL. First URL should use first RenderViewHost. | 429 // Navigate to URL. First URL should use first RenderViewHost. |
| 429 const GURL url("http://www.google.com"); | 430 const GURL url("http://www.google.com"); |
| 430 controller().LoadURL( | 431 controller().LoadURL( |
| 431 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 432 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 432 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 433 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 433 | 434 |
| 434 EXPECT_FALSE(contents()->cross_navigation_pending()); | 435 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 435 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 436 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 436 | 437 |
| 437 // Crash the renderer. | 438 // Crash the renderer. |
| 438 orig_rvh->set_render_view_created(false); | 439 orig_rvh->set_render_view_created(false); |
| 439 | 440 |
| 440 // Navigate to new site. We should not go into PENDING. | 441 // Navigate to new site. We should not go into PENDING. |
| 441 const GURL url2("http://www.yahoo.com"); | 442 const GURL url2("http://www.yahoo.com"); |
| 442 controller().LoadURL( | 443 controller().LoadURL( |
| 443 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 444 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 444 TestRenderViewHost* new_rvh = rvh(); | 445 TestRenderViewHost* new_rvh = rvh(); |
| 445 EXPECT_FALSE(contents()->cross_navigation_pending()); | 446 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 446 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 447 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 447 EXPECT_NE(orig_rvh, new_rvh); | 448 EXPECT_NE(orig_rvh, new_rvh); |
| 448 EXPECT_EQ(orig_rvh_delete_count, 1); | 449 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 449 | 450 |
| 450 // DidNavigate from the new page | 451 // DidNavigate from the new page |
| 451 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 452 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 452 SiteInstance* instance2 = contents()->GetSiteInstance(); | 453 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 453 | 454 |
| 454 EXPECT_FALSE(contents()->cross_navigation_pending()); | 455 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 455 EXPECT_EQ(new_rvh, rvh()); | 456 EXPECT_EQ(new_rvh, rvh()); |
| 456 EXPECT_NE(instance1, instance2); | 457 EXPECT_NE(instance1, instance2); |
| 457 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 458 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 458 | 459 |
| 459 // Close tab and ensure RVHs are deleted. | 460 // Close tab and ensure RVHs are deleted. |
| 460 DeleteContents(); | 461 DeleteContents(); |
| 461 EXPECT_EQ(orig_rvh_delete_count, 1); | 462 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 462 } | 463 } |
| 463 | 464 |
| 464 // Test that opening a new tab in the same SiteInstance and then navigating | 465 // Test that opening a new tab in the same SiteInstance and then navigating |
| 465 // both tabs to a new site will place both tabs in a single SiteInstance. | 466 // both tabs to a new site will place both tabs in a single SiteInstance. |
| 466 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 467 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
| 467 contents()->transition_cross_site = true; | 468 contents()->transition_cross_site = true; |
| 468 TestRenderViewHost* orig_rvh = rvh(); | 469 TestRenderViewHost* orig_rvh = rvh(); |
| 469 SiteInstance* instance1 = contents()->GetSiteInstance(); | 470 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 470 | 471 |
| 471 // Navigate to URL. First URL should use first RenderViewHost. | 472 // Navigate to URL. First URL should use first RenderViewHost. |
| 472 const GURL url("http://www.google.com"); | 473 const GURL url("http://www.google.com"); |
| 473 controller().LoadURL( | 474 controller().LoadURL( |
| 474 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 475 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 475 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 476 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 476 | 477 |
| 477 // Open a new tab with the same SiteInstance, navigated to the same site. | 478 // Open a new tab with the same SiteInstance, navigated to the same site. |
| 478 TestTabContents contents2(browser_context_.get(), instance1); | 479 TestTabContents contents2(browser_context_.get(), instance1); |
| 479 contents2.transition_cross_site = true; | 480 contents2.transition_cross_site = true; |
| 480 contents2.GetController().LoadURL(url, content::Referrer(), | 481 contents2.GetController().LoadURL(url, content::Referrer(), |
| 481 content::PAGE_TRANSITION_TYPED, | 482 content::PAGE_TRANSITION_TYPED, |
| 482 std::string()); | 483 std::string()); |
| 483 // Need this page id to be 2 since the site instance is the same (which is the | 484 // Need this page id to be 2 since the site instance is the same (which is the |
| 484 // scope of page IDs) and we want to consider this a new page. | 485 // scope of page IDs) and we want to consider this a new page. |
| 485 contents2.TestDidNavigate( | 486 contents2.TestDidNavigate( |
| 486 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); | 487 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); |
| 487 | 488 |
| 488 // Navigate first tab to a new site | 489 // Navigate first tab to a new site |
| 489 const GURL url2a("http://www.yahoo.com"); | 490 const GURL url2a("http://www.yahoo.com"); |
| 490 controller().LoadURL( | 491 controller().LoadURL( |
| 491 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 492 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 492 std::string()); | 493 std::string()); |
| 493 orig_rvh->SendShouldCloseACK(true); | 494 orig_rvh->SendShouldCloseACK(true); |
| 494 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 495 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
| 495 contents()->TestDidNavigate( | 496 contents()->TestDidNavigate( |
| 496 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); | 497 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); |
| 497 SiteInstance* instance2a = contents()->GetSiteInstance(); | 498 content::SiteInstance* instance2a = contents()->GetSiteInstance(); |
| 498 EXPECT_NE(instance1, instance2a); | 499 EXPECT_NE(instance1, instance2a); |
| 499 | 500 |
| 500 // Navigate second tab to the same site as the first tab | 501 // Navigate second tab to the same site as the first tab |
| 501 const GURL url2b("http://mail.yahoo.com"); | 502 const GURL url2b("http://mail.yahoo.com"); |
| 502 contents2.GetController().LoadURL(url2b, content::Referrer(), | 503 contents2.GetController().LoadURL(url2b, content::Referrer(), |
| 503 content::PAGE_TRANSITION_TYPED, | 504 content::PAGE_TRANSITION_TYPED, |
| 504 std::string()); | 505 std::string()); |
| 505 TestRenderViewHost* rvh2 = | 506 TestRenderViewHost* rvh2 = |
| 506 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); | 507 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); |
| 507 rvh2->SendShouldCloseACK(true); | 508 rvh2->SendShouldCloseACK(true); |
| 508 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 509 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
| 509 EXPECT_TRUE(pending_rvh_b != NULL); | 510 EXPECT_TRUE(pending_rvh_b != NULL); |
| 510 EXPECT_TRUE(contents2.cross_navigation_pending()); | 511 EXPECT_TRUE(contents2.cross_navigation_pending()); |
| 511 | 512 |
| 512 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 513 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
| 513 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 514 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
| 514 // now covered by the CrossSiteBoundariesAfterCrash test. | 515 // now covered by the CrossSiteBoundariesAfterCrash test. |
| 515 contents2.TestDidNavigate( | 516 contents2.TestDidNavigate( |
| 516 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); | 517 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); |
| 517 SiteInstance* instance2b = contents2.GetSiteInstance(); | 518 content::SiteInstance* instance2b = contents2.GetSiteInstance(); |
| 518 EXPECT_NE(instance1, instance2b); | 519 EXPECT_NE(instance1, instance2b); |
| 519 | 520 |
| 520 // Both tabs should now be in the same SiteInstance. | 521 // Both tabs should now be in the same SiteInstance. |
| 521 EXPECT_EQ(instance2a, instance2b); | 522 EXPECT_EQ(instance2a, instance2b); |
| 522 } | 523 } |
| 523 | 524 |
| 524 // Tests that TabContents uses the current URL, not the SiteInstance's site, to | 525 // Tests that TabContents uses the current URL, not the SiteInstance's site, to |
| 525 // determine whether a navigation is cross-site. | 526 // determine whether a navigation is cross-site. |
| 526 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { | 527 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { |
| 527 contents()->transition_cross_site = true; | 528 contents()->transition_cross_site = true; |
| 528 TestRenderViewHost* orig_rvh = rvh(); | 529 TestRenderViewHost* orig_rvh = rvh(); |
| 529 SiteInstance* instance1 = contents()->GetSiteInstance(); | 530 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 530 | 531 |
| 531 // Navigate to URL. | 532 // Navigate to URL. |
| 532 const GURL url("http://www.google.com"); | 533 const GURL url("http://www.google.com"); |
| 533 controller().LoadURL( | 534 controller().LoadURL( |
| 534 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 535 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 535 contents()->TestDidNavigate( | 536 contents()->TestDidNavigate( |
| 536 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 537 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 537 | 538 |
| 538 // Open a related tab to a second site. | 539 // Open a related tab to a second site. |
| 539 TestTabContents contents2(browser_context_.get(), instance1); | 540 TestTabContents contents2(browser_context_.get(), instance1); |
| 540 contents2.transition_cross_site = true; | 541 contents2.transition_cross_site = true; |
| 541 const GURL url2("http://www.yahoo.com"); | 542 const GURL url2("http://www.yahoo.com"); |
| 542 contents2.GetController().LoadURL(url2, content::Referrer(), | 543 contents2.GetController().LoadURL(url2, content::Referrer(), |
| 543 content::PAGE_TRANSITION_TYPED, | 544 content::PAGE_TRANSITION_TYPED, |
| 544 std::string()); | 545 std::string()); |
| 545 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 546 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
| 546 // pending. | 547 // pending. |
| 547 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 548 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
| 548 contents2.GetRenderViewHost()); | 549 contents2.GetRenderViewHost()); |
| 549 EXPECT_FALSE(contents2.cross_navigation_pending()); | 550 EXPECT_FALSE(contents2.cross_navigation_pending()); |
| 550 contents2.TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED); | 551 contents2.TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED); |
| 551 SiteInstance* instance2 = contents2.GetSiteInstance(); | 552 content::SiteInstance* instance2 = contents2.GetSiteInstance(); |
| 552 EXPECT_NE(instance1, instance2); | 553 EXPECT_NE(instance1, instance2); |
| 553 EXPECT_FALSE(contents2.cross_navigation_pending()); | 554 EXPECT_FALSE(contents2.cross_navigation_pending()); |
| 554 | 555 |
| 555 // Simulate a link click in first tab to second site. Doesn't switch | 556 // Simulate a link click in first tab to second site. Doesn't switch |
| 556 // SiteInstances, because we don't intercept WebKit navigations. | 557 // SiteInstances, because we don't intercept WebKit navigations. |
| 557 contents()->TestDidNavigate( | 558 contents()->TestDidNavigate( |
| 558 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); | 559 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); |
| 559 SiteInstance* instance3 = contents()->GetSiteInstance(); | 560 content::SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 560 EXPECT_EQ(instance1, instance3); | 561 EXPECT_EQ(instance1, instance3); |
| 561 EXPECT_FALSE(contents()->cross_navigation_pending()); | 562 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 562 | 563 |
| 563 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 564 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
| 564 // compare against the current URL, not the SiteInstance's site. | 565 // compare against the current URL, not the SiteInstance's site. |
| 565 const GURL url3("http://mail.yahoo.com"); | 566 const GURL url3("http://mail.yahoo.com"); |
| 566 controller().LoadURL( | 567 controller().LoadURL( |
| 567 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 568 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 568 EXPECT_FALSE(contents()->cross_navigation_pending()); | 569 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 569 contents()->TestDidNavigate( | 570 contents()->TestDidNavigate( |
| 570 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED); | 571 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED); |
| 571 SiteInstance* instance4 = contents()->GetSiteInstance(); | 572 content::SiteInstance* instance4 = contents()->GetSiteInstance(); |
| 572 EXPECT_EQ(instance1, instance4); | 573 EXPECT_EQ(instance1, instance4); |
| 573 } | 574 } |
| 574 | 575 |
| 575 // Test that the onbeforeunload and onunload handlers run when navigating | 576 // Test that the onbeforeunload and onunload handlers run when navigating |
| 576 // across site boundaries. | 577 // across site boundaries. |
| 577 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { | 578 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { |
| 578 contents()->transition_cross_site = true; | 579 contents()->transition_cross_site = true; |
| 579 TestRenderViewHost* orig_rvh = rvh(); | 580 TestRenderViewHost* orig_rvh = rvh(); |
| 580 SiteInstance* instance1 = contents()->GetSiteInstance(); | 581 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 581 | 582 |
| 582 // Navigate to URL. First URL should use first RenderViewHost. | 583 // Navigate to URL. First URL should use first RenderViewHost. |
| 583 const GURL url("http://www.google.com"); | 584 const GURL url("http://www.google.com"); |
| 584 controller().LoadURL( | 585 controller().LoadURL( |
| 585 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 586 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 586 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 587 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 587 EXPECT_FALSE(contents()->cross_navigation_pending()); | 588 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 588 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 589 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 589 | 590 |
| 590 // Navigate to new site, but simulate an onbeforeunload denial. | 591 // Navigate to new site, but simulate an onbeforeunload denial. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 607 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 608 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
| 608 contents()->pending_rvh()); | 609 contents()->pending_rvh()); |
| 609 | 610 |
| 610 // We won't hear DidNavigate until the onunload handler has finished running. | 611 // We won't hear DidNavigate until the onunload handler has finished running. |
| 611 // (No way to simulate that here, but it involves a call from RDH to | 612 // (No way to simulate that here, but it involves a call from RDH to |
| 612 // TabContents::OnCrossSiteResponse.) | 613 // TabContents::OnCrossSiteResponse.) |
| 613 | 614 |
| 614 // DidNavigate from the pending page | 615 // DidNavigate from the pending page |
| 615 contents()->TestDidNavigate( | 616 contents()->TestDidNavigate( |
| 616 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 617 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 617 SiteInstance* instance2 = contents()->GetSiteInstance(); | 618 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 618 EXPECT_FALSE(contents()->cross_navigation_pending()); | 619 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 619 EXPECT_EQ(pending_rvh, rvh()); | 620 EXPECT_EQ(pending_rvh, rvh()); |
| 620 EXPECT_NE(instance1, instance2); | 621 EXPECT_NE(instance1, instance2); |
| 621 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 622 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 622 } | 623 } |
| 623 | 624 |
| 624 // Test that during a slow cross-site navigation, the original renderer can | 625 // Test that during a slow cross-site navigation, the original renderer can |
| 625 // navigate to a different URL and have it displayed, canceling the slow | 626 // navigate to a different URL and have it displayed, canceling the slow |
| 626 // navigation. | 627 // navigation. |
| 627 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { | 628 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { |
| 628 contents()->transition_cross_site = true; | 629 contents()->transition_cross_site = true; |
| 629 TestRenderViewHost* orig_rvh = rvh(); | 630 TestRenderViewHost* orig_rvh = rvh(); |
| 630 SiteInstance* instance1 = contents()->GetSiteInstance(); | 631 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 631 | 632 |
| 632 // Navigate to URL. First URL should use first RenderViewHost. | 633 // Navigate to URL. First URL should use first RenderViewHost. |
| 633 const GURL url("http://www.google.com"); | 634 const GURL url("http://www.google.com"); |
| 634 controller().LoadURL( | 635 controller().LoadURL( |
| 635 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 636 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 636 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 637 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 637 EXPECT_FALSE(contents()->cross_navigation_pending()); | 638 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 638 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 639 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 639 | 640 |
| 640 // Navigate to new site, simulating an onbeforeunload approval. | 641 // Navigate to new site, simulating an onbeforeunload approval. |
| 641 const GURL url2("http://www.yahoo.com"); | 642 const GURL url2("http://www.yahoo.com"); |
| 642 controller().LoadURL( | 643 controller().LoadURL( |
| 643 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 644 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 644 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 645 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 645 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 646 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 646 EXPECT_TRUE(contents()->cross_navigation_pending()); | 647 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 647 | 648 |
| 648 // Suppose the original renderer navigates before the new one is ready. | 649 // Suppose the original renderer navigates before the new one is ready. |
| 649 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 650 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
| 650 | 651 |
| 651 // Verify that the pending navigation is cancelled. | 652 // Verify that the pending navigation is cancelled. |
| 652 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 653 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 653 SiteInstance* instance2 = contents()->GetSiteInstance(); | 654 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 654 EXPECT_FALSE(contents()->cross_navigation_pending()); | 655 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 655 EXPECT_EQ(orig_rvh, rvh()); | 656 EXPECT_EQ(orig_rvh, rvh()); |
| 656 EXPECT_EQ(instance1, instance2); | 657 EXPECT_EQ(instance1, instance2); |
| 657 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 658 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 658 } | 659 } |
| 659 | 660 |
| 660 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { | 661 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
| 661 contents()->transition_cross_site = true; | 662 contents()->transition_cross_site = true; |
| 662 | 663 |
| 663 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 664 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
| 664 const GURL url1("tabcontentstest://blah"); | 665 const GURL url1("tabcontentstest://blah"); |
| 665 controller().LoadURL( | 666 controller().LoadURL( |
| 666 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 667 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 667 TestRenderViewHost* ntp_rvh = rvh(); | 668 TestRenderViewHost* ntp_rvh = rvh(); |
| 668 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); | 669 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); |
| 669 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 670 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
| 670 SiteInstance* instance1 = contents()->GetSiteInstance(); | 671 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 671 | 672 |
| 672 EXPECT_FALSE(contents()->cross_navigation_pending()); | 673 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 673 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); | 674 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); |
| 674 EXPECT_EQ(url1, entry1->GetURL()); | 675 EXPECT_EQ(url1, entry1->GetURL()); |
| 675 EXPECT_EQ(instance1, | 676 EXPECT_EQ(instance1, |
| 676 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 677 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
| 677 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); | 678 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); |
| 678 | 679 |
| 679 // Navigate to new site. | 680 // Navigate to new site. |
| 680 const GURL url2("http://www.google.com"); | 681 const GURL url2("http://www.google.com"); |
| 681 controller().LoadURL( | 682 controller().LoadURL( |
| 682 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 683 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 683 EXPECT_TRUE(contents()->cross_navigation_pending()); | 684 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 684 TestRenderViewHost* google_rvh = contents()->pending_rvh(); | 685 TestRenderViewHost* google_rvh = contents()->pending_rvh(); |
| 685 | 686 |
| 686 // Simulate beforeunload approval. | 687 // Simulate beforeunload approval. |
| 687 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 688 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
| 688 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 689 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 689 | 690 |
| 690 // DidNavigate from the pending page. | 691 // DidNavigate from the pending page. |
| 691 contents()->TestDidNavigate( | 692 contents()->TestDidNavigate( |
| 692 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 693 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 693 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 694 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
| 694 SiteInstance* instance2 = contents()->GetSiteInstance(); | 695 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 695 | 696 |
| 696 EXPECT_FALSE(contents()->cross_navigation_pending()); | 697 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 697 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 698 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
| 698 EXPECT_NE(instance1, instance2); | 699 EXPECT_NE(instance1, instance2); |
| 699 EXPECT_FALSE(contents()->pending_rvh()); | 700 EXPECT_FALSE(contents()->pending_rvh()); |
| 700 EXPECT_EQ(url2, entry2->GetURL()); | 701 EXPECT_EQ(url2, entry2->GetURL()); |
| 701 EXPECT_EQ(instance2, | 702 EXPECT_EQ(instance2, |
| 702 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 703 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
| 703 EXPECT_FALSE(google_rvh->enabled_bindings() & | 704 EXPECT_FALSE(google_rvh->enabled_bindings() & |
| 704 content::BINDINGS_POLICY_WEB_UI); | 705 content::BINDINGS_POLICY_WEB_UI); |
| 705 | 706 |
| 706 // Navigate to third page on same site. | 707 // Navigate to third page on same site. |
| 707 const GURL url3("http://news.google.com"); | 708 const GURL url3("http://news.google.com"); |
| 708 controller().LoadURL( | 709 controller().LoadURL( |
| 709 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 710 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 710 EXPECT_FALSE(contents()->cross_navigation_pending()); | 711 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 711 contents()->TestDidNavigate( | 712 contents()->TestDidNavigate( |
| 712 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); | 713 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); |
| 713 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 714 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
| 714 SiteInstance* instance3 = contents()->GetSiteInstance(); | 715 content::SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 715 | 716 |
| 716 EXPECT_FALSE(contents()->cross_navigation_pending()); | 717 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 717 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 718 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
| 718 EXPECT_EQ(instance2, instance3); | 719 EXPECT_EQ(instance2, instance3); |
| 719 EXPECT_FALSE(contents()->pending_rvh()); | 720 EXPECT_FALSE(contents()->pending_rvh()); |
| 720 EXPECT_EQ(url3, entry3->GetURL()); | 721 EXPECT_EQ(url3, entry3->GetURL()); |
| 721 EXPECT_EQ(instance3, | 722 EXPECT_EQ(instance3, |
| 722 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 723 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
| 723 | 724 |
| 724 // Go back within the site. | 725 // Go back within the site. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 826 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 826 } | 827 } |
| 827 | 828 |
| 828 // Test that the original renderer cannot preempt a cross-site navigation once | 829 // Test that the original renderer cannot preempt a cross-site navigation once |
| 829 // the unload request has been made. At this point, the cross-site navigation | 830 // the unload request has been made. At this point, the cross-site navigation |
| 830 // is almost ready to be displayed, and the original renderer is only given a | 831 // is almost ready to be displayed, and the original renderer is only given a |
| 831 // short chance to run an unload handler. Prevents regression of bug 23942. | 832 // short chance to run an unload handler. Prevents regression of bug 23942. |
| 832 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { | 833 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { |
| 833 contents()->transition_cross_site = true; | 834 contents()->transition_cross_site = true; |
| 834 TestRenderViewHost* orig_rvh = rvh(); | 835 TestRenderViewHost* orig_rvh = rvh(); |
| 835 SiteInstance* instance1 = contents()->GetSiteInstance(); | 836 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 836 | 837 |
| 837 // Navigate to URL. First URL should use first RenderViewHost. | 838 // Navigate to URL. First URL should use first RenderViewHost. |
| 838 const GURL url("http://www.google.com"); | 839 const GURL url("http://www.google.com"); |
| 839 controller().LoadURL( | 840 controller().LoadURL( |
| 840 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 841 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 841 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 842 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 842 EXPECT_FALSE(contents()->cross_navigation_pending()); | 843 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 843 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 844 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 844 | 845 |
| 845 // Navigate to new site, simulating an onbeforeunload approval. | 846 // Navigate to new site, simulating an onbeforeunload approval. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 864 content::PAGE_TRANSITION_TYPED); | 865 content::PAGE_TRANSITION_TYPED); |
| 865 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 866 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
| 866 | 867 |
| 867 // Verify that the pending navigation is still in progress. | 868 // Verify that the pending navigation is still in progress. |
| 868 EXPECT_TRUE(contents()->cross_navigation_pending()); | 869 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 869 EXPECT_TRUE(contents()->pending_rvh() != NULL); | 870 EXPECT_TRUE(contents()->pending_rvh() != NULL); |
| 870 | 871 |
| 871 // DidNavigate from the pending page should commit it. | 872 // DidNavigate from the pending page should commit it. |
| 872 contents()->TestDidNavigate( | 873 contents()->TestDidNavigate( |
| 873 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 874 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 874 SiteInstance* instance2 = contents()->GetSiteInstance(); | 875 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 875 EXPECT_FALSE(contents()->cross_navigation_pending()); | 876 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 876 EXPECT_EQ(pending_rvh, rvh()); | 877 EXPECT_EQ(pending_rvh, rvh()); |
| 877 EXPECT_NE(instance1, instance2); | 878 EXPECT_NE(instance1, instance2); |
| 878 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 879 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 879 } | 880 } |
| 880 | 881 |
| 881 // Test that a cross-site navigation that doesn't commit after the unload | 882 // Test that a cross-site navigation that doesn't commit after the unload |
| 882 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. | 883 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. |
| 883 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { | 884 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { |
| 884 contents()->transition_cross_site = true; | 885 contents()->transition_cross_site = true; |
| 885 TestRenderViewHost* orig_rvh = rvh(); | 886 TestRenderViewHost* orig_rvh = rvh(); |
| 886 SiteInstance* instance1 = contents()->GetSiteInstance(); | 887 content::SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 887 | 888 |
| 888 // Navigate to URL. First URL should use first RenderViewHost. | 889 // Navigate to URL. First URL should use first RenderViewHost. |
| 889 const GURL url("http://www.google.com"); | 890 const GURL url("http://www.google.com"); |
| 890 controller().LoadURL( | 891 controller().LoadURL( |
| 891 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 892 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 892 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 893 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
| 893 EXPECT_FALSE(contents()->cross_navigation_pending()); | 894 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 894 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 895 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
| 895 | 896 |
| 896 // Navigate to new site, simulating an onbeforeunload approval. | 897 // Navigate to new site, simulating an onbeforeunload approval. |
| 897 const GURL url2("http://www.yahoo.com"); | 898 const GURL url2("http://www.yahoo.com"); |
| 898 controller().LoadURL( | 899 controller().LoadURL( |
| 899 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 900 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 900 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 901 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 901 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 902 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 902 EXPECT_TRUE(contents()->cross_navigation_pending()); | 903 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 903 | 904 |
| 904 // Simulate swap out message when the response arrives. | 905 // Simulate swap out message when the response arrives. |
| 905 orig_rvh->set_is_swapped_out(true); | 906 orig_rvh->set_is_swapped_out(true); |
| 906 | 907 |
| 907 // Suppose the navigation doesn't get a chance to commit, and the user | 908 // Suppose the navigation doesn't get a chance to commit, and the user |
| 908 // navigates in the current RVH's SiteInstance. | 909 // navigates in the current RVH's SiteInstance. |
| 909 controller().LoadURL( | 910 controller().LoadURL( |
| 910 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 911 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 911 | 912 |
| 912 // Verify that the pending navigation is cancelled and the renderer is no | 913 // Verify that the pending navigation is cancelled and the renderer is no |
| 913 // longer swapped out. | 914 // longer swapped out. |
| 914 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 915 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 915 SiteInstance* instance2 = contents()->GetSiteInstance(); | 916 content::SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 916 EXPECT_FALSE(contents()->cross_navigation_pending()); | 917 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 917 EXPECT_EQ(orig_rvh, rvh()); | 918 EXPECT_EQ(orig_rvh, rvh()); |
| 918 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 919 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
| 919 EXPECT_EQ(instance1, instance2); | 920 EXPECT_EQ(instance1, instance2); |
| 920 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 921 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 921 } | 922 } |
| 922 | 923 |
| 923 // Test that NavigationEntries have the correct content state after going | 924 // Test that NavigationEntries have the correct content state after going |
| 924 // forward and back. Prevents regression for bug 1116137. | 925 // forward and back. Prevents regression for bug 1116137. |
| 925 TEST_F(TabContentsTest, NavigationEntryContentState) { | 926 TEST_F(TabContentsTest, NavigationEntryContentState) { |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 | 1824 |
| 1824 // It should have a transient entry. | 1825 // It should have a transient entry. |
| 1825 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1826 EXPECT_TRUE(other_controller.GetTransientEntry()); |
| 1826 | 1827 |
| 1827 // And the interstitial should be showing. | 1828 // And the interstitial should be showing. |
| 1828 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | 1829 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); |
| 1829 | 1830 |
| 1830 // And the interstitial should do a reload on don't proceed. | 1831 // And the interstitial should do a reload on don't proceed. |
| 1831 EXPECT_TRUE(other_contents->GetInterstitialPage()->reload_on_dont_proceed()); | 1832 EXPECT_TRUE(other_contents->GetInterstitialPage()->reload_on_dont_proceed()); |
| 1832 } | 1833 } |
| OLD | NEW |