Skip to content

Commit ab8b71a

Browse files
mustaqahmedChromium LUCI CQ
authored andcommitted
Don't adjust untrusted TouchEvents.
Untrusted touch events are not fired to DOM for whatever reason. But they still go through the adjustment and causes problem when event target is an empty document. We need to fix wpt/touch-events/touch-retargeting.html by avoiding untrusted event dispatch but test_driver doesn't support input to shadow DOM yet. So switched the test to be manual for now. I manually verified that both Chrome and Firefox passes the manual test. Fixed: 1230583 Change-Id: Ia82cbf4a65d859d76180dae063ee7840efb7f3ab Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3094727 Commit-Queue: Mustaq Ahmed <[email protected]> Reviewed-by: Robert Flack <[email protected]> Cr-Commit-Position: refs/heads/main@{#918857}
1 parent 3e87ae1 commit ab8b71a

File tree

5 files changed

+55
-55
lines changed

5 files changed

+55
-55
lines changed

third_party/blink/renderer/core/events/touch_event.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ void TouchEvent::Trace(Visitor* visitor) const {
184184
}
185185

186186
DispatchEventResult TouchEvent::DispatchEvent(EventDispatcher& dispatcher) {
187-
GetEventPath().AdjustForTouchEvent(*this);
187+
if (isTrusted())
188+
GetEventPath().AdjustForTouchEvent(*this);
188189
return dispatcher.Dispatch();
189190
}
190191

third_party/blink/renderer/core/events/touch_event_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include "third_party/blink/renderer/core/frame/frame_console.h"
1212
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
1313
#include "third_party/blink/renderer/core/frame/local_frame.h"
14+
#include "third_party/blink/renderer/core/frame/settings.h"
1415
#include "third_party/blink/renderer/core/loader/empty_clients.h"
16+
#include "third_party/blink/renderer/core/script/classic_script.h"
1517
#include "third_party/blink/renderer/core/testing/page_test_base.h"
1618
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
1719
#include "third_party/blink/renderer/platform/wtf/vector.h"
@@ -93,6 +95,18 @@ TEST_F(TouchEventTest,
9395
ElementsAre(mojom::ConsoleMessageSource::kIntervention));
9496
}
9597

98+
TEST_F(TouchEventTest, DispatchWithEmptyDocTargetDoesntCrash) {
99+
String script =
100+
"var empty_document = new Document();"
101+
"var touch = new Touch({'identifier': 0, 'target': empty_document});"
102+
"var touch_event = new TouchEvent('touchmove', {'touches': [touch]});"
103+
"document.dispatchEvent(touch_event);";
104+
105+
GetDocument().GetSettings()->SetScriptEnabled(true);
106+
ClassicScript::CreateUnspecifiedScript(ScriptSourceCode(script))
107+
->RunScript(GetDocument().domWindow());
108+
}
109+
96110
class TouchEventTestNoFrame : public testing::Test {};
97111

98112
TEST_F(TouchEventTestNoFrame, PreventDefaultDoesntRequireFrame) {

third_party/blink/web_tests/NeverFixTests

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,9 @@ crbug.com/687225 external/wpt/css/css-counter-styles/ethiopic-numeric/* [ Skip ]
19101910
wpt_internal/document-transition/* [ Skip ]
19111911
virtual/document-transition/wpt_internal/document-transition/* [ Pass ]
19121912

1913+
# Manual tests in wpt/touch-events
1914+
crbug.com/1247306 external/wpt/touch-events/touch-retargeting-manual.html [ Skip ]
1915+
19131916
# Tests Linux system font available only in Regular style in Linux set of fonts.
19141917
crbug.com/509989 [ Mac ] virtual/text-antialias/font-synthesis-weight-system-linux.html [ Skip ]
19151918
crbug.com/509989 [ Win ] virtual/text-antialias/font-synthesis-weight-system-linux.html [ Skip ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>TouchEvent Retargeting Tests</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
</head>
8+
<body>
9+
<h1>Touch retargeting manual test</h1>
10+
<div>This test requires touch input.</div>
11+
<div id="host"></div>
12+
</body>
13+
<script>
14+
var host = document.getElementById("host");
15+
var root = host.attachShadow({ mode: "open" });
16+
var target = document.createElement("h2");
17+
target.textContent = "Tap on THIS line of text";
18+
root.appendChild(target);
19+
20+
var test_touch_retargeting = async_test("touch_retargeting");
21+
22+
on_event(host, "touchstart", e => {
23+
test_touch_retargeting.step(() => {
24+
assert_equals(e.touches.length, 1, "touches.length is correct");
25+
assert_equals(e.touches[0].target, host, "touches[0] is retargeted to host");
26+
27+
assert_equals(e.targetTouches.length, 1, "targetTouches.length is correct");
28+
assert_equals(e.targetTouches[0].target, host, "targetTouches[0] is retargeted to host");
29+
30+
assert_equals(e.changedTouches.length, 1, "changedTouches.length is correct");
31+
assert_equals(e.changedTouches[0].target, host, "changedTouches[0] is retargeted to host");
32+
});
33+
});
34+
on_event(host, "touchend", e => test_touch_retargeting.done());
35+
</script>
36+
</html>

third_party/blink/web_tests/external/wpt/touch-events/touch-retargeting.html

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)