Bug 1616437 [wpt PR 21873] - Don't make anchor clicks cancel form submission when href=#, a=testonly

Automatic update from web-platform-tests
Don't make anchor clicks cancel form submission when href=#

In http://crrev.com/c/1922699 I made anchor clicks cancel all form
submissions on a page in order to make this test pass:
external/wpt/html/browsers/browsing-the-web/navigating-across-documents/006.html

The test basically says that anchor navigations should take precedence
over form submissions when the form submission is initiated by the
onclick handler of the anchor element.

However, when the anchor has href="#", form submissions should actually
go through, and this has introduced a bug on websites which rely on this
behavior.

This logic I added to cancel form submissions would not be necessary if
we made anchor clicks navigate asynchronously like the spec says to do,
so I made a bug to do so and remove this logic: http://crbug.com/1053679

Bug: 1053312
Change-Id: I27bf193cf0d544222cddad932728a1d0f61ba62a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063265
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743410}

--

wpt-commits: af2a784ca500a061287d26b75f7822cb4cb99b34
wpt-pr: 21873
This commit is contained in:
Joey Arhar 2020-02-21 22:01:49 +00:00 коммит произвёл moz-wptsync-bot
Родитель 025cf894aa
Коммит bbbd30cc4d
5 изменённых файлов: 100 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/C/#following-hyperlinks">
<title>Anchor element with onclick form submission and href to fragment</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- When an anchor element has an onclick handler which submits a form,
the anchor's navigation should occur instead of the form's navigation.
However, if the anchor has an href which is just a fragment like "#",
then the form should be submitted. Many sites rely on this behavior. -->
<iframe name="test"></iframe>
<form target="test" action="form.html"></form>
<a id="anchor" target="test" onclick="document.forms[0].submit()" href="#fragment">Test</a>
<script>
async_test(t => {
const anchor = document.getElementById('anchor');
t.step(() => anchor.click());
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
});
</script>

Просмотреть файл

@ -0,0 +1,35 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/C/#following-hyperlinks">
<title>Anchor element with onclick form submission and href to fragment</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- When an anchor element has an onclick handler which submits a form,
the anchor's navigation should occur instead of the form's navigation.
However, if the anchor has an href which is just a fragment like "#",
then the form should be submitted. Many sites rely on this behavior. -->
<iframe name="test"></iframe>
<form target="test" action="form.html"></form>
<a id="anchor" target="test" onclick="document.forms[0].submit()">Test</a>
<script>
async_test(async t => {
const iframe = document.querySelector('iframe');
const iframeLoadPromise = new Promise(resolve => iframe.onload = resolve);
iframe.src = '/';
await iframeLoadPromise;
const anchor = document.getElementById('anchor');
anchor.href = '/#';
t.step(() => anchor.click());
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
});
</script>

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/C/#following-hyperlinks">
<title>Anchor element with onclick form submission and href to fragment</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- When an anchor element has an onclick handler which submits a form,
the anchor's navigation should occur instead of the form's navigation.
However, if the anchor has an href which is just a fragment like "#",
then the form should be submitted. Many sites rely on this behavior. -->
<iframe name="test"></iframe>
<form target="test" action="form.html"></form>
<a id="anchor" target="test" onclick="document.forms[0].submit()" href="#">Test</a>
<script>
async_test(t => {
const anchor = document.getElementById('anchor');
t.step(() => anchor.click());
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
});
</script>

Просмотреть файл

@ -0,0 +1,5 @@
<!DOCTYPE html>
<script>
parent.postMessage("form navigation", "*");
</script>
form navigation

Просмотреть файл

@ -1,7 +1,7 @@
//META: global=!default, worker
test(() => {
proto = new Number(42)
const proto = {};
assert_equals(String(Object.getPrototypeOf(WorkerLocation)).replace(/\n/g, " ").replace(/\s\s+/g, " "), "function () { [native code] }");
WorkerLocation.__proto__ = proto;
assert_object_equals(Object.getPrototypeOf(WorkerLocation), Object(42));
assert_equals(Object.getPrototypeOf(WorkerLocation), proto);
}, 'Tests that setting the proto of a built in constructor is not reset.');