OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/browser/frame_host/cross_site_transferring_request.h" | 9 #include "content/browser/frame_host/cross_site_transferring_request.h" |
10 #include "content/browser/frame_host/navigation_before_commit_info.h" | 10 #include "content/browser/frame_host/navigation_before_commit_info.h" |
11 #include "content/browser/frame_host/navigation_controller_impl.h" | 11 #include "content/browser/frame_host/navigation_controller_impl.h" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
13 #include "content/browser/frame_host/navigation_request.h" | 13 #include "content/browser/frame_host/navigation_request.h" |
14 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/navigator_impl.h" | 15 #include "content/browser/frame_host/navigator_impl.h" |
16 #include "content/browser/frame_host/render_frame_host_manager.h" | 16 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 17 #include "content/browser/frame_host/render_frame_proxy_host.h" |
17 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 19 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
19 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_widget_host_iterator.h" | 26 #include "content/public/browser/render_widget_host_iterator.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 factory_.set_should_create_webui(should_create_webui); | 275 factory_.set_should_create_webui(should_create_webui); |
275 } | 276 } |
276 | 277 |
277 void NavigateActiveAndCommit(const GURL& url) { | 278 void NavigateActiveAndCommit(const GURL& url) { |
278 // Note: we navigate the active RenderFrameHost because previous navigations | 279 // Note: we navigate the active RenderFrameHost because previous navigations |
279 // won't have committed yet, so NavigateAndCommit does the wrong thing | 280 // won't have committed yet, so NavigateAndCommit does the wrong thing |
280 // for us. | 281 // for us. |
281 controller().LoadURL( | 282 controller().LoadURL( |
282 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 283 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
283 TestRenderViewHost* old_rvh = test_rvh(); | 284 TestRenderViewHost* old_rvh = test_rvh(); |
| 285 TestRenderFrameHost* old_rfh = main_test_rfh(); |
| 286 TestRenderFrameHost* active_rfh = pending_main_rfh() ? |
| 287 static_cast<TestRenderFrameHost*>(pending_main_rfh()) : |
| 288 old_rfh; |
284 | 289 |
285 // Simulate the BeforeUnload_ACK that is received from the current renderer | 290 // Simulate the BeforeUnload_ACK that is received from the current renderer |
286 // for a cross-site navigation. | 291 // for a cross-site navigation. |
287 if (old_rvh != active_rvh()) { | 292 if (old_rfh != active_rfh) { |
288 old_rvh->SendBeforeUnloadACK(true); | 293 old_rfh->SendBeforeUnloadACK(true); |
289 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, old_rvh->rvh_state()); | 294 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); |
290 } | 295 } |
291 | 296 |
292 // Commit the navigation with a new page ID. | 297 // Commit the navigation with a new page ID. |
293 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 298 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
294 active_rvh()->GetSiteInstance()); | 299 active_rfh->GetSiteInstance()); |
295 | 300 |
296 // Use an observer to avoid accessing a deleted renderer later on when the | 301 // Use an observer to avoid accessing a deleted renderer later on when the |
297 // state is being checked. | 302 // state is being checked. |
| 303 RenderFrameHostDeletedObserver rfh_observer(old_rfh); |
298 RenderViewHostDeletedObserver rvh_observer(old_rvh); | 304 RenderViewHostDeletedObserver rvh_observer(old_rvh); |
299 active_test_rvh()->SendNavigate(max_page_id + 1, url); | 305 active_rfh->SendNavigate(max_page_id + 1, url); |
300 | 306 |
301 // Make sure that we start to run the unload handler at the time of commit. | 307 // Make sure that we start to run the unload handler at the time of commit. |
302 bool expecting_rvh_shutdown = false; | 308 bool expecting_rfh_shutdown = false; |
303 if (old_rvh != active_rvh() && !rvh_observer.deleted()) { | 309 if (old_rfh != active_rfh && !rfh_observer.deleted()) { |
304 if (!static_cast<SiteInstanceImpl*>( | 310 if (!old_rfh->GetSiteInstance()->active_frame_count()) { |
305 old_rvh->GetSiteInstance())->active_view_count()) { | 311 expecting_rfh_shutdown = true; |
306 expecting_rvh_shutdown = true; | 312 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SHUTDOWN, |
307 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, | 313 old_rfh->rfh_state()); |
308 old_rvh->rvh_state()); | |
309 } else { | 314 } else { |
310 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | 315 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, |
311 old_rvh->rvh_state()); | 316 old_rfh->rfh_state()); |
312 } | 317 } |
313 } | 318 } |
314 | 319 |
315 // Simulate the swap out ACK coming from the pending renderer. This should | 320 // Simulate the swap out ACK coming from the pending renderer. This should |
316 // either shut down the old RVH or leave it in a swapped out state. | 321 // either shut down the old RFH or leave it in a swapped out state. |
317 if (old_rvh != active_rvh()) { | 322 if (old_rfh != active_rfh) { |
318 old_rvh->OnSwappedOut(false); | 323 old_rfh->OnSwappedOut(); |
319 if (expecting_rvh_shutdown) { | 324 if (expecting_rfh_shutdown) { |
| 325 EXPECT_TRUE(rfh_observer.deleted()); |
320 EXPECT_TRUE(rvh_observer.deleted()); | 326 EXPECT_TRUE(rvh_observer.deleted()); |
321 } else { | 327 } else { |
322 EXPECT_EQ(RenderViewHostImpl::STATE_SWAPPED_OUT, | 328 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, |
323 old_rvh->rvh_state()); | 329 old_rfh->rfh_state()); |
324 } | 330 } |
325 } | 331 } |
326 } | 332 } |
327 | 333 |
328 bool ShouldSwapProcesses(RenderFrameHostManager* manager, | 334 bool ShouldSwapProcesses(RenderFrameHostManager* manager, |
329 const NavigationEntryImpl* current_entry, | 335 const NavigationEntryImpl* current_entry, |
330 const NavigationEntryImpl* new_entry) const { | 336 const NavigationEntryImpl* new_entry) const { |
331 CHECK(new_entry); | 337 CHECK(new_entry); |
332 BrowserContext* browser_context = | 338 BrowserContext* browser_context = |
333 manager->delegate_->GetControllerForRenderManager().GetBrowserContext(); | 339 manager->delegate_->GetControllerForRenderManager().GetBrowserContext(); |
334 const GURL& current_effective_url = current_entry ? | 340 const GURL& current_effective_url = current_entry ? |
335 SiteInstanceImpl::GetEffectiveURL(browser_context, | 341 SiteInstanceImpl::GetEffectiveURL(browser_context, |
336 current_entry->GetURL()) : | 342 current_entry->GetURL()) : |
337 manager->render_frame_host_->GetSiteInstance()->GetSiteURL(); | 343 manager->render_frame_host_->GetSiteInstance()->GetSiteURL(); |
338 bool current_is_view_source_mode = current_entry ? | 344 bool current_is_view_source_mode = current_entry ? |
339 current_entry->IsViewSourceMode() : new_entry->IsViewSourceMode(); | 345 current_entry->IsViewSourceMode() : new_entry->IsViewSourceMode(); |
340 return manager->ShouldSwapBrowsingInstancesForNavigation( | 346 return manager->ShouldSwapBrowsingInstancesForNavigation( |
341 current_effective_url, | 347 current_effective_url, |
342 current_is_view_source_mode, | 348 current_is_view_source_mode, |
343 new_entry->site_instance(), | 349 new_entry->site_instance(), |
344 SiteInstanceImpl::GetEffectiveURL(browser_context, new_entry->GetURL()), | 350 SiteInstanceImpl::GetEffectiveURL(browser_context, new_entry->GetURL()), |
345 new_entry->IsViewSourceMode()); | 351 new_entry->IsViewSourceMode()); |
346 } | 352 } |
347 | 353 |
348 // Creates a test RenderViewHost that's swapped out. | 354 // Creates a test RenderFrameHost that's swapped out. |
349 TestRenderViewHost* CreateSwappedOutRenderViewHost() { | 355 TestRenderFrameHost* CreateSwappedOutRenderFrameHost() { |
350 const GURL kChromeURL("chrome://foo"); | 356 const GURL kChromeURL("chrome://foo"); |
351 const GURL kDestUrl("http://www.google.com/"); | 357 const GURL kDestUrl("http://www.google.com/"); |
352 | 358 |
353 // Navigate our first tab to a chrome url and then to the destination. | 359 // Navigate our first tab to a chrome url and then to the destination. |
354 NavigateActiveAndCommit(kChromeURL); | 360 NavigateActiveAndCommit(kChromeURL); |
355 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 361 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
356 | 362 |
357 // Navigate to a cross-site URL. | 363 // Navigate to a cross-site URL. |
358 contents()->GetController().LoadURL( | 364 contents()->GetController().LoadURL( |
359 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 365 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
360 EXPECT_TRUE(contents()->cross_navigation_pending()); | 366 EXPECT_TRUE(contents()->cross_navigation_pending()); |
361 | 367 |
362 // Manually increase the number of active views in the | 368 // Manually increase the number of active frames in the |
363 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 369 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
364 // destroyed when it gets swapped out. | 370 // destroyed when it gets swapped out. |
365 static_cast<SiteInstanceImpl*>(ntp_rfh->GetSiteInstance())-> | 371 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
366 increment_active_view_count(); | |
367 | 372 |
368 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 373 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
369 CHECK(dest_rfh); | 374 CHECK(dest_rfh); |
370 EXPECT_NE(ntp_rfh, dest_rfh); | 375 EXPECT_NE(ntp_rfh, dest_rfh); |
371 | 376 |
372 // BeforeUnload finishes. | 377 // BeforeUnload finishes. |
373 ntp_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 378 ntp_rfh->SendBeforeUnloadACK(true); |
374 | 379 |
375 dest_rfh->SendNavigate(101, kDestUrl); | 380 dest_rfh->SendNavigate(101, kDestUrl); |
376 ntp_rfh->OnSwappedOut(false); | 381 ntp_rfh->OnSwappedOut(); |
377 | 382 |
378 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut()); | 383 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
379 return ntp_rfh->GetRenderViewHost(); | 384 return ntp_rfh; |
380 } | 385 } |
381 | 386 |
382 NavigationRequest* GetNavigationRequestForRenderFrameManager( | 387 NavigationRequest* GetNavigationRequestForRenderFrameManager( |
383 RenderFrameHostManager* manager) const { | 388 RenderFrameHostManager* manager) const { |
384 return manager->navigation_request_for_testing(); | 389 return manager->navigation_request_for_testing(); |
385 } | 390 } |
386 | 391 |
387 void EnableBrowserSideNavigation() { | 392 void EnableBrowserSideNavigation() { |
388 CommandLine::ForCurrentProcess()->AppendSwitch( | 393 CommandLine::ForCurrentProcess()->AppendSwitch( |
389 switches::kEnableBrowserSideNavigation); | 394 switches::kEnableBrowserSideNavigation); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 ntp_rfh2->SendNavigate(100, kChromeUrl); | 429 ntp_rfh2->SendNavigate(100, kChromeUrl); |
425 | 430 |
426 // The second one is the opposite, creating a cross-site transition and | 431 // The second one is the opposite, creating a cross-site transition and |
427 // requiring a beforeunload ack. | 432 // requiring a beforeunload ack. |
428 contents2->GetController().LoadURL( | 433 contents2->GetController().LoadURL( |
429 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 434 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
430 EXPECT_TRUE(contents2->cross_navigation_pending()); | 435 EXPECT_TRUE(contents2->cross_navigation_pending()); |
431 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 436 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
432 ASSERT_TRUE(dest_rfh2); | 437 ASSERT_TRUE(dest_rfh2); |
433 | 438 |
434 ntp_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 439 ntp_rfh2->SendBeforeUnloadACK(true); |
435 dest_rfh2->SendNavigate(101, kDestUrl); | 440 dest_rfh2->SendNavigate(101, kDestUrl); |
436 | 441 |
437 // The two RFH's should be different in every way. | 442 // The two RFH's should be different in every way. |
438 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 443 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
439 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 444 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
440 dest_rfh2->GetSiteInstance()); | 445 dest_rfh2->GetSiteInstance()); |
441 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 446 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
442 contents()->GetMainFrame()->GetSiteInstance())); | 447 contents()->GetMainFrame()->GetSiteInstance())); |
443 | 448 |
444 // Navigate both to the new tab page, and verify that they share a | 449 // Navigate both to the new tab page, and verify that they share a |
445 // RenderProcessHost (not a SiteInstance). | 450 // RenderProcessHost (not a SiteInstance). |
446 NavigateActiveAndCommit(kChromeUrl); | 451 NavigateActiveAndCommit(kChromeUrl); |
447 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 452 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
448 | 453 |
449 contents2->GetController().LoadURL( | 454 contents2->GetController().LoadURL( |
450 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 455 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
451 dest_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 456 dest_rfh2->SendBeforeUnloadACK(true); |
452 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 457 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
453 | 458 |
454 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 459 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
455 contents2->GetMainFrame()->GetSiteInstance()); | 460 contents2->GetMainFrame()->GetSiteInstance()); |
456 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 461 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
457 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 462 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
458 } | 463 } |
459 | 464 |
460 // Ensure that the browser ignores most IPC messages that arrive from a | 465 // Ensure that the browser ignores most IPC messages that arrive from a |
461 // RenderViewHost that has been swapped out. We do not want to take | 466 // RenderViewHost that has been swapped out. We do not want to take |
(...skipping 11 matching lines...) Expand all Loading... |
473 | 478 |
474 // Send an update favicon message and make sure it works. | 479 // Send an update favicon message and make sure it works. |
475 const base::string16 ntp_title = base::ASCIIToUTF16("NTP Title"); | 480 const base::string16 ntp_title = base::ASCIIToUTF16("NTP Title"); |
476 { | 481 { |
477 PluginFaviconMessageObserver observer(contents()); | 482 PluginFaviconMessageObserver observer(contents()); |
478 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->OnMessageReceived( | 483 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->OnMessageReceived( |
479 ViewHostMsg_UpdateFaviconURL( | 484 ViewHostMsg_UpdateFaviconURL( |
480 ntp_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 485 ntp_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
481 EXPECT_TRUE(observer.favicon_received()); | 486 EXPECT_TRUE(observer.favicon_received()); |
482 } | 487 } |
483 // Create one more view in the same SiteInstance where ntp_rfh | 488 // Create one more frame in the same SiteInstance where ntp_rfh |
484 // exists so that it doesn't get deleted on navigation to another | 489 // exists so that it doesn't get deleted on navigation to another |
485 // site. | 490 // site. |
486 static_cast<SiteInstanceImpl*>(ntp_rfh->GetSiteInstance())-> | 491 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
487 increment_active_view_count(); | |
488 | 492 |
489 | 493 |
490 // Navigate to a cross-site URL. | 494 // Navigate to a cross-site URL. |
491 NavigateActiveAndCommit(kDestUrl); | 495 NavigateActiveAndCommit(kDestUrl); |
492 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); | 496 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); |
493 ASSERT_TRUE(dest_rfh); | 497 ASSERT_TRUE(dest_rfh); |
494 EXPECT_NE(ntp_rfh, dest_rfh); | 498 EXPECT_NE(ntp_rfh, dest_rfh); |
495 | 499 |
496 // The new RVH should be able to update its favicon. | 500 // The new RVH should be able to update its favicon. |
497 const base::string16 dest_title = base::ASCIIToUTF16("Google"); | 501 const base::string16 dest_title = base::ASCIIToUTF16("Google"); |
498 { | 502 { |
499 PluginFaviconMessageObserver observer(contents()); | 503 PluginFaviconMessageObserver observer(contents()); |
500 EXPECT_TRUE( | 504 EXPECT_TRUE( |
501 dest_rfh->GetRenderViewHost()->OnMessageReceived( | 505 dest_rfh->GetRenderViewHost()->OnMessageReceived( |
502 ViewHostMsg_UpdateFaviconURL( | 506 ViewHostMsg_UpdateFaviconURL( |
503 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 507 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
504 EXPECT_TRUE(observer.favicon_received()); | 508 EXPECT_TRUE(observer.favicon_received()); |
505 } | 509 } |
506 | 510 |
507 // The old renderer, being slow, now updates the favicon. It should be | 511 // The old renderer, being slow, now updates the favicon. It should be |
508 // filtered out and not take effect. | 512 // filtered out and not take effect. |
509 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut()); | 513 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
510 { | 514 { |
511 PluginFaviconMessageObserver observer(contents()); | 515 PluginFaviconMessageObserver observer(contents()); |
512 EXPECT_TRUE( | 516 EXPECT_TRUE( |
513 ntp_rfh->GetRenderViewHost()->OnMessageReceived( | 517 ntp_rfh->GetRenderViewHost()->OnMessageReceived( |
514 ViewHostMsg_UpdateFaviconURL( | 518 ViewHostMsg_UpdateFaviconURL( |
515 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 519 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
516 EXPECT_FALSE(observer.favicon_received()); | 520 EXPECT_FALSE(observer.favicon_received()); |
517 } | 521 } |
518 | 522 |
519 // The same logic should apply to RenderFrameHosts as well and routing through | 523 // The same logic should apply to RenderFrameHosts as well and routing through |
(...skipping 28 matching lines...) Expand all Loading... |
548 ntp_process_host->sink().ClearMessages(); | 552 ntp_process_host->sink().ClearMessages(); |
549 FrameHostMsg_RunJavaScriptMessage js_msg( | 553 FrameHostMsg_RunJavaScriptMessage js_msg( |
550 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, | 554 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, |
551 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); | 555 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); |
552 js_msg.EnableMessagePumping(); | 556 js_msg.EnableMessagePumping(); |
553 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); | 557 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); |
554 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 558 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
555 } | 559 } |
556 | 560 |
557 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { | 561 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { |
558 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); | 562 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
559 TestRenderWidgetHostView* swapped_out_rwhv = | 563 TestRenderWidgetHostView* swapped_out_rwhv = |
560 static_cast<TestRenderWidgetHostView*>(swapped_out_rvh->GetView()); | 564 static_cast<TestRenderWidgetHostView*>( |
| 565 swapped_out_rfh->GetRenderViewHost()->GetView()); |
561 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); | 566 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); |
562 | 567 |
563 MockRenderProcessHost* process_host = | 568 MockRenderProcessHost* process_host = |
564 static_cast<MockRenderProcessHost*>(swapped_out_rvh->GetProcess()); | 569 static_cast<MockRenderProcessHost*>(swapped_out_rfh->GetProcess()); |
565 process_host->sink().ClearMessages(); | 570 process_host->sink().ClearMessages(); |
566 | 571 |
567 cc::CompositorFrame frame; | 572 cc::CompositorFrame frame; |
568 ViewHostMsg_SwapCompositorFrame msg( | 573 ViewHostMsg_SwapCompositorFrame msg( |
569 rvh()->GetRoutingID(), 0, frame, std::vector<IPC::Message>()); | 574 rvh()->GetRoutingID(), 0, frame, std::vector<IPC::Message>()); |
570 | 575 |
571 EXPECT_TRUE(swapped_out_rvh->OnMessageReceived(msg)); | 576 EXPECT_TRUE(swapped_out_rfh->render_view_host()->OnMessageReceived(msg)); |
572 EXPECT_TRUE(swapped_out_rwhv->did_swap_compositor_frame()); | 577 EXPECT_TRUE(swapped_out_rwhv->did_swap_compositor_frame()); |
573 } | 578 } |
574 | 579 |
575 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active | 580 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active |
576 // widgets. | 581 // widgets. |
577 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { | 582 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { |
578 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); | 583 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
579 EXPECT_TRUE(swapped_out_rvh->IsSwappedOut()); | 584 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); |
580 | 585 |
581 scoped_ptr<RenderWidgetHostIterator> widgets( | 586 scoped_ptr<RenderWidgetHostIterator> widgets( |
582 RenderWidgetHost::GetRenderWidgetHosts()); | 587 RenderWidgetHost::GetRenderWidgetHosts()); |
583 // We know that there is the only one active widget. Another view is | 588 // We know that there is the only one active widget. Another view is |
584 // now swapped out, so the swapped out view is not included in the | 589 // now swapped out, so the swapped out view is not included in the |
585 // list. | 590 // list. |
586 RenderWidgetHost* widget = widgets->GetNextHost(); | 591 RenderWidgetHost* widget = widgets->GetNextHost(); |
587 EXPECT_FALSE(widgets->GetNextHost()); | 592 EXPECT_FALSE(widgets->GetNextHost()); |
588 RenderViewHost* rvh = RenderViewHost::From(widget); | 593 RenderViewHost* rvh = RenderViewHost::From(widget); |
589 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 594 EXPECT_TRUE(static_cast<RenderViewHostImpl*>(rvh)->is_active()); |
590 static_cast<RenderViewHostImpl*>(rvh)->rvh_state()); | |
591 } | 595 } |
592 | 596 |
593 // Test if RenderViewHost::GetRenderWidgetHosts() returns a subset of | 597 // Test if RenderViewHost::GetRenderWidgetHosts() returns a subset of |
594 // RenderViewHostImpl::GetAllRenderWidgetHosts(). | 598 // RenderViewHostImpl::GetAllRenderWidgetHosts(). |
595 // RenderViewHost::GetRenderWidgetHosts() returns only active widgets, but | 599 // RenderViewHost::GetRenderWidgetHosts() returns only active widgets, but |
596 // RenderViewHostImpl::GetAllRenderWidgetHosts() returns everything | 600 // RenderViewHostImpl::GetAllRenderWidgetHosts() returns everything |
597 // including swapped out ones. | 601 // including swapped out ones. |
598 TEST_F(RenderFrameHostManagerTest, | 602 TEST_F(RenderFrameHostManagerTest, |
599 GetRenderWidgetHostsWithinGetAllRenderWidgetHosts) { | 603 GetRenderWidgetHostsWithinGetAllRenderWidgetHosts) { |
600 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); | 604 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
601 EXPECT_TRUE(swapped_out_rvh->IsSwappedOut()); | 605 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); |
602 | 606 |
603 scoped_ptr<RenderWidgetHostIterator> widgets( | 607 scoped_ptr<RenderWidgetHostIterator> widgets( |
604 RenderWidgetHost::GetRenderWidgetHosts()); | 608 RenderWidgetHost::GetRenderWidgetHosts()); |
605 | 609 |
606 while (RenderWidgetHost* w = widgets->GetNextHost()) { | 610 while (RenderWidgetHost* w = widgets->GetNextHost()) { |
607 bool found = false; | 611 bool found = false; |
608 scoped_ptr<RenderWidgetHostIterator> all_widgets( | 612 scoped_ptr<RenderWidgetHostIterator> all_widgets( |
609 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 613 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
610 while (RenderWidgetHost* widget = all_widgets->GetNextHost()) { | 614 while (RenderWidgetHost* widget = all_widgets->GetNextHost()) { |
611 if (w == widget) { | 615 if (w == widget) { |
612 found = true; | 616 found = true; |
613 break; | 617 break; |
614 } | 618 } |
615 } | 619 } |
616 EXPECT_TRUE(found); | 620 EXPECT_TRUE(found); |
617 } | 621 } |
618 } | 622 } |
619 | 623 |
620 // Test if SiteInstanceImpl::active_view_count() is correctly updated | 624 // Test if SiteInstanceImpl::active_frame_count() is correctly updated |
621 // as views in a SiteInstance get swapped out and in. | 625 // as frames in a SiteInstance get swapped out and in. |
622 TEST_F(RenderFrameHostManagerTest, ActiveViewCountWhileSwappingInandOut) { | 626 TEST_F(RenderFrameHostManagerTest, ActiveFrameCountWhileSwappingInAndOut) { |
623 const GURL kUrl1("http://www.google.com/"); | 627 const GURL kUrl1("http://www.google.com/"); |
624 const GURL kUrl2("http://www.chromium.org/"); | 628 const GURL kUrl2("http://www.chromium.org/"); |
625 | 629 |
626 // Navigate to an initial URL. | 630 // Navigate to an initial URL. |
627 contents()->NavigateAndCommit(kUrl1); | 631 contents()->NavigateAndCommit(kUrl1); |
628 TestRenderViewHost* rvh1 = test_rvh(); | 632 TestRenderFrameHost* rfh1 = main_test_rfh(); |
629 | 633 |
630 SiteInstanceImpl* instance1 = | 634 SiteInstanceImpl* instance1 = rfh1->GetSiteInstance(); |
631 static_cast<SiteInstanceImpl*>(rvh1->GetSiteInstance()); | 635 EXPECT_EQ(instance1->active_frame_count(), 1U); |
632 EXPECT_EQ(instance1->active_view_count(), 1U); | |
633 | 636 |
634 // Create 2 new tabs and simulate them being the opener chain for the main | 637 // Create 2 new tabs and simulate them being the opener chain for the main |
635 // tab. They should be in the same SiteInstance. | 638 // tab. They should be in the same SiteInstance. |
636 scoped_ptr<TestWebContents> opener1( | 639 scoped_ptr<TestWebContents> opener1( |
637 TestWebContents::Create(browser_context(), instance1)); | 640 TestWebContents::Create(browser_context(), instance1)); |
638 contents()->SetOpener(opener1.get()); | 641 contents()->SetOpener(opener1.get()); |
639 | 642 |
640 scoped_ptr<TestWebContents> opener2( | 643 scoped_ptr<TestWebContents> opener2( |
641 TestWebContents::Create(browser_context(), instance1)); | 644 TestWebContents::Create(browser_context(), instance1)); |
642 opener1->SetOpener(opener2.get()); | 645 opener1->SetOpener(opener2.get()); |
643 | 646 |
644 EXPECT_EQ(instance1->active_view_count(), 3U); | 647 EXPECT_EQ(instance1->active_frame_count(), 3U); |
645 | 648 |
646 // Navigate to a cross-site URL (different SiteInstance but same | 649 // Navigate to a cross-site URL (different SiteInstance but same |
647 // BrowsingInstance). | 650 // BrowsingInstance). |
648 contents()->NavigateAndCommit(kUrl2); | 651 contents()->NavigateAndCommit(kUrl2); |
649 TestRenderViewHost* rvh2 = test_rvh(); | 652 TestRenderFrameHost* rfh2 = main_test_rfh(); |
650 SiteInstanceImpl* instance2 = | 653 SiteInstanceImpl* instance2 = rfh2->GetSiteInstance(); |
651 static_cast<SiteInstanceImpl*>(rvh2->GetSiteInstance()); | |
652 | 654 |
653 // rvh2 is on chromium.org which is different from google.com on | 655 // rvh2 is on chromium.org which is different from google.com on |
654 // which other tabs are. | 656 // which other tabs are. |
655 EXPECT_EQ(instance2->active_view_count(), 1U); | 657 EXPECT_EQ(instance2->active_frame_count(), 1U); |
656 | 658 |
657 // There are two active views on google.com now. | 659 // There are two active views on google.com now. |
658 EXPECT_EQ(instance1->active_view_count(), 2U); | 660 EXPECT_EQ(instance1->active_frame_count(), 2U); |
659 | 661 |
660 // Navigate to the original origin (google.com). | 662 // Navigate to the original origin (google.com). |
661 contents()->NavigateAndCommit(kUrl1); | 663 contents()->NavigateAndCommit(kUrl1); |
662 | 664 |
663 EXPECT_EQ(instance1->active_view_count(), 3U); | 665 EXPECT_EQ(instance1->active_frame_count(), 3U); |
664 } | 666 } |
665 | 667 |
666 // This deletes a WebContents when the given RVH is deleted. This is | 668 // This deletes a WebContents when the given RVH is deleted. This is |
667 // only for testing whether deleting an RVH does not cause any UaF in | 669 // only for testing whether deleting an RVH does not cause any UaF in |
668 // other parts of the system. For now, this class is only used for the | 670 // other parts of the system. For now, this class is only used for the |
669 // next test cases to detect the bug mentioned at | 671 // next test cases to detect the bug mentioned at |
670 // http://crbug.com/259859. | 672 // http://crbug.com/259859. |
671 class RenderViewHostDestroyer : public WebContentsObserver { | 673 class RenderViewHostDestroyer : public WebContentsObserver { |
672 public: | 674 public: |
673 RenderViewHostDestroyer(RenderViewHost* render_view_host, | 675 RenderViewHostDestroyer(RenderViewHost* render_view_host, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 TestNotificationTracker notifications; | 807 TestNotificationTracker notifications; |
806 | 808 |
807 SiteInstance* instance = SiteInstance::Create(browser_context()); | 809 SiteInstance* instance = SiteInstance::Create(browser_context()); |
808 | 810 |
809 scoped_ptr<TestWebContents> web_contents( | 811 scoped_ptr<TestWebContents> web_contents( |
810 TestWebContents::Create(browser_context(), instance)); | 812 TestWebContents::Create(browser_context(), instance)); |
811 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 813 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
812 Source<WebContents>(web_contents.get())); | 814 Source<WebContents>(web_contents.get())); |
813 | 815 |
814 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 816 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
815 RenderFrameHostImpl* host; | 817 RenderFrameHostImpl* host = NULL; |
816 | 818 |
817 // 1) The first navigation. -------------------------- | 819 // 1) The first navigation. -------------------------- |
818 const GURL kUrl1("http://www.google.com/"); | 820 const GURL kUrl1("http://www.google.com/"); |
819 NavigationEntryImpl entry1( | 821 NavigationEntryImpl entry1( |
820 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 822 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
821 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 823 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
822 false /* is_renderer_init */); | 824 false /* is_renderer_init */); |
823 host = manager->Navigate(entry1); | 825 host = manager->Navigate(entry1); |
824 | 826 |
825 // The RenderFrameHost created in Init will be reused. | 827 // The RenderFrameHost created in Init will be reused. |
826 EXPECT_TRUE(host == manager->current_frame_host()); | 828 EXPECT_TRUE(host == manager->current_frame_host()); |
827 EXPECT_FALSE(manager->pending_frame_host()); | 829 EXPECT_FALSE(manager->pending_frame_host()); |
828 | 830 |
829 // Commit. | 831 // Commit. |
830 manager->DidNavigateFrame(host); | 832 manager->DidNavigateFrame(host); |
831 // Commit to SiteInstance should be delayed until RenderView commit. | 833 // Commit to SiteInstance should be delayed until RenderView commit. |
832 EXPECT_TRUE(host == manager->current_frame_host()); | 834 EXPECT_TRUE(host == manager->current_frame_host()); |
833 ASSERT_TRUE(host); | 835 ASSERT_TRUE(host); |
834 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 836 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
835 HasSite()); | 837 host->GetSiteInstance()->SetSite(kUrl1); |
836 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); | |
837 | 838 |
838 // 2) Navigate to next site. ------------------------- | 839 // 2) Navigate to next site. ------------------------- |
839 const GURL kUrl2("http://www.google.com/foo"); | 840 const GURL kUrl2("http://www.google.com/foo"); |
840 NavigationEntryImpl entry2( | 841 NavigationEntryImpl entry2( |
841 NULL /* instance */, -1 /* page_id */, kUrl2, | 842 NULL /* instance */, -1 /* page_id */, kUrl2, |
842 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 843 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
843 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 844 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
844 true /* is_renderer_init */); | 845 true /* is_renderer_init */); |
845 host = manager->Navigate(entry2); | 846 host = manager->Navigate(entry2); |
846 | 847 |
847 // The RenderFrameHost created in Init will be reused. | 848 // The RenderFrameHost created in Init will be reused. |
848 EXPECT_TRUE(host == manager->current_frame_host()); | 849 EXPECT_TRUE(host == manager->current_frame_host()); |
849 EXPECT_FALSE(manager->pending_frame_host()); | 850 EXPECT_FALSE(manager->pending_frame_host()); |
850 | 851 |
851 // Commit. | 852 // Commit. |
852 manager->DidNavigateFrame(host); | 853 manager->DidNavigateFrame(host); |
853 EXPECT_TRUE(host == manager->current_frame_host()); | 854 EXPECT_TRUE(host == manager->current_frame_host()); |
854 ASSERT_TRUE(host); | 855 ASSERT_TRUE(host); |
855 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 856 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
856 HasSite()); | |
857 | 857 |
858 // 3) Cross-site navigate to next site. -------------- | 858 // 3) Cross-site navigate to next site. -------------- |
859 const GURL kUrl3("http://webkit.org/"); | 859 const GURL kUrl3("http://webkit.org/"); |
860 NavigationEntryImpl entry3( | 860 NavigationEntryImpl entry3( |
861 NULL /* instance */, -1 /* page_id */, kUrl3, | 861 NULL /* instance */, -1 /* page_id */, kUrl3, |
862 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 862 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
863 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 863 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
864 false /* is_renderer_init */); | 864 false /* is_renderer_init */); |
865 host = manager->Navigate(entry3); | 865 host = manager->Navigate(entry3); |
866 | 866 |
867 // A new RenderFrameHost should be created. | 867 // A new RenderFrameHost should be created. |
868 EXPECT_TRUE(manager->pending_frame_host()); | 868 EXPECT_TRUE(manager->pending_frame_host()); |
869 ASSERT_EQ(host, manager->pending_frame_host()); | 869 ASSERT_EQ(host, manager->pending_frame_host()); |
870 | 870 |
871 notifications.Reset(); | 871 notifications.Reset(); |
872 | 872 |
873 // Commit. | 873 // Commit. |
874 manager->DidNavigateFrame(manager->pending_frame_host()); | 874 manager->DidNavigateFrame(manager->pending_frame_host()); |
875 EXPECT_TRUE(host == manager->current_frame_host()); | 875 EXPECT_TRUE(host == manager->current_frame_host()); |
876 ASSERT_TRUE(host); | 876 ASSERT_TRUE(host); |
877 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 877 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
878 HasSite()); | |
879 // Check the pending RenderFrameHost has been committed. | 878 // Check the pending RenderFrameHost has been committed. |
880 EXPECT_FALSE(manager->pending_frame_host()); | 879 EXPECT_FALSE(manager->pending_frame_host()); |
881 | 880 |
882 // We should observe a notification. | 881 // We should observe a notification. |
883 EXPECT_TRUE( | 882 EXPECT_TRUE( |
884 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 883 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
885 } | 884 } |
886 | 885 |
887 // Tests WebUI creation. | 886 // Tests WebUI creation. |
888 TEST_F(RenderFrameHostManagerTest, WebUI) { | 887 TEST_F(RenderFrameHostManagerTest, WebUI) { |
(...skipping 17 matching lines...) Expand all Loading... |
906 // RenderFrameHost was not live. We test a case where it is live in | 905 // RenderFrameHost was not live. We test a case where it is live in |
907 // WebUIInNewTab. | 906 // WebUIInNewTab. |
908 EXPECT_TRUE(host); | 907 EXPECT_TRUE(host); |
909 EXPECT_EQ(host, manager->current_frame_host()); | 908 EXPECT_EQ(host, manager->current_frame_host()); |
910 EXPECT_FALSE(manager->pending_frame_host()); | 909 EXPECT_FALSE(manager->pending_frame_host()); |
911 | 910 |
912 // It's important that the site instance get set on the Web UI page as soon | 911 // It's important that the site instance get set on the Web UI page as soon |
913 // as the navigation starts, rather than lazily after it commits, so we don't | 912 // as the navigation starts, rather than lazily after it commits, so we don't |
914 // try to re-use the SiteInstance/process for non Web UI things that may | 913 // try to re-use the SiteInstance/process for non Web UI things that may |
915 // get loaded in between. | 914 // get loaded in between. |
916 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 915 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
917 HasSite()); | |
918 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 916 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
919 | 917 |
920 // The Web UI is committed immediately because the RenderViewHost has not been | 918 // The Web UI is committed immediately because the RenderViewHost has not been |
921 // used yet. UpdateStateForNavigate() took the short cut path. | 919 // used yet. UpdateStateForNavigate() took the short cut path. |
922 EXPECT_FALSE(manager->pending_web_ui()); | 920 EXPECT_FALSE(manager->pending_web_ui()); |
923 EXPECT_TRUE(manager->web_ui()); | 921 EXPECT_TRUE(manager->web_ui()); |
924 | 922 |
925 // Commit. | 923 // Commit. |
926 manager->DidNavigateFrame(host); | 924 manager->DidNavigateFrame(host); |
927 EXPECT_TRUE( | 925 EXPECT_TRUE( |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 } | 1047 } |
1050 | 1048 |
1051 // Ensure that we can go back and forward even if a SwapOut ACK isn't received. | 1049 // Ensure that we can go back and forward even if a SwapOut ACK isn't received. |
1052 // See http://crbug.com/93427. | 1050 // See http://crbug.com/93427. |
1053 TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) { | 1051 TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) { |
1054 const GURL kUrl1("http://www.google.com/"); | 1052 const GURL kUrl1("http://www.google.com/"); |
1055 const GURL kUrl2("http://www.chromium.org/"); | 1053 const GURL kUrl2("http://www.chromium.org/"); |
1056 | 1054 |
1057 // Navigate to two pages. | 1055 // Navigate to two pages. |
1058 contents()->NavigateAndCommit(kUrl1); | 1056 contents()->NavigateAndCommit(kUrl1); |
1059 TestRenderViewHost* rvh1 = test_rvh(); | 1057 TestRenderFrameHost* rfh1 = main_test_rfh(); |
1060 | 1058 |
1061 // Keep active_view_count nonzero so that no swapped out views in | 1059 // Keep active_frame_count nonzero so that no swapped out frames in |
1062 // this SiteInstance get forcefully deleted. | 1060 // this SiteInstance get forcefully deleted. |
1063 static_cast<SiteInstanceImpl*>(rvh1->GetSiteInstance())-> | 1061 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1064 increment_active_view_count(); | |
1065 | 1062 |
1066 contents()->NavigateAndCommit(kUrl2); | 1063 contents()->NavigateAndCommit(kUrl2); |
1067 TestRenderViewHost* rvh2 = test_rvh(); | 1064 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1068 static_cast<SiteInstanceImpl*>(rvh2->GetSiteInstance())-> | 1065 rfh2->GetSiteInstance()->increment_active_frame_count(); |
1069 increment_active_view_count(); | |
1070 | 1066 |
1071 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1067 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
1072 // happen, but we have seen it when going back quickly across many entries | 1068 // happen, but we have seen it when going back quickly across many entries |
1073 // (http://crbug.com/93427). | 1069 // (http://crbug.com/93427). |
1074 contents()->GetController().GoBack(); | 1070 contents()->GetController().GoBack(); |
1075 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); | 1071 EXPECT_TRUE(rfh2->is_waiting_for_beforeunload_ack()); |
1076 contents()->ProceedWithCrossSiteNavigation(); | 1072 contents()->ProceedWithCrossSiteNavigation(); |
1077 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); | 1073 EXPECT_FALSE(rfh2->is_waiting_for_beforeunload_ack()); |
1078 | 1074 |
1079 // The back navigation commits. | 1075 // The back navigation commits. |
1080 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1076 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1081 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1077 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
1082 EXPECT_TRUE(rvh2->IsWaitingForUnloadACK()); | 1078 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
1083 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh2->rvh_state()); | 1079 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
1084 | 1080 |
1085 // We should be able to navigate forward. | 1081 // We should be able to navigate forward. |
1086 contents()->GetController().GoForward(); | 1082 contents()->GetController().GoForward(); |
1087 contents()->ProceedWithCrossSiteNavigation(); | 1083 contents()->ProceedWithCrossSiteNavigation(); |
1088 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1084 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
1089 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1085 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
1090 EXPECT_EQ(rvh2, rvh()); | 1086 EXPECT_EQ(rfh2, main_test_rfh()); |
1091 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh2->rvh_state()); | 1087 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1092 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh1->rvh_state()); | 1088 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1093 rvh1->OnSwappedOut(false); | 1089 rfh1->OnSwappedOut(); |
1094 EXPECT_TRUE(rvh1->IsSwappedOut()); | 1090 EXPECT_TRUE(rfh1->is_swapped_out()); |
1095 EXPECT_EQ(RenderViewHostImpl::STATE_SWAPPED_OUT, rvh1->rvh_state()); | 1091 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
1096 } | 1092 } |
1097 | 1093 |
1098 // Test that we create swapped out RVHs for the opener chain when navigating an | 1094 // Test that we create swapped out RFHs for the opener chain when navigating an |
1099 // opened tab cross-process. This allows us to support certain cross-process | 1095 // opened tab cross-process. This allows us to support certain cross-process |
1100 // JavaScript calls (http://crbug.com/99202). | 1096 // JavaScript calls (http://crbug.com/99202). |
1101 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRVHs) { | 1097 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRFHs) { |
1102 const GURL kUrl1("http://www.google.com/"); | 1098 const GURL kUrl1("http://www.google.com/"); |
1103 const GURL kUrl2("http://www.chromium.org/"); | 1099 const GURL kUrl2("http://www.chromium.org/"); |
1104 const GURL kChromeUrl("chrome://foo"); | 1100 const GURL kChromeUrl("chrome://foo"); |
1105 | 1101 |
1106 // Navigate to an initial URL. | 1102 // Navigate to an initial URL. |
1107 contents()->NavigateAndCommit(kUrl1); | 1103 contents()->NavigateAndCommit(kUrl1); |
1108 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | 1104 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); |
| 1105 TestRenderFrameHost* rfh1 = main_test_rfh(); |
1109 TestRenderViewHost* rvh1 = test_rvh(); | 1106 TestRenderViewHost* rvh1 = test_rvh(); |
1110 | 1107 |
1111 // Create 2 new tabs and simulate them being the opener chain for the main | 1108 // Create 2 new tabs and simulate them being the opener chain for the main |
1112 // tab. They should be in the same SiteInstance. | 1109 // tab. They should be in the same SiteInstance. |
1113 scoped_ptr<TestWebContents> opener1( | 1110 scoped_ptr<TestWebContents> opener1( |
1114 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); | 1111 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); |
1115 RenderFrameHostManager* opener1_manager = | 1112 RenderFrameHostManager* opener1_manager = |
1116 opener1->GetRenderManagerForTesting(); | 1113 opener1->GetRenderManagerForTesting(); |
1117 contents()->SetOpener(opener1.get()); | 1114 contents()->SetOpener(opener1.get()); |
1118 | 1115 |
1119 scoped_ptr<TestWebContents> opener2( | 1116 scoped_ptr<TestWebContents> opener2( |
1120 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); | 1117 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); |
1121 RenderFrameHostManager* opener2_manager = | 1118 RenderFrameHostManager* opener2_manager = |
1122 opener2->GetRenderManagerForTesting(); | 1119 opener2->GetRenderManagerForTesting(); |
1123 opener1->SetOpener(opener2.get()); | 1120 opener1->SetOpener(opener2.get()); |
1124 | 1121 |
1125 // Navigate to a cross-site URL (different SiteInstance but same | 1122 // Navigate to a cross-site URL (different SiteInstance but same |
1126 // BrowsingInstance). | 1123 // BrowsingInstance). |
1127 contents()->NavigateAndCommit(kUrl2); | 1124 contents()->NavigateAndCommit(kUrl2); |
| 1125 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1128 TestRenderViewHost* rvh2 = test_rvh(); | 1126 TestRenderViewHost* rvh2 = test_rvh(); |
1129 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 1127 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1130 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1128 EXPECT_TRUE(rfh1->GetSiteInstance()->IsRelatedSiteInstance( |
1131 rvh2->GetSiteInstance())); | 1129 rfh2->GetSiteInstance())); |
1132 | 1130 |
1133 // Ensure rvh1 is placed on swapped out list of the current tab. | 1131 // Ensure rvh1 is placed on swapped out list of the current tab. |
| 1132 EXPECT_TRUE(manager->IsOnSwappedOutList(rfh1)); |
1134 EXPECT_TRUE(manager->IsRVHOnSwappedOutList(rvh1)); | 1133 EXPECT_TRUE(manager->IsRVHOnSwappedOutList(rvh1)); |
| 1134 EXPECT_EQ(rfh1, |
| 1135 manager->GetRenderFrameProxyHost(rfh1->GetSiteInstance()) |
| 1136 ->render_frame_host()); |
1135 EXPECT_EQ(rvh1, | 1137 EXPECT_EQ(rvh1, |
1136 manager->GetSwappedOutRenderViewHost(rvh1->GetSiteInstance())); | 1138 manager->GetSwappedOutRenderViewHost(rvh1->GetSiteInstance())); |
1137 | 1139 |
1138 // Ensure a swapped out RVH is created in the first opener tab. | 1140 // Ensure a swapped out RFH and RFH is created in the first opener tab. |
| 1141 RenderFrameProxyHost* opener1_proxy = |
| 1142 opener1_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); |
| 1143 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); |
1139 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1144 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
1140 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1145 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 1146 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); |
1141 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); | 1147 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); |
1142 EXPECT_TRUE(opener1_rvh->IsSwappedOut()); | 1148 EXPECT_TRUE(opener1_rfh->is_swapped_out()); |
| 1149 EXPECT_FALSE(opener1_rvh->is_active()); |
1143 | 1150 |
1144 // Ensure a swapped out RVH is created in the second opener tab. | 1151 // Ensure a swapped out RFH and RVH is created in the second opener tab. |
| 1152 RenderFrameProxyHost* opener2_proxy = |
| 1153 opener2_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); |
| 1154 RenderFrameHostImpl* opener2_rfh = opener2_proxy->render_frame_host(); |
1145 TestRenderViewHost* opener2_rvh = static_cast<TestRenderViewHost*>( | 1155 TestRenderViewHost* opener2_rvh = static_cast<TestRenderViewHost*>( |
1146 opener2_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1156 opener2_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 1157 EXPECT_TRUE(opener2_manager->IsOnSwappedOutList(opener2_rfh)); |
1147 EXPECT_TRUE(opener2_manager->IsRVHOnSwappedOutList(opener2_rvh)); | 1158 EXPECT_TRUE(opener2_manager->IsRVHOnSwappedOutList(opener2_rvh)); |
1148 EXPECT_TRUE(opener2_rvh->IsSwappedOut()); | 1159 EXPECT_TRUE(opener2_rfh->is_swapped_out()); |
| 1160 EXPECT_FALSE(opener2_rvh->is_active()); |
1149 | 1161 |
1150 // Navigate to a cross-BrowsingInstance URL. | 1162 // Navigate to a cross-BrowsingInstance URL. |
1151 contents()->NavigateAndCommit(kChromeUrl); | 1163 contents()->NavigateAndCommit(kChromeUrl); |
1152 TestRenderViewHost* rvh3 = test_rvh(); | 1164 TestRenderFrameHost* rfh3 = main_test_rfh(); |
1153 EXPECT_NE(rvh1->GetSiteInstance(), rvh3->GetSiteInstance()); | 1165 EXPECT_NE(rfh1->GetSiteInstance(), rfh3->GetSiteInstance()); |
1154 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1166 EXPECT_FALSE(rfh1->GetSiteInstance()->IsRelatedSiteInstance( |
1155 rvh3->GetSiteInstance())); | 1167 rfh3->GetSiteInstance())); |
1156 | 1168 |
1157 // No scripting is allowed across BrowsingInstances, so we should not create | 1169 // No scripting is allowed across BrowsingInstances, so we should not create |
1158 // swapped out RVHs for the opener chain in this case. | 1170 // swapped out RVHs for the opener chain in this case. |
| 1171 EXPECT_FALSE(opener1_manager->GetRenderFrameProxyHost( |
| 1172 rfh3->GetSiteInstance())); |
1159 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 1173 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
1160 rvh3->GetSiteInstance())); | 1174 rfh3->GetSiteInstance())); |
| 1175 EXPECT_FALSE(opener2_manager->GetRenderFrameProxyHost( |
| 1176 rfh3->GetSiteInstance())); |
1161 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( | 1177 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( |
1162 rvh3->GetSiteInstance())); | 1178 rfh3->GetSiteInstance())); |
1163 } | 1179 } |
1164 | 1180 |
1165 // Test that a page can disown the opener of the WebContents. | 1181 // Test that a page can disown the opener of the WebContents. |
1166 TEST_F(RenderFrameHostManagerTest, DisownOpener) { | 1182 TEST_F(RenderFrameHostManagerTest, DisownOpener) { |
1167 const GURL kUrl1("http://www.google.com/"); | 1183 const GURL kUrl1("http://www.google.com/"); |
1168 const GURL kUrl2("http://www.chromium.org/"); | 1184 const GURL kUrl2("http://www.chromium.org/"); |
1169 | 1185 |
1170 // Navigate to an initial URL. | 1186 // Navigate to an initial URL. |
1171 contents()->NavigateAndCommit(kUrl1); | 1187 contents()->NavigateAndCommit(kUrl1); |
1172 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1188 TestRenderFrameHost* rfh1 = main_test_rfh(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 contents()->SetOpener(opener1.get()); | 1378 contents()->SetOpener(opener1.get()); |
1363 | 1379 |
1364 // Navigate to a different WebUI URL (different SiteInstance, same | 1380 // Navigate to a different WebUI URL (different SiteInstance, same |
1365 // BrowsingInstance). | 1381 // BrowsingInstance). |
1366 contents()->NavigateAndCommit(kPluginUrl); | 1382 contents()->NavigateAndCommit(kPluginUrl); |
1367 TestRenderViewHost* rvh2 = test_rvh(); | 1383 TestRenderViewHost* rvh2 = test_rvh(); |
1368 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 1384 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
1369 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1385 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
1370 rvh2->GetSiteInstance())); | 1386 rvh2->GetSiteInstance())); |
1371 | 1387 |
1372 // Ensure a swapped out RVH is created in the first opener tab. | 1388 // Ensure a swapped out RFH and RVH is created in the first opener tab. |
| 1389 RenderFrameProxyHost* opener1_proxy = |
| 1390 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance()); |
| 1391 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); |
1373 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1392 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
1374 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1393 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 1394 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); |
1375 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); | 1395 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); |
1376 EXPECT_TRUE(opener1_rvh->IsSwappedOut()); | 1396 EXPECT_TRUE(opener1_rfh->is_swapped_out()); |
| 1397 EXPECT_FALSE(opener1_rvh->is_active()); |
1377 | 1398 |
1378 // Ensure the new RVH has WebUI bindings. | 1399 // Ensure the new RVH has WebUI bindings. |
1379 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1400 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1380 } | 1401 } |
1381 | 1402 |
1382 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 1403 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
1383 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { | 1404 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { |
1384 TestNotificationTracker notifications; | 1405 TestNotificationTracker notifications; |
1385 | 1406 |
1386 GURL guest_url(std::string(kGuestScheme).append("://abc123")); | 1407 GURL guest_url(std::string(kGuestScheme).append("://abc123")); |
1387 SiteInstance* instance = | 1408 SiteInstance* instance = |
1388 SiteInstance::CreateForURL(browser_context(), guest_url); | 1409 SiteInstance::CreateForURL(browser_context(), guest_url); |
1389 scoped_ptr<TestWebContents> web_contents( | 1410 scoped_ptr<TestWebContents> web_contents( |
1390 TestWebContents::Create(browser_context(), instance)); | 1411 TestWebContents::Create(browser_context(), instance)); |
1391 | 1412 |
1392 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1413 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1393 | 1414 |
1394 RenderFrameHostImpl* host; | 1415 RenderFrameHostImpl* host = NULL; |
1395 | 1416 |
1396 // 1) The first navigation. -------------------------- | 1417 // 1) The first navigation. -------------------------- |
1397 const GURL kUrl1("http://www.google.com/"); | 1418 const GURL kUrl1("http://www.google.com/"); |
1398 NavigationEntryImpl entry1( | 1419 NavigationEntryImpl entry1( |
1399 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1420 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
1400 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1421 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1401 false /* is_renderer_init */); | 1422 false /* is_renderer_init */); |
1402 host = manager->Navigate(entry1); | 1423 host = manager->Navigate(entry1); |
1403 | 1424 |
1404 // The RenderFrameHost created in Init will be reused. | 1425 // The RenderFrameHost created in Init will be reused. |
1405 EXPECT_TRUE(host == manager->current_frame_host()); | 1426 EXPECT_TRUE(host == manager->current_frame_host()); |
1406 EXPECT_FALSE(manager->pending_frame_host()); | 1427 EXPECT_FALSE(manager->pending_frame_host()); |
1407 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1428 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
1408 | 1429 |
1409 // Commit. | 1430 // Commit. |
1410 manager->DidNavigateFrame(host); | 1431 manager->DidNavigateFrame(host); |
1411 // Commit to SiteInstance should be delayed until RenderView commit. | 1432 // Commit to SiteInstance should be delayed until RenderView commit. |
1412 EXPECT_EQ(host, manager->current_frame_host()); | 1433 EXPECT_EQ(host, manager->current_frame_host()); |
1413 ASSERT_TRUE(host); | 1434 ASSERT_TRUE(host); |
1414 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 1435 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1415 HasSite()); | |
1416 | 1436 |
1417 // 2) Navigate to a different domain. ------------------------- | 1437 // 2) Navigate to a different domain. ------------------------- |
1418 // Guests stay in the same process on navigation. | 1438 // Guests stay in the same process on navigation. |
1419 const GURL kUrl2("http://www.chromium.org"); | 1439 const GURL kUrl2("http://www.chromium.org"); |
1420 NavigationEntryImpl entry2( | 1440 NavigationEntryImpl entry2( |
1421 NULL /* instance */, -1 /* page_id */, kUrl2, | 1441 NULL /* instance */, -1 /* page_id */, kUrl2, |
1422 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1442 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
1423 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1443 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
1424 true /* is_renderer_init */); | 1444 true /* is_renderer_init */); |
1425 host = manager->Navigate(entry2); | 1445 host = manager->Navigate(entry2); |
1426 | 1446 |
1427 // The RenderFrameHost created in Init will be reused. | 1447 // The RenderFrameHost created in Init will be reused. |
1428 EXPECT_EQ(host, manager->current_frame_host()); | 1448 EXPECT_EQ(host, manager->current_frame_host()); |
1429 EXPECT_FALSE(manager->pending_frame_host()); | 1449 EXPECT_FALSE(manager->pending_frame_host()); |
1430 | 1450 |
1431 // Commit. | 1451 // Commit. |
1432 manager->DidNavigateFrame(host); | 1452 manager->DidNavigateFrame(host); |
1433 EXPECT_EQ(host, manager->current_frame_host()); | 1453 EXPECT_EQ(host, manager->current_frame_host()); |
1434 ASSERT_TRUE(host); | 1454 ASSERT_TRUE(host); |
1435 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), | 1455 EXPECT_EQ(host->GetSiteInstance(), instance); |
1436 instance); | |
1437 } | 1456 } |
1438 | 1457 |
1439 // Test that we cancel a pending RVH if we close the tab while it's pending. | 1458 // Test that we cancel a pending RVH if we close the tab while it's pending. |
1440 // http://crbug.com/294697. | 1459 // http://crbug.com/294697. |
1441 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyClose) { | 1460 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyClose) { |
1442 TestNotificationTracker notifications; | 1461 TestNotificationTracker notifications; |
1443 | 1462 |
1444 SiteInstance* instance = SiteInstance::Create(browser_context()); | 1463 SiteInstance* instance = SiteInstance::Create(browser_context()); |
1445 | 1464 |
1446 BeforeUnloadFiredWebContentsDelegate delegate; | 1465 BeforeUnloadFiredWebContentsDelegate delegate; |
(...skipping 20 matching lines...) Expand all Loading... |
1467 // We should observe a notification. | 1486 // We should observe a notification. |
1468 EXPECT_TRUE( | 1487 EXPECT_TRUE( |
1469 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1488 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
1470 notifications.Reset(); | 1489 notifications.Reset(); |
1471 | 1490 |
1472 // Commit. | 1491 // Commit. |
1473 manager->DidNavigateFrame(host); | 1492 manager->DidNavigateFrame(host); |
1474 | 1493 |
1475 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1494 // Commit to SiteInstance should be delayed until RenderFrame commits. |
1476 EXPECT_EQ(host, manager->current_frame_host()); | 1495 EXPECT_EQ(host, manager->current_frame_host()); |
1477 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 1496 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
1478 HasSite()); | 1497 host->GetSiteInstance()->SetSite(kUrl1); |
1479 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); | |
1480 | 1498 |
1481 // 2) Cross-site navigate to next site. ------------------------- | 1499 // 2) Cross-site navigate to next site. ------------------------- |
1482 const GURL kUrl2("http://www.example.com"); | 1500 const GURL kUrl2("http://www.example.com"); |
1483 NavigationEntryImpl entry2( | 1501 NavigationEntryImpl entry2( |
1484 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1502 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
1485 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1503 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1486 false /* is_renderer_init */); | 1504 false /* is_renderer_init */); |
1487 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1505 RenderFrameHostImpl* host2 = manager->Navigate(entry2); |
1488 | 1506 |
1489 // A new RenderFrameHost should be created. | 1507 // A new RenderFrameHost should be created. |
(...skipping 18 matching lines...) Expand all Loading... |
1508 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1526 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
1509 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1527 // received. (SwapOut and the corresponding ACK always occur after commit.) |
1510 // Also tests that an early SwapOutACK is properly ignored. | 1528 // Also tests that an early SwapOutACK is properly ignored. |
1511 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1529 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
1512 const GURL kUrl1("http://www.google.com/"); | 1530 const GURL kUrl1("http://www.google.com/"); |
1513 const GURL kUrl2("http://www.chromium.org/"); | 1531 const GURL kUrl2("http://www.chromium.org/"); |
1514 | 1532 |
1515 // Navigate to the first page. | 1533 // Navigate to the first page. |
1516 contents()->NavigateAndCommit(kUrl1); | 1534 contents()->NavigateAndCommit(kUrl1); |
1517 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1535 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1518 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1536 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1519 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1537 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1520 rfh1->GetRenderViewHost()->rvh_state()); | |
1521 | 1538 |
1522 // Navigate to new site, simulating onbeforeunload approval. | 1539 // Navigate to new site, simulating onbeforeunload approval. |
1523 controller().LoadURL( | 1540 controller().LoadURL( |
1524 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1541 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1525 base::TimeTicks now = base::TimeTicks::Now(); | 1542 base::TimeTicks now = base::TimeTicks::Now(); |
1526 contents()->GetMainFrame()->OnMessageReceived( | 1543 contents()->GetMainFrame()->OnMessageReceived( |
1527 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1544 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1528 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1545 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1529 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1546 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1530 rfh1->GetRenderViewHost()->rvh_state()); | |
1531 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1547 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1532 | 1548 |
1533 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1549 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1534 // have no effect. | 1550 // have no effect. |
1535 rfh1->OnSwappedOut(false); | 1551 rfh1->OnSwappedOut(); |
1536 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1552 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1537 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1553 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1538 rfh1->GetRenderViewHost()->rvh_state()); | |
1539 | 1554 |
1540 // The new page commits. | 1555 // The new page commits. |
1541 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1556 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1542 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1557 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1543 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1558 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1544 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1559 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1545 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1560 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1546 rfh2->GetRenderViewHost()->rvh_state()); | 1561 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SHUTDOWN, rfh1->rfh_state()); |
1547 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, | |
1548 rfh1->GetRenderViewHost()->rvh_state()); | |
1549 | 1562 |
1550 // Simulate the swap out ack. | 1563 // Simulate the swap out ack. |
1551 rfh1->OnSwappedOut(false); | 1564 rfh1->OnSwappedOut(); |
1552 | 1565 |
1553 // rfh1 should have been deleted. | 1566 // rfh1 should have been deleted. |
1554 EXPECT_TRUE(rvh_deleted_observer.deleted()); | 1567 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
1555 rfh1 = NULL; | 1568 rfh1 = NULL; |
1556 } | 1569 } |
1557 | 1570 |
1558 // Tests that the RenderFrameHost is properly swapped out when the SwapOut ACK | 1571 // Tests that the RenderFrameHost is properly swapped out when the SwapOut ACK |
1559 // is received. (SwapOut and the corresponding ACK always occur after commit.) | 1572 // is received. (SwapOut and the corresponding ACK always occur after commit.) |
1560 TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { | 1573 TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { |
1561 const GURL kUrl1("http://www.google.com/"); | 1574 const GURL kUrl1("http://www.google.com/"); |
1562 const GURL kUrl2("http://www.chromium.org/"); | 1575 const GURL kUrl2("http://www.chromium.org/"); |
1563 | 1576 |
1564 // Navigate to the first page. | 1577 // Navigate to the first page. |
1565 contents()->NavigateAndCommit(kUrl1); | 1578 contents()->NavigateAndCommit(kUrl1); |
1566 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1579 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1567 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1580 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1568 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1581 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1569 rfh1->GetRenderViewHost()->rvh_state()); | |
1570 | 1582 |
1571 // Increment the number of active views in SiteInstanceImpl so that rfh1 is | 1583 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1572 // not deleted on swap out. | 1584 // not deleted on swap out. |
1573 static_cast<SiteInstanceImpl*>( | 1585 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1574 rfh1->GetSiteInstance())->increment_active_view_count(); | |
1575 | 1586 |
1576 // Navigate to new site, simulating onbeforeunload approval. | 1587 // Navigate to new site, simulating onbeforeunload approval. |
1577 controller().LoadURL( | 1588 controller().LoadURL( |
1578 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1589 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1579 base::TimeTicks now = base::TimeTicks::Now(); | 1590 base::TimeTicks now = base::TimeTicks::Now(); |
1580 contents()->GetMainFrame()->OnMessageReceived( | 1591 contents()->GetMainFrame()->OnMessageReceived( |
1581 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1592 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1582 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1593 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1583 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1594 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1584 rfh1->GetRenderViewHost()->rvh_state()); | |
1585 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1595 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1586 | 1596 |
1587 // The new page commits. | 1597 // The new page commits. |
1588 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1598 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1589 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1599 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1590 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1600 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1591 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1601 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1592 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1602 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1593 rfh2->GetRenderViewHost()->rvh_state()); | 1603 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1594 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | |
1595 rfh1->GetRenderViewHost()->rvh_state()); | |
1596 | 1604 |
1597 // Simulate the swap out ack. | 1605 // Simulate the swap out ack. |
1598 rfh1->OnSwappedOut(false); | 1606 rfh1->OnSwappedOut(); |
1599 | 1607 |
1600 // rfh1 should be swapped out. | 1608 // rfh1 should be swapped out. |
1601 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1609 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
1602 EXPECT_TRUE(rfh1->GetRenderViewHost()->IsSwappedOut()); | 1610 EXPECT_TRUE(rfh1->is_swapped_out()); |
1603 } | 1611 } |
1604 | 1612 |
1605 // Test that the RenderViewHost is properly swapped out if a navigation in the | 1613 // Test that the RenderViewHost is properly swapped out if a navigation in the |
1606 // new renderer commits before sending the SwapOut message to the old renderer. | 1614 // new renderer commits before sending the SwapOut message to the old renderer. |
1607 // This simulates a cross-site navigation to a synchronously committing URL | 1615 // This simulates a cross-site navigation to a synchronously committing URL |
1608 // (e.g., a data URL) and ensures it works properly. | 1616 // (e.g., a data URL) and ensures it works properly. |
1609 TEST_F(RenderFrameHostManagerTest, | 1617 TEST_F(RenderFrameHostManagerTest, |
1610 CommitNewNavigationBeforeSendingSwapOut) { | 1618 CommitNewNavigationBeforeSendingSwapOut) { |
1611 const GURL kUrl1("http://www.google.com/"); | 1619 const GURL kUrl1("http://www.google.com/"); |
1612 const GURL kUrl2("http://www.chromium.org/"); | 1620 const GURL kUrl2("http://www.chromium.org/"); |
1613 | 1621 |
1614 // Navigate to the first page. | 1622 // Navigate to the first page. |
1615 contents()->NavigateAndCommit(kUrl1); | 1623 contents()->NavigateAndCommit(kUrl1); |
1616 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1624 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1617 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1625 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1618 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1626 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1619 rfh1->GetRenderViewHost()->rvh_state()); | |
1620 | 1627 |
1621 // Increment the number of active views in SiteInstanceImpl so that rfh1 is | 1628 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1622 // not deleted on swap out. | 1629 // not deleted on swap out. |
1623 static_cast<SiteInstanceImpl*>( | 1630 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1624 rfh1->GetSiteInstance())->increment_active_view_count(); | |
1625 | 1631 |
1626 // Navigate to new site, simulating onbeforeunload approval. | 1632 // Navigate to new site, simulating onbeforeunload approval. |
1627 controller().LoadURL( | 1633 controller().LoadURL( |
1628 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1634 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1629 base::TimeTicks now = base::TimeTicks::Now(); | 1635 base::TimeTicks now = base::TimeTicks::Now(); |
1630 rfh1->OnMessageReceived( | 1636 rfh1->OnMessageReceived( |
1631 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1637 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1632 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1638 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1633 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1639 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1634 | 1640 |
1635 // The new page commits. | 1641 // The new page commits. |
1636 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1642 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1637 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1643 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1638 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1644 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1639 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1645 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1640 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1646 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1641 rfh2->GetRenderViewHost()->rvh_state()); | 1647 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1642 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | |
1643 rfh1->GetRenderViewHost()->rvh_state()); | |
1644 | 1648 |
1645 // Simulate the swap out ack. | 1649 // Simulate the swap out ack. |
1646 rfh1->OnSwappedOut(false); | 1650 rfh1->OnSwappedOut(); |
1647 | 1651 |
1648 // rfh1 should be swapped out. | 1652 // rfh1 should be swapped out. |
1649 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1653 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
1650 EXPECT_TRUE(rfh1->GetRenderViewHost()->IsSwappedOut()); | 1654 EXPECT_TRUE(rfh1->is_swapped_out()); |
1651 } | 1655 } |
1652 | 1656 |
1653 // Test that a RenderFrameHost is properly deleted or swapped out when a | 1657 // Test that a RenderFrameHost is properly deleted or swapped out when a |
1654 // cross-site navigation is cancelled. | 1658 // cross-site navigation is cancelled. |
1655 TEST_F(RenderFrameHostManagerTest, | 1659 TEST_F(RenderFrameHostManagerTest, |
1656 CancelPendingProperlyDeletesOrSwaps) { | 1660 CancelPendingProperlyDeletesOrSwaps) { |
1657 const GURL kUrl1("http://www.google.com/"); | 1661 const GURL kUrl1("http://www.google.com/"); |
1658 const GURL kUrl2("http://www.chromium.org/"); | 1662 const GURL kUrl2("http://www.chromium.org/"); |
1659 RenderFrameHostImpl* pending_rfh = NULL; | 1663 RenderFrameHostImpl* pending_rfh = NULL; |
1660 base::TimeTicks now = base::TimeTicks::Now(); | 1664 base::TimeTicks now = base::TimeTicks::Now(); |
1661 | 1665 |
1662 // Navigate to the first page. | 1666 // Navigate to the first page. |
1663 contents()->NavigateAndCommit(kUrl1); | 1667 contents()->NavigateAndCommit(kUrl1); |
1664 TestRenderViewHost* rvh1 = test_rvh(); | 1668 TestRenderFrameHost* rfh1 = main_test_rfh(); |
1665 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | 1669 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1666 | 1670 |
1667 // Navigate to a new site, starting a cross-site navigation. | 1671 // Navigate to a new site, starting a cross-site navigation. |
1668 controller().LoadURL( | 1672 controller().LoadURL( |
1669 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1673 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1670 { | 1674 { |
1671 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1675 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1672 ->pending_frame_host(); | 1676 ->pending_frame_host(); |
1673 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | 1677 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
1674 | 1678 |
1675 // Cancel the navigation by simulating a declined beforeunload dialog. | 1679 // Cancel the navigation by simulating a declined beforeunload dialog. |
1676 contents()->GetMainFrame()->OnMessageReceived( | 1680 contents()->GetMainFrame()->OnMessageReceived( |
1677 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1681 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1678 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1682 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1679 | 1683 |
1680 // Since the pending RFH is the only one for the new SiteInstance, it should | 1684 // Since the pending RFH is the only one for the new SiteInstance, it should |
1681 // be deleted. | 1685 // be deleted. |
1682 EXPECT_TRUE(rvh_deleted_observer.deleted()); | 1686 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
1683 } | 1687 } |
1684 | 1688 |
1685 // Start another cross-site navigation. | 1689 // Start another cross-site navigation. |
1686 controller().LoadURL( | 1690 controller().LoadURL( |
1687 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1691 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1688 { | 1692 { |
1689 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1693 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1690 ->pending_frame_host(); | 1694 ->pending_frame_host(); |
1691 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | 1695 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
1692 | 1696 |
1693 // Increment the number of active views in the new SiteInstance, which will | 1697 // Increment the number of active frames in the new SiteInstance, which will |
1694 // cause the pending RFH to be swapped out instead of deleted. | 1698 // cause the pending RFH to be swapped out instead of deleted. |
1695 static_cast<SiteInstanceImpl*>( | 1699 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
1696 pending_rfh->GetSiteInstance())->increment_active_view_count(); | |
1697 | 1700 |
1698 contents()->GetMainFrame()->OnMessageReceived( | 1701 contents()->GetMainFrame()->OnMessageReceived( |
1699 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1702 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1700 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1703 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1701 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1704 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
1702 } | 1705 } |
1703 } | 1706 } |
1704 | 1707 |
1705 // PlzNavigate: Test that a proper NavigationRequest is created by | 1708 // PlzNavigate: Test that a proper NavigationRequest is created by |
1706 // BeginNavigation. | 1709 // BeginNavigation. |
1707 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1710 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1708 const GURL kUrl1("http://www.google.com/"); | 1711 const GURL kUrl1("http://www.google.com/"); |
1709 const GURL kUrl2("http://www.chromium.org/"); | 1712 const GURL kUrl2("http://www.chromium.org/"); |
1710 const GURL kUrl3("http://www.gmail.com/"); | 1713 const GURL kUrl3("http://www.gmail.com/"); |
1711 const int64 kFirstNavRequestID = 1; | 1714 const int64 kFirstNavRequestID = 1; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 // Now commit the same url. | 1771 // Now commit the same url. |
1769 NavigationBeforeCommitInfo commit_info; | 1772 NavigationBeforeCommitInfo commit_info; |
1770 commit_info.navigation_url = kUrl; | 1773 commit_info.navigation_url = kUrl; |
1771 commit_info.navigation_request_id = main_request->navigation_request_id(); | 1774 commit_info.navigation_request_id = main_request->navigation_request_id(); |
1772 render_manager->CommitNavigation(commit_info); | 1775 render_manager->CommitNavigation(commit_info); |
1773 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | 1776 main_request = GetNavigationRequestForRenderFrameManager(render_manager); |
1774 | 1777 |
1775 // The main RFH should not have been changed, and the renderer should have | 1778 // The main RFH should not have been changed, and the renderer should have |
1776 // been initialized. | 1779 // been initialized. |
1777 EXPECT_EQ(rfh, main_test_rfh()); | 1780 EXPECT_EQ(rfh, main_test_rfh()); |
| 1781 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
1778 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1782 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1779 } | 1783 } |
1780 | 1784 |
1781 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 1785 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
1782 // site navigation. | 1786 // site navigation. |
1783 TEST_F(RenderFrameHostManagerTest, | 1787 TEST_F(RenderFrameHostManagerTest, |
1784 BrowserSideNavigationCrossSiteNavigation) { | 1788 BrowserSideNavigationCrossSiteNavigation) { |
1785 const GURL kUrl1("http://www.chromium.org/"); | 1789 const GURL kUrl1("http://www.chromium.org/"); |
1786 const GURL kUrl2("http://www.google.com/"); | 1790 const GURL kUrl2("http://www.google.com/"); |
1787 | 1791 |
1788 // TODO(clamy): we should be enabling browser side navigations here | 1792 // TODO(clamy): we should be enabling browser side navigations here |
1789 // when CommitNavigation is properly implemented. | 1793 // when CommitNavigation is properly implemented. |
1790 // Navigate to the first page. | 1794 // Navigate to the first page. |
1791 contents()->NavigateAndCommit(kUrl1); | 1795 contents()->NavigateAndCommit(kUrl1); |
1792 TestRenderViewHost* rvh1 = test_rvh(); | |
1793 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
1794 RenderFrameHostImpl* rfh = main_test_rfh(); | 1796 RenderFrameHostImpl* rfh = main_test_rfh(); |
| 1797 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
1795 RenderFrameHostManager* render_manager = | 1798 RenderFrameHostManager* render_manager = |
1796 main_test_rfh()->frame_tree_node()->render_manager(); | 1799 main_test_rfh()->frame_tree_node()->render_manager(); |
1797 | 1800 |
1798 EnableBrowserSideNavigation(); | 1801 EnableBrowserSideNavigation(); |
1799 // Navigate to a different site. | 1802 // Navigate to a different site. |
1800 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 1803 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
1801 NavigationRequest* main_request = | 1804 NavigationRequest* main_request = |
1802 GetNavigationRequestForRenderFrameManager(render_manager); | 1805 GetNavigationRequestForRenderFrameManager(render_manager); |
1803 ASSERT_TRUE(main_request); | 1806 ASSERT_TRUE(main_request); |
1804 | 1807 |
1805 NavigationBeforeCommitInfo commit_info; | 1808 NavigationBeforeCommitInfo commit_info; |
1806 commit_info.navigation_url = kUrl2; | 1809 commit_info.navigation_url = kUrl2; |
1807 commit_info.navigation_request_id = main_request->navigation_request_id(); | 1810 commit_info.navigation_request_id = main_request->navigation_request_id(); |
1808 render_manager->CommitNavigation(commit_info); | 1811 render_manager->CommitNavigation(commit_info); |
1809 EXPECT_NE(main_test_rfh(), rfh); | 1812 EXPECT_NE(main_test_rfh(), rfh); |
| 1813 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
1810 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1814 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1811 } | 1815 } |
1812 | 1816 |
1813 // PlzNavigate: Test that a navigation commit is ignored if another request has | 1817 // PlzNavigate: Test that a navigation commit is ignored if another request has |
1814 // been issued in the meantime. | 1818 // been issued in the meantime. |
1815 // TODO(carlosk): add checks to assert that the cancel call was sent to | 1819 // TODO(carlosk): add checks to assert that the cancel call was sent to |
1816 // ResourceDispatcherHost in the IO thread by extending | 1820 // ResourceDispatcherHost in the IO thread by extending |
1817 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc | 1821 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc |
1818 // and plugin_browsertest.cc). | 1822 // and plugin_browsertest.cc). |
1819 TEST_F(RenderFrameHostManagerTest, | 1823 TEST_F(RenderFrameHostManagerTest, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1858 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1855 | 1859 |
1856 // Confirms that a valid, request-matching commit is correctly processed. | 1860 // Confirms that a valid, request-matching commit is correctly processed. |
1857 nbc_info.navigation_url = kUrl2; | 1861 nbc_info.navigation_url = kUrl2; |
1858 nbc_info.navigation_request_id = request_id2; | 1862 nbc_info.navigation_request_id = request_id2; |
1859 render_manager->CommitNavigation(nbc_info); | 1863 render_manager->CommitNavigation(nbc_info); |
1860 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1864 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1861 } | 1865 } |
1862 | 1866 |
1863 } // namespace content | 1867 } // namespace content |
OLD | NEW |