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

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: Address issues with test and fix dchecks in debug mode 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 " }"
53 " window.mouseMoveCount = 0;"
54 " window.touchMoveCount = 0;"
55 " document.addEventListener('mousemove', function(e) {"
56 " window.mouseMoveCount++;"
57 " window.lastMouseMoveEvent = e;"
58 " });"
59 " document.addEventListener('touchmove', function (e) {"
60 " window.touchMoveCount++;"
61 " window.lastTouchMoveEvent = e;"
62 " }, {passive: true});"
63 " document.addEventListener('click', function(e) { jank(100); });"
64 " document.title='ready';"
65 "</script>";
66
67 } // namespace
68
69 namespace content {
70
71 class MainThreadEventQueueBrowserTest : public ContentBrowserTest {
72 public:
73 MainThreadEventQueueBrowserTest() {}
74 ~MainThreadEventQueueBrowserTest() override {}
75
76 RenderWidgetHostImpl* GetWidgetHost() {
77 return RenderWidgetHostImpl::From(
78 shell()->web_contents()->GetRenderViewHost()->GetWidget());
79 }
80
81 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) {
82 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result);
83 }
84
85 protected:
86 void LoadURL(const char* page_data) {
87 const GURL data_url(page_data);
88 NavigateToURL(shell(), data_url);
89
90 RenderWidgetHostImpl* host = GetWidgetHost();
91 host->GetView()->SetSize(gfx::Size(400, 400));
92
93 base::string16 ready_title(base::ASCIIToUTF16("ready"));
94 TitleWatcher watcher(shell()->web_contents(), ready_title);
95 ignore_result(watcher.WaitAndGetTitle());
96
97 MainThreadFrameObserver main_thread_sync(host);
98 main_thread_sync.Wait();
99 }
100
101 int ExecuteScriptAndExtractInt(const std::string& script) {
102 int value = 0;
103 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
104 shell(), "domAutomationController.send(" + script + ")", &value));
105 return value;
106 }
107
108 void DoMouseMove() {
109 // Send a click event to cause some jankiness. This is done via a click
110 // event as ExecuteScript is synchronous.
111 SimulateMouseClick(shell()->web_contents(), 0,
112 blink::WebPointerProperties::ButtonLeft);
113 scoped_refptr<InputMsgWatcher> input_msg_watcher(
114 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::MouseMove));
115 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
116 blink::WebInputEvent::MouseMove, 10, 10, 0));
117 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
118 blink::WebInputEvent::MouseMove, 15, 15, 0));
119 GetWidgetHost()->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(
120 blink::WebInputEvent::MouseMove, 20, 25, 0));
121
122 // Runs until we get the InputMsgAck callback.
123 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, input_msg_watcher->WaitForAck());
124
125 int mouse_move_count = 0;
126 while (mouse_move_count <= 0)
127 mouse_move_count = ExecuteScriptAndExtractInt("window.mouseMoveCount");
128 EXPECT_EQ(1, mouse_move_count);
129
130 int last_mouse_x =
131 ExecuteScriptAndExtractInt("window.lastMouseMoveEvent.x");
132 int last_mouse_y =
133 ExecuteScriptAndExtractInt("window.lastMouseMoveEvent.y");
134 EXPECT_EQ(20, last_mouse_x);
135 EXPECT_EQ(25, last_mouse_y);
136 }
137
138 void DoTouchMove() {
139 SyntheticWebTouchEvent kEvents[4];
140 kEvents[0].PressPoint(10, 10);
141 kEvents[1].PressPoint(10, 10);
142 kEvents[1].MovePoint(0, 20, 20);
143 kEvents[2].PressPoint(10, 10);
144 kEvents[2].MovePoint(0, 30, 30);
145 kEvents[3].PressPoint(10, 10);
146 kEvents[3].MovePoint(0, 35, 40);
147
148 // Send a click event to cause some jankiness. This is done via a click
149 // event as ExecuteScript is synchronous.
150 SimulateMouseClick(shell()->web_contents(), 0,
151 blink::WebPointerProperties::ButtonLeft);
152 scoped_refptr<InputMsgWatcher> input_msg_watcher(
153 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::TouchMove));
154
155 for (const auto& event : kEvents)
156 GetWidgetHost()->ForwardEmulatedTouchEvent(event);
157
158 // Runs until we get the InputMsgAck callback.
159 EXPECT_EQ(INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING,
160 input_msg_watcher->WaitForAck());
161
162 int touch_move_count = 0;
163 while (touch_move_count <= 0)
164 touch_move_count = ExecuteScriptAndExtractInt("window.touchMoveCount");
165 EXPECT_EQ(1, touch_move_count);
166
167 int last_touch_x = ExecuteScriptAndExtractInt(
168 "window.lastTouchMoveEvent.touches[0].pageX");
169 int last_touch_y = ExecuteScriptAndExtractInt(
170 "window.lastTouchMoveEvent.touches[0].pageY");
171 EXPECT_EQ(35, last_touch_x);
172 EXPECT_EQ(40, last_touch_y);
173 }
174
175 private:
176 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueueBrowserTest);
177 };
178
179 IN_PROC_BROWSER_TEST_F(MainThreadEventQueueBrowserTest, MouseMove) {
180 LoadURL(kJankyPageURL);
181 DoMouseMove();
182 }
183
184 // Disabled on MacOS because it doesn't support touch input.
185 #if defined(OS_MACOSX)
186 #define MAYBE_TouchMove DISABLED_TouchMove
187 #else
188 #define MAYBE_TouchMove TouchMove
189 #endif
190 IN_PROC_BROWSER_TEST_F(MainThreadEventQueueBrowserTest, MAYBE_TouchMove) {
191 LoadURL(kJankyPageURL);
192 DoTouchMove();
193 }
194
195 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698