aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-03 14:23:21 -0500
committerGitHub <noreply@github.com>2020-01-03 14:23:21 -0500
commit77db7ea0ee060180ed9994f235a710a1b9096b4f (patch)
treebdaa713e9003bda8046aa57acb7705642fbbb10f
parent2134bb15b7abdc1b9ff3025cc2e2188935da7416 (diff)
parent155f69ce48d5d6ec09cecf9f2a6a4c6ae8454d60 (diff)
downloadservo-77db7ea0ee060180ed9994f235a710a1b9096b4f.tar.gz
servo-77db7ea0ee060180ed9994f235a710a1b9096b4f.zip
Auto merge of #25393 - teapotd:option-constructor, r=jdm
Implement HTMLOptionElement named constructor This change implements `Option` named constructor for `HTMLOptionElement`. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25380 - [X] There are tests for these changes
-rw-r--r--components/script/dom/htmloptionelement.rs38
-rw-r--r--components/script/dom/webidls/HTMLOptionElement.webidl4
-rw-r--r--tests/wpt/metadata/html/dom/idlharness.https.html.ini45
-rw-r--r--tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html.ini5
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-checkValidity.html.ini25
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-reportValidity.html.ini25
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-customError.html.ini13
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valid.html.ini4
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valueMissing.html.ini13
-rw-r--r--tests/wpt/metadata/html/semantics/forms/constraints/form-validation-willValidate.html.ini19
-rw-r--r--tests/wpt/metadata/html/semantics/forms/the-option-element/option-element-constructor.html.ini35
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json2
-rw-r--r--tests/wpt/mozilla/tests/mozilla/interfaces.html1
13 files changed, 136 insertions, 93 deletions
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index 3893aea95ab..4ebb2860a79 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -8,12 +8,14 @@ use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementBinding::HTMLSelectElementMethods;
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
+use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
+use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::characterdata::CharacterData;
use crate::dom::document::Document;
-use crate::dom::element::{AttributeMutation, Element};
+use crate::dom::element::{AttributeMutation, CustomElementCreationMode, Element, ElementCreator};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
@@ -22,8 +24,9 @@ use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
use crate::dom::text::Text;
use crate::dom::virtualmethods::VirtualMethods;
+use crate::dom::window::Window;
use dom_struct::dom_struct;
-use html5ever::{LocalName, Prefix};
+use html5ever::{LocalName, Prefix, QualName};
use std::cell::Cell;
use style::element_state::ElementState;
use style::str::{split_html_space_chars, str_join};
@@ -72,6 +75,37 @@ impl HTMLOptionElement {
)
}
+ // https://html.spec.whatwg.org/multipage/#dom-option
+ pub fn Option(
+ window: &Window,
+ text: DOMString,
+ value: Option<DOMString>,
+ default_selected: bool,
+ selected: bool,
+ ) -> Fallible<DomRoot<HTMLOptionElement>> {
+ let element = Element::create(
+ QualName::new(None, ns!(html), local_name!("option")),
+ None,
+ &window.Document(),
+ ElementCreator::ScriptCreated,
+ CustomElementCreationMode::Synchronous,
+ );
+
+ let option = DomRoot::downcast::<HTMLOptionElement>(element).unwrap();
+
+ if !text.is_empty() {
+ option.upcast::<Node>().SetTextContent(Some(text))
+ }
+
+ if let Some(val) = value {
+ option.SetValue(val)
+ }
+
+ option.SetDefaultSelected(default_selected);
+ option.set_selectedness(selected);
+ Ok(option)
+ }
+
pub fn set_selectedness(&self, selected: bool) {
self.selectedness.set(selected);
}
diff --git a/components/script/dom/webidls/HTMLOptionElement.webidl b/components/script/dom/webidls/HTMLOptionElement.webidl
index 56a379fc8db..65f37458295 100644
--- a/components/script/dom/webidls/HTMLOptionElement.webidl
+++ b/components/script/dom/webidls/HTMLOptionElement.webidl
@@ -3,9 +3,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#htmloptionelement
-[Exposed=Window/*, NamedConstructor=Option(optional DOMString text = "", optional DOMString value,
+[Exposed=Window, NamedConstructor=Option(optional DOMString text = "", optional DOMString value,
optional boolean defaultSelected = false,
- optional boolean selected = false)*/]
+ optional boolean selected = false)]
interface HTMLOptionElement : HTMLElement {
[HTMLConstructor] constructor();
diff --git a/tests/wpt/metadata/html/dom/idlharness.https.html.ini b/tests/wpt/metadata/html/dom/idlharness.https.html.ini
index acb8acc08a7..dfd89a10358 100644
--- a/tests/wpt/metadata/html/dom/idlharness.https.html.ini
+++ b/tests/wpt/metadata/html/dom/idlharness.https.html.ini
@@ -2103,9 +2103,6 @@
[HTMLSelectElement interface: attribute willValidate]
expected: FAIL
- [HTMLOptionElement interface: named constructor]
- expected: FAIL
-
[HTMLMarqueeElement interface: attribute hspace]
expected: FAIL
@@ -2250,9 +2247,6 @@
[HTMLInputElement interface: createInput("url") must inherit property "checkValidity()" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: named constructor prototype property]
- expected: FAIL
-
[HTMLInputElement interface: createInput("week") must inherit property "validationMessage" with the proper type]
expected: FAIL
@@ -3144,9 +3138,6 @@
[HTMLInputElement interface: calling stepDown(long) on createInput("password") with too few arguments must throw TypeError]
expected: FAIL
- [HTMLOptionElement interface: named constructor object]
- expected: FAIL
-
[HTMLFrameElement interface: document.createElement("frame") must inherit property "frameBorder" with the proper type]
expected: FAIL
@@ -3258,9 +3249,6 @@
[HTMLMarqueeElement interface: attribute bgColor]
expected: FAIL
- [Stringification of new Option()]
- expected: FAIL
-
[HTMLInputElement interface: createInput("file") must inherit property "width" with the proper type]
expected: FAIL
@@ -3306,9 +3294,6 @@
[HTMLAreaElement interface: document.createElement("area") must inherit property "coords" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "label" with the proper type]
- expected: FAIL
-
[HTMLTableCellElement interface: document.createElement("th") must inherit property "chOff" with the proper type]
expected: FAIL
@@ -3345,9 +3330,6 @@
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "scrollAmount" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "form" with the proper type]
- expected: FAIL
-
[HTMLInputElement interface: createInput("datetime-local") must inherit property "reportValidity()" with the proper type]
expected: FAIL
@@ -3438,9 +3420,6 @@
[HTMLSelectElement interface: operation setCustomValidity(DOMString)]
expected: FAIL
- [HTMLOptionElement interface: named constructor name]
- expected: FAIL
-
[HTMLVideoElement interface: document.createElement("video") must inherit property "height" with the proper type]
expected: FAIL
@@ -3453,9 +3432,6 @@
[HTMLTableElement interface: attribute rules]
expected: FAIL
- [HTMLOptionElement interface: named constructor length]
- expected: FAIL
-
[HTMLInputElement interface: createInput("email") must inherit property "stepUp(long)" with the proper type]
expected: FAIL
@@ -3741,9 +3717,6 @@
[HTMLInputElement interface: document.createElement("input") must inherit property "valueAsNumber" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "disabled" with the proper type]
- expected: FAIL
-
[HTMLFieldSetElement interface: attribute name]
expected: FAIL
@@ -3960,9 +3933,6 @@
[HTMLAreaElement interface: attribute noHref]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "value" with the proper type]
- expected: FAIL
-
[HTMLInputElement interface: createInput("number") must inherit property "valueAsNumber" with the proper type]
expected: FAIL
@@ -4179,9 +4149,6 @@
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "trueSpeed" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "selected" with the proper type]
- expected: FAIL
-
[HTMLElement interface: attribute contentEditable]
expected: FAIL
@@ -4287,9 +4254,6 @@
[HTMLFormElement interface: document.createElement("form") must inherit property "rel" with the proper type]
expected: FAIL
- [HTMLOptionElement must be primary interface of new Option()]
- expected: FAIL
-
[HTMLIFrameElement interface: attribute allowPaymentRequest]
expected: FAIL
@@ -4347,9 +4311,6 @@
[HTMLBodyElement interface: document.createElement("body") must inherit property "vLink" with the proper type]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "text" with the proper type]
- expected: FAIL
-
[HTMLMediaElement interface: new Audio() must inherit property "seekable" with the proper type]
expected: FAIL
@@ -4518,9 +4479,6 @@
[HTMLMediaElement interface: operation getStartDate()]
expected: FAIL
- [HTMLOptionElement interface: new Option() must inherit property "defaultSelected" with the proper type]
- expected: FAIL
-
[HTMLInputElement interface: createInput("email") must inherit property "list" with the proper type]
expected: FAIL
@@ -5025,3 +4983,6 @@
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
expected: FAIL
+ [HTMLOptionElement interface: named constructor without 'new']
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html.ini b/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html.ini
deleted file mode 100644
index 76dbb504708..00000000000
--- a/tests/wpt/metadata/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[htmloptionscollection.html]
- type: testharness
- [HTMLOptionsCollection.add method insert HTMLOptionElement Option element]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-checkValidity.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
index b83b69dd2bc..ee0eac0e9a4 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
@@ -1,6 +1,5 @@
[form-validation-checkValidity.html]
type: testharness
- expected: ERROR
[[INPUT in TEXT status\] no constraint]
expected: FAIL
@@ -427,3 +426,27 @@
[[INPUT in EMAIL status\] not suffering from being too long (in a form)]
expected: FAIL
+ [[select\] no constraint (in a form)]
+ expected: FAIL
+
+ [[select\] suffering from being missing (in a form)]
+ expected: FAIL
+
+ [[textarea\] suffering from being missing (in a form)]
+ expected: FAIL
+
+ [[select\] no constraint]
+ expected: FAIL
+
+ [[select\] suffering from being missing]
+ expected: FAIL
+
+ [[textarea\] no constraint]
+ expected: FAIL
+
+ [[textarea\] suffering from being missing]
+ expected: FAIL
+
+ [[textarea\] no constraint (in a form)]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-reportValidity.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
index 4dbcff22c2c..d8114fa0ed1 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
@@ -1,6 +1,5 @@
[form-validation-reportValidity.html]
type: testharness
- expected: ERROR
[[INPUT in TEXT status\] no constraint]
expected: FAIL
@@ -433,3 +432,27 @@
[[INPUT in EMAIL status\] not suffering from being too long (in a form)]
expected: FAIL
+ [[select\] no constraint (in a form)]
+ expected: FAIL
+
+ [[select\] suffering from being missing (in a form)]
+ expected: FAIL
+
+ [[textarea\] suffering from being missing (in a form)]
+ expected: FAIL
+
+ [[select\] no constraint]
+ expected: FAIL
+
+ [[select\] suffering from being missing]
+ expected: FAIL
+
+ [[textarea\] no constraint]
+ expected: FAIL
+
+ [[textarea\] suffering from being missing]
+ expected: FAIL
+
+ [[textarea\] no constraint (in a form)]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-customError.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-customError.html.ini
index e9618f1c032..25ad3f2bd44 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-customError.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-customError.html.ini
@@ -1,6 +1,5 @@
[form-validation-validity-customError.html]
type: testharness
- expected: ERROR
[[input\] The validity.customError must be true if the custom validity error message is not empty]
expected: FAIL
@@ -13,3 +12,15 @@
[[button\] The validity.customError must be false if the custom validity error message is empty]
expected: FAIL
+ [[select\] The validity.customError must be false i the custom validity error message is empty]
+ expected: FAIL
+
+ [[select\] The validity.customError must be true if the custom validity error message is not empty]
+ expected: FAIL
+
+ [[textarea\] The validity.customError must be false if the custom validity error message is empty]
+ expected: FAIL
+
+ [[textarea\] The validity.customError must be true if the custom validity error message is not empty]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valid.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
index 3f11b627f2a..9fb1fc2bf7a 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
@@ -1,6 +1,5 @@
[form-validation-validity-valid.html]
type: testharness
- expected: ERROR
[[INPUT in TEXT status\] validity.valid must be false if validity.tooLong is true]
expected: FAIL
@@ -154,3 +153,6 @@
[[INPUT in DATETIME-LOCAL status\] validity.valid must be false if validity.valueMissing is true]
expected: FAIL
+ [[textarea\] validity.valid must be false if validity.valueMissing is true]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valueMissing.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valueMissing.html.ini
index de840378f42..f6390136918 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valueMissing.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-validity-valueMissing.html.ini
@@ -1,6 +1,5 @@
[form-validation-validity-valueMissing.html]
type: testharness
- expected: ERROR
[[INPUT in TEXT status\] The required attribute is not set]
expected: FAIL
@@ -304,3 +303,15 @@
[[INPUT in DATETIME-LOCAL status\] The value attribute is empty string]
expected: FAIL
+ [[textarea\] The value is not empty]
+ expected: FAIL
+
+ [[textarea\] The value is empty]
+ expected: FAIL
+
+ [[textarea\] The required attribute is not set]
+ expected: FAIL
+
+ [[select\] Selected the option with value equals to empty]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-willValidate.html.ini b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-willValidate.html.ini
index 599a5aeb57c..3823eb5fe6a 100644
--- a/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-willValidate.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/constraints/form-validation-willValidate.html.ini
@@ -1,6 +1,5 @@
[form-validation-willValidate.html]
type: testharness
- expected: ERROR
[[INPUT in HIDDEN status\] Must be barred from the constraint validation]
expected: FAIL
@@ -268,3 +267,21 @@
[[output\] The willValidate attribute must be false since OUTPUT is not a submittable element]
expected: FAIL
+ [[textarea\] Must be barred from the constraint validation]
+ expected: FAIL
+
+ [[textarea\] The willValidate attribute must be false if it has a datalist ancestor]
+ expected: FAIL
+
+ [[textarea\] The willValidate attribute must be true if an element is mutable]
+ expected: FAIL
+
+ [[select\] The willValidate attribute must be false if it has a datalist ancestor]
+ expected: FAIL
+
+ [[select\] The willValidate attribute must be true if an element is mutable]
+ expected: FAIL
+
+ [[select\] Must be barred from the constraint validation]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-element-constructor.html.ini b/tests/wpt/metadata/html/semantics/forms/the-option-element/option-element-constructor.html.ini
deleted file mode 100644
index 25d32bc456c..00000000000
--- a/tests/wpt/metadata/html/semantics/forms/the-option-element/option-element-constructor.html.ini
+++ /dev/null
@@ -1,35 +0,0 @@
-[option-element-constructor.html]
- type: testharness
- [Option constructor with no arguments]
- expected: FAIL
-
- [Option constructor with falsy arguments]
- expected: FAIL
-
- [Option constructor creates HTMLOptionElement with specified text and value]
- expected: FAIL
-
- [Option constructor handles selectedness correctly when specified with defaultSelected only]
- expected: FAIL
-
- [Option constructor handles selectedness correctly, even when incongruous with defaultSelected]
- expected: FAIL
-
- [Option constructor treats undefined text and value correctly]
- expected: FAIL
-
- [Option constructor treats empty text and value correctly]
- expected: FAIL
-
- [Option constructor treats falsy selected and defaultSelected correctly]
- expected: FAIL
-
- [Option constructor treats truthy selected and defaultSelected correctly]
- expected: FAIL
-
- [Option constructor does not set dirtiness (so, manipulating the selected content attribute still updates the selected IDL attribute)]
- expected: FAIL
-
- [Prototype of object created with named constructor]
- expected: FAIL
-
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index b259b7bc24d..559e6baff6c 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -19024,7 +19024,7 @@
"testharness"
],
"mozilla/interfaces.html": [
- "08e8181e6e639caeaecd84c16d582c0ec3f99474",
+ "945a8b33a109b0cc37db9351f94b9afd3eac798e",
"testharness"
],
"mozilla/interfaces.js": [
diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.html b/tests/wpt/mozilla/tests/mozilla/interfaces.html
index 08e8181e6e6..945a8b33a10 100644
--- a/tests/wpt/mozilla/tests/mozilla/interfaces.html
+++ b/tests/wpt/mozilla/tests/mozilla/interfaces.html
@@ -186,6 +186,7 @@ test_interfaces([
"NodeList",
"OfflineAudioCompletionEvent",
"OfflineAudioContext",
+ "Option",
"OscillatorNode",
"PageTransitionEvent",
"PannerNode",