// What else should we test? // XXXbz we need more tests here to test liveness!
}
function test_getElementsByTagName() { var doc = ParseFile("nodelist_data_1.xml"); var root = doc.documentElement;
// Check that getElementsByTagName returns an HTMLCollection. Assert.equal(
ChromeUtils.getClassName(doc.getElementsByTagName("*")), "HTMLCollection"
); Assert.ok(
ChromeUtils.getClassName(root.getElementsByTagName("*")), "HTMLCollection"
);
// Check that getElementsByTagName excludes the element it's called on. Assert.equal(
doc.getElementsByTagName("*").length,
root.getElementsByTagName("*").length + 1
); Assert.equal(doc.getElementById("test2").getElementsByTagName("*").length, 8); Assert.equal(
doc.getElementById("test2").getElementsByTagName("test").length,
3
);
// Check that the first element of getElementsByTagName on the document is // the right thing. Assert.equal(doc.getElementsByTagName("*").item(0), root);
// Check that we get the right things in the right order var numTests = doc.getElementsByTagName("test").length; Assert.equal(numTests, 5);
for (var i = 1; i <= numTests; ++i) { Assert.ok(Element.isInstance(doc.getElementById("test" + i))); Assert.equal(
doc.getElementById("test" + i),
doc.getElementsByTagName("test").item(i - 1)
);
}
// Check that we handle tagnames containing ':' correctly Assert.equal(
ChromeUtils.getClassName(doc.getElementsByTagName("foo:test")), "HTMLCollection"
); Assert.equal(doc.getElementsByTagName("foo:test").length, 2);
function test_getElementsByTagNameNS() { var doc = ParseFile("nodelist_data_1.xml"); var root = doc.documentElement;
// Check that getElementsByTagNameNS returns an HTMLCollection. Assert.equal(
ChromeUtils.getClassName(doc.getElementsByTagNameNS("*", "*")), "HTMLCollection"
); Assert.equal(
ChromeUtils.getClassName(root.getElementsByTagNameNS("*", "*")), "HTMLCollection"
);
// Check that passing "" and null for the namespace URI gives the same result var list1 = doc.getElementsByTagNameNS("", "test"); var list2 = doc.getElementsByTagNameNS(null, "test"); Assert.equal(list1.length, list2.length); for (var i = 0; i < list1.length; ++i) { Assert.equal(list1.item(i), list2.item(i));
}
// Check that getElementsByTagNameNS excludes the element it's called on. Assert.equal(
doc.getElementsByTagNameNS("*", "*").length,
root.getElementsByTagNameNS("*", "*").length + 1
); Assert.equal(
doc.getElementById("test2").getElementsByTagNameNS("*", "*").length,
8
); Assert.equal(
doc.getElementById("test2").getElementsByTagNameNS("", "test").length,
1
); Assert.equal(
doc.getElementById("test2").getElementsByTagNameNS("*", "test").length,
7
);
// Check that the first element of getElementsByTagNameNS on the document is // the right thing. Assert.equal(doc.getElementsByTagNameNS("*", "*").item(0), root); Assert.equal(doc.getElementsByTagNameNS(null, "*").item(0), root);
// Check that we get the right things in the right order
var numTests = doc.getElementsByTagNameNS("*", "test").length; Assert.equal(numTests, 14);
for (i = 1; i <= numTests; ++i) { Assert.ok(Element.isInstance(doc.getElementById("test" + i))); Assert.equal(
doc.getElementById("test" + i),
doc.getElementsByTagNameNS("*", "test").item(i - 1)
);
}
// Check general proper functioning of having a non-wildcard namespace. var test2 = doc.getElementById("test2"); Assert.equal(doc.getElementsByTagNameNS("", "test").length, 3); Assert.equal(test2.getElementsByTagNameNS("", "test").length, 1); Assert.equal(doc.getElementsByTagNameNS("foo", "test").length, 7); Assert.equal(test2.getElementsByTagNameNS("foo", "test").length, 4); Assert.equal(doc.getElementsByTagNameNS("foo2", "test").length, 0); Assert.equal(test2.getElementsByTagNameNS("foo2", "test").length, 0); Assert.equal(doc.getElementsByTagNameNS("bar", "test").length, 4); Assert.equal(test2.getElementsByTagNameNS("bar", "test").length, 2);
// Check that previously-unknown namespaces are handled right. Note that we // can just hardcode the strings, since we're running only once in XPCshell. // If someone wants to run these in a browser, some use of Math.random() may // be in order.
list1 = doc.getElementsByTagNameNS("random-bogus-namespace", "foo");
list2 = doc.documentElement.getElementsByTagNameNS( "random-bogus-namespace2", "foo"
); Assert.notEqual(list1, list2); Assert.equal(list1.length, 0); Assert.equal(list2.length, 0); var newNode = doc.createElementNS("random-bogus-namespace", "foo");
doc.documentElement.appendChild(newNode);
newNode = doc.createElementNS("random-bogus-namespace2", "foo");
doc.documentElement.appendChild(newNode); Assert.equal(list1.length, 1); Assert.equal(list2.length, 1);
}
function test_getElementsByAttribute() { var doc = ParseFile("nodelist_data_2.xhtml"); var root = doc.documentElement;
var master1 = doc.getElementById("master1"); var master2 = doc.getElementById("master2"); var master3 = doc.getElementById("master3"); var external = doc.getElementById("external");
// Test the various combinations of attributes with colons in the name Assert.equal(root.getElementsByAttribute("foo:foo", "foo").length, 16); Assert.equal(master1.getElementsByAttribute("foo:foo", "foo").length, 5); Assert.equal(master2.getElementsByAttribute("foo:foo", "foo").length, 4); Assert.equal(master3.getElementsByAttribute("foo:foo", "foo").length, 4); Assert.equal(external.getElementsByAttribute("foo:foo", "foo").length, 2);
// Check that getElementsByAttributeNS returns an HTMLCollection. Assert.equal(
ChromeUtils.getClassName(root.getElementsByAttributeNS("*", "*", "*")), "HTMLCollection"
);
var master1 = doc.getElementById("master1"); var master2 = doc.getElementById("master2"); var master3 = doc.getElementById("master3"); var external = doc.getElementById("external");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.