| 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 663 |
| 664 // Back to page A (page_id 1) and commit. | 664 // Back to page A (page_id 1) and commit. |
| 665 CommonNavigationParams common_params_A; | 665 CommonNavigationParams common_params_A; |
| 666 RequestNavigationParams request_params_A; | 666 RequestNavigationParams request_params_A; |
| 667 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 667 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 668 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 668 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 669 request_params_A.current_history_list_length = 2; | 669 request_params_A.current_history_list_length = 2; |
| 670 request_params_A.current_history_list_offset = 1; | 670 request_params_A.current_history_list_offset = 1; |
| 671 request_params_A.pending_history_list_offset = 0; | 671 request_params_A.pending_history_list_offset = 0; |
| 672 request_params_A.page_id = 1; | 672 request_params_A.page_id = 1; |
| 673 request_params_A.nav_entry_id = 1; |
| 673 request_params_A.page_state = state_A; | 674 request_params_A.page_state = state_A; |
| 674 frame()->OnNavigate(common_params_A, StartNavigationParams(), | 675 frame()->OnNavigate(common_params_A, StartNavigationParams(), |
| 675 request_params_A); | 676 request_params_A); |
| 676 EXPECT_EQ(1, view()->historyBackListCount()); | 677 EXPECT_EQ(1, view()->historyBackListCount()); |
| 677 EXPECT_EQ(2, view()->historyBackListCount() + | 678 EXPECT_EQ(2, view()->historyBackListCount() + |
| 678 view()->historyForwardListCount() + 1); | 679 view()->historyForwardListCount() + 1); |
| 679 ProcessPendingMessages(); | 680 ProcessPendingMessages(); |
| 680 | 681 |
| 681 // Respond to a swap out request. | 682 // Respond to a swap out request. |
| 682 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, true, | 683 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, true, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 694 // Ensure the old page gets reloaded, not swappedout://. | 695 // Ensure the old page gets reloaded, not swappedout://. |
| 695 CommonNavigationParams common_params; | 696 CommonNavigationParams common_params; |
| 696 RequestNavigationParams request_params; | 697 RequestNavigationParams request_params; |
| 697 common_params.url = GURL("data:text/html,<div>Page A</div>"); | 698 common_params.url = GURL("data:text/html,<div>Page A</div>"); |
| 698 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; | 699 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; |
| 699 common_params.transition = ui::PAGE_TRANSITION_RELOAD; | 700 common_params.transition = ui::PAGE_TRANSITION_RELOAD; |
| 700 request_params.current_history_list_length = 2; | 701 request_params.current_history_list_length = 2; |
| 701 request_params.current_history_list_offset = 0; | 702 request_params.current_history_list_offset = 0; |
| 702 request_params.pending_history_list_offset = 0; | 703 request_params.pending_history_list_offset = 0; |
| 703 request_params.page_id = 1; | 704 request_params.page_id = 1; |
| 705 request_params.nav_entry_id = 1; |
| 704 request_params.page_state = state_A; | 706 request_params.page_state = state_A; |
| 705 frame()->OnNavigate(common_params, StartNavigationParams(), request_params); | 707 frame()->OnNavigate(common_params, StartNavigationParams(), request_params); |
| 706 ProcessPendingMessages(); | 708 ProcessPendingMessages(); |
| 707 | 709 |
| 708 // Verify page A committed, not swappedout://. | 710 // Verify page A committed, not swappedout://. |
| 709 const IPC::Message* frame_navigate_msg = | 711 const IPC::Message* frame_navigate_msg = |
| 710 render_thread_->sink().GetUniqueMessageMatching( | 712 render_thread_->sink().GetUniqueMessageMatching( |
| 711 FrameHostMsg_DidCommitProvisionalLoad::ID); | 713 FrameHostMsg_DidCommitProvisionalLoad::ID); |
| 712 EXPECT_TRUE(frame_navigate_msg); | 714 EXPECT_TRUE(frame_navigate_msg); |
| 713 | 715 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 EXPECT_EQ(page_id_C, page_id); | 868 EXPECT_EQ(page_id_C, page_id); |
| 867 EXPECT_NE(state_A, state); | 869 EXPECT_NE(state_A, state); |
| 868 EXPECT_NE(state_B, state); | 870 EXPECT_NE(state_B, state); |
| 869 EXPECT_EQ(state_C, state); | 871 EXPECT_EQ(state_C, state); |
| 870 } | 872 } |
| 871 | 873 |
| 872 // Test that stale back/forward navigations arriving from the browser are | 874 // Test that stale back/forward navigations arriving from the browser are |
| 873 // ignored. See http://crbug.com/86758. | 875 // ignored. See http://crbug.com/86758. |
| 874 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { | 876 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { |
| 875 // Load page A. | 877 // Load page A. |
| 876 LoadHTML("<div>Page A</div>"); | 878 LoadHTML("<div id=pagename>Page A</div>"); |
| 877 EXPECT_EQ(1, view()->history_list_length_); | 879 EXPECT_EQ(1, view()->history_list_length_); |
| 878 EXPECT_EQ(0, view()->history_list_offset_); | 880 EXPECT_EQ(0, view()->history_list_offset_); |
| 879 | 881 |
| 880 // Load page B, which will trigger an UpdateState message for page A. | 882 // Load page B, which will trigger an UpdateState message for page A. |
| 881 LoadHTML("<div>Page B</div>"); | 883 LoadHTML("<div id=pagename>Page B</div>"); |
| 882 EXPECT_EQ(2, view()->history_list_length_); | 884 EXPECT_EQ(2, view()->history_list_length_); |
| 883 EXPECT_EQ(1, view()->history_list_offset_); | 885 EXPECT_EQ(1, view()->history_list_offset_); |
| 884 | 886 |
| 885 // Check for a valid UpdateState message for page A. | 887 // Check for a valid UpdateState message for page A. |
| 886 ProcessPendingMessages(); | 888 ProcessPendingMessages(); |
| 887 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 889 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 888 ViewHostMsg_UpdateState::ID); | 890 ViewHostMsg_UpdateState::ID); |
| 889 ASSERT_TRUE(msg_A); | 891 ASSERT_TRUE(msg_A); |
| 890 ViewHostMsg_UpdateState::Param param; | 892 ViewHostMsg_UpdateState::Param param; |
| 891 ViewHostMsg_UpdateState::Read(msg_A, ¶m); | 893 ViewHostMsg_UpdateState::Read(msg_A, ¶m); |
| 892 int page_id_A = get<0>(param); | 894 int page_id_A = get<0>(param); |
| 893 PageState state_A = get<1>(param); | 895 PageState state_A = get<1>(param); |
| 894 EXPECT_EQ(1, page_id_A); | 896 EXPECT_EQ(1, page_id_A); |
| 895 render_thread_->sink().ClearMessages(); | 897 render_thread_->sink().ClearMessages(); |
| 896 | 898 |
| 897 // Back to page A (page_id 1) and commit. | 899 // Back to page A (nav_entry_id 1) and commit. |
| 898 CommonNavigationParams common_params_A; | 900 CommonNavigationParams common_params_A; |
| 899 RequestNavigationParams request_params_A; | 901 RequestNavigationParams request_params_A; |
| 900 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 902 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 901 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 903 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 902 request_params_A.current_history_list_length = 2; | 904 request_params_A.current_history_list_length = 2; |
| 903 request_params_A.current_history_list_offset = 1; | 905 request_params_A.current_history_list_offset = 1; |
| 904 request_params_A.pending_history_list_offset = 0; | 906 request_params_A.pending_history_list_offset = 0; |
| 905 request_params_A.page_id = 1; | 907 request_params_A.page_id = 1; |
| 908 request_params_A.nav_entry_id = 1; |
| 906 request_params_A.page_state = state_A; | 909 request_params_A.page_state = state_A; |
| 907 frame()->OnNavigate(common_params_A, StartNavigationParams(), | 910 frame()->OnNavigate(common_params_A, StartNavigationParams(), |
| 908 request_params_A); | 911 request_params_A); |
| 909 ProcessPendingMessages(); | 912 ProcessPendingMessages(); |
| 910 | 913 |
| 911 // A new navigation commits, clearing the forward history. | 914 // A new navigation commits, clearing the forward history. |
| 912 LoadHTML("<div>Page C</div>"); | 915 LoadHTML("<div id=pagename>Page C</div>"); |
| 913 EXPECT_EQ(2, view()->history_list_length_); | 916 EXPECT_EQ(2, view()->history_list_length_); |
| 914 EXPECT_EQ(1, view()->history_list_offset_); | 917 EXPECT_EQ(1, view()->history_list_offset_); |
| 915 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3 | 918 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3 |
| 919 int was_page_c = -1; |
| 920 base::string16 check_page_c = base::ASCIIToUTF16( |
| 921 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); |
| 922 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
| 923 EXPECT_EQ(1, was_page_c); |
| 916 | 924 |
| 917 // The browser then sends a stale navigation to B, which should be ignored. | 925 // The browser then sends a stale navigation to B, which should be ignored. |
| 918 CommonNavigationParams common_params_B; | 926 CommonNavigationParams common_params_B; |
| 919 RequestNavigationParams request_params_B; | 927 RequestNavigationParams request_params_B; |
| 920 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 928 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 921 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 929 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 922 request_params_B.current_history_list_length = 2; | 930 request_params_B.current_history_list_length = 2; |
| 923 request_params_B.current_history_list_offset = 0; | 931 request_params_B.current_history_list_offset = 0; |
| 924 request_params_B.pending_history_list_offset = 1; | 932 request_params_B.pending_history_list_offset = 1; |
| 925 request_params_B.page_id = 2; | 933 request_params_B.page_id = 2; |
| 934 request_params_B.nav_entry_id = 2; |
| 926 request_params_B.page_state = | 935 request_params_B.page_state = |
| 927 state_A; // Doesn't matter, just has to be present. | 936 state_A; // Doesn't matter, just has to be present. |
| 928 frame()->OnNavigate(common_params_B, StartNavigationParams(), | 937 frame()->OnNavigate(common_params_B, StartNavigationParams(), |
| 929 request_params_B); | 938 request_params_B); |
| 930 | 939 |
| 931 // State should be unchanged. | 940 // State should be unchanged. |
| 932 EXPECT_EQ(2, view()->history_list_length_); | 941 EXPECT_EQ(2, view()->history_list_length_); |
| 933 EXPECT_EQ(1, view()->history_list_offset_); | 942 EXPECT_EQ(1, view()->history_list_offset_); |
| 934 EXPECT_EQ(3, view()->page_id_); // page C, not page B | 943 EXPECT_EQ(3, view()->page_id_); // page C, not page B |
| 944 was_page_c = -1; |
| 945 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
| 946 EXPECT_EQ(1, was_page_c); |
| 935 | 947 |
| 936 // Check for a valid DidDropNavigation message. | 948 // Check for a valid DidDropNavigation message. |
| 937 ProcessPendingMessages(); | 949 ProcessPendingMessages(); |
| 938 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 950 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 939 FrameHostMsg_DidDropNavigation::ID); | 951 FrameHostMsg_DidDropNavigation::ID); |
| 940 ASSERT_TRUE(msg); | 952 ASSERT_TRUE(msg); |
| 941 render_thread_->sink().ClearMessages(); | 953 render_thread_->sink().ClearMessages(); |
| 942 } | 954 } |
| 943 | 955 |
| 944 // Test that our IME backend sends a notification message when the input focus | 956 // Test that our IME backend sends a notification message when the input focus |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 2393 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 2382 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2394 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
| 2383 ExecuteJavaScript("debugger;"); | 2395 ExecuteJavaScript("debugger;"); |
| 2384 | 2396 |
| 2385 // CloseWhilePaused should resume execution and continue here. | 2397 // CloseWhilePaused should resume execution and continue here. |
| 2386 EXPECT_FALSE(IsPaused()); | 2398 EXPECT_FALSE(IsPaused()); |
| 2387 Detach(); | 2399 Detach(); |
| 2388 } | 2400 } |
| 2389 | 2401 |
| 2390 } // namespace content | 2402 } // namespace content |
| OLD | NEW |