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

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 1631963002: Plumb firing passive event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_passive_listeners_2a
Patch Set: Renamed enum value as per wez@ request Created 4 years, 10 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 "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/process/kill.h" 15 #include "base/process/kill.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_piece.h" 18 #include "base/strings/string_piece.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
21 #include "base/test/test_timeouts.h" 21 #include "base/test/test_timeouts.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "content/browser/renderer_host/render_widget_host_impl.h" 24 #include "content/browser/renderer_host/render_widget_host_impl.h"
25 #include "content/browser/web_contents/web_contents_impl.h" 25 #include "content/browser/web_contents/web_contents_impl.h"
26 #include "content/browser/web_contents/web_contents_view.h" 26 #include "content/browser/web_contents/web_contents_view.h"
27 #include "content/common/input/synthetic_web_input_event_builders.h" 27 #include "content/common/input/synthetic_web_input_event_builders.h"
28 #include "content/common/input_messages.h"
28 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
29 #include "content/public/browser/browser_context.h" 30 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/histogram_fetcher.h" 31 #include "content/public/browser/histogram_fetcher.h"
31 #include "content/public/browser/navigation_entry.h" 32 #include "content/public/browser/navigation_entry.h"
32 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/browser/render_frame_host.h" 35 #include "content/public/browser/render_frame_host.h"
35 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
36 #include "content/public/browser/render_view_host.h" 37 #include "content/public/browser/render_view_host.h"
37 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 ->ScheduleComposite(); 1067 ->ScheduleComposite();
1067 } 1068 }
1068 1069
1069 FrameWatcher::FrameWatcher() 1070 FrameWatcher::FrameWatcher()
1070 : BrowserMessageFilter(ViewMsgStart), frames_to_wait_(0) { 1071 : BrowserMessageFilter(ViewMsgStart), frames_to_wait_(0) {
1071 } 1072 }
1072 1073
1073 FrameWatcher::~FrameWatcher() { 1074 FrameWatcher::~FrameWatcher() {
1074 } 1075 }
1075 1076
1076 void FrameWatcher::ReceivedFrameSwap() { 1077 void FrameWatcher::ReceivedFrameSwap(cc::CompositorFrameMetadata metadata) {
1077 --frames_to_wait_; 1078 --frames_to_wait_;
1079 last_metadata_ = metadata;
1078 if (frames_to_wait_ == 0) 1080 if (frames_to_wait_ == 0)
1079 quit_.Run(); 1081 quit_.Run();
1080 } 1082 }
1081 1083
1082 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { 1084 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) {
1083 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { 1085 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) {
1084 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1086 ViewHostMsg_SwapCompositorFrame::Param param;
1085 base::Bind(&FrameWatcher::ReceivedFrameSwap, this)); 1087 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1088 return false;
1089 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
1090 base::get<1>(param).AssignTo(frame.get());
1091
1092 BrowserThread::PostTask(
1093 BrowserThread::UI, FROM_HERE,
1094 base::Bind(&FrameWatcher::ReceivedFrameSwap, this, frame->metadata));
1086 } 1095 }
1087 return false; 1096 return false;
1088 } 1097 }
1089 1098
1090 void FrameWatcher::AttachTo(WebContents* web_contents) { 1099 void FrameWatcher::AttachTo(WebContents* web_contents) {
1091 DCHECK(web_contents); 1100 DCHECK(web_contents);
1092 RenderWidgetHostImpl* widget_host = RenderWidgetHostImpl::From( 1101 RenderWidgetHostImpl* widget_host = RenderWidgetHostImpl::From(
1093 web_contents->GetRenderViewHost()->GetWidget()); 1102 web_contents->GetRenderViewHost()->GetWidget());
1094 widget_host->GetProcess()->AddFilter(this); 1103 widget_host->GetProcess()->AddFilter(this);
1095 } 1104 }
1096 1105
1097 void FrameWatcher::WaitFrames(int frames_to_wait) { 1106 void FrameWatcher::WaitFrames(int frames_to_wait) {
1098 if (frames_to_wait <= 0) 1107 if (frames_to_wait <= 0)
1099 return; 1108 return;
1100 base::RunLoop run_loop; 1109 base::RunLoop run_loop;
1101 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); 1110 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
1102 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); 1111 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait);
1103 run_loop.Run(); 1112 run_loop.Run();
1104 } 1113 }
1105 1114
1115 const cc::CompositorFrameMetadata& FrameWatcher::LastMetadata() {
1116 return last_metadata_;
1117 }
1118
1106 MainThreadFrameObserver::MainThreadFrameObserver( 1119 MainThreadFrameObserver::MainThreadFrameObserver(
1107 RenderWidgetHost* render_widget_host) 1120 RenderWidgetHost* render_widget_host)
1108 : render_widget_host_(render_widget_host), 1121 : render_widget_host_(render_widget_host),
1109 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) { 1122 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) {
1110 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost 1123 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost
1111 // messages similarly to what WebContentsObserver can do with RFH and RVW. 1124 // messages similarly to what WebContentsObserver can do with RFH and RVW.
1112 render_widget_host_->GetProcess()->AddRoute(routing_id_, this); 1125 render_widget_host_->GetProcess()->AddRoute(routing_id_, this);
1113 } 1126 }
1114 1127
1115 MainThreadFrameObserver::~MainThreadFrameObserver() { 1128 MainThreadFrameObserver::~MainThreadFrameObserver() {
(...skipping 17 matching lines...) Expand all
1133 bool MainThreadFrameObserver::OnMessageReceived(const IPC::Message& msg) { 1146 bool MainThreadFrameObserver::OnMessageReceived(const IPC::Message& msg) {
1134 if (msg.type() == ViewHostMsg_WaitForNextFrameForTests_ACK::ID && 1147 if (msg.type() == ViewHostMsg_WaitForNextFrameForTests_ACK::ID &&
1135 msg.routing_id() == routing_id_) { 1148 msg.routing_id() == routing_id_) {
1136 BrowserThread::PostTask( 1149 BrowserThread::PostTask(
1137 BrowserThread::UI, FROM_HERE, 1150 BrowserThread::UI, FROM_HERE,
1138 base::Bind(&MainThreadFrameObserver::Quit, base::Unretained(this))); 1151 base::Bind(&MainThreadFrameObserver::Quit, base::Unretained(this)));
1139 } 1152 }
1140 return true; 1153 return true;
1141 } 1154 }
1142 1155
1156 InputMsgWatcher::InputMsgWatcher(RenderWidgetHost* render_widget_host,
1157 blink::WebInputEvent::Type type)
1158 : BrowserMessageFilter(InputMsgStart),
1159 wait_for_type_(type),
1160 ack_result_(INPUT_EVENT_ACK_STATE_UNKNOWN) {
1161 render_widget_host->GetProcess()->AddFilter(this);
1162 }
1163
1164 InputMsgWatcher::~InputMsgWatcher() {}
1165
1166 void InputMsgWatcher::ReceivedAck(blink::WebInputEvent::Type ack_type,
Charlie Reis 2016/02/16 22:25:22 Can you add some DCHECKs for which threads you exp
dtapuska 2016/02/17 03:34:57 Done.
1167 uint32_t ack_state) {
1168 if (wait_for_type_ == ack_type) {
1169 ack_result_ = ack_state;
1170 if (!quit_.is_null())
1171 quit_.Run();
1172 }
1173 }
1174
1175 bool InputMsgWatcher::OnMessageReceived(const IPC::Message& message) {
1176 if (message.type() == InputHostMsg_HandleInputEvent_ACK::ID) {
1177 InputHostMsg_HandleInputEvent_ACK::Param params;
1178 InputHostMsg_HandleInputEvent_ACK::Read(&message, &params);
1179 blink::WebInputEvent::Type ack_type = base::get<0>(params).type;
1180 InputEventAckState ack_state = base::get<0>(params).state;
1181 BrowserThread::PostTask(
1182 BrowserThread::UI, FROM_HERE,
1183 base::Bind(&InputMsgWatcher::ReceivedAck, this, ack_type, ack_state));
1184 }
1185 return false;
1186 }
1187
1188 uint32_t InputMsgWatcher::WaitForAck() {
1189 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN)
1190 return ack_result_;
1191 base::RunLoop run_loop;
1192 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
1193 run_loop.Run();
1194 return ack_result_;
1195 }
1196
1143 } // namespace content 1197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698