diff options
5 files changed, 55 insertions, 7 deletions
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 737bc67bd4c..9183a78de0c 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -6,6 +6,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; +use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementBinding::HTMLSelectElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; @@ -14,6 +15,8 @@ use dom::characterdata::CharacterData; use dom::document::Document; use dom::element::{AttributeMutation, Element}; use dom::htmlelement::HTMLElement; +use dom::htmlformelement::HTMLFormElement; +use dom::htmloptgroupelement::HTMLOptGroupElement; use dom::htmlscriptelement::HTMLScriptElement; use dom::htmlselectelement::HTMLSelectElement; use dom::node::{Node, UnbindContext}; @@ -110,6 +113,19 @@ impl HTMLOptionElementMethods for HTMLOptionElement { self.upcast::<Node>().SetTextContent(Some(value)) } + // https://html.spec.whatwg.org/multipage/#dom-option-form + fn GetForm(&self) -> Option<Root<HTMLFormElement>> { + let parent = self.upcast::<Node>().GetParentNode().and_then(|p| + if p.is::<HTMLOptGroupElement>() { + p.upcast::<Node>().GetParentNode() + } else { + Some(p) + } + ); + + parent.and_then(|p| p.downcast::<HTMLSelectElement>().and_then(|s| s.GetForm())) + } + // https://html.spec.whatwg.org/multipage/#attr-option-value fn Value(&self) -> DOMString { let element = self.upcast::<Element>(); diff --git a/components/script/dom/webidls/HTMLOptionElement.webidl b/components/script/dom/webidls/HTMLOptionElement.webidl index a5c7c3295da..d4bc5bcdc83 100644 --- a/components/script/dom/webidls/HTMLOptionElement.webidl +++ b/components/script/dom/webidls/HTMLOptionElement.webidl @@ -9,7 +9,7 @@ [Exposed=(Window,Worker)] interface HTMLOptionElement : HTMLElement { attribute boolean disabled; - //readonly attribute HTMLFormElement? form; + readonly attribute HTMLFormElement? form; attribute DOMString label; attribute boolean defaultSelected; attribute boolean selected; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 6c9c977a95b..7bbdda39bc3 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -37215,6 +37215,12 @@ "deleted_reftests": {}, "items": { "testharness": { + "html/semantics/forms/the-option-element/option-form.html": [ + { + "path": "html/semantics/forms/the-option-element/option-form.html", + "url": "/html/semantics/forms/the-option-element/option-form.html" + } + ], "html/semantics/interactive-elements/the-dialog-element/dialog-open.html": [ { "path": "html/semantics/interactive-elements/the-dialog-element/dialog-open.html", diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index f4b4a274fd0..0898618fa9f 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -3855,15 +3855,9 @@ [HTMLOptGroupElement interface: document.createElement("optgroup") must inherit property "label" with the proper type (1)] expected: FAIL - [HTMLOptionElement interface: attribute form] - expected: FAIL - [HTMLOptionElement interface: attribute index] expected: FAIL - [HTMLOptionElement interface: document.createElement("option") must inherit property "form" with the proper type (1)] - expected: FAIL - [HTMLOptionElement interface: document.createElement("option") must inherit property "index" with the proper type (7)] expected: FAIL diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-form.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-form.html new file mode 100644 index 00000000000..1a68b5c1ca8 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-form.html @@ -0,0 +1,32 @@ +<!doctype html> +<meta charset=utf-8> +<title>HTMLOptionElement.form</title> +<link rel=author title="Sergey Alexandrov" href="mailto:splavgm@gmail.com"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#dom-option-form"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<form id="form"> + <select id="select"> + <optgroup id="optgroup"></optgroup> + </select> +</form> +<div id=log></div> + +<script> +test(function () { + var form = document.getElementById("form"); + var select = document.getElementById("select"); + var optgroup = document.getElementById("optgroup"); + + var o1 = document.createElement("option"); + assert_equals(o1.form, null); + + select.appendChild(o1); + assert_equals(o1.form, select.form); + + var o2 = document.createElement("option"); + select.appendChild(o2); + assert_equals(o2.form, select.form); + +}, "form"); +</script> |