| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
| 13 #include "content/child/request_extra_data.h" | 13 #include "content/child/request_extra_data.h" |
| 14 #include "content/child/service_worker/service_worker_network_provider.h" | 14 #include "content/child/service_worker/service_worker_network_provider.h" |
| 15 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 16 #include "content/common/ssl_status_serialization.h" | 16 #include "content/common/ssl_status_serialization.h" |
| 17 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
| 20 #include "content/public/browser/web_ui_controller_factory.h" | 20 #include "content/public/browser/web_ui_controller_factory.h" |
| 21 #include "content/public/common/bindings_policy.h" | 21 #include "content/public/common/bindings_policy.h" |
| 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/page_zoom.h" | 23 #include "content/public/common/page_zoom.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/common/url_utils.h" | 25 #include "content/public/common/url_utils.h" |
| 25 #include "content/public/renderer/content_renderer_client.h" | 26 #include "content/public/renderer/content_renderer_client.h" |
| 26 #include "content/public/renderer/document_state.h" | 27 #include "content/public/renderer/document_state.h" |
| 27 #include "content/public/renderer/navigation_state.h" | 28 #include "content/public/renderer/navigation_state.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/public/test/frame_load_waiter.h" | 30 #include "content/public/test/frame_load_waiter.h" |
| 30 #include "content/public/test/render_view_test.h" | 31 #include "content/public/test/render_view_test.h" |
| 31 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is | 525 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is |
| 525 // already swapped out. http://crbug.com/93427. | 526 // already swapped out. http://crbug.com/93427. |
| 526 TEST_F(RenderViewImplTest, SendSwapOutACK) { | 527 TEST_F(RenderViewImplTest, SendSwapOutACK) { |
| 527 LoadHTML("<div>Page A</div>"); | 528 LoadHTML("<div>Page A</div>"); |
| 528 int initial_page_id = view_page_id(); | 529 int initial_page_id = view_page_id(); |
| 529 | 530 |
| 530 // Increment the ref count so that we don't exit when swapping out. | 531 // Increment the ref count so that we don't exit when swapping out. |
| 531 RenderProcess::current()->AddRefProcess(); | 532 RenderProcess::current()->AddRefProcess(); |
| 532 | 533 |
| 533 // Respond to a swap out request. | 534 // Respond to a swap out request. |
| 534 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 535 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
| 536 content::FrameReplicationState()); |
| 535 | 537 |
| 536 // Ensure the swap out commits synchronously. | 538 // Ensure the swap out commits synchronously. |
| 537 EXPECT_NE(initial_page_id, view_page_id()); | 539 EXPECT_NE(initial_page_id, view_page_id()); |
| 538 | 540 |
| 539 // Check for a valid OnSwapOutACK. | 541 // Check for a valid OnSwapOutACK. |
| 540 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 542 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 541 FrameHostMsg_SwapOut_ACK::ID); | 543 FrameHostMsg_SwapOut_ACK::ID); |
| 542 ASSERT_TRUE(msg); | 544 ASSERT_TRUE(msg); |
| 543 | 545 |
| 544 // It is possible to get another swap out request. Ensure that we send | 546 // It is possible to get another swap out request. Ensure that we send |
| 545 // an ACK, even if we don't have to do anything else. | 547 // an ACK, even if we don't have to do anything else. |
| 546 render_thread_->sink().ClearMessages(); | 548 render_thread_->sink().ClearMessages(); |
| 547 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 549 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
| 550 content::FrameReplicationState()); |
| 548 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( | 551 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( |
| 549 FrameHostMsg_SwapOut_ACK::ID); | 552 FrameHostMsg_SwapOut_ACK::ID); |
| 550 ASSERT_TRUE(msg2); | 553 ASSERT_TRUE(msg2); |
| 551 | 554 |
| 552 // If we navigate back to this RenderView, ensure we don't send a state | 555 // If we navigate back to this RenderView, ensure we don't send a state |
| 553 // update for the swapped out URL. (http://crbug.com/72235) | 556 // update for the swapped out URL. (http://crbug.com/72235) |
| 554 FrameMsg_Navigate_Params nav_params; | 557 FrameMsg_Navigate_Params nav_params; |
| 555 nav_params.common_params.url = GURL("data:text/html,<div>Page B</div>"); | 558 nav_params.common_params.url = GURL("data:text/html,<div>Page B</div>"); |
| 556 nav_params.common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 559 nav_params.common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 557 nav_params.common_params.transition = ui::PAGE_TRANSITION_TYPED; | 560 nav_params.common_params.transition = ui::PAGE_TRANSITION_TYPED; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 params_A.current_history_list_offset = 1; | 600 params_A.current_history_list_offset = 1; |
| 598 params_A.pending_history_list_offset = 0; | 601 params_A.pending_history_list_offset = 0; |
| 599 params_A.page_id = 1; | 602 params_A.page_id = 1; |
| 600 params_A.commit_params.page_state = state_A; | 603 params_A.commit_params.page_state = state_A; |
| 601 params_A.commit_params.browser_navigation_start = | 604 params_A.commit_params.browser_navigation_start = |
| 602 base::TimeTicks::FromInternalValue(1); | 605 base::TimeTicks::FromInternalValue(1); |
| 603 frame()->OnNavigate(params_A); | 606 frame()->OnNavigate(params_A); |
| 604 ProcessPendingMessages(); | 607 ProcessPendingMessages(); |
| 605 | 608 |
| 606 // Respond to a swap out request. | 609 // Respond to a swap out request. |
| 607 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 610 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
| 611 content::FrameReplicationState()); |
| 608 | 612 |
| 609 // Check for a OnSwapOutACK. | 613 // Check for a OnSwapOutACK. |
| 610 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 614 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 611 FrameHostMsg_SwapOut_ACK::ID); | 615 FrameHostMsg_SwapOut_ACK::ID); |
| 612 ASSERT_TRUE(msg); | 616 ASSERT_TRUE(msg); |
| 613 render_thread_->sink().ClearMessages(); | 617 render_thread_->sink().ClearMessages(); |
| 614 | 618 |
| 615 // It is possible to get a reload request at this point, containing the | 619 // It is possible to get a reload request at this point, containing the |
| 616 // params.page_state of the initial page (e.g., if the new page fails the | 620 // params.page_state of the initial page (e.g., if the new page fails the |
| 617 // provisional load in the renderer process, after we unload the old page). | 621 // provisional load in the renderer process, after we unload the old page). |
| (...skipping 18 matching lines...) Expand all Loading... |
| 636 FrameHostMsg_DidCommitProvisionalLoad::ID); | 640 FrameHostMsg_DidCommitProvisionalLoad::ID); |
| 637 EXPECT_TRUE(frame_navigate_msg); | 641 EXPECT_TRUE(frame_navigate_msg); |
| 638 | 642 |
| 639 // Read URL out of the parent trait of the params object. | 643 // Read URL out of the parent trait of the params object. |
| 640 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; | 644 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; |
| 641 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, | 645 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, |
| 642 &commit_params); | 646 &commit_params); |
| 643 EXPECT_NE(GURL("swappedout://"), commit_params.a.url); | 647 EXPECT_NE(GURL("swappedout://"), commit_params.a.url); |
| 644 } | 648 } |
| 645 | 649 |
| 650 // Verify that security origins are replicated properly to RenderFrameProxies |
| 651 // when swapping out. |
| 652 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { |
| 653 // This test should only run with --site-per-process, since origin |
| 654 // replication only happens in that mode. |
| 655 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
| 656 return; |
| 657 |
| 658 LoadHTML( |
| 659 "Hello <iframe src='data:text/html,frame 1'></iframe>" |
| 660 "<iframe src='data:text/html,frame 2'></iframe>"); |
| 661 WebFrame* web_frame = frame()->GetWebFrame(); |
| 662 RenderFrameImpl* child_frame = static_cast<RenderFrameImpl*>( |
| 663 RenderFrame::FromWebFrame(web_frame->firstChild())); |
| 664 |
| 665 // Swap the child frame out and pass a serialized origin to be set for |
| 666 // WebRemoteFrame. |
| 667 content::FrameReplicationState replication_state; |
| 668 replication_state.origin = url::Origin("http://foo.com"); |
| 669 child_frame->OnSwapOut(kProxyRoutingId, replication_state); |
| 670 |
| 671 // The child frame should now be a WebRemoteFrame. |
| 672 EXPECT_TRUE(web_frame->firstChild()->isWebRemoteFrame()); |
| 673 |
| 674 // Expect the origin to be updated properly. |
| 675 blink::WebSecurityOrigin origin = web_frame->firstChild()->securityOrigin(); |
| 676 EXPECT_EQ(origin.toString(), |
| 677 WebString::fromUTF8(replication_state.origin.string())); |
| 678 |
| 679 // Now, swap out the second frame using a unique origin and verify that it is |
| 680 // replicated correctly. |
| 681 replication_state.origin = url::Origin(); |
| 682 RenderFrameImpl* child_frame2 = static_cast<RenderFrameImpl*>( |
| 683 RenderFrame::FromWebFrame(web_frame->lastChild())); |
| 684 child_frame2->OnSwapOut(kProxyRoutingId + 1, replication_state); |
| 685 EXPECT_TRUE(web_frame->lastChild()->isWebRemoteFrame()); |
| 686 EXPECT_TRUE(web_frame->lastChild()->securityOrigin().isUnique()); |
| 687 } |
| 646 | 688 |
| 647 // Test that we get the correct UpdateState message when we go back twice | 689 // Test that we get the correct UpdateState message when we go back twice |
| 648 // quickly without committing. Regression test for http://crbug.com/58082. | 690 // quickly without committing. Regression test for http://crbug.com/58082. |
| 649 // Disabled: http://crbug.com/157357 . | 691 // Disabled: http://crbug.com/157357 . |
| 650 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { | 692 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { |
| 651 // Load page A. | 693 // Load page A. |
| 652 LoadHTML("<div>Page A</div>"); | 694 LoadHTML("<div>Page A</div>"); |
| 653 | 695 |
| 654 // Load page B, which will trigger an UpdateState message for page A. | 696 // Load page B, which will trigger an UpdateState message for page A. |
| 655 LoadHTML("<div>Page B</div>"); | 697 LoadHTML("<div>Page B</div>"); |
| (...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 | 2536 |
| 2495 gfx::Size initial_size_; | 2537 gfx::Size initial_size_; |
| 2496 }; | 2538 }; |
| 2497 | 2539 |
| 2498 TEST_F(RenderViewImplInitialSizeTest, InitialSize) { | 2540 TEST_F(RenderViewImplInitialSizeTest, InitialSize) { |
| 2499 ASSERT_EQ(initial_size_, view_->GetSize()); | 2541 ASSERT_EQ(initial_size_, view_->GetSize()); |
| 2500 ASSERT_EQ(initial_size_, gfx::Size(view_->GetWebView()->size())); | 2542 ASSERT_EQ(initial_size_, gfx::Size(view_->GetWebView()->size())); |
| 2501 } | 2543 } |
| 2502 | 2544 |
| 2503 } // namespace content | 2545 } // namespace content |
| OLD | NEW |