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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "content/child/request_extra_data.h" | 20 #include "content/child/request_extra_data.h" |
21 #include "content/child/service_worker/service_worker_network_provider.h" | 21 #include "content/child/service_worker/service_worker_network_provider.h" |
22 #include "content/common/frame_messages.h" | 22 #include "content/common/frame_messages.h" |
| 23 #include "content/common/frame_replication_state.h" |
23 #include "content/common/site_isolation_policy.h" | 24 #include "content/common/site_isolation_policy.h" |
24 #include "content/common/ssl_status_serialization.h" | 25 #include "content/common/ssl_status_serialization.h" |
25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
26 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
27 #include "content/public/browser/native_web_keyboard_event.h" | 28 #include "content/public/browser/native_web_keyboard_event.h" |
28 #include "content/public/browser/web_ui_controller_factory.h" | 29 #include "content/public/browser/web_ui_controller_factory.h" |
29 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
30 #include "content/public/common/browser_side_navigation_policy.h" | 31 #include "content/public/common/browser_side_navigation_policy.h" |
31 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
32 #include "content/public/common/page_zoom.h" | 33 #include "content/public/common/page_zoom.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 148 } |
148 }; | 149 }; |
149 | 150 |
150 // Timestamps logged close to each other under low resolution timers | 151 // Timestamps logged close to each other under low resolution timers |
151 // are more likely to record the same value. Allow for this by relaxing | 152 // are more likely to record the same value. Allow for this by relaxing |
152 // constraints on systems with these timers. | 153 // constraints on systems with these timers. |
153 bool TimeTicksGT(const base::TimeTicks& x, const base::TimeTicks& y) { | 154 bool TimeTicksGT(const base::TimeTicks& x, const base::TimeTicks& y) { |
154 return base::TimeTicks::IsHighResolution() ? x > y : x >= y; | 155 return base::TimeTicks::IsHighResolution() ? x > y : x >= y; |
155 } | 156 } |
156 | 157 |
| 158 // FrameReplicationState is normally maintained in the browser process, |
| 159 // but the function below provides a way for tests to construct a partial |
| 160 // FrameReplicationState within the renderer process. We say "partial", |
| 161 // because some fields of FrameReplicationState cannot be filled out |
| 162 // by content-layer, renderer code (still the constructed, partial |
| 163 // FrameReplicationState is sufficiently complete to avoid trigerring |
| 164 // asserts that a default/empty FrameReplicationState would). |
| 165 FrameReplicationState ReconstructReplicationStateForTesting( |
| 166 TestRenderFrame* test_render_frame) { |
| 167 blink::WebLocalFrame* frame = test_render_frame->GetWebFrame(); |
| 168 |
| 169 FrameReplicationState result; |
| 170 // can't recover result.scope - no way to get WebTreeScopeType via public |
| 171 // blink API... |
| 172 result.name = base::UTF16ToUTF8(base::StringPiece16(frame->assignedName())); |
| 173 result.unique_name = |
| 174 base::UTF16ToUTF8(base::StringPiece16(frame->uniqueName())); |
| 175 result.sandbox_flags = frame->effectiveSandboxFlags(); |
| 176 // result.should_enforce_strict_mixed_content_checking is calculated in the |
| 177 // browser... |
| 178 result.origin = frame->securityOrigin(); |
| 179 |
| 180 return result; |
| 181 } |
| 182 |
157 } // namespace | 183 } // namespace |
158 | 184 |
159 class RenderViewImplTest : public RenderViewTest { | 185 class RenderViewImplTest : public RenderViewTest { |
160 public: | 186 public: |
161 RenderViewImplTest() { | 187 RenderViewImplTest() { |
162 // Attach a pseudo keyboard device to this object. | 188 // Attach a pseudo keyboard device to this object. |
163 mock_keyboard_.reset(new MockKeyboard()); | 189 mock_keyboard_.reset(new MockKeyboard()); |
164 } | 190 } |
165 | 191 |
166 ~RenderViewImplTest() override {} | 192 ~RenderViewImplTest() override {} |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 741 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
716 return; | 742 return; |
717 } | 743 } |
718 LoadHTML("<div>Page A</div>"); | 744 LoadHTML("<div>Page A</div>"); |
719 int initial_page_id = view_page_id(); | 745 int initial_page_id = view_page_id(); |
720 | 746 |
721 // Increment the ref count so that we don't exit when swapping out. | 747 // Increment the ref count so that we don't exit when swapping out. |
722 RenderProcess::current()->AddRefProcess(); | 748 RenderProcess::current()->AddRefProcess(); |
723 | 749 |
724 // Respond to a swap out request. | 750 // Respond to a swap out request. |
725 frame()->SwapOut(kProxyRoutingId, true, content::FrameReplicationState()); | 751 frame()->SwapOut(kProxyRoutingId, true, |
| 752 ReconstructReplicationStateForTesting(frame())); |
726 | 753 |
727 // Ensure the swap out commits synchronously. | 754 // Ensure the swap out commits synchronously. |
728 EXPECT_NE(initial_page_id, view_page_id()); | 755 EXPECT_NE(initial_page_id, view_page_id()); |
729 | 756 |
730 // Check for a valid OnSwapOutACK. | 757 // Check for a valid OnSwapOutACK. |
731 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 758 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
732 FrameHostMsg_SwapOut_ACK::ID); | 759 FrameHostMsg_SwapOut_ACK::ID); |
733 ASSERT_TRUE(msg); | 760 ASSERT_TRUE(msg); |
734 | 761 |
735 // It is possible to get another swap out request. Ensure that we send | 762 // It is possible to get another swap out request. Ensure that we send |
736 // an ACK, even if we don't have to do anything else. | 763 // an ACK, even if we don't have to do anything else. |
737 render_thread_->sink().ClearMessages(); | 764 render_thread_->sink().ClearMessages(); |
738 frame()->SwapOut(kProxyRoutingId, false, content::FrameReplicationState()); | 765 frame()->SwapOut(kProxyRoutingId, false, |
| 766 ReconstructReplicationStateForTesting(frame())); |
739 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( | 767 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( |
740 FrameHostMsg_SwapOut_ACK::ID); | 768 FrameHostMsg_SwapOut_ACK::ID); |
741 ASSERT_TRUE(msg2); | 769 ASSERT_TRUE(msg2); |
742 | 770 |
743 // If we navigate back to this RenderView, ensure we don't send a state | 771 // If we navigate back to this RenderView, ensure we don't send a state |
744 // update for the swapped out URL. (http://crbug.com/72235) | 772 // update for the swapped out URL. (http://crbug.com/72235) |
745 CommonNavigationParams common_params; | 773 CommonNavigationParams common_params; |
746 RequestNavigationParams request_params; | 774 RequestNavigationParams request_params; |
747 common_params.url = GURL("data:text/html,<div>Page B</div>"); | 775 common_params.url = GURL("data:text/html,<div>Page B</div>"); |
748 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 776 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 request_params_A.page_id = 1; | 824 request_params_A.page_id = 1; |
797 request_params_A.nav_entry_id = 1; | 825 request_params_A.nav_entry_id = 1; |
798 request_params_A.page_state = state_A; | 826 request_params_A.page_state = state_A; |
799 frame()->Navigate(common_params_A, StartNavigationParams(), request_params_A); | 827 frame()->Navigate(common_params_A, StartNavigationParams(), request_params_A); |
800 EXPECT_EQ(1, view()->historyBackListCount()); | 828 EXPECT_EQ(1, view()->historyBackListCount()); |
801 EXPECT_EQ(2, view()->historyBackListCount() + | 829 EXPECT_EQ(2, view()->historyBackListCount() + |
802 view()->historyForwardListCount() + 1); | 830 view()->historyForwardListCount() + 1); |
803 ProcessPendingMessages(); | 831 ProcessPendingMessages(); |
804 | 832 |
805 // Respond to a swap out request. | 833 // Respond to a swap out request. |
806 frame()->SwapOut(kProxyRoutingId, true, content::FrameReplicationState()); | 834 frame()->SwapOut(kProxyRoutingId, true, |
| 835 ReconstructReplicationStateForTesting(frame())); |
807 | 836 |
808 // Check for a OnSwapOutACK. | 837 // Check for a OnSwapOutACK. |
809 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 838 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
810 FrameHostMsg_SwapOut_ACK::ID); | 839 FrameHostMsg_SwapOut_ACK::ID); |
811 ASSERT_TRUE(msg); | 840 ASSERT_TRUE(msg); |
812 render_thread_->sink().ClearMessages(); | 841 render_thread_->sink().ClearMessages(); |
813 | 842 |
814 // It is possible to get a reload request at this point, containing the | 843 // It is possible to get a reload request at this point, containing the |
815 // params.page_state of the initial page (e.g., if the new page fails the | 844 // params.page_state of the initial page (e.g., if the new page fails the |
816 // provisional load in the renderer process, after we unload the old page). | 845 // provisional load in the renderer process, after we unload the old page). |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 881 |
853 LoadHTML( | 882 LoadHTML( |
854 "Hello <iframe src='data:text/html,frame 1'></iframe>" | 883 "Hello <iframe src='data:text/html,frame 1'></iframe>" |
855 "<iframe src='data:text/html,frame 2'></iframe>"); | 884 "<iframe src='data:text/html,frame 2'></iframe>"); |
856 WebFrame* web_frame = frame()->GetWebFrame(); | 885 WebFrame* web_frame = frame()->GetWebFrame(); |
857 TestRenderFrame* child_frame = static_cast<TestRenderFrame*>( | 886 TestRenderFrame* child_frame = static_cast<TestRenderFrame*>( |
858 RenderFrame::FromWebFrame(web_frame->firstChild())); | 887 RenderFrame::FromWebFrame(web_frame->firstChild())); |
859 | 888 |
860 // Swap the child frame out and pass a replicated origin to be set for | 889 // Swap the child frame out and pass a replicated origin to be set for |
861 // WebRemoteFrame. | 890 // WebRemoteFrame. |
862 content::FrameReplicationState replication_state; | 891 content::FrameReplicationState replication_state = |
| 892 ReconstructReplicationStateForTesting(child_frame); |
863 replication_state.origin = url::Origin(GURL("http://foo.com")); | 893 replication_state.origin = url::Origin(GURL("http://foo.com")); |
864 child_frame->SwapOut(kProxyRoutingId, true, replication_state); | 894 child_frame->SwapOut(kProxyRoutingId, true, replication_state); |
865 | 895 |
866 // The child frame should now be a WebRemoteFrame. | 896 // The child frame should now be a WebRemoteFrame. |
867 EXPECT_TRUE(web_frame->firstChild()->isWebRemoteFrame()); | 897 EXPECT_TRUE(web_frame->firstChild()->isWebRemoteFrame()); |
868 | 898 |
869 // Expect the origin to be updated properly. | 899 // Expect the origin to be updated properly. |
870 blink::WebSecurityOrigin origin = web_frame->firstChild()->securityOrigin(); | 900 blink::WebSecurityOrigin origin = web_frame->firstChild()->securityOrigin(); |
871 EXPECT_EQ(origin.toString(), | 901 EXPECT_EQ(origin.toString(), |
872 WebString::fromUTF8(replication_state.origin.Serialize())); | 902 WebString::fromUTF8(replication_state.origin.Serialize())); |
(...skipping 17 matching lines...) Expand all Loading... |
890 // This test should only run with --site-per-process. | 920 // This test should only run with --site-per-process. |
891 if (!AreAllSitesIsolatedForTesting()) | 921 if (!AreAllSitesIsolatedForTesting()) |
892 return; | 922 return; |
893 | 923 |
894 LoadHTML("Hello <iframe src='data:text/html,frame 1'></iframe>"); | 924 LoadHTML("Hello <iframe src='data:text/html,frame 1'></iframe>"); |
895 WebFrame* web_frame = frame()->GetWebFrame(); | 925 WebFrame* web_frame = frame()->GetWebFrame(); |
896 TestRenderFrame* child_frame = static_cast<TestRenderFrame*>( | 926 TestRenderFrame* child_frame = static_cast<TestRenderFrame*>( |
897 RenderFrame::FromWebFrame(web_frame->firstChild())); | 927 RenderFrame::FromWebFrame(web_frame->firstChild())); |
898 | 928 |
899 // Swap the child frame out. | 929 // Swap the child frame out. |
900 child_frame->SwapOut(kProxyRoutingId, true, content::FrameReplicationState()); | 930 FrameReplicationState replication_state = |
| 931 ReconstructReplicationStateForTesting(child_frame); |
| 932 child_frame->SwapOut(kProxyRoutingId, true, replication_state); |
901 EXPECT_TRUE(web_frame->firstChild()->isWebRemoteFrame()); | 933 EXPECT_TRUE(web_frame->firstChild()->isWebRemoteFrame()); |
902 | 934 |
903 // Do the first step of a remote-to-local transition for the child proxy, | 935 // Do the first step of a remote-to-local transition for the child proxy, |
904 // which is to create a provisional local frame. | 936 // which is to create a provisional local frame. |
905 int routing_id = kProxyRoutingId + 1; | 937 int routing_id = kProxyRoutingId + 1; |
906 FrameMsg_NewFrame_WidgetParams widget_params; | 938 FrameMsg_NewFrame_WidgetParams widget_params; |
907 widget_params.routing_id = MSG_ROUTING_NONE; | 939 widget_params.routing_id = MSG_ROUTING_NONE; |
908 widget_params.hidden = false; | 940 widget_params.hidden = false; |
909 RenderFrameImpl::CreateFrame(routing_id, kProxyRoutingId, MSG_ROUTING_NONE, | 941 RenderFrameImpl::CreateFrame(routing_id, kProxyRoutingId, MSG_ROUTING_NONE, |
910 frame()->GetRoutingID(), MSG_ROUTING_NONE, | 942 frame()->GetRoutingID(), MSG_ROUTING_NONE, |
911 content::FrameReplicationState(), nullptr, | 943 replication_state, nullptr, widget_params, |
912 widget_params, blink::WebFrameOwnerProperties()); | 944 blink::WebFrameOwnerProperties()); |
913 TestRenderFrame* provisional_frame = | 945 TestRenderFrame* provisional_frame = |
914 static_cast<TestRenderFrame*>(RenderFrameImpl::FromRoutingID(routing_id)); | 946 static_cast<TestRenderFrame*>(RenderFrameImpl::FromRoutingID(routing_id)); |
915 EXPECT_TRUE(provisional_frame); | 947 EXPECT_TRUE(provisional_frame); |
916 | 948 |
917 // Detach the child frame (currently remote) in the main frame. | 949 // Detach the child frame (currently remote) in the main frame. |
918 ExecuteJavaScriptForTests( | 950 ExecuteJavaScriptForTests( |
919 "document.body.removeChild(document.querySelector('iframe'));"); | 951 "document.body.removeChild(document.querySelector('iframe'));"); |
920 RenderFrameProxy* child_proxy = | 952 RenderFrameProxy* child_proxy = |
921 RenderFrameProxy::FromRoutingID(kProxyRoutingId); | 953 RenderFrameProxy::FromRoutingID(kProxyRoutingId); |
922 EXPECT_FALSE(child_proxy); | 954 EXPECT_FALSE(child_proxy); |
(...skipping 26 matching lines...) Expand all Loading... |
949 // shutdown of frame() in RenderViewTest.TearDown. | 981 // shutdown of frame() in RenderViewTest.TearDown. |
950 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 982 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
951 blink::WebView* new_web_view = view()->createView( | 983 blink::WebView* new_web_view = view()->createView( |
952 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", | 984 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", |
953 blink::WebNavigationPolicyNewForegroundTab, false); | 985 blink::WebNavigationPolicyNewForegroundTab, false); |
954 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 986 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
955 | 987 |
956 // Respond to a swap out request. | 988 // Respond to a swap out request. |
957 TestRenderFrame* new_main_frame = | 989 TestRenderFrame* new_main_frame = |
958 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame()); | 990 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame()); |
959 new_main_frame->SwapOut(kProxyRoutingId, true, | 991 new_main_frame->SwapOut( |
960 content::FrameReplicationState()); | 992 kProxyRoutingId, true, |
| 993 ReconstructReplicationStateForTesting(new_main_frame)); |
961 | 994 |
962 // Simulate getting painted after swapping out. | 995 // Simulate getting painted after swapping out. |
963 new_view->DidFlushPaint(); | 996 new_view->DidFlushPaint(); |
964 | 997 |
965 new_view->Close(); | 998 new_view->Close(); |
966 new_view->Release(); | 999 new_view->Release(); |
967 } | 1000 } |
968 | 1001 |
969 // Verify that the renderer process doesn't crash when device scale factor | 1002 // Verify that the renderer process doesn't crash when device scale factor |
970 // changes after a cross-process navigation has commited. | 1003 // changes after a cross-process navigation has commited. |
971 // See https://crbug.com/571603. | 1004 // See https://crbug.com/571603. |
972 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) { | 1005 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) { |
973 // This test should only run with out-of-process iframes enabled. | 1006 // This test should only run with out-of-process iframes enabled. |
974 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) | 1007 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
975 return; | 1008 return; |
976 | 1009 |
977 // The bug reproduces if zoom is used for devices scale factor. | 1010 // The bug reproduces if zoom is used for devices scale factor. |
978 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1011 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
979 switches::kEnableUseZoomForDSF); | 1012 switches::kEnableUseZoomForDSF); |
980 | 1013 |
981 LoadHTML("Hello world!"); | 1014 LoadHTML("Hello world!"); |
982 | 1015 |
983 // Swap the main frame out after which it should become a WebRemoteFrame. | 1016 // Swap the main frame out after which it should become a WebRemoteFrame. |
984 TestRenderFrame* main_frame = | 1017 TestRenderFrame* main_frame = |
985 static_cast<TestRenderFrame*>(view()->GetMainRenderFrame()); | 1018 static_cast<TestRenderFrame*>(view()->GetMainRenderFrame()); |
986 main_frame->SwapOut(kProxyRoutingId, true, content::FrameReplicationState()); | 1019 main_frame->SwapOut(kProxyRoutingId, true, |
| 1020 ReconstructReplicationStateForTesting(main_frame)); |
987 EXPECT_TRUE(view()->webview()->mainFrame()->isWebRemoteFrame()); | 1021 EXPECT_TRUE(view()->webview()->mainFrame()->isWebRemoteFrame()); |
988 | 1022 |
989 // This should not cause a crash. | 1023 // This should not cause a crash. |
990 view()->OnDeviceScaleFactorChanged(); | 1024 view()->OnDeviceScaleFactorChanged(); |
991 } | 1025 } |
992 | 1026 |
993 // Test that we get the correct UpdateState message when we go back twice | 1027 // Test that we get the correct UpdateState message when we go back twice |
994 // quickly without committing. Regression test for http://crbug.com/58082. | 1028 // quickly without committing. Regression test for http://crbug.com/58082. |
995 // Disabled: http://crbug.com/157357 . | 1029 // Disabled: http://crbug.com/157357 . |
996 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { | 1030 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { |
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2754 FROM_HERE, | 2788 FROM_HERE, |
2755 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2789 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2756 ExecuteJavaScriptForTests("debugger;"); | 2790 ExecuteJavaScriptForTests("debugger;"); |
2757 | 2791 |
2758 // CloseWhilePaused should resume execution and continue here. | 2792 // CloseWhilePaused should resume execution and continue here. |
2759 EXPECT_FALSE(IsPaused()); | 2793 EXPECT_FALSE(IsPaused()); |
2760 Detach(); | 2794 Detach(); |
2761 } | 2795 } |
2762 | 2796 |
2763 } // namespace content | 2797 } // namespace content |
OLD | NEW |