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