diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 155098247b6..234a10f9448 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -3235,6 +3235,18 @@ impl Element { let root = node.GetRootNode(); root.is::() } + + // https://html.spec.whatwg.org/multipage/#cannot-navigate + pub fn cannot_navigate(&self) -> bool { + let document = document_from_node(self); + + // Step 1. + !document.is_fully_active() || + ( + // Step 2. + !self.is::() && !self.is_connected() + ) + } } impl Element { diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 6a4a4b97fe5..e81613d750d 100755 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -317,7 +317,11 @@ impl HTMLFormElement { /// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit) pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitter) { - // TODO: Step 1. If form cannot navigate , then return. + // Step 1 + if self.upcast::().cannot_navigate() { + return; + } + // Step 2 if self.constructing_entry_list.get() { return; @@ -342,6 +346,11 @@ impl HTMLFormElement { if event.DefaultPrevented() { return; } + + // Step 7-3 + if self.upcast::().cannot_navigate() { + return; + } } // Step 8 @@ -353,7 +362,10 @@ impl HTMLFormElement { None => return, }; - // TODO: Step 10. If form cannot navigate, then return. + // Step 10 + if self.upcast::().cannot_navigate() { + return; + } // Step 11 let mut action = submitter.action(); diff --git a/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini b/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini index be409a414f9..79e10b2df01 100644 --- a/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini +++ b/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini @@ -18,7 +18,3 @@ [redispatch during post-click handling] expected: TIMEOUT - - [disconnected form should not submit] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini b/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini index 13f78590065..680eb46f5d3 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini @@ -1,15 +1,9 @@ [button-click-submits.html] type: testharness expected: TIMEOUT - [clicking a button with .click() should not trigger a submit (form disconnected)] - expected: FAIL - [clicking a button by dispatching an event should trigger a submit (form connected)] expected: TIMEOUT - [clicking a button that cancels the event should not trigger a submit] - expected: FAIL - [clicking the child of a button by dispatching a bubbling event should trigger a submit] expected: TIMEOUT