Commit 2e1ab2b0 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Replace eventSender.mouseScrollBy with gpuBenchmarking.smoothScrollBy Part1

After we finish the scroll unification, the scrolls happens mainly on
the compositor thread, and the scroll code in the main thread will be
removed. eventSender sends the scroll events to main thread, so it
would not work after the scroll unification. We should replace
eventSender.mouseScrollBy with gpuBenchmarking.smoothScrollBy
in all the layout tests, this is part 1.

Bug: 1047176
Change-Id: If746d2b7a4b0a031829105115d9c27d46a27cfa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119532
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759417}
parent 25681b3b
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_keyboard_event.h" #include "third_party/blink/public/common/input/web_keyboard_event.h"
#include "third_party/blink/public/common/input/web_mouse_wheel_event.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h" #include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/range.h" #include "third_party/blink/renderer/core/dom/range.h"
...@@ -3040,4 +3041,45 @@ TEST_F(EventHandlerSimTest, PenDraggingOnElementActive) { ...@@ -3040,4 +3041,45 @@ TEST_F(EventHandlerSimTest, PenDraggingOnElementActive) {
GetDocument().getElementById("target")); GetDocument().getElementById("target"));
} }
TEST_F(EventHandlerSimTest, TestNoCrashOnMouseWheelZeroDelta) {
WebView().MainFrameWidget()->Resize(WebSize(800, 600));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<body>
<div id="area" style="width:100px;height:100px">
</div>
<p id='log'>no wheel event</p>
</body>
<script>
document.addEventListener('wheel', (e) => {
let log = document.getElementById('log');
log.innerText = 'received wheel event, deltaX: ' + e.deltaX + ' deltaY: ' + e.deltaY;
});
</script>
)HTML");
Compositor().BeginFrame();
// Set mouse position and active web view.
InitializeMousePositionAndActivateView(50, 50);
Compositor().BeginFrame();
WebElement element = GetDocument().getElementById("log");
WebMouseWheelEvent wheel_event(
blink::WebInputEvent::kMouseWheel, blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
wheel_event.SetPositionInScreen(50, 50);
wheel_event.delta_x = 0;
wheel_event.delta_y = 0;
wheel_event.phase = WebMouseWheelEvent::kPhaseBegan;
GetDocument().GetFrame()->GetEventHandler().HandleWheelEvent(wheel_event);
EXPECT_EQ("received wheel event, deltaX: 0 deltaY: 0",
element.InnerHTML().Utf8());
ASSERT_EQ(0,
GetDocument().View()->LayoutViewport()->GetScrollOffset().Height());
ASSERT_EQ(0,
GetDocument().View()->LayoutViewport()->GetScrollOffset().Width());
}
} // namespace blink } // namespace blink
CONSOLE WARNING: line 25: Element.createShadowRoot is deprecated and will be removed in M80, around February 2020. Please use Element.attachShadow instead. See https://www.chromestatus.com/features/4507242028072960 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.
PASS: mousewheel event is fired.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="../../../resources/gesture-util.js"></script>
<head> <script src="../../../resources/testharness.js"></script>
<script src="../resources/event-sender-util.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<div id="host"></div> <div id="host"></div>
<pre id="console"></pre>
<script> <script>
var receivedMouseWheel = false;
function createBox(name) { function createBox(name) {
var div = document.createElement('div'); var div = document.createElement('div');
div.style.width = '100px'; div.style.width = '100px';
div.style.height = '100px'; div.style.height = '100px';
div.addEventListener('mousewheel', function(e) { div.addEventListener('mousewheel', function(e) {
debug('PASS: mousewheel event is fired.'); receivedMouseWheel = true;
}); });
return div; return div;
} }
var shadowRoot = host.createShadowRoot(); promise_test(async () => {
var shadowDiv = createBox('shadow'); var shadowRoot = host.attachShadow({ mode: 'open' });
shadowRoot.appendChild(shadowDiv); var shadowDiv = createBox('shadow');
shadowRoot.appendChild(shadowDiv);
mouseMoveToElem(shadowDiv); var center = elementCenter(shadowDiv);
eventSender.mouseScrollBy(0, 1); await wheelTick(1, center, 'up');
var successfullyParsed = true; assert_true(receivedMouseWheel);
}, "Verify a mousewheel event is fired when wheeling over shadow div element.");
</script> </script>
</body>
</html>
CONSOLE WARNING: line 25: Element.createShadowRoot is deprecated and will be removed in M80, around February 2020. Please use Element.attachShadow instead. See https://www.chromestatus.com/features/4507242028072960 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.
PASS: mousewheel event is fired.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="../../../resources/gesture-util.js"></script>
<head> <script src="../../../resources/testharness.js"></script>
<script src="../resources/event-sender-util.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<div id="host"></div> <div id="host"></div>
<pre id="console"></pre>
<script> <script>
var receivedMouseWheel = false;
function createInput(name) { function createInput(name) {
var div = document.createElement('input'); var div = document.createElement('input');
div.style.width = '100px'; div.style.width = '100px';
div.style.height = '100px'; div.style.height = '100px';
div.addEventListener('mousewheel', function(e) { div.addEventListener('mousewheel', function(e) {
debug('PASS: mousewheel event is fired.'); receivedMouseWheel = true;
}); });
return div; return div;
} }
var shadowRoot = host.createShadowRoot(); promise_test(async () => {
var shadowDiv = createInput('shadow'); var shadowRoot = host.attachShadow({ mode: 'open' });
shadowRoot.appendChild(shadowDiv); var shadowDiv = createInput('shadow');
shadowRoot.appendChild(shadowDiv);
mouseMoveToElem(shadowDiv); var center = elementCenter(shadowDiv);
eventSender.mouseScrollBy(0, 1); await wheelTick(1, center, 'up');
var successfullyParsed = true; assert_true(receivedMouseWheel);
}, "Verify a mousewheel event is fired when wheeling over shadow div element.");
</script> </script>
</body>
</html>
This test can be used to verify that a mousewheel event is fired when wheeling over the subframe but not dispatched to the parent frame.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
PASS received mousewheel event.
<script src="../../resources/js-test.js"></script> <!DOCTYPE html>
<p id="description"></p> <script src="../../resources/gesture-util.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<iframe id="frame" src="resources/iframe-mousewheel.html"></iframe> <iframe id="frame" src="resources/iframe-mousewheel.html"></iframe>
<div id="console"></div>
<script>
if (window.testRunner)
testRunner.waitUntilDone();
var testFinished = false;
description("This test can be used to verify that a mousewheel event is fired when wheeling over the subframe but not dispatched to the parent frame."); <script>
var receivedMouseWheel = false;
var iframeReceivedMouseWheel = false;
document.addEventListener("wheel", function() { document.addEventListener("wheel", function() {
testFailed("Received wheel event in parent"); receivedMouseWheel = true;
if (window.testRunner)
testRunner.notifyDone();
}); });
function iframeMouseWheel() function iframeMouseWheel()
{ {
if (testFinished) iframeReceivedMouseWheel = true;
return;
testFinished = true;
setTimeout(done, 0);
} }
function done() promise_test(async () => {
{
testPassed("received mousewheel event.");
if (window.testRunner)
testRunner.notifyDone();
}
function runTest()
{
if (!window.eventSender)
return;
var frame = document.getElementById("frame"); var frame = document.getElementById("frame");
var centerX = frame.offsetLeft + frame.offsetWidth / 2; var center = elementCenter(frame);
var centerY = frame.offsetTop + frame.offsetHeight / 2; await wheelTick(1, center, 'up', 4000);
eventSender.mouseMoveTo(centerX, centerY); assert_false(receivedMouseWheel, "Received wheel event in parent");
eventSender.mouseScrollBy(0, 53); assert_true(iframeReceivedMouseWheel, "Received wheel event in iframe");
} }, "Mousewheel in iframe doesn't dispatch to parent.");
window.onload = runTest;
</script> </script>
Ensures that a mouse scrolling with (deltaX=0, deltaY=0) doesn't crash the browser.
Passes if doesn't crash.
<html>
<head>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function runTest()
{
if (!window.eventSender)
return;
var area = document.getElementById('area');
var x = area.offsetLeft + area.offsetWidth / 2;
var y = area.offsetTop + area.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseScrollBy(0, 0);
}
</script>
</head>
<body onload="runTest()">
<p id="description">Ensures that a mouse scrolling with (deltaX=0, deltaY=0) doesn't crash the browser.
<p>Passes if doesn't crash.
<div id="area" style="width:100px;height:100px">
</div>
</body>
</html>
Tests the interaction between the standard 'wheel' event and the non-standard 'mousewheel' one
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Standard wheel event was fired.
PASS testEvent.__proto__ is WheelEvent.prototype
PASS successfullyParsed is true
TEST COMPLETE
TOP TOP TOP TOP TOP TOP TOP Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here END END END END END END END
<!DOCTYPE html> <!DOCTYPE html>
<html> <script src="../../../resources/gesture-util.js"></script>
<head> <script src="../../../resources/testharness.js"></script>
<link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-WheelEvent"> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/js-test.js"></script>
<script>
function runTest() {
var div = document.getElementById('target');
div.addEventListener('wheel', wheelHandler);
div.addEventListener('mousewheel', mouseWheelHandler);
if (window.eventSender) {
eventSender.mouseMoveTo(div.offsetLeft + 5, div.offsetTop + 5);
eventSender.mouseScrollBy(10, 20, false, true, 0, true, "phaseBegan");
finishJSTest();
} else {
debug("FAIL: This test requires window.eventSender.");
finishJSTest();
}
}
var testEvent;
function wheelHandler(e) {
testEvent = e;
testPassed("Standard wheel event was fired.");
shouldBe("testEvent.__proto__", "WheelEvent.prototype");
}
function mouseWheelHandler(e) {
testFailed("mousewheel event should not have fired.");
}
</script>
</head>
<body>
<span id="parent"> <span id="parent">
<div id="target" style="border:solid 1px green; width:220px; height:70px; overflow:scroll"> <div id="target" style="border:solid 1px green; width:220px; height:70px; overflow:scroll">
TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP
...@@ -44,11 +14,28 @@ function mouseWheelHandler(e) { ...@@ -44,11 +14,28 @@ function mouseWheelHandler(e) {
END END END END END END END END END END END END END END
</div> </div>
</span> </span>
<script> <script>
description("Tests the interaction between the standard 'wheel' event and the non-standard 'mousewheel' one"); var receivedMouseWheel = false;
window.jsTestIsAsync = true; var testEvent;
function wheelHandler(e) {
testEvent = e;
}
function mouseWheelHandler(e) {
receivedMouseWheel = true;
}
promise_test(async () => {
var div = document.getElementById('target');
div.addEventListener('wheel', wheelHandler);
div.addEventListener('mousewheel', mouseWheelHandler);
var center = elementCenter(div);
await wheelTick(20, center, 'upleft', 4000);
assert_equals(testEvent.__proto__, WheelEvent.prototype, "Standard wheel event was fired.");
assert_false(receivedMouseWheel, "mousewheel event should not have fired.");
}, "Tests the interaction between the standard and the non-standard 'mousewheel'.");
runTest();
</script> </script>
</body>
</html>
...@@ -186,6 +186,14 @@ function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type, d ...@@ -186,6 +186,14 @@ function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type, d
}); });
} }
function wheelTick(scroll_tick, center, direction, speed_in_pixels_s) {
if (typeof(speed_in_pixels_s) == "undefined")
speed_in_pixels_s = SPEED_INSTANT;
// Do not allow precise scrolling deltas for tick wheel scroll.
return smoothScroll(scroll_tick * pixelsPerTick(), center.x, center.y, GestureSourceType.MOUSE_INPUT,
direction, speed_in_pixels_s, false /* precise_scrolling_deltas */);
}
const LEGACY_MOUSE_WHEEL_TICK_MULTIPLIER = 120; const LEGACY_MOUSE_WHEEL_TICK_MULTIPLIER = 120;
// Returns the number of pixels per wheel tick which is a platform specific value. // Returns the number of pixels per wheel tick which is a platform specific value.
......
CONSOLE ERROR: line 25: Uncaught TypeError: host.createShadowRoot is not a function
FAIL successfullyParsed should be true. Was false.
TEST COMPLETE
CONSOLE ERROR: line 25: Uncaught TypeError: host.createShadowRoot is not a function
FAIL successfullyParsed should be true. Was false.
TEST COMPLETE
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment