Implement createCaption and deleteCaption on HTMLTableElement

Update web-platform-tests expected data
This commit is contained in:
David Zbarsky 2015-08-07 04:07:15 -04:00
parent 78792cced2
commit e24a867ab6
8 changed files with 59 additions and 51 deletions

View file

@ -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();
}
}
}

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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');

View file

@ -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,7 +34,18 @@
<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();
@ -45,12 +59,28 @@
assert_true(test2Caption instanceof HTMLTableCaptionElement);
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>