| 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 #include <tuple> | 7 #include <tuple> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "content/public/renderer/content_renderer_client.h" | 43 #include "content/public/renderer/content_renderer_client.h" |
| 44 #include "content/public/renderer/document_state.h" | 44 #include "content/public/renderer/document_state.h" |
| 45 #include "content/public/renderer/navigation_state.h" | 45 #include "content/public/renderer/navigation_state.h" |
| 46 #include "content/public/test/browser_test_utils.h" | 46 #include "content/public/test/browser_test_utils.h" |
| 47 #include "content/public/test/frame_load_waiter.h" | 47 #include "content/public/test/frame_load_waiter.h" |
| 48 #include "content/public/test/render_view_test.h" | 48 #include "content/public/test/render_view_test.h" |
| 49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
| 50 #include "content/renderer/accessibility/render_accessibility_impl.h" | 50 #include "content/renderer/accessibility/render_accessibility_impl.h" |
| 51 #include "content/renderer/devtools/devtools_agent.h" | 51 #include "content/renderer/devtools/devtools_agent.h" |
| 52 #include "content/renderer/gpu/render_widget_compositor.h" | 52 #include "content/renderer/gpu/render_widget_compositor.h" |
| 53 #include "content/renderer/history_controller.h" | 53 #include "content/renderer/history_entry.h" |
| 54 #include "content/renderer/history_serialization.h" | 54 #include "content/renderer/history_serialization.h" |
| 55 #include "content/renderer/navigation_state_impl.h" | 55 #include "content/renderer/navigation_state_impl.h" |
| 56 #include "content/renderer/render_frame_proxy.h" | 56 #include "content/renderer/render_frame_proxy.h" |
| 57 #include "content/renderer/render_process.h" | 57 #include "content/renderer/render_process.h" |
| 58 #include "content/renderer/render_view_impl.h" | 58 #include "content/renderer/render_view_impl.h" |
| 59 #include "content/shell/browser/shell.h" | 59 #include "content/shell/browser/shell.h" |
| 60 #include "content/shell/browser/shell_browser_context.h" | 60 #include "content/shell/browser/shell_browser_context.h" |
| 61 #include "content/test/mock_keyboard.h" | 61 #include "content/test/mock_keyboard.h" |
| 62 #include "content/test/test_render_frame.h" | 62 #include "content/test/test_render_frame.h" |
| 63 #include "net/base/net_errors.h" | 63 #include "net/base/net_errors.h" |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 578 } |
| 579 | 579 |
| 580 // Test that we get form state change notifications when input fields change. | 580 // Test that we get form state change notifications when input fields change. |
| 581 TEST_F(RenderViewImplTest, OnNavStateChanged) { | 581 TEST_F(RenderViewImplTest, OnNavStateChanged) { |
| 582 view()->set_send_content_state_immediately(true); | 582 view()->set_send_content_state_immediately(true); |
| 583 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); | 583 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); |
| 584 | 584 |
| 585 // We should NOT have gotten a form state change notification yet. | 585 // We should NOT have gotten a form state change notification yet. |
| 586 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 586 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 587 FrameHostMsg_UpdateState::ID)); | 587 FrameHostMsg_UpdateState::ID)); |
| 588 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | |
| 589 ViewHostMsg_UpdateState::ID)); | |
| 590 render_thread_->sink().ClearMessages(); | 588 render_thread_->sink().ClearMessages(); |
| 591 | 589 |
| 592 // Change the value of the input. We should have gotten an update state | 590 // Change the value of the input. We should have gotten an update state |
| 593 // notification. We need to spin the message loop to catch this update. | 591 // notification. We need to spin the message loop to catch this update. |
| 594 ExecuteJavaScriptForTests( | 592 ExecuteJavaScriptForTests( |
| 595 "document.getElementById('elt_text').value = 'foo';"); | 593 "document.getElementById('elt_text').value = 'foo';"); |
| 596 ProcessPendingMessages(); | 594 ProcessPendingMessages(); |
| 597 | 595 |
| 598 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 596 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
| 599 FrameHostMsg_UpdateState::ID)); | 597 FrameHostMsg_UpdateState::ID)); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { | 928 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { |
| 931 // Load page A. | 929 // Load page A. |
| 932 LoadHTML("<div>Page A</div>"); | 930 LoadHTML("<div>Page A</div>"); |
| 933 | 931 |
| 934 // Load page B, which will trigger an UpdateState message for page A. | 932 // Load page B, which will trigger an UpdateState message for page A. |
| 935 LoadHTML("<div>Page B</div>"); | 933 LoadHTML("<div>Page B</div>"); |
| 936 | 934 |
| 937 // Check for a valid UpdateState message for page A. | 935 // Check for a valid UpdateState message for page A. |
| 938 ProcessPendingMessages(); | 936 ProcessPendingMessages(); |
| 939 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 937 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 940 ViewHostMsg_UpdateState::ID); | 938 FrameHostMsg_UpdateState::ID); |
| 941 ASSERT_TRUE(msg_A); | 939 ASSERT_TRUE(msg_A); |
| 942 ViewHostMsg_UpdateState::Param param; | 940 FrameHostMsg_UpdateState::Param param; |
| 943 ViewHostMsg_UpdateState::Read(msg_A, ¶m); | 941 FrameHostMsg_UpdateState::Read(msg_A, ¶m); |
| 944 PageState state_A = std::get<0>(param); | 942 PageState state_A = std::get<0>(param); |
| 945 render_thread_->sink().ClearMessages(); | 943 render_thread_->sink().ClearMessages(); |
| 946 | 944 |
| 947 // Load page C, which will trigger an UpdateState message for page B. | 945 // Load page C, which will trigger an UpdateState message for page B. |
| 948 LoadHTML("<div>Page C</div>"); | 946 LoadHTML("<div>Page C</div>"); |
| 949 | 947 |
| 950 // Check for a valid UpdateState for page B. | 948 // Check for a valid UpdateState for page B. |
| 951 ProcessPendingMessages(); | 949 ProcessPendingMessages(); |
| 952 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( | 950 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( |
| 953 ViewHostMsg_UpdateState::ID); | 951 FrameHostMsg_UpdateState::ID); |
| 954 ASSERT_TRUE(msg_B); | 952 ASSERT_TRUE(msg_B); |
| 955 ViewHostMsg_UpdateState::Read(msg_B, ¶m); | 953 FrameHostMsg_UpdateState::Read(msg_B, ¶m); |
| 956 PageState state_B = std::get<0>(param); | 954 PageState state_B = std::get<0>(param); |
| 957 EXPECT_NE(state_A, state_B); | 955 EXPECT_NE(state_A, state_B); |
| 958 render_thread_->sink().ClearMessages(); | 956 render_thread_->sink().ClearMessages(); |
| 959 | 957 |
| 960 // Load page D, which will trigger an UpdateState message for page C. | 958 // Load page D, which will trigger an UpdateState message for page C. |
| 961 LoadHTML("<div>Page D</div>"); | 959 LoadHTML("<div>Page D</div>"); |
| 962 | 960 |
| 963 // Check for a valid UpdateState for page C. | 961 // Check for a valid UpdateState for page C. |
| 964 ProcessPendingMessages(); | 962 ProcessPendingMessages(); |
| 965 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( | 963 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( |
| 966 ViewHostMsg_UpdateState::ID); | 964 FrameHostMsg_UpdateState::ID); |
| 967 ASSERT_TRUE(msg_C); | 965 ASSERT_TRUE(msg_C); |
| 968 ViewHostMsg_UpdateState::Read(msg_C, ¶m); | 966 FrameHostMsg_UpdateState::Read(msg_C, ¶m); |
| 969 PageState state_C = std::get<0>(param); | 967 PageState state_C = std::get<0>(param); |
| 970 EXPECT_NE(state_B, state_C); | 968 EXPECT_NE(state_B, state_C); |
| 971 render_thread_->sink().ClearMessages(); | 969 render_thread_->sink().ClearMessages(); |
| 972 | 970 |
| 973 // Go back to C and commit, preparing for our real test. | 971 // Go back to C and commit, preparing for our real test. |
| 974 CommonNavigationParams common_params_C; | 972 CommonNavigationParams common_params_C; |
| 975 RequestNavigationParams request_params_C; | 973 RequestNavigationParams request_params_C; |
| 976 common_params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 974 common_params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 977 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 975 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 978 request_params_C.current_history_list_length = 4; | 976 request_params_C.current_history_list_length = 4; |
| 979 request_params_C.current_history_list_offset = 3; | 977 request_params_C.current_history_list_offset = 3; |
| 980 request_params_C.pending_history_list_offset = 2; | 978 request_params_C.pending_history_list_offset = 2; |
| 979 request_params_C.nav_entry_id = 3; |
| 981 request_params_C.page_state = state_C; | 980 request_params_C.page_state = state_C; |
| 982 frame()->Navigate(common_params_C, StartNavigationParams(), request_params_C); | 981 frame()->Navigate(common_params_C, StartNavigationParams(), request_params_C); |
| 983 ProcessPendingMessages(); | 982 ProcessPendingMessages(); |
| 984 render_thread_->sink().ClearMessages(); | 983 render_thread_->sink().ClearMessages(); |
| 985 | 984 |
| 986 // Go back twice quickly, such that page B does not have a chance to commit. | 985 // Go back twice quickly, such that page B does not have a chance to commit. |
| 987 // This leads to two changes to the back/forward list but only one change to | 986 // This leads to two changes to the back/forward list but only one change to |
| 988 // the RenderView's page ID. | 987 // the RenderView's page ID. |
| 989 | 988 |
| 990 // Back to page B without committing. | 989 // Back to page B without committing. |
| 991 CommonNavigationParams common_params_B; | 990 CommonNavigationParams common_params_B; |
| 992 RequestNavigationParams request_params_B; | 991 RequestNavigationParams request_params_B; |
| 993 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 992 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 994 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 993 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 995 request_params_B.current_history_list_length = 4; | 994 request_params_B.current_history_list_length = 4; |
| 996 request_params_B.current_history_list_offset = 2; | 995 request_params_B.current_history_list_offset = 2; |
| 997 request_params_B.pending_history_list_offset = 1; | 996 request_params_B.pending_history_list_offset = 1; |
| 997 request_params_B.nav_entry_id = 2; |
| 998 request_params_B.page_state = state_B; | 998 request_params_B.page_state = state_B; |
| 999 frame()->Navigate(common_params_B, StartNavigationParams(), request_params_B); | 999 frame()->Navigate(common_params_B, StartNavigationParams(), request_params_B); |
| 1000 | 1000 |
| 1001 // Back to page A and commit. | 1001 // Back to page A and commit. |
| 1002 CommonNavigationParams common_params; | 1002 CommonNavigationParams common_params; |
| 1003 RequestNavigationParams request_params; | 1003 RequestNavigationParams request_params; |
| 1004 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 1004 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
| 1005 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 1005 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
| 1006 request_params.current_history_list_length = 4; | 1006 request_params.current_history_list_length = 4; |
| 1007 request_params.current_history_list_offset = 2; | 1007 request_params.current_history_list_offset = 2; |
| 1008 request_params.pending_history_list_offset = 0; | 1008 request_params.pending_history_list_offset = 0; |
| 1009 request_params.nav_entry_id = 1; |
| 1009 request_params.page_state = state_A; | 1010 request_params.page_state = state_A; |
| 1010 frame()->Navigate(common_params, StartNavigationParams(), request_params); | 1011 frame()->Navigate(common_params, StartNavigationParams(), request_params); |
| 1011 ProcessPendingMessages(); | 1012 ProcessPendingMessages(); |
| 1012 | 1013 |
| 1013 // Now ensure that the UpdateState message we receive is consistent | 1014 // Now ensure that the UpdateState message we receive is consistent |
| 1014 // and represents page C in state. | 1015 // and represents page C in state. |
| 1015 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 1016 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 1016 ViewHostMsg_UpdateState::ID); | 1017 FrameHostMsg_UpdateState::ID); |
| 1017 ASSERT_TRUE(msg); | 1018 ASSERT_TRUE(msg); |
| 1018 ViewHostMsg_UpdateState::Read(msg, ¶m); | 1019 FrameHostMsg_UpdateState::Read(msg, ¶m); |
| 1019 PageState state = std::get<0>(param); | 1020 PageState state = std::get<0>(param); |
| 1020 EXPECT_NE(state_A, state); | 1021 EXPECT_NE(state_A, state); |
| 1021 EXPECT_NE(state_B, state); | 1022 EXPECT_NE(state_B, state); |
| 1022 EXPECT_EQ(state_C, state); | 1023 EXPECT_EQ(state_C, state); |
| 1023 } | 1024 } |
| 1024 | 1025 |
| 1025 // Test that our IME backend sends a notification message when the input focus | 1026 // Test that our IME backend sends a notification message when the input focus |
| 1026 // changes. | 1027 // changes. |
| 1027 TEST_F(RenderViewImplTest, OnImeTypeChanged) { | 1028 TEST_F(RenderViewImplTest, OnImeTypeChanged) { |
| 1028 // Load an HTML page consisting of two input fields. | 1029 // Load an HTML page consisting of two input fields. |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2555 ExpectPauseAndResume(3); | 2556 ExpectPauseAndResume(3); |
| 2556 blink::WebScriptSource source2( | 2557 blink::WebScriptSource source2( |
| 2557 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2558 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
| 2558 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1); | 2559 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1); |
| 2559 | 2560 |
| 2560 EXPECT_FALSE(IsPaused()); | 2561 EXPECT_FALSE(IsPaused()); |
| 2561 Detach(); | 2562 Detach(); |
| 2562 } | 2563 } |
| 2563 | 2564 |
| 2564 } // namespace content | 2565 } // namespace content |
| OLD | NEW |