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

Side by Side Diff: content/browser/renderer_host/input/main_thread_event_queue_browsertest.cc

Issue 2162143002: Don't use PostTask queueing between compositor and main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix fairness of post tasks it was causing some tests to fail Created 4 years, 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <utility>
6
7 #include "base/auto_reset.h"
8 #include "base/bind.h"
9 #include "base/command_line.h"
10 #include "base/macros.h"
11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h"
14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
15 #include "content/browser/renderer_host/render_widget_host_impl.h"
16 #include "content/browser/renderer_host/render_widget_host_view_base.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/common/input/synthetic_web_input_event_builders.h"
19 #include "content/common/input_messages.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/content_browser_test.h"
25 #include "content/public/test/content_browser_test_utils.h"
26 #include "content/public/test/test_utils.h"
27 #include "content/shell/browser/shell.h"
28 #include "third_party/WebKit/public/web/WebInputEvent.h"
29 #include "ui/events/event_switches.h"
30 #include "ui/events/latency_info.h"
31
32 using blink::WebInputEvent;
33
34 namespace {
35
36 const char kJankyPageURL[] =
37 "data:text/html;charset=utf-8,"
38 "<!DOCTYPE html>"
39 "<meta name='viewport' content='width=device-width'/>"
40 "<style>"
41 "html, body {"
42 " margin: 0;"
43 "}"
44 ".spacer { height: 10000px; }"
45 "</style>"
46 "<div class=spacer></div>"
47 "<script>"
48 " function jank(millis)"
49 " {"
50 " var end = performance.now() + millis;"
51 " while(performance.now() < end) {};"
52 " window.mouseMoveCount = 0;"
53 " window.touchMoveCount = 0;"
54 " }"
55 " window.mouseMoveCount = 0;"
56 " window.touchMoveCount = 0;"
57 " document.addEventListener('mousemove', function(e) {"
58 " window.mouseMoveCount++;"
59 " window.lastMouseMoveEvent = e;"
60 " });"
61 " document.addEventListener('touchmove', function (e) {"
62 " window.touchMoveCount++;"
63 " window.lastTouchMoveEvent = e;"
64 " }, {passive: true});"
65 " document.addEventListener('click', function(e) { jank(500); });"
66 " document.title='ready';"
67 "</script>";
68
69 } // namespace
70
71 namespace content {
72
73 class MainThreadEventQueueBrowserTest : public ContentBrowserTest {
74 public:
75 MainThreadEventQueueBrowserTest() {}
76 ~MainThreadEventQueueBrowserTest() override {}
77
78 RenderWidgetHostImpl* GetWidgetHost() {
79 return RenderWidgetHostImpl::From(
80 shell()->web_contents()->GetRenderViewHost()->GetWidget());
81 }
82
83 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) {
84 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result);
85 }
86
87 protected:
88 void LoadURL(const char* page_data) {
89 const GURL data_url(page_data);
90 NavigateToURL(shell(), data_url);
91
92 RenderWidgetHostImpl* host = GetWidgetHost();
93 host->GetView()->SetSize(gfx::Size(400, 400));
94
95 base::string16 ready_title(base::ASCIIToUTF16("ready"));
96 TitleWatcher watcher(shell()->web_contents(), ready_title);
97 ignore_result(watcher.WaitAndGetTitle());
98
99 MainThreadFrameObserver main_thread_sync(host);
100 main_thread_sync.Wait();
101 }
102
103 int ExecuteScriptAndExtractInt(const std::string& script) {
104 int value = 0;
105 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
106 shell(), "domAutomationController.send(" + script + ")", &value));
107 return value;
108 }
109
110 void DoMouseMove() {
111 // Send a click event to cause some jankiness. This is done via a click
112 // event as ExecuteScript is synchronous.
113 SimulateMouseClick(shell()->web_contents(), 0,
114 blink::WebPointerProperties::ButtonLeft);
115 scoped_refptr<InputMsgWatcher> input_msg_watcher(
116 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::MouseMove));
117 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
118 blink::WebInputEvent::MouseMove, 10, 10, 0));
119 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
120 blink::WebInputEvent::MouseMove, 15, 15, 0));
121 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
122 blink::WebInputEvent::MouseMove, 20, 25, 0));
123
124 // Runs until we get the InputMsgAck callback.
125 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, input_msg_watcher->WaitForAck());
126
127 int mouse_move_count = 0;
128 while (mouse_move_count <= 0)
129 mouse_move_count = ExecuteScriptAndExtractInt("window.mouseMoveCount");
130 EXPECT_EQ(1, mouse_move_count);
131
132 int last_mouse_x =
133 ExecuteScriptAndExtractInt("window.lastMouseMoveEvent.x");
134 int last_mouse_y =
135 ExecuteScriptAndExtractInt("window.lastMouseMoveEvent.y");
136 EXPECT_EQ(20, last_mouse_x);
137 EXPECT_EQ(25, last_mouse_y);
138 }
139
140 void DoTouchMove() {
141 SyntheticWebTouchEvent kEvents[4];
142 kEvents[0].PressPoint(10, 10);
143 kEvents[1].PressPoint(10, 10);
144 kEvents[1].MovePoint(0, 20, 20);
145 kEvents[2].PressPoint(10, 10);
146 kEvents[2].MovePoint(0, 30, 30);
147 kEvents[3].PressPoint(10, 10);
148 kEvents[3].MovePoint(0, 35, 40);
149
150 // Send a click event to cause some jankiness. This is done via a click
151 // event as ExecuteScript is synchronous.
152 SimulateMouseClick(shell()->web_contents(), 0,
153 blink::WebPointerProperties::ButtonLeft);
154 scoped_refptr<InputMsgWatcher> input_msg_watcher(
155 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::TouchMove));
156
157 for (const auto& event : kEvents)
158 GetWidgetHost()->ForwardEmulatedTouchEvent(event);
159
160 // Runs until we get the InputMsgAck callback.
161 EXPECT_EQ(INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING,
162 input_msg_watcher->WaitForAck());
163
164 int touch_move_count = 0;
165 while (touch_move_count <= 0)
166 touch_move_count = ExecuteScriptAndExtractInt("window.touchMoveCount");
167 EXPECT_EQ(1, touch_move_count);
168
169 int last_touch_x = ExecuteScriptAndExtractInt(
170 "window.lastTouchMoveEvent.touches[0].pageX");
171 int last_touch_y = ExecuteScriptAndExtractInt(
172 "window.lastTouchMoveEvent.touches[0].pageY");
173 EXPECT_EQ(35, last_touch_x);
174 EXPECT_EQ(40, last_touch_y);
175 }
176
177 private:
178 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueueBrowserTest);
179 };
180
181 IN_PROC_BROWSER_TEST_F(MainThreadEventQueueBrowserTest, MouseMove) {
182 LoadURL(kJankyPageURL);
183 DoMouseMove();
184 }
185
186 // Disabled on MacOS because it doesn't support touch input.
187 #if defined(OS_MACOSX)
188 #define MAYBE_TouchMove DISABLED_TouchMove
189 #else
190 #define MAYBE_TouchMove TouchMove
191 #endif
192 IN_PROC_BROWSER_TEST_F(MainThreadEventQueueBrowserTest, MAYBE_TouchMove) {
193 LoadURL(kJankyPageURL);
194 DoTouchMove();
195 }
196
197 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/input_router_impl.cc ('k') | content/common/input/input_event_dispatch_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698