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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 PageStateToHistoryEntry(std::get<0>(host_nav_params).page_state); | 637 PageStateToHistoryEntry(std::get<0>(host_nav_params).page_state); |
638 blink::WebHTTPBody body = entry->root().httpBody(); | 638 blink::WebHTTPBody body = entry->root().httpBody(); |
639 blink::WebHTTPBody::Element element; | 639 blink::WebHTTPBody::Element element; |
640 bool successful = body.elementAt(0, element); | 640 bool successful = body.elementAt(0, element); |
641 EXPECT_TRUE(successful); | 641 EXPECT_TRUE(successful); |
642 EXPECT_EQ(blink::WebHTTPBody::Element::TypeData, element.type); | 642 EXPECT_EQ(blink::WebHTTPBody::Element::TypeData, element.type); |
643 EXPECT_EQ(length, element.data.size()); | 643 EXPECT_EQ(length, element.data.size()); |
644 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); | 644 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); |
645 } | 645 } |
646 | 646 |
647 // Check that page ID will be initialized in case of navigation | |
648 // that replaces current entry. | |
649 TEST_F(RenderViewImplTest, OnBrowserNavigationUpdatePageID) { | |
650 // An http url will trigger a resource load so cannot be used here. | |
651 CommonNavigationParams common_params; | |
652 StartNavigationParams start_params; | |
653 RequestNavigationParams request_params; | |
654 common_params.url = GURL("data:text/html,<div>Page</div>"); | |
655 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
656 common_params.transition = ui::PAGE_TRANSITION_TYPED; | |
657 | |
658 // Set up params to emulate a browser side navigation | |
659 // that should replace current entry. | |
660 common_params.should_replace_current_entry = true; | |
661 request_params.page_id = -1; | |
662 request_params.nav_entry_id = 1; | |
663 request_params.current_history_list_length = 1; | |
664 | |
665 frame()->Navigate(common_params, start_params, request_params); | |
666 ProcessPendingMessages(); | |
667 | |
668 // Page ID should be initialized. | |
669 EXPECT_NE(view_page_id(), -1); | |
670 | |
671 const IPC::Message* frame_navigate_msg = | |
672 render_thread_->sink().GetUniqueMessageMatching( | |
673 FrameHostMsg_DidCommitProvisionalLoad::ID); | |
674 EXPECT_TRUE(frame_navigate_msg); | |
675 | |
676 FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params; | |
677 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, | |
678 &host_nav_params); | |
679 EXPECT_TRUE(std::get<0>(host_nav_params).page_state.IsValid()); | |
680 | |
681 const IPC::Message* frame_page_id_msg = | |
682 render_thread_->sink().GetUniqueMessageMatching( | |
683 FrameHostMsg_DidAssignPageId::ID); | |
684 EXPECT_TRUE(frame_page_id_msg); | |
685 | |
686 FrameHostMsg_DidAssignPageId::Param host_page_id_params; | |
687 FrameHostMsg_DidAssignPageId::Read(frame_page_id_msg, &host_page_id_params); | |
688 | |
689 EXPECT_EQ(std::get<0>(host_page_id_params), view_page_id()); | |
690 } | |
691 | |
692 #if defined(OS_ANDROID) | 647 #if defined(OS_ANDROID) |
693 TEST_F(RenderViewImplTest, OnNavigationLoadDataWithBaseURL) { | 648 TEST_F(RenderViewImplTest, OnNavigationLoadDataWithBaseURL) { |
694 CommonNavigationParams common_params; | 649 CommonNavigationParams common_params; |
695 common_params.url = GURL("data:text/html,"); | 650 common_params.url = GURL("data:text/html,"); |
696 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 651 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
697 common_params.transition = ui::PAGE_TRANSITION_TYPED; | 652 common_params.transition = ui::PAGE_TRANSITION_TYPED; |
698 common_params.base_url_for_data_url = GURL("about:blank"); | 653 common_params.base_url_for_data_url = GURL("about:blank"); |
699 common_params.history_url_for_data_url = GURL("about:blank"); | 654 common_params.history_url_for_data_url = GURL("about:blank"); |
700 RequestNavigationParams request_params; | 655 RequestNavigationParams request_params; |
701 request_params.data_url_as_string = | 656 request_params.data_url_as_string = |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 // Load page B, which will trigger an UpdateState message for page A. | 968 // Load page B, which will trigger an UpdateState message for page A. |
1014 LoadHTML("<div>Page B</div>"); | 969 LoadHTML("<div>Page B</div>"); |
1015 | 970 |
1016 // Check for a valid UpdateState message for page A. | 971 // Check for a valid UpdateState message for page A. |
1017 ProcessPendingMessages(); | 972 ProcessPendingMessages(); |
1018 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 973 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
1019 ViewHostMsg_UpdateState::ID); | 974 ViewHostMsg_UpdateState::ID); |
1020 ASSERT_TRUE(msg_A); | 975 ASSERT_TRUE(msg_A); |
1021 ViewHostMsg_UpdateState::Param param; | 976 ViewHostMsg_UpdateState::Param param; |
1022 ViewHostMsg_UpdateState::Read(msg_A, ¶m); | 977 ViewHostMsg_UpdateState::Read(msg_A, ¶m); |
1023 int page_id_A = std::get<0>(param); | 978 PageState state_A = std::get<0>(param); |
1024 PageState state_A = std::get<1>(param); | |
1025 EXPECT_EQ(1, page_id_A); | |
1026 render_thread_->sink().ClearMessages(); | 979 render_thread_->sink().ClearMessages(); |
1027 | 980 |
1028 // Load page C, which will trigger an UpdateState message for page B. | 981 // Load page C, which will trigger an UpdateState message for page B. |
1029 LoadHTML("<div>Page C</div>"); | 982 LoadHTML("<div>Page C</div>"); |
1030 | 983 |
1031 // Check for a valid UpdateState for page B. | 984 // Check for a valid UpdateState for page B. |
1032 ProcessPendingMessages(); | 985 ProcessPendingMessages(); |
1033 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( | 986 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( |
1034 ViewHostMsg_UpdateState::ID); | 987 ViewHostMsg_UpdateState::ID); |
1035 ASSERT_TRUE(msg_B); | 988 ASSERT_TRUE(msg_B); |
1036 ViewHostMsg_UpdateState::Read(msg_B, ¶m); | 989 ViewHostMsg_UpdateState::Read(msg_B, ¶m); |
1037 int page_id_B = std::get<0>(param); | 990 PageState state_B = std::get<0>(param); |
1038 PageState state_B = std::get<1>(param); | |
1039 EXPECT_EQ(2, page_id_B); | |
1040 EXPECT_NE(state_A, state_B); | 991 EXPECT_NE(state_A, state_B); |
1041 render_thread_->sink().ClearMessages(); | 992 render_thread_->sink().ClearMessages(); |
1042 | 993 |
1043 // Load page D, which will trigger an UpdateState message for page C. | 994 // Load page D, which will trigger an UpdateState message for page C. |
1044 LoadHTML("<div>Page D</div>"); | 995 LoadHTML("<div>Page D</div>"); |
1045 | 996 |
1046 // Check for a valid UpdateState for page C. | 997 // Check for a valid UpdateState for page C. |
1047 ProcessPendingMessages(); | 998 ProcessPendingMessages(); |
1048 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( | 999 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( |
1049 ViewHostMsg_UpdateState::ID); | 1000 ViewHostMsg_UpdateState::ID); |
1050 ASSERT_TRUE(msg_C); | 1001 ASSERT_TRUE(msg_C); |
1051 ViewHostMsg_UpdateState::Read(msg_C, ¶m); | 1002 ViewHostMsg_UpdateState::Read(msg_C, ¶m); |
1052 int page_id_C = std::get<0>(param); | 1003 PageState state_C = std::get<0>(param); |
1053 PageState state_C = std::get<1>(param); | |
1054 EXPECT_EQ(3, page_id_C); | |
1055 EXPECT_NE(state_B, state_C); | 1004 EXPECT_NE(state_B, state_C); |
1056 render_thread_->sink().ClearMessages(); | 1005 render_thread_->sink().ClearMessages(); |
1057 | 1006 |
1058 // Go back to C and commit, preparing for our real test. | 1007 // Go back to C and commit, preparing for our real test. |
1059 CommonNavigationParams common_params_C; | 1008 CommonNavigationParams common_params_C; |
1060 RequestNavigationParams request_params_C; | 1009 RequestNavigationParams request_params_C; |
1061 common_params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 1010 common_params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1062 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 1011 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
1063 request_params_C.current_history_list_length = 4; | 1012 request_params_C.current_history_list_length = 4; |
1064 request_params_C.current_history_list_offset = 3; | 1013 request_params_C.current_history_list_offset = 3; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 request_params.page_state = state_A; | 1046 request_params.page_state = state_A; |
1098 frame()->Navigate(common_params, StartNavigationParams(), request_params); | 1047 frame()->Navigate(common_params, StartNavigationParams(), request_params); |
1099 ProcessPendingMessages(); | 1048 ProcessPendingMessages(); |
1100 | 1049 |
1101 // Now ensure that the UpdateState message we receive is consistent | 1050 // Now ensure that the UpdateState message we receive is consistent |
1102 // and represents page C in both page_id and state. | 1051 // and represents page C in both page_id and state. |
1103 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 1052 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
1104 ViewHostMsg_UpdateState::ID); | 1053 ViewHostMsg_UpdateState::ID); |
1105 ASSERT_TRUE(msg); | 1054 ASSERT_TRUE(msg); |
1106 ViewHostMsg_UpdateState::Read(msg, ¶m); | 1055 ViewHostMsg_UpdateState::Read(msg, ¶m); |
1107 int page_id = std::get<0>(param); | 1056 PageState state = std::get<0>(param); |
1108 PageState state = std::get<1>(param); | |
1109 EXPECT_EQ(page_id_C, page_id); | |
1110 EXPECT_NE(state_A, state); | 1057 EXPECT_NE(state_A, state); |
1111 EXPECT_NE(state_B, state); | 1058 EXPECT_NE(state_B, state); |
1112 EXPECT_EQ(state_C, state); | 1059 EXPECT_EQ(state_C, state); |
1113 } | 1060 } |
1114 | 1061 |
1115 // Test that our IME backend sends a notification message when the input focus | 1062 // Test that our IME backend sends a notification message when the input focus |
1116 // changes. | 1063 // changes. |
1117 TEST_F(RenderViewImplTest, OnImeTypeChanged) { | 1064 TEST_F(RenderViewImplTest, OnImeTypeChanged) { |
1118 // Load an HTML page consisting of two input fields. | 1065 // Load an HTML page consisting of two input fields. |
1119 LoadHTML("<html>" | 1066 LoadHTML("<html>" |
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 ExpectPauseAndResume(3); | 2504 ExpectPauseAndResume(3); |
2558 blink::WebScriptSource source2( | 2505 blink::WebScriptSource source2( |
2559 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2506 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
2560 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2507 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
2561 | 2508 |
2562 EXPECT_FALSE(IsPaused()); | 2509 EXPECT_FALSE(IsPaused()); |
2563 Detach(); | 2510 Detach(); |
2564 } | 2511 } |
2565 | 2512 |
2566 } // namespace content | 2513 } // namespace content |
OLD | NEW |