diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index 41f0af855e7..a8a1cdf1b7b 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -14,7 +14,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
-use dom::node::{Node, NodeHelpers, NodeTypeId};
+use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node};
use dom::virtualmethods::VirtualMethods;
use util::str::{self, DOMString, LengthOrPercentageOrAuto};
@@ -80,11 +80,34 @@ impl<'a> HTMLTableElementMethods for &'a HTMLTableElement {
let node = NodeCast::from_ref(self);
if let Some(ref caption) = self.GetCaption() {
- assert!(node.RemoveChild(NodeCast::from_ref(caption.r())).is_ok());
+ NodeCast::from_ref(caption.r()).remove_self();
}
if let Some(caption) = new_caption {
- assert!(node.AppendChild(NodeCast::from_ref(caption)).is_ok());
+ assert!(node.InsertBefore(NodeCast::from_ref(caption),
+ node.GetFirstChild().as_ref().map(|n| n.r())).is_ok());
+ }
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-table-createcaption
+ fn CreateCaption(self) -> Root {
+ let caption = match self.GetCaption() {
+ Some(caption) => caption,
+ None => {
+ let caption = HTMLTableCaptionElement::new("caption".to_owned(),
+ None,
+ document_from_node(self).r());
+ self.SetCaption(Some(caption.r()));
+ caption
+ }
+ };
+ HTMLElementCast::from_root(caption)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-table-deletecaption
+ fn DeleteCaption(self) {
+ if let Some(caption) = self.GetCaption() {
+ NodeCast::from_ref(caption.r()).remove_self();
}
}
}
diff --git a/components/script/dom/webidls/HTMLTableElement.webidl b/components/script/dom/webidls/HTMLTableElement.webidl
index 7aca85e2b60..26639442ee4 100644
--- a/components/script/dom/webidls/HTMLTableElement.webidl
+++ b/components/script/dom/webidls/HTMLTableElement.webidl
@@ -6,8 +6,8 @@
// https://www.whatwg.org/html/#htmltableelement
interface HTMLTableElement : HTMLElement {
attribute HTMLTableCaptionElement? caption;
- //HTMLElement createCaption();
- //void deleteCaption();
+ HTMLElement createCaption();
+ void deleteCaption();
// attribute HTMLTableSectionElement? tHead;
//HTMLElement createTHead();
//void deleteTHead();
diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini
index aefba4a34f2..8082c6e4c4b 100644
--- a/tests/wpt/metadata/html/dom/interfaces.html.ini
+++ b/tests/wpt/metadata/html/dom/interfaces.html.ini
@@ -4566,12 +4566,6 @@
[HTMLTableElement interface: existence and properties of interface object]
expected: FAIL
- [HTMLTableElement interface: operation createCaption()]
- expected: FAIL
-
- [HTMLTableElement interface: operation deleteCaption()]
- expected: FAIL
-
[HTMLTableElement interface: attribute tHead]
expected: FAIL
@@ -4638,12 +4632,6 @@
[HTMLTableElement interface: attribute cellSpacing]
expected: FAIL
- [HTMLTableElement interface: document.createElement("table") must inherit property "createCaption" with the proper type (1)]
- expected: FAIL
-
- [HTMLTableElement interface: document.createElement("table") must inherit property "deleteCaption" with the proper type (2)]
- expected: FAIL
-
[HTMLTableElement interface: document.createElement("table") must inherit property "tHead" with the proper type (3)]
expected: FAIL
diff --git a/tests/wpt/metadata/html/semantics/tabular-data/the-caption-element/caption_001.html.ini b/tests/wpt/metadata/html/semantics/tabular-data/the-caption-element/caption_001.html.ini
index 10db3e14929..ab6dcbaa27c 100644
--- a/tests/wpt/metadata/html/semantics/tabular-data/the-caption-element/caption_001.html.ini
+++ b/tests/wpt/metadata/html/semantics/tabular-data/the-caption-element/caption_001.html.ini
@@ -1,8 +1,5 @@
[caption_001.html]
type: testharness
- [setting caption on a table]
- expected: FAIL
-
[caption of the third table element should be null]
expected: FAIL
diff --git a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/caption-methods.html.ini b/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/caption-methods.html.ini
deleted file mode 100644
index 5417cceb4bd..00000000000
--- a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/caption-methods.html.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-[caption-methods.html]
- type: testharness
- [createCaption method returns the first caption element child of the table]
- expected: FAIL
-
- [createCaption method creates a new caption and inserts it as the first node of the table element]
- expected: FAIL
-
- [deleteCaption method removes the first caption element child of the table element]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/delete-caption.html.ini b/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/delete-caption.html.ini
deleted file mode 100644
index 58658cdd9c6..00000000000
--- a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/delete-caption.html.ini
+++ /dev/null
@@ -1,20 +0,0 @@
-[delete-caption.html]
- type: testharness
- [deleteCaption() delete only caption on table]
- expected: FAIL
-
- [deleteCaption() returns undefined]
- expected: FAIL
-
- [deleteCaption()]
- expected: FAIL
-
- [deleteCaption() does not throw any exceptions when called on a table without a caption]
- expected: FAIL
-
- [deleteCaption() does not delete captions in descendent tables]
- expected: FAIL
-
- [deleteCaption() handles captions from different namespaces]
- expected: FAIL
-
diff --git a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-caption-element/caption_001.html b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-caption-element/caption_001.html
index 5393d1ed5c5..ecb1bef8543 100644
--- a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-caption-element/caption_001.html
+++ b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-caption-element/caption_001.html
@@ -37,6 +37,7 @@
table.caption = caption;
assert_equals(caption.parentNode, table);
+ assert_equals(table.firstChild, caption);
assert_equals(table.caption.innerHTML, "new caption");
captions = table.getElementsByTagName('caption');
diff --git a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/caption-methods.html b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/caption-methods.html
index 5091c6b8c04..79546eb5946 100644
--- a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/caption-methods.html
+++ b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/caption-methods.html
@@ -11,6 +11,8 @@
+
caption
@@ -19,6 +21,7 @@
+ caption
cell |
cell |
@@ -31,7 +34,18 @@
cell |
+