Skip to content

Commit

Permalink
Now passing output tests as well as anyone
Browse files Browse the repository at this point in the history
  • Loading branch information
pshaughn committed Jan 6, 2020
1 parent fd2950e commit a322c60
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/htmlformelement.rs
Expand Up @@ -1058,7 +1058,7 @@ impl HTMLFormElement {
NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLOutputElement,
)) => {
// Unimplemented
child.downcast::<HTMLOutputElement>().unwrap().reset();
},
_ => {},
}
Expand Down
46 changes: 46 additions & 0 deletions components/script/dom/htmloutputelement.rs
Expand Up @@ -3,10 +3,12 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::attr::Attr;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::HTMLOutputElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLOutputElementBinding::HTMLOutputElementMethods;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlelement::HTMLElement;
Expand All @@ -23,6 +25,7 @@ pub struct HTMLOutputElement {
htmlelement: HTMLElement,
form_owner: MutNullableDom<HTMLFormElement>,
labels_node_list: MutNullableDom<NodeList>,
default_value_override: DomRefCell<Option<DOMString>>,
}

impl HTMLOutputElement {
Expand All @@ -35,6 +38,7 @@ impl HTMLOutputElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
form_owner: Default::default(),
labels_node_list: Default::default(),
default_value_override: DomRefCell::new(None),
}
}

Expand All @@ -52,6 +56,11 @@ impl HTMLOutputElement {
HTMLOutputElementBinding::Wrap,
)
}

pub fn reset(&self) {
Node::string_replace_all(self.DefaultValue(), self.upcast::<Node>());
*self.default_value_override.borrow_mut() = None;
}
}

impl HTMLOutputElementMethods for HTMLOutputElement {
Expand All @@ -68,6 +77,43 @@ impl HTMLOutputElementMethods for HTMLOutputElement {

// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
make_labels_getter!(Labels, labels_node_list);

// https://html.spec.whatwg.org/multipage/#dom-output-defaultvaleu
fn DefaultValue(&self) -> DOMString {
let dvo = self.default_value_override.borrow();
if let Some(ref dv) = *dvo {
dv.clone()
} else {
self.upcast::<Node>().descendant_text_content()
}
}

// https://html.spec.whatwg.org/multipage/#dom-output-defaultvalue
fn SetDefaultValue(&self, value: DOMString) {
if self.default_value_override.borrow().is_none() {
// Step 1 ("and return")
Node::string_replace_all(value.clone(), self.upcast::<Node>());
} else {
// Step 2, if not returned from step 1
*self.default_value_override.borrow_mut() = Some(value);
}
}

// https://html.spec.whatwg.org/multipage/#dom-output-value
fn Value(&self) -> DOMString {
self.upcast::<Node>().descendant_text_content()
}

// https://html.spec.whatwg.org/multipage/#dom-output-value
fn SetValue(&self, value: DOMString) {
*self.default_value_override.borrow_mut() = Some(self.DefaultValue());
Node::string_replace_all(value, self.upcast::<Node>());
}

// https://html.spec.whatwg.org/multipage/#dom-output-type
fn Type(&self) -> DOMString {
return DOMString::from("output");
}
}

impl VirtualMethods for HTMLOutputElement {
Expand Down
15 changes: 15 additions & 0 deletions components/script/dom/node.rs
Expand Up @@ -2017,6 +2017,16 @@ impl Node {
parent.owner_doc().remove_script_and_layout_blocker();
}

// https://dom.spec.whatwg.org/multipage/#string-replace-all
pub fn string_replace_all(string: DOMString, parent: &Node) {
if string.len() == 0 {
Node::replace_all(None, parent);
} else {
let text = Text::new(string, &document_from_node(parent));
Node::replace_all(Some(text.upcast::<Node>()), parent);
};
}

// https://dom.spec.whatwg.org/#concept-node-pre-remove
fn pre_remove(child: &Node, parent: &Node) -> Fallible<DomRoot<Node>> {
// Step 1.
Expand Down Expand Up @@ -2213,6 +2223,11 @@ impl Node {
Node::collect_text_contents(self.children())
}

/// <https://html.spec.whatwg.org/multipage/#descendant-text-content>
pub fn descendant_text_content(&self) -> DOMString {
Node::collect_text_contents(self.traverse_preorder(ShadowIncluding::No))
}

pub fn collect_text_contents<T: Iterator<Item = DomRoot<Node>>>(iterator: T) -> DOMString {
let mut content = String::new();
for node in iterator {
Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/webidls/HTMLOutputElement.webidl
Expand Up @@ -12,11 +12,11 @@ interface HTMLOutputElement : HTMLElement {
// [CEReactions]
// attribute DOMString name;

// readonly attribute DOMString type;
// [CEReactions]
// attribute DOMString defaultValue;
// [CEReactions]
// attribute DOMString value;
[Pure] readonly attribute DOMString type;
[CEReactions]
attribute DOMString defaultValue;
[CEReactions]
attribute DOMString value;

// readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions tests/wpt/metadata/html/dom/idlharness.https.html.ini
Expand Up @@ -2070,9 +2070,6 @@
[HTMLInputElement interface: createInput("button") must inherit property "align" with the proper type]
expected: FAIL
[HTMLOutputElement interface: document.createElement("output") must inherit property "value" with the proper type]
expected: FAIL
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "start()" with the proper type]
expected: FAIL
Expand Down Expand Up @@ -2715,9 +2712,6 @@
[Stringification of document.createElement("menu")]
expected: FAIL
[HTMLOutputElement interface: attribute defaultValue]
expected: FAIL
[HTMLCanvasElement interface: calling toBlob(BlobCallback, DOMString, any) on document.createElement("canvas") with too few arguments must throw TypeError]
expected: FAIL
Expand Down Expand Up @@ -3720,9 +3714,6 @@
[HTMLInputElement interface: createInput("time") must inherit property "reportValidity()" with the proper type]
expected: FAIL
[HTMLOutputElement interface: attribute value]
expected: FAIL
[HTMLObjectElement interface: attribute declare]
expected: FAIL
Expand Down Expand Up @@ -3900,9 +3891,6 @@
[HTMLInputElement interface: createInput("time") must inherit property "list" with the proper type]
expected: FAIL

[HTMLOutputElement interface: document.createElement("output") must inherit property "type" with the proper type]
expected: FAIL

[HTMLInputElement interface: calling stepUp(long) on createInput("file") with too few arguments must throw TypeError]
expected: FAIL

Expand Down Expand Up @@ -4542,9 +4530,6 @@
[HTMLEmbedElement interface: attribute width]
expected: FAIL
[HTMLOutputElement interface: attribute type]
expected: FAIL
[HTMLObjectElement interface: document.createElement("object") must inherit property "standby" with the proper type]
expected: FAIL
Expand Down Expand Up @@ -4761,9 +4746,6 @@
[HTMLSelectElement interface: document.createElement("select") must inherit property "willValidate" with the proper type]
expected: FAIL

[HTMLOutputElement interface: document.createElement("output") must inherit property "defaultValue" with the proper type]
expected: FAIL

[HTMLInputElement interface: calling stepDown(long) on createInput("reset") with too few arguments must throw TypeError]
expected: FAIL

Expand Down

This file was deleted.

Expand Up @@ -2,6 +2,3 @@
[Descendant mutations and output.value and .defaultValue]
expected: FAIL

[output and output.form.reset()]
expected: FAIL

This file was deleted.

0 comments on commit a322c60

Please sign in to comment.