Truly independent web browser
LibWeb: Set NavigateEvent.sourceElement for hyperlinks and forms
Shannon Booth0d5fea702991
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex cf441c7262f..abdb9936bd5 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -659,12 +659,11 @@ void Element::follow_the_hyperlink(Optional<Utf16String> hyperlink_suffix, HTML:// 11. Navigate targetNavigable to urlString using subject's node document, with referrerPolicy set to subject's// hyperlink referrer policy, userInvolvement set to userInvolvement, and sourceElement set to subject.- // FIXME: Set sourceElement.auto url = url_string_with_suffix.has_value()? URL::Parser::basic_parse(url_string_with_suffix->utf16_view()): URL::Parser::basic_parse(url_string);VERIFY(url.has_value());- MUST(target_navigable->navigate({ .url = url.release_value(), .source_document = document(), .referrer_policy = hyperlink_referrer_policy(), .user_involvement = user_involvement }));+ MUST(target_navigable->navigate({ .url = url.release_value(), .source_document = document(), .referrer_policy = hyperlink_referrer_policy(), .user_involvement = user_involvement, .source_element = this }));}// https://html.spec.whatwg.org/multipage/links.html#hyperlink-referrer-policydiff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cppindex e2261bfad5b..4e0745d264a 100644--- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp@@ -335,21 +335,21 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(GC::Ref<HTMLElement> submif (scheme.is_one_of("http"sv, "https"sv)) {if (method == MethodAttributeState::GET)- TRY_OR_THROW_OOM(vm, mutate_action_url(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement));+ TRY_OR_THROW_OOM(vm, mutate_action_url(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement, submitter));else- TRY_OR_THROW_OOM(vm, submit_as_entity_body(parsed_action.release_value(), move(entry_list), encoding_type, move(encoding), *target_navigable, history_handling, options.user_involvement));+ TRY_OR_THROW_OOM(vm, submit_as_entity_body(parsed_action.release_value(), move(entry_list), encoding_type, move(encoding), *target_navigable, history_handling, options.user_involvement, submitter));} else if (scheme.is_one_of("ftp"sv, "javascript"sv)) {- get_action_url(parsed_action.release_value(), move(entry_list), *target_navigable, history_handling, options.user_involvement);+ get_action_url(parsed_action.release_value(), move(entry_list), *target_navigable, history_handling, options.user_involvement, submitter);} else if (scheme.is_one_of("data"sv, "file"sv)) {if (method == MethodAttributeState::GET)- TRY_OR_THROW_OOM(vm, mutate_action_url(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement));+ TRY_OR_THROW_OOM(vm, mutate_action_url(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement, submitter));else- get_action_url(parsed_action.release_value(), move(entry_list), *target_navigable, history_handling, options.user_involvement);+ get_action_url(parsed_action.release_value(), move(entry_list), *target_navigable, history_handling, options.user_involvement, submitter);} else if (scheme == "mailto"sv) {if (method == MethodAttributeState::GET)- TRY_OR_THROW_OOM(vm, mail_with_headers(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement));+ TRY_OR_THROW_OOM(vm, mail_with_headers(parsed_action.release_value(), move(entry_list), move(encoding), *target_navigable, history_handling, options.user_involvement, submitter));else- TRY_OR_THROW_OOM(vm, mail_as_body(parsed_action.release_value(), move(entry_list), encoding_type, move(encoding), *target_navigable, history_handling, options.user_involvement));+ TRY_OR_THROW_OOM(vm, mail_as_body(parsed_action.release_value(), move(entry_list), encoding_type, move(encoding), *target_navigable, history_handling, options.user_involvement, submitter));} else {dbgln("Failed to submit form: Unknown scheme: {}", scheme);return {};@@ -906,7 +906,7 @@ static ErrorOr<Utf16String> plain_text_encode(Vector<DOMURL::QueryParam> const&}// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submit-mutate-action-ErrorOr<void> HTMLFormElement::mutate_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+ErrorOr<void> HTMLFormElement::mutate_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Let pairs be the result of converting to a list of name-value pairs with entry list.auto pairs = TRY(convert_to_list_of_name_value_pairs(entry_list));@@ -918,12 +918,12 @@ ErrorOr<void> HTMLFormElement::mutate_action_url(URL::URL parsed_action, GC::Conparsed_action.set_query(query);// 4. Plan to navigate to parsed action.- plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement);+ plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement, submitter);return {};}// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submit-body-ErrorOr<void> HTMLFormElement::submit_as_entity_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+ErrorOr<void> HTMLFormElement::submit_as_entity_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Assert: method is POST.@@ -982,20 +982,20 @@ ErrorOr<void> HTMLFormElement::submit_as_entity_body(URL::URL parsed_action, GC:}// 3. Plan to navigate to parsed action given a POST resource whose request body is body and request content-type is mimeType.- plan_to_navigate_to(parsed_action, POSTResource { .request_body = move(body), .request_content_type = mime_type, .request_content_type_directives = move(mime_type_directives) }, move(entry_list), target_navigable, history_handling, user_involvement);+ plan_to_navigate_to(parsed_action, POSTResource { .request_body = move(body), .request_content_type = mime_type, .request_content_type_directives = move(mime_type_directives) }, move(entry_list), target_navigable, history_handling, user_involvement, submitter);return {};}// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submit-get-action-void HTMLFormElement::get_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+void HTMLFormElement::get_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Plan to navigate to parsed action.// Spec Note: entry list is discarded.- plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement);+ plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement, submitter);}// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submit-mailto-headers-ErrorOr<void> HTMLFormElement::mail_with_headers(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+ErrorOr<void> HTMLFormElement::mail_with_headers(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Let pairs be the result of converting to a list of name-value pairs with entry list.auto pairs = TRY(convert_to_list_of_name_value_pairs(entry_list));@@ -1010,11 +1010,11 @@ ErrorOr<void> HTMLFormElement::mail_with_headers(URL::URL parsed_action, GC::Conparsed_action.set_query(headers);// 5. Plan to navigate to parsed action.- plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement);+ plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement, submitter);return {};}-ErrorOr<void> HTMLFormElement::mail_as_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+ErrorOr<void> HTMLFormElement::mail_as_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, [[maybe_unused]] Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Let pairs be the result of converting to a list of name-value pairs with entry list.auto pairs = TRY(convert_to_list_of_name_value_pairs(entry_list));@@ -1062,12 +1062,12 @@ ErrorOr<void> HTMLFormElement::mail_as_body(URL::URL parsed_action, GC::Conservaparsed_action.set_query(query_builder.string_view());// 7. Plan to navigate to parsed action.- plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement);+ plan_to_navigate_to(move(parsed_action), Empty {}, move(entry_list), target_navigable, history_handling, user_involvement, submitter);return {};}// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plan-to-navigate-void HTMLFormElement::plan_to_navigate_to(URL::URL url, DocumentResource post_resource, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement)+void HTMLFormElement::plan_to_navigate_to(URL::URL url, DocumentResource post_resource, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter){// 1. Let referrerPolicy be the empty string.ReferrerPolicy::ReferrerPolicy referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString;@@ -1084,14 +1084,15 @@ void HTMLFormElement::plan_to_navigate_to(URL::URL url, DocumentResource post_re}// 4. Queue an element task on the DOM manipulation task source given the form element and the following steps:- // NOTE: `this`, `actual_resource` and `target_navigable` are protected by GC::HeapFunction.- queue_an_element_task(Task::Source::DOMManipulation, [this, url, post_resource, entry_list = move(entry_list), target_navigable, history_handling, referrer_policy, user_involvement]() {+ // NOTE: `this`, `actual_resource`, `target_navigable` and `submitter` are protected by GC::HeapFunction.+ queue_an_element_task(Task::Source::DOMManipulation, [this, url, post_resource, entry_list = move(entry_list), target_navigable, history_handling, referrer_policy, user_involvement, submitter]() {// 1. Set the form's planned navigation to null.m_planned_navigation = {};// 2. Navigate targetNavigable to url using the form element's node document, with historyHandling set to historyHandling,- // referrerPolicy set to referrerPolicy, documentResource set to postResource, and formDataEntryList set to entry list.- MUST(target_navigable->navigate({ .url = url, .source_document = this->document(), .document_resource = post_resource, .response = nullptr, .exceptions_enabled = false, .history_handling = history_handling, .form_data_entry_list = move(entry_list), .referrer_policy = referrer_policy, .user_involvement = user_involvement }));+ // userInvolvement set to userInvolvement, sourceElement set to submitter, referrerPolicy set to referrerPolicy,+ // documentResource set to postResource, and formDataEntryList set to entry list.+ MUST(target_navigable->navigate({ .url = url, .source_document = this->document(), .document_resource = post_resource, .response = nullptr, .exceptions_enabled = false, .history_handling = history_handling, .form_data_entry_list = move(entry_list), .referrer_policy = referrer_policy, .user_involvement = user_involvement, .source_element = submitter }));});// 5. Set the form's planned navigation to the just-queued task.diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.h b/Libraries/LibWeb/HTML/HTMLFormElement.hindex 4a796e74ac2..5ee633c21c4 100644--- a/Libraries/LibWeb/HTML/HTMLFormElement.h+++ b/Libraries/LibWeb/HTML/HTMLFormElement.h@@ -135,12 +135,12 @@ private:ErrorOr<Utf16String> pick_an_encoding() const;- ErrorOr<void> mutate_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);- ErrorOr<void> submit_as_entity_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);- void get_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);- ErrorOr<void> mail_with_headers(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);- ErrorOr<void> mail_as_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);- void plan_to_navigate_to(URL::URL url, DocumentResource post_resource, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);+ ErrorOr<void> mutate_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);+ ErrorOr<void> submit_as_entity_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);+ void get_action_url(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);+ ErrorOr<void> mail_with_headers(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);+ ErrorOr<void> mail_as_body(URL::URL parsed_action, GC::ConservativeVector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, Utf16String encoding, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);+ void plan_to_navigate_to(URL::URL url, DocumentResource post_resource, GC::ConservativeVector<XHR::FormDataEntry> entry_list, GC::Ref<Navigable> target_navigable, NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement, GC::Ref<HTMLElement> submitter);size_t tree_order_insertion_index(HTMLElement const&) const;void recompute_default_button(size_t start_index = 0);diff --git a/Libraries/LibWeb/HTML/Navigation.cpp b/Libraries/LibWeb/HTML/Navigation.cppindex 53690ef6ca2..f211ce49d69 100644--- a/Libraries/LibWeb/HTML/Navigation.cpp+++ b/Libraries/LibWeb/HTML/Navigation.cpp@@ -1165,6 +1165,10 @@ bool Navigation::inner_navigate_event_firing_algorithm(event_init.has_ua_visual_transition = false;// 16. Initialize event's sourceElement to sourceElement.+ // AD-HOC: Do not expose an element from a cross-origin initiator to this document. All engines implement this.+ // See https://github.com/whatwg/html/pull/13090+ if (source_element && !source_element->document().origin().is_same_origin_domain(document.origin()))+ source_element = nullptr;event_init.source_element = source_element;// 18. Initialize event's signal to event's abort controller's signal.diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 4c67cfe32b4..adad0697e09 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -229,6 +229,15 @@ Text/input/wpt-import/navigation-api/navigate-event/defaultPrevented-navigation-Text/input/wpt-import/navigation-api/navigate-event/event-constructor.htmlText/input/wpt-import/navigation-api/navigate-event/reentry-from-focus-reset-navigate-api-tracker.htmlText/input/wpt-import/navigation-api/navigate-event/signal-abort-reentry-navigate-api-tracker.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-form-traverse.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-form.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.html+Text/input/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.htmlText/input/wpt-import/navigation-api/ordering-and-transition/anchor-download-intercept.htmlText/input/wpt-import/navigation-api/ordering-and-transition/intercept-async.htmlText/input/wpt-import/navigation-api/ordering-and-transition/reload-no-popstate.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.txtnew file mode 100644index 00000000000..2a2ec42abfd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Fragment <a> click fires navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.txtnew file mode 100644index 00000000000..2a2ec42abfd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Fragment <a> click fires navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.txtnew file mode 100644index 00000000000..0cd338fc937--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass <form> submission with GET method and submitter passed into requestSubmit+Pass <form> submission with GET method and submitter is clicked\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get.txtnew file mode 100644index 00000000000..2dbf3e551f0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-get.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass <form> submission with GET method fires navigate event but with formData null\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.txtnew file mode 100644index 00000000000..4c57c08426a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass <form> requestSubmit() sets sourceElement\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-traverse.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-traverse.txtnew file mode 100644index 00000000000..86206e28c72--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form-traverse.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass reloading a page created from form submission results in formData of null, not the original form data\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form.txtnew file mode 100644index 00000000000..4d64dcc067b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-form.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass <form> submission fires navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.txtnew file mode 100644index 00000000000..61844fad87c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass <svg:a> click fires navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.txtnew file mode 100644index 00000000000..5178695f83c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass NavigateEvent.sourceElement should be null for cross-origin same-document initiators\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.htmlnew file mode 100644index 00000000000..6ba40121ac3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-fragment.html@@ -0,0 +1,26 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<a id="a" href="#1"></a>+<script>+async_test(t => {+ navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_true(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(e.formData, null);+ assert_equals(new URL(e.destination.url).hash, "#1");+ assert_true(e.destination.sameDocument);+ 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);+ });+ a.click();+}, "Fragment <a> click fires navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.htmlnew file mode 100644index 00000000000..64a26dd4c51--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-anchor-userInitiated.html@@ -0,0 +1,30 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../resources/testdriver-actions.js"></script>+<a id="a" href="#1">Click me</a>+<script>+async_test(t => {+ navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_true(e.userInitiated);+ assert_true(e.hashChange);+ assert_equals(e.formData, null);+ assert_equals(e.downloadRequest, null);+ assert_equals(new URL(e.destination.url).hash, "#1");+ assert_true(e.destination.sameDocument);+ 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);+ });++ test_driver.click(a);+}, "Fragment <a> click fires navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.htmlnew file mode 100644index 00000000000..90c6c060311--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get-sourceElement.html@@ -0,0 +1,41 @@+<!doctype html>+<meta charset="utf-8">+<title>Test that sourceElement is set correctly for forms with method=GET</title>+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=2042943">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<form id="form">+ <input id="submitter" type="submit">+</form>+<script>+"use strict";++promise_setup(() => new Promise(r => onload = r));++promise_test(async () => {+ let {promise: waitForSuccess, resolve} = Promise.withResolvers();+ navigation.onnavigatesuccess = resolve;+ let sourceElement;+ navigation.onnavigate = e => {+ e.intercept();+ sourceElement = e.sourceElement;+ };+ form.requestSubmit(submitter);+ await waitForSuccess;+ assert_equals(sourceElement, submitter, "NavigateEvent.sourceElement should be set to the submitter passed into requestSubmit.");+}, "<form> submission with GET method and submitter passed into requestSubmit");++promise_test(async () => {+ let {promise: waitForSuccess, resolve} = Promise.withResolvers();+ navigation.onnavigatesuccess = resolve;+ let sourceElement;+ navigation.onnavigate = e => {+ e.intercept();+ sourceElement = e.sourceElement;+ };+ submitter.click();+ await waitForSuccess;+ assert_equals(sourceElement, submitter, "NavigateEvent.sourceElement should be set to the submitter that was clicked.");+}, "<form> submission with GET method and submitter is clicked");++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get.htmlnew file mode 100644index 00000000000..b2064119068--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-get.html@@ -0,0 +1,28 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<form id="form" action=""></form>+<script>+async_test(t => {+ navigation.onnavigate = t.step_func_done(e => {+ e.preventDefault();++ assert_equals(e.navigationType, "replace");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_false(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(e.destination.url, location.href + "?");+ assert_false(e.destination.sameDocument);+ assert_equals(e.destination.key, "");+ assert_equals(e.destination.id, "");+ assert_equals(e.destination.index, -1);++ // 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());+}, "<form> submission with GET method fires navigate event but with formData null");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.htmlnew file mode 100644index 00000000000..716d2e5e03f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-requestSubmit.html@@ -0,0 +1,35 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<form id="form" method="post" action="">+<input type="submit" id="submit1">+<input type="image" id="submit2">+<button type="submit" id="submit3">+</form>+<script>+promise_test(async () => {+ await new Promise(r => window.onload = r);++ let sourceElement;+ navigation.onnavigate = e => {+ e.preventDefault();+ sourceElement = e.sourceElement;+ };++ form.requestSubmit(submit1);+ await new Promise(r => navigation.onnavigateerror = r);+ assert_equals(sourceElement, submit1);++ form.requestSubmit(submit2);+ await new Promise(r => navigation.onnavigateerror = r);+ assert_equals(sourceElement, submit2);++ form.requestSubmit(submit3);+ await new Promise(r => navigation.onnavigateerror = r);+ assert_equals(sourceElement, submit3);++ form.requestSubmit();+ await new Promise(r => navigation.onnavigateerror = r);+ assert_equals(sourceElement, form);+}, "<form> requestSubmit() sets sourceElement");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-traverse.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-traverse.htmlnew file mode 100644index 00000000000..1535663de03--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form-traverse.html@@ -0,0 +1,45 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<iframe id="iframe" name="i" src="../../common/blank.html"></iframe>+<form id="form" action="../../common/blank.html?1" method="post" target="i"></form>+<script>+async_test(t => {+ window.onload = t.step_func(() => {+ navigation.onnavigate = t.step_func_done(() => {+ assert_unreached("onnavigate should not have fired in source window");+ });+ iframe.contentWindow.navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_not_equals(e.formData, null);+ assert_equals(e.sourceElement, form);++ iframe.onload = t.step_func(() => {+ // Avoid the replace behavior that occurs if you navigate during the load handler+ t.step_timeout(() => {+ iframe.contentWindow.navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_equals(e.formData, null);+ });++ iframe.contentWindow.onhashchange = t.step_func(() => {+ iframe.contentWindow.navigation.onnavigate = t.step_func_done(e => {+ assert_equals(e.navigationType, "traverse");+ assert_equals(e.formData, null);+ });++ // 3: go back+ iframe.contentWindow.history.back();+ });++ // 2: navigate from ../../common/blank.html?1-with-form-data to ../../common/blank.html?1#1-with-form-data+ iframe.contentWindow.location.hash = "#1";+ }, 0);+ });+ });++ // 1: submit the form, navigating from ../../common/blank.html to ../../common/blank.html?1-with-form-data+ form.submit();+ });+}, "reloading a page created from form submission results in formData of null, not the original form data");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form.htmlnew file mode 100644index 00000000000..7589fddc331--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-form.html@@ -0,0 +1,26 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<form id="form" method="post" action=""></form>+<script>+async_test(t => {+ navigation.onnavigate = t.step_func_done(e => {+ e.preventDefault();++ assert_equals(e.navigationType, "replace");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_false(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(e.destination.url, location.href);+ assert_false(e.destination.sameDocument);+ assert_equals(e.destination.key, "");+ assert_equals(e.destination.id, "");+ assert_equals(e.destination.index, -1);+ assert_not_equals(e.formData, null);+ assert_equals(e.sourceElement, form);+ });+ window.onload = t.step_func(() => form.submit());+}, "<form> submission fires navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.htmlnew file mode 100644index 00000000000..de4080770a7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-svg-anchor-fragment.html@@ -0,0 +1,26 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<svg><a id="a" href="#1"></a></svg>+<script>+async_test(t => {+ navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_true(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(e.formData, null);+ assert_equals(new URL(e.destination.url).hash, "#1");+ assert_true(e.destination.sameDocument);+ 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);+ });+ document.getElementById("a").dispatchEvent(new MouseEvent('click'));+}, "<svg:a> click fires navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/echo-sourceElement.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/echo-sourceElement.htmlnew file mode 100644index 00000000000..121827bae00--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/echo-sourceElement.html@@ -0,0 +1,13 @@+<!doctype html>+<script>+ navigation.onnavigate = e => {+ if (e.destination.url.includes("#test")) {+ window.parent.postMessage({+ type: "result",+ sourceElementIsNull: e.sourceElement === null,+ sourceElementName: e.sourceElement ? e.sourceElement.tagName : "null"+ }, "*");+ }+ };+ window.parent.postMessage({ type: "ready" }, "*");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.htmlnew file mode 100644index 00000000000..dab258227c2--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/sourceElement-cross-origin.sub.html@@ -0,0 +1,20 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<iframe id="theFrame" name="theFrame" src="http://{{domains[www1]}}:{{ports[http][0]}}/navigation-api/navigate-event/resources/echo-sourceElement.html"></iframe>+<script>+async_test(t => {+ window.addEventListener("message", t.step_func(e => {+ if (e.data.type === "ready") {+ const a = document.createElement("a");+ a.href = document.getElementById("theFrame").src + "#test";+ a.target = "theFrame";+ document.body.appendChild(a);+ a.click();+ } else if (e.data.type === "result") {+ assert_true(e.data.sourceElementIsNull, "sourceElement must be null for cross-origin initiators (it was " + e.data.sourceElementName + ")");+ t.done();+ }+ }));+}, "NavigateEvent.sourceElement should be null for cross-origin same-document initiators");+</script>