OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/prefs/pref_value_store.h" | 10 #include "chrome/browser/prefs/pref_value_store.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 310 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
311 | 311 |
312 // Navigate to new site | 312 // Navigate to new site |
313 const GURL url2("http://www.yahoo.com"); | 313 const GURL url2("http://www.yahoo.com"); |
314 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 314 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
315 EXPECT_TRUE(contents()->cross_navigation_pending()); | 315 EXPECT_TRUE(contents()->cross_navigation_pending()); |
316 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 316 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
317 int pending_rvh_delete_count = 0; | 317 int pending_rvh_delete_count = 0; |
318 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 318 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
319 | 319 |
| 320 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 321 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 322 orig_rvh->SendShouldCloseACK(true); |
| 323 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 324 |
320 // DidNavigate from the pending page | 325 // DidNavigate from the pending page |
321 ViewHostMsg_FrameNavigate_Params params2; | 326 ViewHostMsg_FrameNavigate_Params params2; |
322 InitNavigateParams(¶ms2, 1, url2); | 327 InitNavigateParams(¶ms2, 1, url2); |
323 contents()->TestDidNavigate(pending_rvh, params2); | 328 contents()->TestDidNavigate(pending_rvh, params2); |
324 SiteInstance* instance2 = contents()->GetSiteInstance(); | 329 SiteInstance* instance2 = contents()->GetSiteInstance(); |
325 | 330 |
326 EXPECT_FALSE(contents()->cross_navigation_pending()); | 331 EXPECT_FALSE(contents()->cross_navigation_pending()); |
327 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 332 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
328 EXPECT_NE(instance1, instance2); | 333 EXPECT_NE(instance1, instance2); |
329 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 334 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
330 EXPECT_EQ(orig_rvh_delete_count, 1); | 335 // We keep the original RVH around, swapped out. |
| 336 EXPECT_TRUE(contents()->render_manager()->IsSwappedOut(orig_rvh)); |
| 337 EXPECT_EQ(orig_rvh_delete_count, 0); |
331 | 338 |
332 // Going back should switch SiteInstances again. The first SiteInstance is | 339 // Going back should switch SiteInstances again. The first SiteInstance is |
333 // stored in the NavigationEntry, so it should be the same as at the start. | 340 // stored in the NavigationEntry, so it should be the same as at the start. |
| 341 // We should use the same RVH as before, swapping it back in. |
334 controller().GoBack(); | 342 controller().GoBack(); |
335 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); | 343 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); |
| 344 EXPECT_EQ(orig_rvh, goback_rvh); |
336 EXPECT_TRUE(contents()->cross_navigation_pending()); | 345 EXPECT_TRUE(contents()->cross_navigation_pending()); |
337 | 346 |
| 347 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
| 348 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
| 349 pending_rvh->SendShouldCloseACK(true); |
| 350 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
| 351 |
338 // DidNavigate from the back action | 352 // DidNavigate from the back action |
339 contents()->TestDidNavigate(goback_rvh, params1); | 353 contents()->TestDidNavigate(goback_rvh, params1); |
340 EXPECT_FALSE(contents()->cross_navigation_pending()); | 354 EXPECT_FALSE(contents()->cross_navigation_pending()); |
341 EXPECT_EQ(goback_rvh, contents()->render_view_host()); | 355 EXPECT_EQ(goback_rvh, contents()->render_view_host()); |
| 356 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 357 // The pending RVH should now be swapped out, not deleted. |
| 358 EXPECT_TRUE(contents()->render_manager()->IsSwappedOut(pending_rvh)); |
| 359 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 360 |
| 361 // Close tab and ensure RVHs are deleted. |
| 362 DeleteContents(); |
| 363 EXPECT_EQ(orig_rvh_delete_count, 1); |
342 EXPECT_EQ(pending_rvh_delete_count, 1); | 364 EXPECT_EQ(pending_rvh_delete_count, 1); |
343 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | |
344 } | 365 } |
345 | 366 |
346 // Test that navigating across a site boundary after a crash creates a new | 367 // Test that navigating across a site boundary after a crash creates a new |
347 // RVH without requiring a cross-site transition (i.e., PENDING state). | 368 // RVH without requiring a cross-site transition (i.e., PENDING state). |
348 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 369 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
349 contents()->transition_cross_site = true; | 370 contents()->transition_cross_site = true; |
350 TestRenderViewHost* orig_rvh = rvh(); | 371 TestRenderViewHost* orig_rvh = rvh(); |
351 int orig_rvh_delete_count = 0; | 372 int orig_rvh_delete_count = 0; |
352 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 373 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
353 SiteInstance* instance1 = contents()->GetSiteInstance(); | 374 SiteInstance* instance1 = contents()->GetSiteInstance(); |
(...skipping 11 matching lines...) Expand all Loading... |
365 // Crash the renderer. | 386 // Crash the renderer. |
366 orig_rvh->set_render_view_created(false); | 387 orig_rvh->set_render_view_created(false); |
367 | 388 |
368 // Navigate to new site. We should not go into PENDING. | 389 // Navigate to new site. We should not go into PENDING. |
369 const GURL url2("http://www.yahoo.com"); | 390 const GURL url2("http://www.yahoo.com"); |
370 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 391 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
371 TestRenderViewHost* new_rvh = rvh(); | 392 TestRenderViewHost* new_rvh = rvh(); |
372 EXPECT_FALSE(contents()->cross_navigation_pending()); | 393 EXPECT_FALSE(contents()->cross_navigation_pending()); |
373 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 394 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
374 EXPECT_NE(orig_rvh, new_rvh); | 395 EXPECT_NE(orig_rvh, new_rvh); |
| 396 EXPECT_FALSE(contents()->render_manager()->IsSwappedOut(orig_rvh)); |
375 EXPECT_EQ(orig_rvh_delete_count, 1); | 397 EXPECT_EQ(orig_rvh_delete_count, 1); |
376 | 398 |
377 // DidNavigate from the new page | 399 // DidNavigate from the new page |
378 ViewHostMsg_FrameNavigate_Params params2; | 400 ViewHostMsg_FrameNavigate_Params params2; |
379 InitNavigateParams(¶ms2, 1, url2); | 401 InitNavigateParams(¶ms2, 1, url2); |
380 contents()->TestDidNavigate(new_rvh, params2); | 402 contents()->TestDidNavigate(new_rvh, params2); |
381 SiteInstance* instance2 = contents()->GetSiteInstance(); | 403 SiteInstance* instance2 = contents()->GetSiteInstance(); |
382 | 404 |
383 EXPECT_FALSE(contents()->cross_navigation_pending()); | 405 EXPECT_FALSE(contents()->cross_navigation_pending()); |
384 EXPECT_EQ(new_rvh, rvh()); | 406 EXPECT_EQ(new_rvh, rvh()); |
385 EXPECT_NE(instance1, instance2); | 407 EXPECT_NE(instance1, instance2); |
386 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 408 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 409 |
| 410 // Close tab and ensure RVHs are deleted. |
| 411 DeleteContents(); |
| 412 EXPECT_EQ(orig_rvh_delete_count, 1); |
387 } | 413 } |
388 | 414 |
389 // Test that opening a new tab in the same SiteInstance and then navigating | 415 // Test that opening a new tab in the same SiteInstance and then navigating |
390 // both tabs to a new site will place both tabs in a single SiteInstance. | 416 // both tabs to a new site will place both tabs in a single SiteInstance. |
391 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 417 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
392 contents()->transition_cross_site = true; | 418 contents()->transition_cross_site = true; |
393 TestRenderViewHost* orig_rvh = rvh(); | 419 TestRenderViewHost* orig_rvh = rvh(); |
394 SiteInstance* instance1 = contents()->GetSiteInstance(); | 420 SiteInstance* instance1 = contents()->GetSiteInstance(); |
395 | 421 |
396 // Navigate to URL. First URL should use first RenderViewHost. | 422 // Navigate to URL. First URL should use first RenderViewHost. |
397 const GURL url("http://www.google.com"); | 423 const GURL url("http://www.google.com"); |
398 controller().LoadURL(url, GURL(), PageTransition::TYPED); | 424 controller().LoadURL(url, GURL(), PageTransition::TYPED); |
399 ViewHostMsg_FrameNavigate_Params params1; | 425 ViewHostMsg_FrameNavigate_Params params1; |
400 InitNavigateParams(¶ms1, 1, url); | 426 InitNavigateParams(¶ms1, 1, url); |
401 contents()->TestDidNavigate(orig_rvh, params1); | 427 contents()->TestDidNavigate(orig_rvh, params1); |
402 | 428 |
403 // Open a new tab with the same SiteInstance, navigated to the same site. | 429 // Open a new tab with the same SiteInstance, navigated to the same site. |
404 TestTabContents contents2(profile(), instance1); | 430 TestTabContents contents2(profile(), instance1); |
405 params1.page_id = 2; // Need this since the site instance is the same (which | 431 params1.page_id = 2; // Need this since the site instance is the same (which |
406 // is the scope of page IDs) and we want to consider | 432 // is the scope of page IDs) and we want to consider |
407 // this a new page. | 433 // this a new page. |
408 contents2.transition_cross_site = true; | 434 contents2.transition_cross_site = true; |
409 contents2.controller().LoadURL(url, GURL(), PageTransition::TYPED); | 435 contents2.controller().LoadURL(url, GURL(), PageTransition::TYPED); |
410 contents2.TestDidNavigate(contents2.render_view_host(), params1); | 436 contents2.TestDidNavigate(contents2.render_view_host(), params1); |
411 | 437 |
412 // Navigate first tab to a new site | 438 // Navigate first tab to a new site |
413 const GURL url2a("http://www.yahoo.com"); | 439 const GURL url2a("http://www.yahoo.com"); |
414 controller().LoadURL(url2a, GURL(), PageTransition::TYPED); | 440 controller().LoadURL(url2a, GURL(), PageTransition::TYPED); |
| 441 orig_rvh->SendShouldCloseACK(true); |
415 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 442 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
416 ViewHostMsg_FrameNavigate_Params params2a; | 443 ViewHostMsg_FrameNavigate_Params params2a; |
417 InitNavigateParams(¶ms2a, 1, url2a); | 444 InitNavigateParams(¶ms2a, 1, url2a); |
418 contents()->TestDidNavigate(pending_rvh_a, params2a); | 445 contents()->TestDidNavigate(pending_rvh_a, params2a); |
419 SiteInstance* instance2a = contents()->GetSiteInstance(); | 446 SiteInstance* instance2a = contents()->GetSiteInstance(); |
420 EXPECT_NE(instance1, instance2a); | 447 EXPECT_NE(instance1, instance2a); |
421 | 448 |
422 // Navigate second tab to the same site as the first tab | 449 // Navigate second tab to the same site as the first tab |
423 const GURL url2b("http://mail.yahoo.com"); | 450 const GURL url2b("http://mail.yahoo.com"); |
424 contents2.controller().LoadURL(url2b, GURL(), PageTransition::TYPED); | 451 contents2.controller().LoadURL(url2b, GURL(), PageTransition::TYPED); |
| 452 TestRenderViewHost* rvh2 = |
| 453 static_cast<TestRenderViewHost*>(contents2.render_view_host()); |
| 454 rvh2->SendShouldCloseACK(true); |
425 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 455 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
426 EXPECT_TRUE(pending_rvh_b != NULL); | 456 EXPECT_TRUE(pending_rvh_b != NULL); |
427 EXPECT_TRUE(contents2.cross_navigation_pending()); | 457 EXPECT_TRUE(contents2.cross_navigation_pending()); |
428 | 458 |
429 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 459 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
430 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 460 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
431 // now covered by the CrossSiteBoundariesAfterCrash test. | 461 // now covered by the CrossSiteBoundariesAfterCrash test. |
432 | 462 |
433 ViewHostMsg_FrameNavigate_Params params2b; | 463 ViewHostMsg_FrameNavigate_Params params2b; |
434 InitNavigateParams(¶ms2b, 2, url2b); | 464 InitNavigateParams(¶ms2b, 2, url2b); |
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 TestInterstitialPage* interstitial = | 1641 TestInterstitialPage* interstitial = |
1612 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1642 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1613 TestInterstitialPageStateGuard state_guard(interstitial); | 1643 TestInterstitialPageStateGuard state_guard(interstitial); |
1614 interstitial->Show(); | 1644 interstitial->Show(); |
1615 interstitial->TestDidNavigate(1, kGURL); | 1645 interstitial->TestDidNavigate(1, kGURL); |
1616 | 1646 |
1617 // While the interstitial is showing, let's simulate the hidden page | 1647 // While the interstitial is showing, let's simulate the hidden page |
1618 // attempting to show a JS message. | 1648 // attempting to show a JS message. |
1619 IPC::Message* dummy_message = new IPC::Message; | 1649 IPC::Message* dummy_message = new IPC::Message; |
1620 bool did_suppress_message = false; | 1650 bool did_suppress_message = false; |
1621 contents()->RunJavaScriptMessage(L"This is an informative message", L"OK", | 1651 contents()->RunJavaScriptMessage(contents()->render_view_host(), |
| 1652 L"This is an informative message", L"OK", |
1622 kGURL, ui::MessageBoxFlags::kIsJavascriptAlert, dummy_message, | 1653 kGURL, ui::MessageBoxFlags::kIsJavascriptAlert, dummy_message, |
1623 &did_suppress_message); | 1654 &did_suppress_message); |
1624 EXPECT_TRUE(did_suppress_message); | 1655 EXPECT_TRUE(did_suppress_message); |
1625 } | 1656 } |
1626 | 1657 |
1627 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 1658 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
1628 // interstitial it isn't copied over to the destination. | 1659 // interstitial it isn't copied over to the destination. |
1629 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { | 1660 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { |
1630 // Navigate to a page. | 1661 // Navigate to a page. |
1631 GURL url1("http://www.google.com"); | 1662 GURL url1("http://www.google.com"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 window.close_count = 0; | 1769 window.close_count = 0; |
1739 | 1770 |
1740 const int kWindowCount = 4; | 1771 const int kWindowCount = 4; |
1741 for (int i = 0; i < kWindowCount; i++) { | 1772 for (int i = 0; i < kWindowCount; i++) { |
1742 tab_contents->AddConstrainedDialog(&window); | 1773 tab_contents->AddConstrainedDialog(&window); |
1743 } | 1774 } |
1744 EXPECT_EQ(window.close_count, 0); | 1775 EXPECT_EQ(window.close_count, 0); |
1745 delete tab_contents; | 1776 delete tab_contents; |
1746 EXPECT_EQ(window.close_count, kWindowCount); | 1777 EXPECT_EQ(window.close_count, kWindowCount); |
1747 } | 1778 } |
OLD | NEW |