Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 2870633002: Use ScopedTaskEnvironment instead of MessageLoop in RenderViewTest. (Closed)
Patch Set: fix-build-error Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "build/build_config.h" 23 #include "build/build_config.h"
23 #include "cc/trees/layer_tree_host.h" 24 #include "cc/trees/layer_tree_host.h"
24 #include "content/child/request_extra_data.h" 25 #include "content/child/request_extra_data.h"
25 #include "content/child/service_worker/service_worker_network_provider.h" 26 #include "content/child/service_worker/service_worker_network_provider.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 request_params.current_history_list_length = view()->history_list_length_; 256 request_params.current_history_list_length = view()->history_list_length_;
256 frame()->Navigate(common_params, start_params, request_params); 257 frame()->Navigate(common_params, start_params, request_params);
257 258
258 // The load actually happens asynchronously, so we pump messages to process 259 // The load actually happens asynchronously, so we pump messages to process
259 // the pending continuation. 260 // the pending continuation.
260 FrameLoadWaiter(frame()).Wait(); 261 FrameLoadWaiter(frame()).Wait();
261 } 262 }
262 263
263 template<class T> 264 template<class T>
264 typename T::Param ProcessAndReadIPC() { 265 typename T::Param ProcessAndReadIPC() {
265 ProcessPendingMessages(); 266 base::RunLoop().RunUntilIdle();
266 const IPC::Message* message = 267 const IPC::Message* message =
267 render_thread_->sink().GetUniqueMessageMatching(T::ID); 268 render_thread_->sink().GetUniqueMessageMatching(T::ID);
268 typename T::Param param; 269 typename T::Param param;
269 EXPECT_TRUE(message); 270 EXPECT_TRUE(message);
270 if (message) 271 if (message)
271 T::Read(message, &param); 272 T::Read(message, &param);
272 return param; 273 return param;
273 } 274 }
274 275
275 // Sends IPC messages that emulates a key-press event. 276 // Sends IPC messages that emulates a key-press event.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 582
582 // We should NOT have gotten a form state change notification yet. 583 // We should NOT have gotten a form state change notification yet.
583 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 584 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
584 FrameHostMsg_UpdateState::ID)); 585 FrameHostMsg_UpdateState::ID));
585 render_thread_->sink().ClearMessages(); 586 render_thread_->sink().ClearMessages();
586 587
587 // Change the value of the input. We should have gotten an update state 588 // Change the value of the input. We should have gotten an update state
588 // notification. We need to spin the message loop to catch this update. 589 // notification. We need to spin the message loop to catch this update.
589 ExecuteJavaScriptForTests( 590 ExecuteJavaScriptForTests(
590 "document.getElementById('elt_text').value = 'foo';"); 591 "document.getElementById('elt_text').value = 'foo';");
591 ProcessPendingMessages(); 592 base::RunLoop().RunUntilIdle();
592 593
593 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( 594 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching(
594 FrameHostMsg_UpdateState::ID)); 595 FrameHostMsg_UpdateState::ID));
595 } 596 }
596 597
597 TEST_F(RenderViewImplTest, OnNavigationHttpPost) { 598 TEST_F(RenderViewImplTest, OnNavigationHttpPost) {
598 // An http url will trigger a resource load so cannot be used here. 599 // An http url will trigger a resource load so cannot be used here.
599 CommonNavigationParams common_params; 600 CommonNavigationParams common_params;
600 StartNavigationParams start_params; 601 StartNavigationParams start_params;
601 RequestNavigationParams request_params; 602 RequestNavigationParams request_params;
602 common_params.url = GURL("data:text/html,<div>Page</div>"); 603 common_params.url = GURL("data:text/html,<div>Page</div>");
603 common_params.navigation_type = FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT; 604 common_params.navigation_type = FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT;
604 common_params.transition = ui::PAGE_TRANSITION_TYPED; 605 common_params.transition = ui::PAGE_TRANSITION_TYPED;
605 common_params.method = "POST"; 606 common_params.method = "POST";
606 607
607 // Set up post data. 608 // Set up post data.
608 const char raw_data[] = "post \0\ndata"; 609 const char raw_data[] = "post \0\ndata";
609 const size_t length = arraysize(raw_data); 610 const size_t length = arraysize(raw_data);
610 scoped_refptr<ResourceRequestBodyImpl> post_data(new ResourceRequestBodyImpl); 611 scoped_refptr<ResourceRequestBodyImpl> post_data(new ResourceRequestBodyImpl);
611 post_data->AppendBytes(raw_data, length); 612 post_data->AppendBytes(raw_data, length);
612 common_params.post_data = post_data; 613 common_params.post_data = post_data;
613 614
614 frame()->Navigate(common_params, start_params, request_params); 615 frame()->Navigate(common_params, start_params, request_params);
615 ProcessPendingMessages(); 616 base::RunLoop().RunUntilIdle();
616 617
617 const IPC::Message* frame_navigate_msg = 618 const IPC::Message* frame_navigate_msg =
618 render_thread_->sink().GetUniqueMessageMatching( 619 render_thread_->sink().GetUniqueMessageMatching(
619 FrameHostMsg_DidCommitProvisionalLoad::ID); 620 FrameHostMsg_DidCommitProvisionalLoad::ID);
620 EXPECT_TRUE(frame_navigate_msg); 621 EXPECT_TRUE(frame_navigate_msg);
621 622
622 FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params; 623 FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params;
623 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, 624 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg,
624 &host_nav_params); 625 &host_nav_params);
625 EXPECT_EQ("POST", std::get<0>(host_nav_params).method); 626 EXPECT_EQ("POST", std::get<0>(host_nav_params).method);
(...skipping 20 matching lines...) Expand all
646 common_params.base_url_for_data_url = GURL("about:blank"); 647 common_params.base_url_for_data_url = GURL("about:blank");
647 common_params.history_url_for_data_url = GURL("about:blank"); 648 common_params.history_url_for_data_url = GURL("about:blank");
648 RequestNavigationParams request_params; 649 RequestNavigationParams request_params;
649 request_params.data_url_as_string = 650 request_params.data_url_as_string =
650 "data:text/html,<html><head><title>Data page</title></head></html>"; 651 "data:text/html,<html><head><title>Data page</title></head></html>";
651 652
652 frame()->Navigate(common_params, StartNavigationParams(), 653 frame()->Navigate(common_params, StartNavigationParams(),
653 request_params); 654 request_params);
654 const IPC::Message* frame_title_msg = nullptr; 655 const IPC::Message* frame_title_msg = nullptr;
655 do { 656 do {
656 ProcessPendingMessages(); 657 base::RunLoop().RunUntilIdle();
657 frame_title_msg = render_thread_->sink().GetUniqueMessageMatching( 658 frame_title_msg = render_thread_->sink().GetUniqueMessageMatching(
658 FrameHostMsg_UpdateTitle::ID); 659 FrameHostMsg_UpdateTitle::ID);
659 } while (!frame_title_msg); 660 } while (!frame_title_msg);
660 661
661 // Check post data sent to browser matches. 662 // Check post data sent to browser matches.
662 FrameHostMsg_UpdateTitle::Param title_params; 663 FrameHostMsg_UpdateTitle::Param title_params;
663 EXPECT_TRUE(FrameHostMsg_UpdateTitle::Read(frame_title_msg, &title_params)); 664 EXPECT_TRUE(FrameHostMsg_UpdateTitle::Read(frame_title_msg, &title_params));
664 EXPECT_EQ(base::ASCIIToUTF16("Data page"), std::get<0>(title_params)); 665 EXPECT_EQ(base::ASCIIToUTF16("Data page"), std::get<0>(title_params));
665 } 666 }
666 #endif 667 #endif
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // quickly without committing. Regression test for http://crbug.com/58082. 926 // quickly without committing. Regression test for http://crbug.com/58082.
926 // Disabled: http://crbug.com/157357 . 927 // Disabled: http://crbug.com/157357 .
927 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { 928 TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) {
928 // Load page A. 929 // Load page A.
929 LoadHTML("<div>Page A</div>"); 930 LoadHTML("<div>Page A</div>");
930 931
931 // 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.
932 LoadHTML("<div>Page B</div>"); 933 LoadHTML("<div>Page B</div>");
933 934
934 // Check for a valid UpdateState message for page A. 935 // Check for a valid UpdateState message for page A.
935 ProcessPendingMessages(); 936 base::RunLoop().RunUntilIdle();
936 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( 937 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching(
937 FrameHostMsg_UpdateState::ID); 938 FrameHostMsg_UpdateState::ID);
938 ASSERT_TRUE(msg_A); 939 ASSERT_TRUE(msg_A);
939 FrameHostMsg_UpdateState::Param param; 940 FrameHostMsg_UpdateState::Param param;
940 FrameHostMsg_UpdateState::Read(msg_A, &param); 941 FrameHostMsg_UpdateState::Read(msg_A, &param);
941 PageState state_A = std::get<0>(param); 942 PageState state_A = std::get<0>(param);
942 render_thread_->sink().ClearMessages(); 943 render_thread_->sink().ClearMessages();
943 944
944 // 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.
945 LoadHTML("<div>Page C</div>"); 946 LoadHTML("<div>Page C</div>");
946 947
947 // Check for a valid UpdateState for page B. 948 // Check for a valid UpdateState for page B.
948 ProcessPendingMessages(); 949 base::RunLoop().RunUntilIdle();
949 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( 950 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching(
950 FrameHostMsg_UpdateState::ID); 951 FrameHostMsg_UpdateState::ID);
951 ASSERT_TRUE(msg_B); 952 ASSERT_TRUE(msg_B);
952 FrameHostMsg_UpdateState::Read(msg_B, &param); 953 FrameHostMsg_UpdateState::Read(msg_B, &param);
953 PageState state_B = std::get<0>(param); 954 PageState state_B = std::get<0>(param);
954 EXPECT_NE(state_A, state_B); 955 EXPECT_NE(state_A, state_B);
955 render_thread_->sink().ClearMessages(); 956 render_thread_->sink().ClearMessages();
956 957
957 // 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.
958 LoadHTML("<div>Page D</div>"); 959 LoadHTML("<div>Page D</div>");
959 960
960 // Check for a valid UpdateState for page C. 961 // Check for a valid UpdateState for page C.
961 ProcessPendingMessages(); 962 base::RunLoop().RunUntilIdle();
962 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( 963 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching(
963 FrameHostMsg_UpdateState::ID); 964 FrameHostMsg_UpdateState::ID);
964 ASSERT_TRUE(msg_C); 965 ASSERT_TRUE(msg_C);
965 FrameHostMsg_UpdateState::Read(msg_C, &param); 966 FrameHostMsg_UpdateState::Read(msg_C, &param);
966 PageState state_C = std::get<0>(param); 967 PageState state_C = std::get<0>(param);
967 EXPECT_NE(state_B, state_C); 968 EXPECT_NE(state_B, state_C);
968 render_thread_->sink().ClearMessages(); 969 render_thread_->sink().ClearMessages();
969 970
970 // Go back to C and commit, preparing for our real test. 971 // Go back to C and commit, preparing for our real test.
971 CommonNavigationParams common_params_C; 972 CommonNavigationParams common_params_C;
972 RequestNavigationParams request_params_C; 973 RequestNavigationParams request_params_C;
973 common_params_C.navigation_type = 974 common_params_C.navigation_type =
974 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT; 975 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT;
975 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 976 common_params_C.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
976 request_params_C.current_history_list_length = 4; 977 request_params_C.current_history_list_length = 4;
977 request_params_C.current_history_list_offset = 3; 978 request_params_C.current_history_list_offset = 3;
978 request_params_C.pending_history_list_offset = 2; 979 request_params_C.pending_history_list_offset = 2;
979 request_params_C.nav_entry_id = 3; 980 request_params_C.nav_entry_id = 3;
980 request_params_C.page_state = state_C; 981 request_params_C.page_state = state_C;
981 frame()->Navigate(common_params_C, StartNavigationParams(), request_params_C); 982 frame()->Navigate(common_params_C, StartNavigationParams(), request_params_C);
982 ProcessPendingMessages(); 983 base::RunLoop().RunUntilIdle();
983 render_thread_->sink().ClearMessages(); 984 render_thread_->sink().ClearMessages();
984 985
985 // Go back twice quickly, such that page B does not have a chance to commit. 986 // Go back twice quickly, such that page B does not have a chance to commit.
986 // This leads to two changes to the back/forward list but only one change to 987 // This leads to two changes to the back/forward list but only one change to
987 // the RenderView's page ID. 988 // the RenderView's page ID.
988 989
989 // Back to page B without committing. 990 // Back to page B without committing.
990 CommonNavigationParams common_params_B; 991 CommonNavigationParams common_params_B;
991 RequestNavigationParams request_params_B; 992 RequestNavigationParams request_params_B;
992 common_params_B.navigation_type = 993 common_params_B.navigation_type =
(...skipping 11 matching lines...) Expand all
1004 RequestNavigationParams request_params; 1005 RequestNavigationParams request_params;
1005 common_params.navigation_type = 1006 common_params.navigation_type =
1006 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT; 1007 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT;
1007 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 1008 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
1008 request_params.current_history_list_length = 4; 1009 request_params.current_history_list_length = 4;
1009 request_params.current_history_list_offset = 2; 1010 request_params.current_history_list_offset = 2;
1010 request_params.pending_history_list_offset = 0; 1011 request_params.pending_history_list_offset = 0;
1011 request_params.nav_entry_id = 1; 1012 request_params.nav_entry_id = 1;
1012 request_params.page_state = state_A; 1013 request_params.page_state = state_A;
1013 frame()->Navigate(common_params, StartNavigationParams(), request_params); 1014 frame()->Navigate(common_params, StartNavigationParams(), request_params);
1014 ProcessPendingMessages(); 1015 base::RunLoop().RunUntilIdle();
1015 1016
1016 // Now ensure that the UpdateState message we receive is consistent 1017 // Now ensure that the UpdateState message we receive is consistent
1017 // and represents page C in state. 1018 // and represents page C in state.
1018 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( 1019 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
1019 FrameHostMsg_UpdateState::ID); 1020 FrameHostMsg_UpdateState::ID);
1020 ASSERT_TRUE(msg); 1021 ASSERT_TRUE(msg);
1021 FrameHostMsg_UpdateState::Read(msg, &param); 1022 FrameHostMsg_UpdateState::Read(msg, &param);
1022 PageState state = std::get<0>(param); 1023 PageState state = std::get<0>(param);
1023 EXPECT_NE(state_A, state); 1024 EXPECT_NE(state_A, state);
1024 EXPECT_NE(state_B, state); 1025 EXPECT_NE(state_B, state);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 {"test13", ui::TEXT_INPUT_MODE_URL}, 1074 {"test13", ui::TEXT_INPUT_MODE_URL},
1074 {"test14", ui::TEXT_INPUT_MODE_DEFAULT}, 1075 {"test14", ui::TEXT_INPUT_MODE_DEFAULT},
1075 {"test15", ui::TEXT_INPUT_MODE_VERBATIM}, 1076 {"test15", ui::TEXT_INPUT_MODE_VERBATIM},
1076 }; 1077 };
1077 1078
1078 const int kRepeatCount = 10; 1079 const int kRepeatCount = 10;
1079 for (int i = 0; i < kRepeatCount; i++) { 1080 for (int i = 0; i < kRepeatCount; i++) {
1080 // Move the input focus to the first <input> element, where we should 1081 // Move the input focus to the first <input> element, where we should
1081 // activate IMEs. 1082 // activate IMEs.
1082 ExecuteJavaScriptForTests("document.getElementById('test1').focus();"); 1083 ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
1083 ProcessPendingMessages(); 1084 base::RunLoop().RunUntilIdle();
1084 render_thread_->sink().ClearMessages(); 1085 render_thread_->sink().ClearMessages();
1085 1086
1086 // Update the IME status and verify if our IME backend sends an IPC message 1087 // Update the IME status and verify if our IME backend sends an IPC message
1087 // to activate IMEs. 1088 // to activate IMEs.
1088 view()->UpdateTextInputState(); 1089 view()->UpdateTextInputState();
1089 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0); 1090 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0);
1090 EXPECT_TRUE(msg != NULL); 1091 EXPECT_TRUE(msg != NULL);
1091 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type()); 1092 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type());
1092 ViewHostMsg_TextInputStateChanged::Param params; 1093 ViewHostMsg_TextInputStateChanged::Param params;
1093 ViewHostMsg_TextInputStateChanged::Read(msg, &params); 1094 ViewHostMsg_TextInputStateChanged::Read(msg, &params);
1094 TextInputState p = std::get<0>(params); 1095 TextInputState p = std::get<0>(params);
1095 ui::TextInputType type = p.type; 1096 ui::TextInputType type = p.type;
1096 ui::TextInputMode input_mode = p.mode; 1097 ui::TextInputMode input_mode = p.mode;
1097 bool can_compose_inline = p.can_compose_inline; 1098 bool can_compose_inline = p.can_compose_inline;
1098 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, type); 1099 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, type);
1099 EXPECT_EQ(true, can_compose_inline); 1100 EXPECT_EQ(true, can_compose_inline);
1100 1101
1101 // Move the input focus to the second <input> element, where we should 1102 // Move the input focus to the second <input> element, where we should
1102 // de-activate IMEs. 1103 // de-activate IMEs.
1103 ExecuteJavaScriptForTests("document.getElementById('test2').focus();"); 1104 ExecuteJavaScriptForTests("document.getElementById('test2').focus();");
1104 ProcessPendingMessages(); 1105 base::RunLoop().RunUntilIdle();
1105 render_thread_->sink().ClearMessages(); 1106 render_thread_->sink().ClearMessages();
1106 1107
1107 // Update the IME status and verify if our IME backend sends an IPC message 1108 // Update the IME status and verify if our IME backend sends an IPC message
1108 // to de-activate IMEs. 1109 // to de-activate IMEs.
1109 view()->UpdateTextInputState(); 1110 view()->UpdateTextInputState();
1110 msg = render_thread_->sink().GetMessageAt(0); 1111 msg = render_thread_->sink().GetMessageAt(0);
1111 EXPECT_TRUE(msg != NULL); 1112 EXPECT_TRUE(msg != NULL);
1112 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type()); 1113 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type());
1113 ViewHostMsg_TextInputStateChanged::Read(msg, &params); 1114 ViewHostMsg_TextInputStateChanged::Read(msg, &params);
1114 p = std::get<0>(params); 1115 p = std::get<0>(params);
1115 type = p.type; 1116 type = p.type;
1116 input_mode = p.mode; 1117 input_mode = p.mode;
1117 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, type); 1118 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, type);
1118 1119
1119 for (size_t i = 0; i < arraysize(kInputModeTestCases); i++) { 1120 for (size_t i = 0; i < arraysize(kInputModeTestCases); i++) {
1120 const InputModeTestCase* test_case = &kInputModeTestCases[i]; 1121 const InputModeTestCase* test_case = &kInputModeTestCases[i];
1121 std::string javascript = 1122 std::string javascript =
1122 base::StringPrintf("document.getElementById('%s').focus();", 1123 base::StringPrintf("document.getElementById('%s').focus();",
1123 test_case->input_id); 1124 test_case->input_id);
1124 // Move the input focus to the target <input> element, where we should 1125 // Move the input focus to the target <input> element, where we should
1125 // activate IMEs. 1126 // activate IMEs.
1126 ExecuteJavaScriptAndReturnIntValue(base::ASCIIToUTF16(javascript), NULL); 1127 ExecuteJavaScriptAndReturnIntValue(base::ASCIIToUTF16(javascript), NULL);
1127 ProcessPendingMessages(); 1128 base::RunLoop().RunUntilIdle();
1128 render_thread_->sink().ClearMessages(); 1129 render_thread_->sink().ClearMessages();
1129 1130
1130 // Update the IME status and verify if our IME backend sends an IPC 1131 // Update the IME status and verify if our IME backend sends an IPC
1131 // message to activate IMEs. 1132 // message to activate IMEs.
1132 view()->UpdateTextInputState(); 1133 view()->UpdateTextInputState();
1133 ProcessPendingMessages(); 1134 base::RunLoop().RunUntilIdle();
1134 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0); 1135 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0);
1135 EXPECT_TRUE(msg != NULL); 1136 EXPECT_TRUE(msg != NULL);
1136 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type()); 1137 EXPECT_EQ(ViewHostMsg_TextInputStateChanged::ID, msg->type());
1137 ViewHostMsg_TextInputStateChanged::Read(msg, &params); 1138 ViewHostMsg_TextInputStateChanged::Read(msg, &params);
1138 p = std::get<0>(params); 1139 p = std::get<0>(params);
1139 type = p.type; 1140 type = p.type;
1140 input_mode = p.mode; 1141 input_mode = p.mode;
1141 EXPECT_EQ(test_case->expected_mode, input_mode); 1142 EXPECT_EQ(test_case->expected_mode, input_mode);
1142 } 1143 }
1143 } 1144 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 base::string16(), 1264 base::string16(),
1264 std::vector<blink::WebCompositionUnderline>(), 1265 std::vector<blink::WebCompositionUnderline>(),
1265 gfx::Range::InvalidRange(), 1266 gfx::Range::InvalidRange(),
1266 0, 0); 1267 0, 0);
1267 break; 1268 break;
1268 } 1269 }
1269 1270
1270 // Update the status of our IME back-end. 1271 // Update the status of our IME back-end.
1271 // TODO(hbono): we should verify messages to be sent from the back-end. 1272 // TODO(hbono): we should verify messages to be sent from the back-end.
1272 view()->UpdateTextInputState(); 1273 view()->UpdateTextInputState();
1273 ProcessPendingMessages(); 1274 base::RunLoop().RunUntilIdle();
1274 render_thread_->sink().ClearMessages(); 1275 render_thread_->sink().ClearMessages();
1275 1276
1276 if (ime_message->result) { 1277 if (ime_message->result) {
1277 // Retrieve the content of this page and compare it with the expected 1278 // Retrieve the content of this page and compare it with the expected
1278 // result. 1279 // result.
1279 const int kMaxOutputCharacters = 128; 1280 const int kMaxOutputCharacters = 128;
1280 base::string16 output = WebFrameContentDumper::DumpWebViewAsText( 1281 base::string16 output = WebFrameContentDumper::DumpWebViewAsText(
1281 view()->GetWebView(), kMaxOutputCharacters) 1282 view()->GetWebView(), kMaxOutputCharacters)
1282 .Utf16(); 1283 .Utf16();
1283 EXPECT_EQ(base::WideToUTF16(ime_message->result), output); 1284 EXPECT_EQ(base::WideToUTF16(ime_message->result), output);
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 // override) are not comparable with the wall time (returned by the Blink API). 2050 // override) are not comparable with the wall time (returned by the Blink API).
2050 TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) { 2051 TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) {
2051 // Verify that a navigation that claims to have started in the future - 42 2052 // Verify that a navigation that claims to have started in the future - 42
2052 // days from now is *not* reported as one that starts in the future; as we 2053 // days from now is *not* reported as one that starts in the future; as we
2053 // sanitize the override allowing a maximum of ::Now(). 2054 // sanitize the override allowing a maximum of ::Now().
2054 auto late_common_params = MakeCommonNavigationParams(TimeDelta::FromDays(42)); 2055 auto late_common_params = MakeCommonNavigationParams(TimeDelta::FromDays(42));
2055 late_common_params.method = "POST"; 2056 late_common_params.method = "POST";
2056 2057
2057 frame()->Navigate(late_common_params, StartNavigationParams(), 2058 frame()->Navigate(late_common_params, StartNavigationParams(),
2058 RequestNavigationParams()); 2059 RequestNavigationParams());
2059 ProcessPendingMessages(); 2060 base::RunLoop().RunUntilIdle();
2060 base::Time after_navigation = 2061 base::Time after_navigation =
2061 base::Time::Now() + base::TimeDelta::FromDays(1); 2062 base::Time::Now() + base::TimeDelta::FromDays(1);
2062 2063
2063 base::Time late_nav_reported_start = 2064 base::Time late_nav_reported_start =
2064 base::Time::FromDoubleT(GetMainFrame()->Performance().NavigationStart()); 2065 base::Time::FromDoubleT(GetMainFrame()->Performance().NavigationStart());
2065 EXPECT_LE(late_nav_reported_start, after_navigation); 2066 EXPECT_LE(late_nav_reported_start, after_navigation);
2066 } 2067 }
2067 2068
2068 // Checks that a browser-initiated navigation in an initial document that has 2069 // Checks that a browser-initiated navigation in an initial document that has
2069 // been accessed does not use browser-side timestamp (there may be arbitrary 2070 // been accessed does not use browser-side timestamp (there may be arbitrary
(...skipping 13 matching lines...) Expand all
2083 if (!IsBrowserSideNavigationEnabled()) 2084 if (!IsBrowserSideNavigationEnabled())
2084 EXPECT_GT(std::get<2>(nav_params), common_params.navigation_start); 2085 EXPECT_GT(std::get<2>(nav_params), common_params.navigation_start);
2085 else 2086 else
2086 EXPECT_EQ(common_params.navigation_start, std::get<2>(nav_params)); 2087 EXPECT_EQ(common_params.navigation_start, std::get<2>(nav_params));
2087 } 2088 }
2088 2089
2089 TEST_F(RenderViewImplTest, NavigationStartForReload) { 2090 TEST_F(RenderViewImplTest, NavigationStartForReload) {
2090 const char url_string[] = "data:text/html,<div>Page</div>"; 2091 const char url_string[] = "data:text/html,<div>Page</div>";
2091 // Navigate once, then reload. 2092 // Navigate once, then reload.
2092 LoadHTML(url_string); 2093 LoadHTML(url_string);
2093 ProcessPendingMessages(); 2094 base::RunLoop().RunUntilIdle();
2094 render_thread_->sink().ClearMessages(); 2095 render_thread_->sink().ClearMessages();
2095 2096
2096 CommonNavigationParams common_params; 2097 CommonNavigationParams common_params;
2097 common_params.url = GURL(url_string); 2098 common_params.url = GURL(url_string);
2098 common_params.navigation_type = 2099 common_params.navigation_type =
2099 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 2100 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2100 common_params.transition = ui::PAGE_TRANSITION_RELOAD; 2101 common_params.transition = ui::PAGE_TRANSITION_RELOAD;
2101 2102
2102 // The browser navigation_start should not be used because beforeunload will 2103 // The browser navigation_start should not be used because beforeunload will
2103 // be fired during Navigate. 2104 // be fired during Navigate.
(...skipping 13 matching lines...) Expand all
2117 EXPECT_EQ(common_params.navigation_start, std::get<2>(host_nav_params)); 2118 EXPECT_EQ(common_params.navigation_start, std::get<2>(host_nav_params));
2118 } 2119 }
2119 } 2120 }
2120 2121
2121 TEST_F(RenderViewImplTest, NavigationStartForSameProcessHistoryNavigation) { 2122 TEST_F(RenderViewImplTest, NavigationStartForSameProcessHistoryNavigation) {
2122 LoadHTML("<div id=pagename>Page A</div>"); 2123 LoadHTML("<div id=pagename>Page A</div>");
2123 LoadHTML("<div id=pagename>Page B</div>"); 2124 LoadHTML("<div id=pagename>Page B</div>");
2124 PageState back_state = GetCurrentPageState(); 2125 PageState back_state = GetCurrentPageState();
2125 LoadHTML("<div id=pagename>Page C</div>"); 2126 LoadHTML("<div id=pagename>Page C</div>");
2126 PageState forward_state = GetCurrentPageState(); 2127 PageState forward_state = GetCurrentPageState();
2127 ProcessPendingMessages(); 2128 base::RunLoop().RunUntilIdle();
2128 render_thread_->sink().ClearMessages(); 2129 render_thread_->sink().ClearMessages();
2129 2130
2130 // Go back. 2131 // Go back.
2131 CommonNavigationParams common_params_back; 2132 CommonNavigationParams common_params_back;
2132 common_params_back.url = 2133 common_params_back.url =
2133 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>"); 2134 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>");
2134 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 2135 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2135 common_params_back.navigation_type = 2136 common_params_back.navigation_type =
2136 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT; 2137 FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT;
2137 GoToOffsetWithParams(-1, back_state, common_params_back, 2138 GoToOffsetWithParams(-1, back_state, common_params_back,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 ExpectPauseAndResume(3); 2591 ExpectPauseAndResume(3);
2591 blink::WebScriptSource source2( 2592 blink::WebScriptSource source2(
2592 WebString::FromUTF8("function func2() { func1(); }; func2();")); 2593 WebString::FromUTF8("function func2() { func1(); }; func2();"));
2593 frame()->GetWebFrame()->ExecuteScriptInIsolatedWorld(17, &source2, 1); 2594 frame()->GetWebFrame()->ExecuteScriptInIsolatedWorld(17, &source2, 1);
2594 2595
2595 EXPECT_FALSE(IsPaused()); 2596 EXPECT_FALSE(IsPaused());
2596 Detach(); 2597 Detach();
2597 } 2598 }
2598 2599
2599 } // namespace content 2600 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl_browsertest.cc ('k') | content/renderer/render_view_browsertest_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698