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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is | 540 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is |
540 // already swapped out. http://crbug.com/93427. | 541 // already swapped out. http://crbug.com/93427. |
541 TEST_F(RenderViewImplTest, SendSwapOutACK) { | 542 TEST_F(RenderViewImplTest, SendSwapOutACK) { |
542 LoadHTML("<div>Page A</div>"); | 543 LoadHTML("<div>Page A</div>"); |
543 int initial_page_id = view_page_id(); | 544 int initial_page_id = view_page_id(); |
544 | 545 |
545 // Increment the ref count so that we don't exit when swapping out. | 546 // Increment the ref count so that we don't exit when swapping out. |
546 RenderProcess::current()->AddRefProcess(); | 547 RenderProcess::current()->AddRefProcess(); |
547 | 548 |
548 // Respond to a swap out request. | 549 // Respond to a swap out request. |
549 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 550 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
551 content::FrameReplicationState()); | |
nasko
2014/11/20 17:22:54
What would be the WebRemoteFrame origin if we pass
alexmos
2014/11/20 21:09:10
It will be a unique origin. Do you mean checking
| |
550 | 552 |
551 // Ensure the swap out commits synchronously. | 553 // Ensure the swap out commits synchronously. |
552 EXPECT_NE(initial_page_id, view_page_id()); | 554 EXPECT_NE(initial_page_id, view_page_id()); |
553 | 555 |
554 // Check for a valid OnSwapOutACK. | 556 // Check for a valid OnSwapOutACK. |
555 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 557 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
556 FrameHostMsg_SwapOut_ACK::ID); | 558 FrameHostMsg_SwapOut_ACK::ID); |
557 ASSERT_TRUE(msg); | 559 ASSERT_TRUE(msg); |
558 | 560 |
559 // It is possible to get another swap out request. Ensure that we send | 561 // It is possible to get another swap out request. Ensure that we send |
560 // an ACK, even if we don't have to do anything else. | 562 // an ACK, even if we don't have to do anything else. |
561 render_thread_->sink().ClearMessages(); | 563 render_thread_->sink().ClearMessages(); |
562 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 564 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
565 content::FrameReplicationState()); | |
563 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( | 566 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( |
564 FrameHostMsg_SwapOut_ACK::ID); | 567 FrameHostMsg_SwapOut_ACK::ID); |
565 ASSERT_TRUE(msg2); | 568 ASSERT_TRUE(msg2); |
566 | 569 |
567 // If we navigate back to this RenderView, ensure we don't send a state | 570 // If we navigate back to this RenderView, ensure we don't send a state |
568 // update for the swapped out URL. (http://crbug.com/72235) | 571 // update for the swapped out URL. (http://crbug.com/72235) |
569 FrameMsg_Navigate_Params nav_params; | 572 FrameMsg_Navigate_Params nav_params; |
570 nav_params.common_params.url = GURL("data:text/html,<div>Page B</div>"); | 573 nav_params.common_params.url = GURL("data:text/html,<div>Page B</div>"); |
571 nav_params.common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 574 nav_params.common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
572 nav_params.common_params.transition = ui::PAGE_TRANSITION_TYPED; | 575 nav_params.common_params.transition = ui::PAGE_TRANSITION_TYPED; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 params_A.current_history_list_offset = 1; | 615 params_A.current_history_list_offset = 1; |
613 params_A.pending_history_list_offset = 0; | 616 params_A.pending_history_list_offset = 0; |
614 params_A.page_id = 1; | 617 params_A.page_id = 1; |
615 params_A.commit_params.page_state = state_A; | 618 params_A.commit_params.page_state = state_A; |
616 params_A.commit_params.browser_navigation_start = | 619 params_A.commit_params.browser_navigation_start = |
617 base::TimeTicks::FromInternalValue(1); | 620 base::TimeTicks::FromInternalValue(1); |
618 frame()->OnNavigate(params_A); | 621 frame()->OnNavigate(params_A); |
619 ProcessPendingMessages(); | 622 ProcessPendingMessages(); |
620 | 623 |
621 // Respond to a swap out request. | 624 // Respond to a swap out request. |
622 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId); | 625 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, |
626 content::FrameReplicationState()); | |
623 | 627 |
624 // Check for a OnSwapOutACK. | 628 // Check for a OnSwapOutACK. |
625 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 629 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
626 FrameHostMsg_SwapOut_ACK::ID); | 630 FrameHostMsg_SwapOut_ACK::ID); |
627 ASSERT_TRUE(msg); | 631 ASSERT_TRUE(msg); |
628 render_thread_->sink().ClearMessages(); | 632 render_thread_->sink().ClearMessages(); |
629 | 633 |
630 // It is possible to get a reload request at this point, containing the | 634 // It is possible to get a reload request at this point, containing the |
631 // params.page_state of the initial page (e.g., if the new page fails the | 635 // params.page_state of the initial page (e.g., if the new page fails the |
632 // provisional load in the renderer process, after we unload the old page). | 636 // provisional load in the renderer process, after we unload the old page). |
(...skipping 18 matching lines...) Expand all Loading... | |
651 FrameHostMsg_DidCommitProvisionalLoad::ID); | 655 FrameHostMsg_DidCommitProvisionalLoad::ID); |
652 EXPECT_TRUE(frame_navigate_msg); | 656 EXPECT_TRUE(frame_navigate_msg); |
653 | 657 |
654 // Read URL out of the parent trait of the params object. | 658 // Read URL out of the parent trait of the params object. |
655 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; | 659 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; |
656 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, | 660 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, |
657 &commit_params); | 661 &commit_params); |
658 EXPECT_NE(GURL("swappedout://"), commit_params.a.url); | 662 EXPECT_NE(GURL("swappedout://"), commit_params.a.url); |
659 } | 663 } |
660 | 664 |
665 // Verify that security origins are replicated properly to RenderFrameProxies | |
666 // when swapping out. | |
667 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { | |
668 // This test should only run with --site-per-process, since origin | |
669 // replication only happens in that mode. | |
670 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | |
671 return; | |
672 | |
673 LoadHTML("Hello <iframe src='data:text/html,world' name='frame'></iframe>"); | |
674 RenderFrameImpl* child_frame = static_cast<RenderFrameImpl*>( | |
675 RenderFrame::FromWebFrame(frame()->GetWebFrame()->firstChild())); | |
676 | |
677 // Swap the child frame out and pass a serialized origin to be set for | |
678 // WebRemoteFrame. | |
679 content::FrameReplicationState replication_state; | |
680 replication_state.origin = url::Origin("http://foo.com"); | |
681 child_frame->OnSwapOut(kProxyRoutingId, replication_state); | |
682 | |
683 // The child frame should now be a WebRemoteFrame. | |
684 EXPECT_TRUE(frame()->GetWebFrame()->firstChild()->isWebRemoteFrame()); | |
685 | |
686 // Expect the origin to be updated properly. | |
687 blink::WebSecurityOrigin origin = | |
688 frame()->GetWebFrame()->firstChild()->securityOrigin(); | |
689 EXPECT_EQ(origin.toString(), | |
690 WebString::fromUTF8(replication_state.origin.string())); | |
691 } | |
661 | 692 |
662 // Test that we get the correct UpdateState message when we go back twice | 693 // Test that we get the correct UpdateState message when we go back twice |
663 // quickly without committing. Regression test for http://crbug.com/58082. | 694 // quickly without committing. Regression test for http://crbug.com/58082. |
664 // Disabled: http://crbug.com/157357 . | 695 // Disabled: http://crbug.com/157357 . |
665 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { | 696 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { |
666 // Load page A. | 697 // Load page A. |
667 LoadHTML("<div>Page A</div>"); | 698 LoadHTML("<div>Page A</div>"); |
668 | 699 |
669 // Load page B, which will trigger an UpdateState message for page A. | 700 // Load page B, which will trigger an UpdateState message for page A. |
670 LoadHTML("<div>Page B</div>"); | 701 LoadHTML("<div>Page B</div>"); |
(...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2509 | 2540 |
2510 gfx::Size initial_size_; | 2541 gfx::Size initial_size_; |
2511 }; | 2542 }; |
2512 | 2543 |
2513 TEST_F(RenderViewImplInitialSizeTest, InitialSize) { | 2544 TEST_F(RenderViewImplInitialSizeTest, InitialSize) { |
2514 ASSERT_EQ(initial_size_, view_->GetSize()); | 2545 ASSERT_EQ(initial_size_, view_->GetSize()); |
2515 ASSERT_EQ(initial_size_, gfx::Size(view_->GetWebView()->size())); | 2546 ASSERT_EQ(initial_size_, gfx::Size(view_->GetWebView()->size())); |
2516 } | 2547 } |
2517 | 2548 |
2518 } // namespace content | 2549 } // namespace content |
OLD | NEW |