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" |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 709 |
710 // Back to page A (page_id 1) and commit. | 710 // Back to page A (page_id 1) and commit. |
711 CommonNavigationParams common_params_A; | 711 CommonNavigationParams common_params_A; |
712 RequestNavigationParams request_params_A; | 712 RequestNavigationParams request_params_A; |
713 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 713 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
714 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 714 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
715 request_params_A.current_history_list_length = 2; | 715 request_params_A.current_history_list_length = 2; |
716 request_params_A.current_history_list_offset = 1; | 716 request_params_A.current_history_list_offset = 1; |
717 request_params_A.pending_history_list_offset = 0; | 717 request_params_A.pending_history_list_offset = 0; |
718 request_params_A.page_id = 1; | 718 request_params_A.page_id = 1; |
| 719 request_params_A.nav_entry_id = 1; |
719 request_params_A.page_state = state_A; | 720 request_params_A.page_state = state_A; |
720 NavigateMainFrame(common_params_A, StartNavigationParams(), request_params_A); | 721 NavigateMainFrame(common_params_A, StartNavigationParams(), request_params_A); |
721 EXPECT_EQ(1, view()->historyBackListCount()); | 722 EXPECT_EQ(1, view()->historyBackListCount()); |
722 EXPECT_EQ(2, view()->historyBackListCount() + | 723 EXPECT_EQ(2, view()->historyBackListCount() + |
723 view()->historyForwardListCount() + 1); | 724 view()->historyForwardListCount() + 1); |
724 ProcessPendingMessages(); | 725 ProcessPendingMessages(); |
725 | 726 |
726 // Respond to a swap out request. | 727 // Respond to a swap out request. |
727 SwapOut(frame(), kProxyRoutingId, true, content::FrameReplicationState()); | 728 SwapOut(frame(), kProxyRoutingId, true, content::FrameReplicationState()); |
728 | 729 |
729 // Check for a OnSwapOutACK. | 730 // Check for a OnSwapOutACK. |
730 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 731 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
731 FrameHostMsg_SwapOut_ACK::ID); | 732 FrameHostMsg_SwapOut_ACK::ID); |
732 ASSERT_TRUE(msg); | 733 ASSERT_TRUE(msg); |
733 render_thread_->sink().ClearMessages(); | 734 render_thread_->sink().ClearMessages(); |
734 | 735 |
735 // It is possible to get a reload request at this point, containing the | 736 // It is possible to get a reload request at this point, containing the |
736 // params.page_state of the initial page (e.g., if the new page fails the | 737 // params.page_state of the initial page (e.g., if the new page fails the |
737 // provisional load in the renderer process, after we unload the old page). | 738 // provisional load in the renderer process, after we unload the old page). |
738 // Ensure the old page gets reloaded, not swappedout://. | 739 // Ensure the old page gets reloaded, not swappedout://. |
739 CommonNavigationParams common_params; | 740 CommonNavigationParams common_params; |
740 RequestNavigationParams request_params; | 741 RequestNavigationParams request_params; |
741 common_params.url = GURL("data:text/html,<div>Page A</div>"); | 742 common_params.url = GURL("data:text/html,<div>Page A</div>"); |
742 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; | 743 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; |
743 common_params.transition = ui::PAGE_TRANSITION_RELOAD; | 744 common_params.transition = ui::PAGE_TRANSITION_RELOAD; |
744 request_params.current_history_list_length = 2; | 745 request_params.current_history_list_length = 2; |
745 request_params.current_history_list_offset = 0; | 746 request_params.current_history_list_offset = 0; |
746 request_params.pending_history_list_offset = 0; | 747 request_params.pending_history_list_offset = 0; |
747 request_params.page_id = 1; | 748 request_params.page_id = 1; |
| 749 request_params.nav_entry_id = 1; |
748 request_params.page_state = state_A; | 750 request_params.page_state = state_A; |
749 NavigateMainFrame(common_params, StartNavigationParams(), request_params); | 751 NavigateMainFrame(common_params, StartNavigationParams(), request_params); |
750 ProcessPendingMessages(); | 752 ProcessPendingMessages(); |
751 | 753 |
752 // Verify page A committed, not swappedout://. | 754 // Verify page A committed, not swappedout://. |
753 const IPC::Message* frame_navigate_msg = | 755 const IPC::Message* frame_navigate_msg = |
754 render_thread_->sink().GetUniqueMessageMatching( | 756 render_thread_->sink().GetUniqueMessageMatching( |
755 FrameHostMsg_DidCommitProvisionalLoad::ID); | 757 FrameHostMsg_DidCommitProvisionalLoad::ID); |
756 EXPECT_TRUE(frame_navigate_msg); | 758 EXPECT_TRUE(frame_navigate_msg); |
757 | 759 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 EXPECT_EQ(page_id_C, page_id); | 910 EXPECT_EQ(page_id_C, page_id); |
909 EXPECT_NE(state_A, state); | 911 EXPECT_NE(state_A, state); |
910 EXPECT_NE(state_B, state); | 912 EXPECT_NE(state_B, state); |
911 EXPECT_EQ(state_C, state); | 913 EXPECT_EQ(state_C, state); |
912 } | 914 } |
913 | 915 |
914 // Test that stale back/forward navigations arriving from the browser are | 916 // Test that stale back/forward navigations arriving from the browser are |
915 // ignored. See http://crbug.com/86758. | 917 // ignored. See http://crbug.com/86758. |
916 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { | 918 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { |
917 // Load page A. | 919 // Load page A. |
918 LoadHTML("<div>Page A</div>"); | 920 LoadHTML("<div id=pagename>Page A</div>"); |
919 EXPECT_EQ(1, view()->history_list_length_); | 921 EXPECT_EQ(1, view()->history_list_length_); |
920 EXPECT_EQ(0, view()->history_list_offset_); | 922 EXPECT_EQ(0, view()->history_list_offset_); |
921 | 923 |
922 // Load page B, which will trigger an UpdateState message for page A. | 924 // Load page B, which will trigger an UpdateState message for page A. |
923 LoadHTML("<div>Page B</div>"); | 925 LoadHTML("<div id=pagename>Page B</div>"); |
924 EXPECT_EQ(2, view()->history_list_length_); | 926 EXPECT_EQ(2, view()->history_list_length_); |
925 EXPECT_EQ(1, view()->history_list_offset_); | 927 EXPECT_EQ(1, view()->history_list_offset_); |
926 | 928 |
927 // Check for a valid UpdateState message for page A. | 929 // Check for a valid UpdateState message for page A. |
928 ProcessPendingMessages(); | 930 ProcessPendingMessages(); |
929 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 931 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
930 ViewHostMsg_UpdateState::ID); | 932 ViewHostMsg_UpdateState::ID); |
931 ASSERT_TRUE(msg_A); | 933 ASSERT_TRUE(msg_A); |
932 ViewHostMsg_UpdateState::Param param; | 934 ViewHostMsg_UpdateState::Param param; |
933 ViewHostMsg_UpdateState::Read(msg_A, ¶m); | 935 ViewHostMsg_UpdateState::Read(msg_A, ¶m); |
934 int page_id_A = get<0>(param); | 936 int page_id_A = get<0>(param); |
935 PageState state_A = get<1>(param); | 937 PageState state_A = get<1>(param); |
936 EXPECT_EQ(1, page_id_A); | 938 EXPECT_EQ(1, page_id_A); |
937 render_thread_->sink().ClearMessages(); | 939 render_thread_->sink().ClearMessages(); |
938 | 940 |
939 // Back to page A (page_id 1) and commit. | 941 // Back to page A (nav_entry_id 1) and commit. |
940 CommonNavigationParams common_params_A; | 942 CommonNavigationParams common_params_A; |
941 RequestNavigationParams request_params_A; | 943 RequestNavigationParams request_params_A; |
942 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 944 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
943 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 945 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
944 request_params_A.current_history_list_length = 2; | 946 request_params_A.current_history_list_length = 2; |
945 request_params_A.current_history_list_offset = 1; | 947 request_params_A.current_history_list_offset = 1; |
946 request_params_A.pending_history_list_offset = 0; | 948 request_params_A.pending_history_list_offset = 0; |
947 request_params_A.page_id = 1; | 949 request_params_A.page_id = 1; |
| 950 request_params_A.nav_entry_id = 1; |
948 request_params_A.page_state = state_A; | 951 request_params_A.page_state = state_A; |
949 NavigateMainFrame(common_params_A, StartNavigationParams(), request_params_A); | 952 NavigateMainFrame(common_params_A, StartNavigationParams(), request_params_A); |
950 ProcessPendingMessages(); | 953 ProcessPendingMessages(); |
951 | 954 |
952 // A new navigation commits, clearing the forward history. | 955 // A new navigation commits, clearing the forward history. |
953 LoadHTML("<div>Page C</div>"); | 956 LoadHTML("<div id=pagename>Page C</div>"); |
954 EXPECT_EQ(2, view()->history_list_length_); | 957 EXPECT_EQ(2, view()->history_list_length_); |
955 EXPECT_EQ(1, view()->history_list_offset_); | 958 EXPECT_EQ(1, view()->history_list_offset_); |
956 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3 | 959 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3 |
| 960 int was_page_c = -1; |
| 961 base::string16 check_page_c = base::ASCIIToUTF16( |
| 962 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); |
| 963 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
| 964 EXPECT_EQ(1, was_page_c); |
957 | 965 |
958 // The browser then sends a stale navigation to B, which should be ignored. | 966 // The browser then sends a stale navigation to B, which should be ignored. |
959 CommonNavigationParams common_params_B; | 967 CommonNavigationParams common_params_B; |
960 RequestNavigationParams request_params_B; | 968 RequestNavigationParams request_params_B; |
961 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 969 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
962 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 970 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
963 request_params_B.current_history_list_length = 2; | 971 request_params_B.current_history_list_length = 2; |
964 request_params_B.current_history_list_offset = 0; | 972 request_params_B.current_history_list_offset = 0; |
965 request_params_B.pending_history_list_offset = 1; | 973 request_params_B.pending_history_list_offset = 1; |
966 request_params_B.page_id = 2; | 974 request_params_B.page_id = 2; |
| 975 request_params_B.nav_entry_id = 2; |
967 request_params_B.page_state = | 976 request_params_B.page_state = |
968 state_A; // Doesn't matter, just has to be present. | 977 state_A; // Doesn't matter, just has to be present. |
969 NavigateMainFrame(common_params_B, StartNavigationParams(), request_params_B); | 978 NavigateMainFrame(common_params_B, StartNavigationParams(), request_params_B); |
970 | 979 |
971 // State should be unchanged. | 980 // State should be unchanged. |
972 EXPECT_EQ(2, view()->history_list_length_); | 981 EXPECT_EQ(2, view()->history_list_length_); |
973 EXPECT_EQ(1, view()->history_list_offset_); | 982 EXPECT_EQ(1, view()->history_list_offset_); |
974 EXPECT_EQ(3, view()->page_id_); // page C, not page B | 983 EXPECT_EQ(3, view()->page_id_); // page C, not page B |
| 984 was_page_c = -1; |
| 985 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
| 986 EXPECT_EQ(1, was_page_c); |
975 | 987 |
976 // Check for a valid DidDropNavigation message. | 988 // Check for a valid DidDropNavigation message. |
977 ProcessPendingMessages(); | 989 ProcessPendingMessages(); |
978 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 990 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
979 FrameHostMsg_DidDropNavigation::ID); | 991 FrameHostMsg_DidDropNavigation::ID); |
980 ASSERT_TRUE(msg); | 992 ASSERT_TRUE(msg); |
981 render_thread_->sink().ClearMessages(); | 993 render_thread_->sink().ClearMessages(); |
982 } | 994 } |
983 | 995 |
984 // Test that our IME backend sends a notification message when the input focus | 996 // Test that our IME backend sends a notification message when the input focus |
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2422 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 2434 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
2423 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2435 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2424 ExecuteJavaScript("debugger;"); | 2436 ExecuteJavaScript("debugger;"); |
2425 | 2437 |
2426 // CloseWhilePaused should resume execution and continue here. | 2438 // CloseWhilePaused should resume execution and continue here. |
2427 EXPECT_FALSE(IsPaused()); | 2439 EXPECT_FALSE(IsPaused()); |
2428 Detach(); | 2440 Detach(); |
2429 } | 2441 } |
2430 | 2442 |
2431 } // namespace content | 2443 } // namespace content |
OLD | NEW |