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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/dom_operation_notification_details.h" | 7 #include "chrome/browser/dom_operation_notification_details.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 293 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
294 | 294 |
295 // Navigate to new site | 295 // Navigate to new site |
296 const GURL url2("http://www.yahoo.com"); | 296 const GURL url2("http://www.yahoo.com"); |
297 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 297 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
298 EXPECT_TRUE(contents()->cross_navigation_pending()); | 298 EXPECT_TRUE(contents()->cross_navigation_pending()); |
299 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 299 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
300 int pending_rvh_delete_count = 0; | 300 int pending_rvh_delete_count = 0; |
301 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 301 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
302 | 302 |
| 303 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 304 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 305 orig_rvh->SendShouldCloseACK(true); |
| 306 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 307 |
303 // DidNavigate from the pending page | 308 // DidNavigate from the pending page |
304 ViewHostMsg_FrameNavigate_Params params2; | 309 ViewHostMsg_FrameNavigate_Params params2; |
305 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 310 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); |
306 contents()->TestDidNavigate(pending_rvh, params2); | 311 contents()->TestDidNavigate(pending_rvh, params2); |
307 SiteInstance* instance2 = contents()->GetSiteInstance(); | 312 SiteInstance* instance2 = contents()->GetSiteInstance(); |
308 | 313 |
309 EXPECT_FALSE(contents()->cross_navigation_pending()); | 314 EXPECT_FALSE(contents()->cross_navigation_pending()); |
310 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 315 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
311 EXPECT_NE(instance1, instance2); | 316 EXPECT_NE(instance1, instance2); |
312 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 317 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
313 EXPECT_EQ(orig_rvh_delete_count, 1); | 318 // We keep the original RVH around, swapped out. |
| 319 EXPECT_TRUE(contents()->render_manager()->IsSwappedOut(orig_rvh)); |
| 320 EXPECT_EQ(orig_rvh_delete_count, 0); |
314 | 321 |
315 // Going back should switch SiteInstances again. The first SiteInstance is | 322 // Going back should switch SiteInstances again. The first SiteInstance is |
316 // stored in the NavigationEntry, so it should be the same as at the start. | 323 // stored in the NavigationEntry, so it should be the same as at the start. |
| 324 // We should use the same RVH as before, swapping it back in. |
317 controller().GoBack(); | 325 controller().GoBack(); |
318 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); | 326 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); |
| 327 EXPECT_EQ(orig_rvh, goback_rvh); |
319 EXPECT_TRUE(contents()->cross_navigation_pending()); | 328 EXPECT_TRUE(contents()->cross_navigation_pending()); |
320 | 329 |
| 330 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
| 331 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
| 332 pending_rvh->SendShouldCloseACK(true); |
| 333 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
| 334 |
321 // DidNavigate from the back action | 335 // DidNavigate from the back action |
322 contents()->TestDidNavigate(goback_rvh, params1); | 336 contents()->TestDidNavigate(goback_rvh, params1); |
323 EXPECT_FALSE(contents()->cross_navigation_pending()); | 337 EXPECT_FALSE(contents()->cross_navigation_pending()); |
324 EXPECT_EQ(goback_rvh, contents()->render_view_host()); | 338 EXPECT_EQ(goback_rvh, contents()->render_view_host()); |
| 339 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 340 // The pending RVH should now be swapped out, not deleted. |
| 341 EXPECT_TRUE(contents()->render_manager()->IsSwappedOut(pending_rvh)); |
| 342 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 343 |
| 344 // Close tab and ensure RVHs are deleted. |
| 345 DeleteContents(); |
| 346 EXPECT_EQ(orig_rvh_delete_count, 1); |
325 EXPECT_EQ(pending_rvh_delete_count, 1); | 347 EXPECT_EQ(pending_rvh_delete_count, 1); |
326 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | |
327 } | 348 } |
328 | 349 |
329 // Test that navigating across a site boundary after a crash creates a new | 350 // Test that navigating across a site boundary after a crash creates a new |
330 // RVH without requiring a cross-site transition (i.e., PENDING state). | 351 // RVH without requiring a cross-site transition (i.e., PENDING state). |
331 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 352 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
332 contents()->transition_cross_site = true; | 353 contents()->transition_cross_site = true; |
333 TestRenderViewHost* orig_rvh = rvh(); | 354 TestRenderViewHost* orig_rvh = rvh(); |
334 int orig_rvh_delete_count = 0; | 355 int orig_rvh_delete_count = 0; |
335 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 356 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
336 SiteInstance* instance1 = contents()->GetSiteInstance(); | 357 SiteInstance* instance1 = contents()->GetSiteInstance(); |
(...skipping 11 matching lines...) Expand all Loading... |
348 // Crash the renderer. | 369 // Crash the renderer. |
349 orig_rvh->set_render_view_created(false); | 370 orig_rvh->set_render_view_created(false); |
350 | 371 |
351 // Navigate to new site. We should not go into PENDING. | 372 // Navigate to new site. We should not go into PENDING. |
352 const GURL url2("http://www.yahoo.com"); | 373 const GURL url2("http://www.yahoo.com"); |
353 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 374 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
354 TestRenderViewHost* new_rvh = rvh(); | 375 TestRenderViewHost* new_rvh = rvh(); |
355 EXPECT_FALSE(contents()->cross_navigation_pending()); | 376 EXPECT_FALSE(contents()->cross_navigation_pending()); |
356 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 377 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
357 EXPECT_NE(orig_rvh, new_rvh); | 378 EXPECT_NE(orig_rvh, new_rvh); |
| 379 EXPECT_FALSE(contents()->render_manager()->IsSwappedOut(orig_rvh)); |
358 EXPECT_EQ(orig_rvh_delete_count, 1); | 380 EXPECT_EQ(orig_rvh_delete_count, 1); |
359 | 381 |
360 // DidNavigate from the new page | 382 // DidNavigate from the new page |
361 ViewHostMsg_FrameNavigate_Params params2; | 383 ViewHostMsg_FrameNavigate_Params params2; |
362 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 384 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); |
363 contents()->TestDidNavigate(new_rvh, params2); | 385 contents()->TestDidNavigate(new_rvh, params2); |
364 SiteInstance* instance2 = contents()->GetSiteInstance(); | 386 SiteInstance* instance2 = contents()->GetSiteInstance(); |
365 | 387 |
366 EXPECT_FALSE(contents()->cross_navigation_pending()); | 388 EXPECT_FALSE(contents()->cross_navigation_pending()); |
367 EXPECT_EQ(new_rvh, rvh()); | 389 EXPECT_EQ(new_rvh, rvh()); |
368 EXPECT_NE(instance1, instance2); | 390 EXPECT_NE(instance1, instance2); |
369 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 391 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 392 |
| 393 // Close tab and ensure RVHs are deleted. |
| 394 DeleteContents(); |
| 395 EXPECT_EQ(orig_rvh_delete_count, 1); |
370 } | 396 } |
371 | 397 |
372 // Test that opening a new tab in the same SiteInstance and then navigating | 398 // Test that opening a new tab in the same SiteInstance and then navigating |
373 // both tabs to a new site will place both tabs in a single SiteInstance. | 399 // both tabs to a new site will place both tabs in a single SiteInstance. |
374 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 400 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
375 contents()->transition_cross_site = true; | 401 contents()->transition_cross_site = true; |
376 TestRenderViewHost* orig_rvh = rvh(); | 402 TestRenderViewHost* orig_rvh = rvh(); |
377 SiteInstance* instance1 = contents()->GetSiteInstance(); | 403 SiteInstance* instance1 = contents()->GetSiteInstance(); |
378 | 404 |
379 // Navigate to URL. First URL should use first RenderViewHost. | 405 // Navigate to URL. First URL should use first RenderViewHost. |
380 const GURL url("http://www.google.com"); | 406 const GURL url("http://www.google.com"); |
381 controller().LoadURL(url, GURL(), PageTransition::TYPED); | 407 controller().LoadURL(url, GURL(), PageTransition::TYPED); |
382 ViewHostMsg_FrameNavigate_Params params1; | 408 ViewHostMsg_FrameNavigate_Params params1; |
383 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 409 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); |
384 contents()->TestDidNavigate(orig_rvh, params1); | 410 contents()->TestDidNavigate(orig_rvh, params1); |
385 | 411 |
386 // Open a new tab with the same SiteInstance, navigated to the same site. | 412 // Open a new tab with the same SiteInstance, navigated to the same site. |
387 TestTabContents contents2(profile(), instance1); | 413 TestTabContents contents2(profile(), instance1); |
388 params1.page_id = 2; // Need this since the site instance is the same (which | 414 params1.page_id = 2; // Need this since the site instance is the same (which |
389 // is the scope of page IDs) and we want to consider | 415 // is the scope of page IDs) and we want to consider |
390 // this a new page. | 416 // this a new page. |
391 contents2.transition_cross_site = true; | 417 contents2.transition_cross_site = true; |
392 contents2.controller().LoadURL(url, GURL(), PageTransition::TYPED); | 418 contents2.controller().LoadURL(url, GURL(), PageTransition::TYPED); |
393 contents2.TestDidNavigate(contents2.render_view_host(), params1); | 419 contents2.TestDidNavigate(contents2.render_view_host(), params1); |
394 | 420 |
395 // Navigate first tab to a new site | 421 // Navigate first tab to a new site |
396 const GURL url2a("http://www.yahoo.com"); | 422 const GURL url2a("http://www.yahoo.com"); |
397 controller().LoadURL(url2a, GURL(), PageTransition::TYPED); | 423 controller().LoadURL(url2a, GURL(), PageTransition::TYPED); |
| 424 orig_rvh->SendShouldCloseACK(true); |
398 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 425 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
399 ViewHostMsg_FrameNavigate_Params params2a; | 426 ViewHostMsg_FrameNavigate_Params params2a; |
400 InitNavigateParams(¶ms2a, 1, url2a, PageTransition::TYPED); | 427 InitNavigateParams(¶ms2a, 1, url2a, PageTransition::TYPED); |
401 contents()->TestDidNavigate(pending_rvh_a, params2a); | 428 contents()->TestDidNavigate(pending_rvh_a, params2a); |
402 SiteInstance* instance2a = contents()->GetSiteInstance(); | 429 SiteInstance* instance2a = contents()->GetSiteInstance(); |
403 EXPECT_NE(instance1, instance2a); | 430 EXPECT_NE(instance1, instance2a); |
404 | 431 |
405 // Navigate second tab to the same site as the first tab | 432 // Navigate second tab to the same site as the first tab |
406 const GURL url2b("http://mail.yahoo.com"); | 433 const GURL url2b("http://mail.yahoo.com"); |
407 contents2.controller().LoadURL(url2b, GURL(), PageTransition::TYPED); | 434 contents2.controller().LoadURL(url2b, GURL(), PageTransition::TYPED); |
| 435 TestRenderViewHost* rvh2 = |
| 436 static_cast<TestRenderViewHost*>(contents2.render_view_host()); |
| 437 rvh2->SendShouldCloseACK(true); |
408 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 438 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
409 EXPECT_TRUE(pending_rvh_b != NULL); | 439 EXPECT_TRUE(pending_rvh_b != NULL); |
410 EXPECT_TRUE(contents2.cross_navigation_pending()); | 440 EXPECT_TRUE(contents2.cross_navigation_pending()); |
411 | 441 |
412 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 442 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
413 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 443 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
414 // now covered by the CrossSiteBoundariesAfterCrash test. | 444 // now covered by the CrossSiteBoundariesAfterCrash test. |
415 | 445 |
416 ViewHostMsg_FrameNavigate_Params params2b; | 446 ViewHostMsg_FrameNavigate_Params params2b; |
417 InitNavigateParams(¶ms2b, 2, url2b, PageTransition::TYPED); | 447 InitNavigateParams(¶ms2b, 2, url2b, PageTransition::TYPED); |
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 TestInterstitialPage* interstitial = | 1625 TestInterstitialPage* interstitial = |
1596 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1626 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1597 TestInterstitialPageStateGuard state_guard(interstitial); | 1627 TestInterstitialPageStateGuard state_guard(interstitial); |
1598 interstitial->Show(); | 1628 interstitial->Show(); |
1599 interstitial->TestDidNavigate(1, kGURL); | 1629 interstitial->TestDidNavigate(1, kGURL); |
1600 | 1630 |
1601 // While the interstitial is showing, let's simulate the hidden page | 1631 // While the interstitial is showing, let's simulate the hidden page |
1602 // attempting to show a JS message. | 1632 // attempting to show a JS message. |
1603 IPC::Message* dummy_message = new IPC::Message; | 1633 IPC::Message* dummy_message = new IPC::Message; |
1604 bool did_suppress_message = false; | 1634 bool did_suppress_message = false; |
1605 contents()->RunJavaScriptMessage(L"This is an informative message", L"OK", | 1635 contents()->RunJavaScriptMessage(contents()->render_view_host(), |
| 1636 L"This is an informative message", L"OK", |
1606 kGURL, ui::MessageBoxFlags::kIsJavascriptAlert, dummy_message, | 1637 kGURL, ui::MessageBoxFlags::kIsJavascriptAlert, dummy_message, |
1607 &did_suppress_message); | 1638 &did_suppress_message); |
1608 EXPECT_TRUE(did_suppress_message); | 1639 EXPECT_TRUE(did_suppress_message); |
1609 } | 1640 } |
1610 | 1641 |
1611 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 1642 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
1612 // interstitial it isn't copied over to the destination. | 1643 // interstitial it isn't copied over to the destination. |
1613 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { | 1644 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { |
1614 // Navigate to a page. | 1645 // Navigate to a page. |
1615 GURL url1("http://www.google.com"); | 1646 GURL url1("http://www.google.com"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 window.close_count = 0; | 1753 window.close_count = 0; |
1723 | 1754 |
1724 const int kWindowCount = 4; | 1755 const int kWindowCount = 4; |
1725 for (int i = 0; i < kWindowCount; i++) { | 1756 for (int i = 0; i < kWindowCount; i++) { |
1726 tab_contents->AddConstrainedDialog(&window); | 1757 tab_contents->AddConstrainedDialog(&window); |
1727 } | 1758 } |
1728 EXPECT_EQ(window.close_count, 0); | 1759 EXPECT_EQ(window.close_count, 0); |
1729 delete tab_contents; | 1760 delete tab_contents; |
1730 EXPECT_EQ(window.close_count, kWindowCount); | 1761 EXPECT_EQ(window.close_count, kWindowCount); |
1731 } | 1762 } |
OLD | NEW |