From 57649bfadd66e501d325a2a05803447fd5c3df05 Mon Sep 17 00:00:00 2001 From: Nate Chapin Date: Thu, 28 Sep 2023 20:02:42 -0700 Subject: [PATCH] NavigateEvent sourceElement prototype Adds a new attribute to the NavigateEvent, sourceElement, which is the Element that initiated the navigation (if any). Set for anchor clicks (both HTML and SVG ) and form submissions. Implemented behind the NavigateEventSourceElement flag. I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/fJhFQV-2v38/m/p7F00AQhAAAJ Explainer: https://github.com/WICG/navigation-api/commit/85edaf1d4d42355b020807cd56f6a22784978c3d Bug: 1483000 Change-Id: Icb09e7ac425aee1c7772c1bfcdafeaa0883bc072 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4385906 Auto-Submit: Nate Chapin Commit-Queue: Domenic Denicola Reviewed-by: Domenic Denicola Cr-Commit-Position: refs/heads/main@{#1203020} --- .../navigate-event/event-constructor.html | 12 +++++-- .../navigate-anchor-cross-origin.html | 1 + ...avigate-anchor-download-userInitiated.html | 1 + .../navigate-anchor-download.html | 1 + .../navigate-anchor-fragment.html | 1 + ...ate-anchor-same-origin-cross-document.html | 1 + .../navigate-anchor-userInitiated.html | 1 + .../navigate-anchor-with-target.html | 1 + ...ate-destination-getState-back-forward.html | 1 + ...avigate-destination-getState-navigate.html | 1 + .../navigate-destination-getState-reload.html | 1 + .../navigate-event/navigate-form-get.html | 1 + .../navigate-event/navigate-form-reload.html | 1 + .../navigate-form-requestSubmit.html | 35 +++++++++++++++++++ .../navigate-form-traverse.html | 1 + .../navigate-form-userInitiated.html | 1 + .../navigate-form-with-target.html | 1 + .../navigate-event/navigate-form.html | 1 + .../navigate-history-back-after-fragment.html | 1 + ...navigate-history-back-after-pushState.html | 1 + .../navigate-history-back-cross-document.html | 1 + .../navigate-event/navigate-history-go-0.html | 1 + .../navigate-history-pushState.html | 1 + .../navigate-history-replaceState.html | 1 + .../navigate-iframe-location.html | 1 + .../navigate-event/navigate-location.html | 1 + .../navigate-event/navigate-meta-refresh.html | 1 + ...vigate-navigation-back-cross-document.html | 1 + ...vigation-back-same-document-in-iframe.html | 1 + ...avigate-navigation-back-same-document.html | 1 + .../navigate-navigation-navigate.html | 1 + .../navigate-svg-anchor-fragment.html | 26 ++++++++++++++ .../navigate-event/navigate-to-srcdoc.html | 1 + .../navigate-window-open-self.html | 1 + .../navigate-event/navigate-window-open.html | 1 + 35 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 navigation-api/navigate-event/navigate-form-requestSubmit.html create mode 100644 navigation-api/navigate-event/navigate-svg-anchor-fragment.html diff --git a/navigation-api/navigate-event/event-constructor.html b/navigation-api/navigate-event/event-constructor.html index a668730e35f1aa2..863681ced730d1c 100644 --- a/navigation-api/navigate-event/event-constructor.html +++ b/navigation-api/navigate-event/event-constructor.html @@ -18,7 +18,8 @@ signal: (new AbortController()).signal, formData: null, downloadRequest: null, - info: null + info: null, + sourceElement: null }); }); }, "destination is required"); @@ -35,7 +36,8 @@ hashChange: false, formData: null, downloadRequest: null, - info: null + info: null, + sourceElement: null }); }); }); @@ -50,6 +52,7 @@ const signal = (new AbortController()).signal; const downloadRequest = "abc"; const hasUAVisualTransition = true; + const sourceElement = document.createElement("a"); const event = new NavigateEvent("navigate", { navigationType: "replace", @@ -61,7 +64,8 @@ formData, downloadRequest, info, - hasUAVisualTransition + hasUAVisualTransition, + sourceElement }); assert_equals(event.navigationType, "replace"); @@ -74,6 +78,7 @@ assert_equals(event.downloadRequest, downloadRequest); assert_equals(event.info, info); assert_equals(event.hasUAVisualTransition, hasUAVisualTransition); + assert_equals(event.sourceElement, sourceElement); }); history.pushState(2, null, "#2"); }, "all properties are reflected back"); @@ -93,6 +98,7 @@ assert_equals(event.formData, null); assert_equals(event.downloadRequest, null); assert_equals(event.info, undefined); + assert_equals(event.sourceElement, null); }); history.pushState(3, null, "#3"); }, "defaults are as expected"); diff --git a/navigation-api/navigate-event/navigate-anchor-cross-origin.html b/navigation-api/navigate-event/navigate-anchor-cross-origin.html index ee0992485078fd8..62e5adb20ae88c3 100644 --- a/navigation-api/navigate-event/navigate-anchor-cross-origin.html +++ b/navigation-api/navigate-event/navigate-anchor-cross-origin.html @@ -17,6 +17,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, document.getElementById("a")); e.preventDefault(); }); a.click(); diff --git a/navigation-api/navigate-event/navigate-anchor-download-userInitiated.html b/navigation-api/navigate-event/navigate-anchor-download-userInitiated.html index b9506984dad8d8c..69181425292e758 100644 --- a/navigation-api/navigate-event/navigate-anchor-download-userInitiated.html +++ b/navigation-api/navigate-event/navigate-anchor-download-userInitiated.html @@ -21,6 +21,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, document.getElementById("a")); e.preventDefault(); t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0); }); diff --git a/navigation-api/navigate-event/navigate-anchor-download.html b/navigation-api/navigate-event/navigate-anchor-download.html index 05fb0ecf2fe6f60..d04245ec253ce0b 100644 --- a/navigation-api/navigate-event/navigate-anchor-download.html +++ b/navigation-api/navigate-event/navigate-anchor-download.html @@ -25,6 +25,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, a); e.preventDefault(); }); a.click(); diff --git a/navigation-api/navigate-event/navigate-anchor-fragment.html b/navigation-api/navigate-event/navigate-anchor-fragment.html index 51221ebcad381b0..6443ccecd1d702c 100644 --- a/navigation-api/navigate-event/navigate-anchor-fragment.html +++ b/navigation-api/navigate-event/navigate-anchor-fragment.html @@ -17,6 +17,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, document.getElementById("a")); e.preventDefault(); t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0); }); diff --git a/navigation-api/navigate-event/navigate-anchor-same-origin-cross-document.html b/navigation-api/navigate-event/navigate-anchor-same-origin-cross-document.html index 68f5bf0627c123f..5a6dce7ec8bcc9b 100644 --- a/navigation-api/navigate-event/navigate-anchor-same-origin-cross-document.html +++ b/navigation-api/navigate-event/navigate-anchor-same-origin-cross-document.html @@ -18,6 +18,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, document.getElementById("a")); e.preventDefault(); }); a.click(); diff --git a/navigation-api/navigate-event/navigate-anchor-userInitiated.html b/navigation-api/navigate-event/navigate-anchor-userInitiated.html index 39192c915132485..bb76e7a3fbe6512 100644 --- a/navigation-api/navigate-event/navigate-anchor-userInitiated.html +++ b/navigation-api/navigate-event/navigate-anchor-userInitiated.html @@ -20,6 +20,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, document.getElementById("a")); e.preventDefault(); t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0); }); diff --git a/navigation-api/navigate-event/navigate-anchor-with-target.html b/navigation-api/navigate-event/navigate-anchor-with-target.html index 6407b963beb7cd8..e4b897d82f3ddc6 100644 --- a/navigation-api/navigate-event/navigate-anchor-with-target.html +++ b/navigation-api/navigate-event/navigate-anchor-with-target.html @@ -23,6 +23,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, null); e.preventDefault(); }); a.click(); diff --git a/navigation-api/navigate-event/navigate-destination-getState-back-forward.html b/navigation-api/navigate-event/navigate-destination-getState-back-forward.html index c8b1043aba6f5ee..869fc1648157b25 100644 --- a/navigation-api/navigate-event/navigate-destination-getState-back-forward.html +++ b/navigation-api/navigate-event/navigate-destination-getState-back-forward.html @@ -19,6 +19,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, null); }); navigation.back(); }), 0); diff --git a/navigation-api/navigate-event/navigate-destination-getState-navigate.html b/navigation-api/navigate-event/navigate-destination-getState-navigate.html index 5dac40de566e9e4..d19a16851453a0e 100644 --- a/navigation-api/navigate-event/navigate-destination-getState-navigate.html +++ b/navigation-api/navigate-event/navigate-destination-getState-navigate.html @@ -16,6 +16,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, null); }); navigation.navigate("#foo", { state: navState }); }, 0); diff --git a/navigation-api/navigate-event/navigate-destination-getState-reload.html b/navigation-api/navigate-event/navigate-destination-getState-reload.html index a180e086a94b084..ac6528ce7ef261a 100644 --- a/navigation-api/navigate-event/navigate-destination-getState-reload.html +++ b/navigation-api/navigate-event/navigate-destination-getState-reload.html @@ -16,6 +16,7 @@ assert_equals(e.destination.key, ""); assert_equals(e.destination.id, ""); assert_equals(e.destination.index, -1); + assert_equals(e.sourceElement, null); e.intercept(); }); navigation.updateCurrentEntry({ state: navState }); diff --git a/navigation-api/navigate-event/navigate-form-get.html b/navigation-api/navigate-event/navigate-form-get.html index 87a102ddc0598f9..7a71a1c3050a0cc 100644 --- a/navigation-api/navigate-event/navigate-form-get.html +++ b/navigation-api/navigate-event/navigate-form-get.html @@ -21,6 +21,7 @@ // Because it's a GET, not a POST assert_equals(e.formData, null); + assert_equals(e.sourceElement, form); }); window.onload = t.step_func(() => form.submit()); }, "
submission with GET method fires navigate event but with formData null"); diff --git a/navigation-api/navigate-event/navigate-form-reload.html b/navigation-api/navigate-event/navigate-form-reload.html index f18a11ebdaca671..217169053722c2b 100644 --- a/navigation-api/navigate-event/navigate-form-reload.html +++ b/navigation-api/navigate-event/navigate-form-reload.html @@ -12,6 +12,7 @@ iframe.contentWindow.navigation.onnavigate = t.step_func(e => { assert_equals(e.navigationType, "push"); assert_not_equals(e.formData, null); + assert_equals(e.sourceElement, null); iframe.onload = t.step_func(() => { iframe.contentWindow.navigation.onnavigate = t.step_func_done(e => { diff --git a/navigation-api/navigate-event/navigate-form-requestSubmit.html b/navigation-api/navigate-event/navigate-form-requestSubmit.html new file mode 100644 index 000000000000000..38dd9c7eee649f3 --- /dev/null +++ b/navigation-api/navigate-event/navigate-form-requestSubmit.html @@ -0,0 +1,35 @@ + + + + + + +