| 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" |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; | 761 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; |
| 762 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> | 762 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> |
| 763 decidePolicyForNavigation(popup_policy_info); | 763 decidePolicyForNavigation(popup_policy_info); |
| 764 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 764 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
| 765 | 765 |
| 766 // Clean up after the new view so we don't leak it. | 766 // Clean up after the new view so we don't leak it. |
| 767 new_view->Close(); | 767 new_view->Close(); |
| 768 new_view->Release(); | 768 new_view->Release(); |
| 769 } | 769 } |
| 770 | 770 |
| 771 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is | |
| 772 // already swapped out. http://crbug.com/93427. | |
| 773 TEST_F(RenderViewImplTest, SendSwapOutACK) { | |
| 774 // This test is invalid in --site-per-process mode, as swapped-out is no | |
| 775 // longer used. | |
| 776 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | |
| 777 return; | |
| 778 } | |
| 779 LoadHTML("<div>Page A</div>"); | |
| 780 int initial_page_id = view_page_id(); | |
| 781 | |
| 782 // Increment the ref count so that we don't exit when swapping out. | |
| 783 RenderProcess::current()->AddRefProcess(); | |
| 784 | |
| 785 // Respond to a swap out request. | |
| 786 frame()->SwapOut(kProxyRoutingId, true, | |
| 787 ReconstructReplicationStateForTesting(frame())); | |
| 788 | |
| 789 // Ensure the swap out commits synchronously. | |
| 790 EXPECT_NE(initial_page_id, view_page_id()); | |
| 791 | |
| 792 // Check for a valid OnSwapOutACK. | |
| 793 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | |
| 794 FrameHostMsg_SwapOut_ACK::ID); | |
| 795 ASSERT_TRUE(msg); | |
| 796 | |
| 797 // It is possible to get another swap out request. Ensure that we send | |
| 798 // an ACK, even if we don't have to do anything else. | |
| 799 render_thread_->sink().ClearMessages(); | |
| 800 frame()->SwapOut(kProxyRoutingId, false, | |
| 801 ReconstructReplicationStateForTesting(frame())); | |
| 802 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( | |
| 803 FrameHostMsg_SwapOut_ACK::ID); | |
| 804 ASSERT_TRUE(msg2); | |
| 805 | |
| 806 // If we navigate back to this RenderView, ensure we don't send a state | |
| 807 // update for the swapped out URL. (http://crbug.com/72235) | |
| 808 CommonNavigationParams common_params; | |
| 809 RequestNavigationParams request_params; | |
| 810 common_params.url = GURL("data:text/html,<div>Page B</div>"); | |
| 811 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
| 812 common_params.transition = ui::PAGE_TRANSITION_TYPED; | |
| 813 request_params.current_history_list_length = 1; | |
| 814 request_params.current_history_list_offset = 0; | |
| 815 request_params.pending_history_list_offset = 1; | |
| 816 request_params.page_id = -1; | |
| 817 frame()->Navigate(common_params, StartNavigationParams(), request_params); | |
| 818 ProcessPendingMessages(); | |
| 819 const IPC::Message* msg3 = render_thread_->sink().GetUniqueMessageMatching( | |
| 820 ViewHostMsg_UpdateState::ID); | |
| 821 EXPECT_FALSE(msg3); | |
| 822 } | |
| 823 | |
| 824 // Ensure the RenderViewImpl reloads the previous page if a reload request | |
| 825 // arrives while it is showing swappedout://. http://crbug.com/143155. | |
| 826 TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { | |
| 827 // This test is invalid in --site-per-process mode, as swapped-out is no | |
| 828 // longer used. | |
| 829 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | |
| 830 return; | |
| 831 } | |
| 832 | |
| 833 // Load page A. | |
| 834 LoadHTML("<div>Page A</div>"); | |
| 835 | |
| 836 // Load page B, which will trigger an UpdateState message for page A. | |
| 837 LoadHTML("<div>Page B</div>"); | |
| 838 | |
| 839 // Check for a valid UpdateState message for page A. | |
| 840 ProcessPendingMessages(); | |
| 841 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | |
| 842 ViewHostMsg_UpdateState::ID); | |
| 843 ASSERT_TRUE(msg_A); | |
| 844 ViewHostMsg_UpdateState::Param params; | |
| 845 ViewHostMsg_UpdateState::Read(msg_A, ¶ms); | |
| 846 int page_id_A = base::get<0>(params); | |
| 847 PageState state_A = base::get<1>(params); | |
| 848 EXPECT_EQ(1, page_id_A); | |
| 849 render_thread_->sink().ClearMessages(); | |
| 850 | |
| 851 // Back to page A (page_id 1) and commit. | |
| 852 CommonNavigationParams common_params_A; | |
| 853 RequestNavigationParams request_params_A; | |
| 854 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
| 855 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | |
| 856 request_params_A.current_history_list_length = 2; | |
| 857 request_params_A.current_history_list_offset = 1; | |
| 858 request_params_A.pending_history_list_offset = 0; | |
| 859 request_params_A.page_id = 1; | |
| 860 request_params_A.nav_entry_id = 1; | |
| 861 request_params_A.page_state = state_A; | |
| 862 frame()->Navigate(common_params_A, StartNavigationParams(), request_params_A); | |
| 863 EXPECT_EQ(1, view()->historyBackListCount()); | |
| 864 EXPECT_EQ(2, view()->historyBackListCount() + | |
| 865 view()->historyForwardListCount() + 1); | |
| 866 ProcessPendingMessages(); | |
| 867 | |
| 868 // Respond to a swap out request. | |
| 869 frame()->SwapOut(kProxyRoutingId, true, | |
| 870 ReconstructReplicationStateForTesting(frame())); | |
| 871 | |
| 872 // Check for a OnSwapOutACK. | |
| 873 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | |
| 874 FrameHostMsg_SwapOut_ACK::ID); | |
| 875 ASSERT_TRUE(msg); | |
| 876 render_thread_->sink().ClearMessages(); | |
| 877 | |
| 878 // It is possible to get a reload request at this point, containing the | |
| 879 // params.page_state of the initial page (e.g., if the new page fails the | |
| 880 // provisional load in the renderer process, after we unload the old page). | |
| 881 // Ensure the old page gets reloaded, not swappedout://. | |
| 882 CommonNavigationParams common_params; | |
| 883 RequestNavigationParams request_params; | |
| 884 common_params.url = GURL("data:text/html,<div>Page A</div>"); | |
| 885 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; | |
| 886 common_params.transition = ui::PAGE_TRANSITION_RELOAD; | |
| 887 request_params.current_history_list_length = 2; | |
| 888 request_params.current_history_list_offset = 0; | |
| 889 request_params.pending_history_list_offset = 0; | |
| 890 request_params.page_id = 1; | |
| 891 request_params.nav_entry_id = 1; | |
| 892 request_params.page_state = state_A; | |
| 893 frame()->Navigate(common_params, StartNavigationParams(), request_params); | |
| 894 ProcessPendingMessages(); | |
| 895 | |
| 896 // Verify page A committed, not swappedout://. | |
| 897 const IPC::Message* frame_navigate_msg = | |
| 898 render_thread_->sink().GetUniqueMessageMatching( | |
| 899 FrameHostMsg_DidCommitProvisionalLoad::ID); | |
| 900 EXPECT_TRUE(frame_navigate_msg); | |
| 901 | |
| 902 // Read URL out of the parent trait of the params object. | |
| 903 FrameHostMsg_DidCommitProvisionalLoad::Param commit_load_params; | |
| 904 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, | |
| 905 &commit_load_params); | |
| 906 EXPECT_NE(GURL("swappedout://"), base::get<0>(commit_load_params).url); | |
| 907 } | |
| 908 | |
| 909 // Verify that security origins are replicated properly to RenderFrameProxies | 771 // Verify that security origins are replicated properly to RenderFrameProxies |
| 910 // when swapping out. | 772 // when swapping out. |
| 911 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { | 773 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { |
| 912 // This test should only run with --site-per-process, since origin | 774 // This test should only run with --site-per-process, since origin |
| 913 // replication only happens in that mode. | 775 // replication only happens in that mode. |
| 914 if (!AreAllSitesIsolatedForTesting()) | 776 if (!AreAllSitesIsolatedForTesting()) |
| 915 return; | 777 return; |
| 916 | 778 |
| 917 LoadHTML( | 779 LoadHTML( |
| 918 "Hello <iframe src='data:text/html,frame 1'></iframe>" | 780 "Hello <iframe src='data:text/html,frame 1'></iframe>" |
| (...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2475 FROM_HERE, | 2337 FROM_HERE, |
| 2476 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2338 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
| 2477 ExecuteJavaScriptForTests("debugger;"); | 2339 ExecuteJavaScriptForTests("debugger;"); |
| 2478 | 2340 |
| 2479 // CloseWhilePaused should resume execution and continue here. | 2341 // CloseWhilePaused should resume execution and continue here. |
| 2480 EXPECT_FALSE(IsPaused()); | 2342 EXPECT_FALSE(IsPaused()); |
| 2481 Detach(); | 2343 Detach(); |
| 2482 } | 2344 } |
| 2483 | 2345 |
| 2484 } // namespace content | 2346 } // namespace content |
| OLD | NEW |