aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Zbarsky <dzbarsky@gmail.com>2015-08-07 04:07:15 -0400
committerDavid Zbarsky <dzbarsky@gmail.com>2015-08-08 15:24:05 -0400
commite24a867ab69a898915fa0ee80f4cfc56eb5e622c (patch)
tree4b474bb6e410c0e611881666a78ec3dc4d2a7ed9
parent78792cced2c4f1702a0bc2039bdebf07f8bcd901 (diff)
downloadservo-e24a867ab69a898915fa0ee80f4cfc56eb5e622c.tar.gz
servo-e24a867ab69a898915fa0ee80f4cfc56eb5e622c.zip
Implement createCaption and deleteCaption on HTMLTableElement
Update web-platform-tests expected data
-rw-r--r--components/script/dom/htmltableelement.rs29
-rw-r--r--components/script/dom/webidls/HTMLTableElement.webidl4
-rw-r--r--tests/wpt/metadata/html/dom/interfaces.html.ini12
-rw-r--r--tests/wpt/metadata/html/semantics/tabular-data/the-caption-element/caption_001.html.ini3
-rw-r--r--tests/wpt/metadata/html/semantics/tabular-data/the-table-element/caption-methods.html.ini11
-rw-r--r--tests/wpt/metadata/html/semantics/tabular-data/the-table-element/delete-caption.html.ini20
-rw-r--r--tests/wpt/web-platform-tests/html/semantics/tabular-data/the-caption-element/caption_001.html1
-rw-r--r--tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/caption-methods.html30
8 files changed, 59 insertions, 51 deletions
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<HTMLElement> {
+ 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 3fd0ad22507..54bf458a3c5 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 @@
</head>
<body>
<div id="log"></div>
+ <table id="table0" style="display:none">
+ </table>
<table id="table1" style="display:none">
<caption id="caption1">caption</caption>
<tr>
@@ -19,6 +21,7 @@
</tr>
</table>
<table id="table2" style="display:none">
+ <foo:caption>caption</foo:caption>
<tr>
<td>cell</td>
<td>cell</td>
@@ -31,8 +34,19 @@
<td>cell</td>
</tr>
</table>
+ <table id="table4" style="display:none">
+ </table>
<script>
test(function () {
+ var table0 = document.getElementById('table0');
+ var caption = document.createElementNS("foo", "caption");
+ table0.appendChild(caption);
+ var table0FirstNode = table0.firstChild;
+ var testCaption = table0.createCaption();
+ assert_not_equals(testCaption, table0FirstNode);
+ assert_equals(testCaption, table0.firstChild);
+ }, "createCaption method creates new caption if existing caption is not in html namespace")
+ test(function () {
var table1 = document.getElementById('table1');
var testCaption = table1.createCaption();
var table1FirstCaption = table1.caption;
@@ -46,11 +60,27 @@
assert_equals(table2FirstNode, test2Caption);
}, "createCaption method creates a new caption and inserts it as the first node of the table element")
test(function () {
+ var table = document.createElement('table');
+ assert_equals(table.createCaption(), table.createCaption());
+ }, "createCaption will not create new caption if one exists")
+ test(function () {
+ var table = document.createElementNS("http://www.w3.org/1999/xhtml", "foo:table")
+ var caption = table.createCaption();
+ assert_equals(caption.prefix, null);
+ }, "createCaption will not copy table's prefix")
+ test(function () {
var table3 = document.getElementById('table3');
assert_equals(table3.caption.textContent, "caption 3");
table3.deleteCaption();
assert_equals(table3.caption, null);
}, "deleteCaption method removes the first caption element child of the table element")
+ test(function () {
+ var table4 = document.getElementById('table4');
+ var caption = document.createElementNS("foo", "caption");
+ table4.appendChild(caption);
+ table4.deleteCaption();
+ assert_equals(caption.parentNode, table4);
+ }, "deleteCaption method not remove caption that is not in html namespace")
</script>
</body>
</html>