Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to Range tests #265

Merged
merged 12 commits into from
Dec 25, 2013
Merged
2 changes: 1 addition & 1 deletion XMLHttpRequest/abort-event-loadend.htm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function()
xhr.onloadstart = function()
{
test.step(function()
{
Expand Down
2 changes: 1 addition & 1 deletion XMLHttpRequest/getresponseheader-error-state.htm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
})
}
var url = location.protocol + 'www1.' + location.hostname + (location.pathname.replace(/getresponseheader-error-state\.htm/, 'resources/nocors/folder.txt'))
var url = location.protocol + "//" + 'www1.' + location.hostname + (location.pathname.replace(/getresponseheader-error-state\.htm/, 'resources/nocors/folder.txt'))
client.open("GET", url)
client.send(null)
})
Expand Down
1 change: 1 addition & 0 deletions conformance-checkers/messages.json

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions conformance-checkers/vnu-map.json

This file was deleted.

186 changes: 181 additions & 5 deletions dom/nodes/Node-textContent.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// XXX: setting.
// XXX mutation observers?
// XXX Range gravitation?

var documents, doctypes;
setup(function() {
documents = [
[document, "parser"],
[document.implementation.createDocument("", "test", null), "createDocument"],
[document.implementation.createHTMLDocument("title"), "createHTMLDocument"],
]
doctypes = [
[document.doctype, "parser"],
[document.implementation.createDocumentType("x", "", ""), "script"],
]
})

// Getting
// DocumentFragment, Element:
test(function() {
var element = document.createElement("div")
Expand Down Expand Up @@ -79,11 +95,171 @@
}, "For a Comment with data, textContent should be that data")

// Any other node:
documents.forEach(function(argument) {
var doc = argument[0], creator = argument[1]
test(function() {
assert_equals(doc.textContent, null)
}, "For Documents created by " + creator + ", textContent should be null")
})

doctypes.forEach(function(argument) {
var doctype = argument[0], creator = argument[1]
test(function() {
assert_equals(doctype.textContent, null)
}, "For DocumentType created by " + creator + ", textContent should be null")
})

// Setting
// DocumentFragment, Element:
var arguments = [
[null, null],
[undefined, null],
["", null],
[42, "42"],
["abc", "abc"],
["<b>xyz<\/b>", "<b>xyz<\/b>"],
["d\0e", "d\0e"]
// XXX unpaired surrogate?
]
arguments.forEach(function(aValue) {
var argument = aValue[0], expectation = aValue[1]
var check = function(aElementOrDocumentFragment) {
if (expectation === null) {
assert_equals(aElementOrDocumentFragment.textContent, "")
assert_equals(aElementOrDocumentFragment.firstChild, null)
} else {
assert_equals(aElementOrDocumentFragment.textContent, expectation)
assert_equals(aElementOrDocumentFragment.childNodes.length, 1,
"Should have one child")
var firstChild = aElementOrDocumentFragment.firstChild
assert_true(firstChild instanceof Text, "child should be a Text")
assert_equals(firstChild.data, expectation)
}
}

test(function() {
var el = document.createElement("div")
el.textContent = argument
check(el)
}, "Element without children set to " + format_value(argument))

test(function() {
var el = document.createElement("div")
var text = el.appendChild(document.createTextNode(""))
el.textContent = argument
check(el)
assert_equals(text.parentNode, null,
"Preexisting Text should have been removed")
}, "Element with empty text node as child set to " + format_value(argument))

test(function() {
var el = document.createElement("div")
el.appendChild(document.createComment(" abc "))
el.appendChild(document.createTextNode("\tDEF\t"))
el.appendChild(document.createProcessingInstruction("x", " ghi "))
el.textContent = argument
check(el)
}, "Element with children set to " + format_value(argument))

test(function() {
var el = document.createElement("div")
var child = document.createElement("div")
el.appendChild(child)
child.appendChild(document.createComment(" abc "))
child.appendChild(document.createTextNode("\tDEF\t"))
child.appendChild(document.createProcessingInstruction("x", " ghi "))
el.textContent = argument
check(el)
assert_equals(child.childNodes.length, 3,
"Should not have changed the internal structure of the removed nodes.")
}, "Element with descendants set to " + format_value(argument))

test(function() {
var df = document.createDocumentFragment()
df.textContent = argument
check(df)
}, "DocumentFragment without children set to " + format_value(argument))

test(function() {
var df = document.createDocumentFragment()
var text = df.appendChild(document.createTextNode(""))
df.textContent = argument
check(df)
assert_equals(text.parentNode, null,
"Preexisting Text should have been removed")
}, "DocumentFragment with empty text node as child set to " + format_value(argument))

test(function() {
var df = document.createDocumentFragment()
df.appendChild(document.createComment(" abc "))
df.appendChild(document.createTextNode("\tDEF\t"))
df.appendChild(document.createProcessingInstruction("x", " ghi "))
df.textContent = argument
check(df)
}, "DocumentFragment with children set to " + format_value(argument))

test(function() {
var df = document.createDocumentFragment()
var child = document.createElement("div")
df.appendChild(child)
child.appendChild(document.createComment(" abc "))
child.appendChild(document.createTextNode("\tDEF\t"))
child.appendChild(document.createProcessingInstruction("x", " ghi "))
df.textContent = argument
check(df)
assert_equals(child.childNodes.length, 3,
"Should not have changed the internal structure of the removed nodes.")
}, "DocumentFragment with descendants set to " + format_value(argument))
})

// Text, ProcessingInstruction, Comment:
test(function() {
var text = document.createTextNode("abc")
text.textContent = "def"
assert_equals(text.textContent, "def")
assert_equals(text.data, "def")
}, "For a Text, textContent should set the data")

test(function() {
assert_equals(document.textContent, null)
}, "For Documents, textContent should be null")
var pi = document.createProcessingInstruction("x", "abc")
pi.textContent = "def"
assert_equals(pi.textContent, "def")
assert_equals(pi.data, "def")
assert_equals(pi.target, "x")
}, "For a ProcessingInstruction, textContent should set the data")

test(function() {
assert_equals(document.doctype.textContent, null)
}, "For DocumentType, textContent should be null")
var comment = document.createComment("abc")
comment.textContent = "def"
assert_equals(comment.textContent, "def")
assert_equals(comment.data, "def")
}, "For a Comment, textContent should set the data")

// Any other node:
documents.forEach(function(argument) {
var doc = argument[0], creator = argument[1]
test(function() {
var root = doc.documentElement
doc.textContent = "a"
assert_equals(doc.textContent, null)
assert_equals(doc.documentElement, root)
}, "For Documents created by " + creator + ", setting textContent should do nothing")
})

doctypes.forEach(function(argument) {
var doctype = argument[0], creator = argument[1]
test(function() {
var props = {
name: doctype.name,
publicId: doctype.publicId,
systemId: doctype.systemId,
}
doctype.textContent = "b"
assert_equals(doctype.textContent, null)
assert_equals(doctype.name, props.name, "name should not change")
assert_equals(doctype.publicId, props.publicId, "publicId should not change")
assert_equals(doctype.systemId, props.systemId, "systemId should not change")
}, "For DocumentType created by " + creator + ", setting textContent should do nothing")
})

</script>
3 changes: 2 additions & 1 deletion dom/nodes/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
assert_throws(new TypeError(), function() { attr.appendChild(document.createTextNode("fail")) })
assert_throws(new TypeError(), function() { attr.appendChild(null) })
assert_equals(attr.value, "pass")
assert_false("childNodes" in attr)
assert_false("childNodes" in attr, "Should not have childNodes")
assert_false("textContent" in attr, "Should not have textContent")
}, "AttrExodus")

// setAttribute exhaustive tests
Expand Down
1 change: 1 addition & 0 deletions html/dom/documents/dom-tree-accessors/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ document.getElementsByClassName-same.html
dir document.getElementsByName
document.head-01.html
document.head-02.html
document.images.html
document.title-01.html
document.title-02.xhtml
document.title-03.html
Expand Down
105 changes: 105 additions & 0 deletions html/dom/documents/dom-tree-accessors/document.images.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!doctype html>
<meta charset=utf-8>
<title>Document.images</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<div id=test>
<img>
<img id=x><img name=y><img id=z1 name=z2>
<img id=a><img id=a>
<img name=b><img name=b>
<img id=><img name=>
<input type=image name=input>
</div>
<script>
function assert_all(aAssertFunc, aCollection) {
for (var i = 0; i < aCollection.length; ++i) {
aAssertFunc(aCollection[i]);
}
}

var XHTML = "http://www.w3.org/1999/xhtml";
var div, images, c;

setup(function() {
div = document.getElementById("test");
var foreign =
div.appendChild(document.createElementNS("http://example.org", "img"));
foreign.setAttribute("id", "f");

images = [].slice.call(div.getElementsByTagNameNS(XHTML, "img"));

c = document.images;
});

test(function() {
assert_equals(c.length, 10);
assert_array_equals(c, images);

assert_all(function (aElement) {
assert_equals(aElement.namespaceURI, XHTML);
}, c);
}, "document.images should contain all HTML img elements");

test(function() {
assert_equals(c.x, images[1]);
assert_equals(c.namedItem("x"), images[1]);
assert_true("x" in c, '"x" in c');
}, "img with id");

test(function() {
assert_equals(c.y, images[2]);
assert_equals(c.namedItem("y"), images[2]);
assert_true("y" in c, '"y" in c');
}, "img with name");

test(function() {
assert_equals(c.z1, images[3]);
assert_equals(c.namedItem("z1"), images[3]);
assert_true("z1" in c, '"z1" in c');
assert_equals(c.z2, images[3]);
assert_equals(c.namedItem("z2"), images[3]);
assert_true("z2" in c, '"z2" in c');
}, "img with id and name");

test(function() {
assert_equals(c.a, images[4]);
assert_equals(c.namedItem("a"), images[4]);
assert_true("a" in c, '"a" in c');
}, "Two img elements with the same id");

test(function() {
assert_equals(c.b, images[6]);
assert_equals(c.namedItem("b"), images[6]);
assert_true("b" in c, '"b" in c');
}, "Two img elements with the same name");

test(function() {
assert_equals(c.c, undefined);
assert_equals(c.namedItem("c"), null);
assert_false("c" in c, '"c" in c');
}, "Unknown name should not be in the collection");

test(function() {
assert_equals(c.f, undefined);
assert_equals(c.namedItem("f"), null);
assert_false("f" in c, '"f" in c');
}, "Foreign element should not be in the collection");

test(function() {
assert_equals(c.input, undefined);
assert_equals(c.namedItem("input"), null);
assert_false("input" in c, '"input" in c');
var input = div.getElementsByTagName("input")[0];
assert_all(function (aElement) {
assert_not_equals(aElement.namespaceURI, input);
}, c);
}, "Input elements should not be in the collection");

test(function() {
assert_equals(c[""], undefined);
assert_equals(c.namedItem(""), null);
assert_false("" in c, '"" in c');
}, "The empty string should not be in the collections");
</script>