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