mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 08:18:41 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
|
|
@ -0,0 +1,89 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<title>Selectors-API Level 2 Test Suite: HTML with Selectors Level 3</title>
|
||||
<!-- Selectors API Test Suite Version 3 -->
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/dom/nodes/selectors.js"></script>
|
||||
<script src="/dom/nodes/ParentNode-querySelector-All.js"></script>
|
||||
<script src="ParentNode-query-queryAll.js"></script>
|
||||
<style>iframe { visibility: hidden; position: absolute; }</style>
|
||||
|
||||
<div id="log">This test requires JavaScript.</div>
|
||||
|
||||
<script>
|
||||
async_test(function() {
|
||||
var frame = document.createElement("iframe");
|
||||
frame.onload = this.step_func_done(init);
|
||||
frame.src = "/dom/nodes/ParentNode-querySelector-All-content.html#target";
|
||||
document.body.appendChild(frame);
|
||||
});
|
||||
|
||||
function init(e) {
|
||||
/*
|
||||
* This test suite tests Selectors API methods in 4 different contexts:
|
||||
* 1. Document node
|
||||
* 2. In-document Element node
|
||||
* 3. Detached Element node (an element with no parent, not in the document)
|
||||
* 4. Document Fragment node
|
||||
*
|
||||
* For each context, the following tests are run:
|
||||
*
|
||||
* The interface check tests ensure that each type of node exposes the Selectors API methods.
|
||||
*
|
||||
* The matches() tests are run
|
||||
* All the selectors tested for both the valid and invalid selector tests are found in selectors.js.
|
||||
* See comments in that file for documentation of the format used.
|
||||
*
|
||||
* The level2-lib.js file contains all the common test functions for running each of the aforementioned tests
|
||||
*/
|
||||
|
||||
var docType = "html"; // Only run tests suitable for HTML
|
||||
|
||||
// Prepare the nodes for testing
|
||||
var doc = e.target.contentDocument; // Document Node tests
|
||||
|
||||
var element = doc.getElementById("root"); // In-document Element Node tests
|
||||
|
||||
//Setup the namespace tests
|
||||
setupSpecialElements(doc, element);
|
||||
|
||||
var outOfScope = element.cloneNode(true); // Append this to the body before running the in-document
|
||||
// Element tests, but after running the Document tests. This
|
||||
// tests that no elements that are not descendants of element
|
||||
// are selected.
|
||||
|
||||
traverse(outOfScope, function(elem) { // Annotate each element as being a clone; used for verifying
|
||||
elem.setAttribute("data-clone", ""); // that none of these elements ever match.
|
||||
});
|
||||
|
||||
|
||||
var detached = element.cloneNode(true); // Detached Element Node tests
|
||||
|
||||
var fragment = doc.createDocumentFragment(); // Fragment Node tests
|
||||
fragment.appendChild(element.cloneNode(true));
|
||||
|
||||
// Setup Tests
|
||||
interfaceCheckQuery("Document", doc);
|
||||
interfaceCheckQuery("Detached Element", detached);
|
||||
interfaceCheckQuery("Fragment", fragment);
|
||||
interfaceCheckQuery("In-document Element", element);
|
||||
|
||||
runSpecialSelectorTests("Document", doc);
|
||||
runSpecialSelectorTests("Detached Element", detached);
|
||||
runSpecialSelectorTests("Fragment", fragment);
|
||||
runSpecialSelectorTests("In-document Element", element);
|
||||
|
||||
verifyStaticList("Document", doc, doc);
|
||||
verifyStaticList("Detached Element", doc, detached);
|
||||
verifyStaticList("Fragment", doc, fragment);
|
||||
verifyStaticList("In-document Element", doc, element);
|
||||
|
||||
runInvalidSelectorTestQuery("Document", doc, invalidSelectors);
|
||||
runInvalidSelectorTestQuery("Detached Element", detached, invalidSelectors);
|
||||
runInvalidSelectorTestQuery("Fragment", fragment, invalidSelectors);
|
||||
runInvalidSelectorTestQuery("In-document Element", element, invalidSelectors);
|
||||
|
||||
runValidSelectorTest("In-document", doc, scopedSelectors, "html");
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,275 @@
|
|||
/*
|
||||
* Check that the query and queryAll methods exist on the given Node
|
||||
*/
|
||||
function interfaceCheckQuery(type, obj) {
|
||||
test(function() {
|
||||
var q = typeof obj.query === "function";
|
||||
assert_true(q, type + " supports query.");
|
||||
}, type + " supports query")
|
||||
|
||||
test(function() {
|
||||
var qa = typeof obj.queryAll === "function";
|
||||
assert_true( qa, type + " supports queryAll.");
|
||||
}, type + " supports queryAll")
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that the NodeList returned by queryAll is static and and that a new list is created after
|
||||
* each call. A static list should not be affected by subsequent changes to the DOM.
|
||||
*/
|
||||
function verifyStaticList(type, doc, root) {
|
||||
var pre, post, preLength;
|
||||
|
||||
test(function() {
|
||||
pre = root.queryAll("div");
|
||||
preLength = pre.length;
|
||||
|
||||
var div = doc.createElement("div");
|
||||
(root.body || root).appendChild(div);
|
||||
|
||||
assert_equals(pre.length, preLength, "The length of the NodeList should not change.")
|
||||
}, type + ": static NodeList")
|
||||
|
||||
test(function() {
|
||||
post = root.queryAll("div"),
|
||||
assert_equals(post.length, preLength + 1, "The length of the new NodeList should be 1 more than the previous list.")
|
||||
}, type + ": new NodeList")
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify handling of special values for the selector parameter, including stringification of
|
||||
* null and undefined, and the handling of the empty string.
|
||||
*/
|
||||
function runSpecialSelectorTests(type, root) {
|
||||
test(function() { // 1
|
||||
assert_equals(root.queryAll(null).length, 1, "This should query one element with the tag name 'NULL'.");
|
||||
}, type + ".queryAll null")
|
||||
|
||||
test(function() { // 2
|
||||
assert_equals(root.queryAll(undefined).length, 1, "This should query one elements with the tag name 'UNDEFINED'.");
|
||||
}, type + ".queryAll undefined")
|
||||
|
||||
test(function() { // 3
|
||||
assert_throws(TypeError(), function() {
|
||||
root.queryAll();
|
||||
}, "This should throw a TypeError.")
|
||||
}, type + ".queryAll no parameter")
|
||||
|
||||
test(function() { // 4
|
||||
var elm = root.query(null)
|
||||
assert_not_equals(elm, null, "This should query an element.");
|
||||
assert_equals(elm.tagName.toUpperCase(), "NULL", "The tag name should be 'NULL'.")
|
||||
}, type + ".query null")
|
||||
|
||||
test(function() { // 5
|
||||
var elm = root.query(undefined)
|
||||
assert_not_equals(elm, undefined, "This should query an element.");
|
||||
assert_equals(elm.tagName.toUpperCase(), "UNDEFINED", "The tag name should be 'UNDEFINED'.")
|
||||
}, type + ".query undefined")
|
||||
|
||||
test(function() { // 6
|
||||
assert_throws(TypeError(), function() {
|
||||
root.query();
|
||||
}, "This should throw a TypeError.")
|
||||
}, type + ".query no parameter.")
|
||||
|
||||
test(function() { // 7
|
||||
result = root.queryAll("*");
|
||||
var i = 0;
|
||||
traverse(root, function(elem) {
|
||||
if (elem !== root) {
|
||||
assert_equals(elem, result[i++], "The result in index " + i + " should be in tree order.")
|
||||
}
|
||||
})
|
||||
}, type + ".queryAll tree order");
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute queries with the specified valid selectors for both query() and queryAll()
|
||||
* Only run these tests when results are expected. Don't run for syntax error tests.
|
||||
*
|
||||
* context.queryAll(selector, refNodes)
|
||||
* context.queryAll(selector) // Only if refNodes is not specified
|
||||
* root.queryAll(selector, context) // Only if refNodes is not specified
|
||||
* root.queryAll(selector, refNodes) // Only if context is not specified
|
||||
* root.queryAll(selector) // Only if neither context nor refNodes is specified
|
||||
*
|
||||
* Equivalent tests will be run for .query() as well.
|
||||
*/
|
||||
function runValidSelectorTest(type, root, selectors, docType) {
|
||||
var nodeType = getNodeType(root);
|
||||
|
||||
for (var i = 0; i < selectors.length; i++) {
|
||||
var s = selectors[i];
|
||||
var n = s["name"];
|
||||
var q = s["selector"];
|
||||
var e = s["expect"];
|
||||
|
||||
var ctx = s["ctx"];
|
||||
var ref = s["ref"];
|
||||
|
||||
if (!s["exclude"] || (s["exclude"].indexOf(nodeType) === -1 && s["exclude"].indexOf(docType) === -1)) {
|
||||
var foundall, found, context, refNodes, refArray;
|
||||
|
||||
if (s["testType"] & TEST_FIND) {
|
||||
|
||||
|
||||
/*
|
||||
* If ctx and ref are specified:
|
||||
* context.queryAll(selector, refNodes)
|
||||
* context.query(selector, refNodes)
|
||||
*/
|
||||
if (ctx && ref) {
|
||||
context = root.querySelector(ctx);
|
||||
refNodes = root.querySelectorAll(ref);
|
||||
refArray = Array.prototype.slice.call(refNodes, 0);
|
||||
|
||||
test(function() {
|
||||
foundall = context.queryAll(q, refNodes);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Context Element].queryAll: " + n + " (with refNodes NodeList): " + q);
|
||||
|
||||
test(function() {
|
||||
foundall = context.queryAll(q, refArray);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Context Element].queryAll: " + n + " (with refNodes Array): " + q);
|
||||
|
||||
test(function() {
|
||||
found = context.query(q, refNodes);
|
||||
verifyElement(found, foundall, expect)
|
||||
}, type + " [Context Element].query: " + n + " (with refNodes NodeList): " + q);
|
||||
|
||||
test(function() {
|
||||
found = context.query(q, refArray);
|
||||
verifyElement(found, foundall, expect)
|
||||
}, type + " [Context Element].query: " + n + " (with refNodes Array): " + q);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If ctx is specified, ref is not:
|
||||
* context.queryAll(selector)
|
||||
* context.query(selector)
|
||||
* root.queryAll(selector, context)
|
||||
* root.query(selector, context)
|
||||
*/
|
||||
if (ctx && !ref) {
|
||||
context = root.querySelector(ctx);
|
||||
|
||||
test(function() {
|
||||
foundall = context.queryAll(q);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Context Element].queryAll: " + n + " (with no refNodes): " + q);
|
||||
|
||||
test(function() {
|
||||
found = context.query(q);
|
||||
verifyElement(found, foundall, expect)
|
||||
}, type + " [Context Element].query: " + n + " (with no refNodes): " + q);
|
||||
|
||||
test(function() {
|
||||
foundall = root.queryAll(q, context);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Root Node].queryAll: " + n + " (with refNode Element): " + q);
|
||||
|
||||
test(function() {
|
||||
foundall = root.query(q, context);
|
||||
verifyElement(found, foundall, expect);
|
||||
}, type + " [Root Node].query: " + n + " (with refNode Element): " + q);
|
||||
}
|
||||
|
||||
/*
|
||||
* If ref is specified, ctx is not:
|
||||
* root.queryAll(selector, refNodes)
|
||||
* root.query(selector, refNodes)
|
||||
*/
|
||||
if (!ctx && ref) {
|
||||
refNodes = root.querySelectorAll(ref);
|
||||
refArray = Array.prototype.slice.call(refNodes, 0);
|
||||
|
||||
test(function() {
|
||||
foundall = root.queryAll(q, refNodes);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Root Node].queryAll: " + n + " (with refNodes NodeList): " + q);
|
||||
|
||||
test(function() {
|
||||
foundall = root.queryAll(q, refArray);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + " [Root Node].queryAll: " + n + " (with refNodes Array): " + q);
|
||||
|
||||
test(function() {
|
||||
found = root.query(q, refNodes);
|
||||
verifyElement(found, foundall, expect);
|
||||
}, type + " [Root Node].query: " + n + " (with refNodes NodeList): " + q);
|
||||
|
||||
test(function() {
|
||||
found = root.query(q, refArray);
|
||||
verifyElement(found, foundall, expect);
|
||||
}, type + " [Root Node].query: " + n + " (with refNodes Array): " + q);
|
||||
}
|
||||
|
||||
/*
|
||||
* If neither ctx nor ref is specified:
|
||||
* root.queryAll(selector)
|
||||
* root.query(selector)
|
||||
*/
|
||||
if (!ctx && !ref) {
|
||||
test(function() {
|
||||
foundall = root.queryAll(q);
|
||||
verifyNodeList(foundall, expect);
|
||||
}, type + ".queryAll: " + n + " (with no refNodes): " + q);
|
||||
|
||||
test(function() {
|
||||
found = root.query(q);
|
||||
verifyElement(found, foundall, expect);
|
||||
}, type + ".query: " + n + " (with no refNodes): " + q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute queries with the specified invalid selectors for both query() and queryAll()
|
||||
* Only run these tests when errors are expected. Don't run for valid selector tests.
|
||||
*/
|
||||
function runInvalidSelectorTestQuery(type, root, selectors) {
|
||||
for (var i = 0; i < selectors.length; i++) {
|
||||
var s = selectors[i];
|
||||
var n = s["name"];
|
||||
var q = s["selector"];
|
||||
|
||||
test(function() {
|
||||
assert_throws("SyntaxError", function() {
|
||||
root.query(q)
|
||||
})
|
||||
}, type + ".query: " + n + ": " + q);
|
||||
|
||||
test(function() {
|
||||
assert_throws("SyntaxError", function() {
|
||||
root.queryAll(q)
|
||||
})
|
||||
}, type + ".queryAll: " + n + ": " + q);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyNodeList(resultAll, expect) {
|
||||
assert_not_equals(resultAll, null, "The method should not return null.");
|
||||
assert_equals(resultAll.length, e.length, "The method should return the expected number of matches.");
|
||||
|
||||
for (var i = 0; i < e.length; i++) {
|
||||
assert_not_equals(resultAll[i], null, "The item in index " + i + " should not be null.")
|
||||
assert_equals(resultAll[i].getAttribute("id"), e[i], "The item in index " + i + " should have the expected ID.");
|
||||
assert_false(resultAll[i].hasAttribute("data-clone"), "This should not be a cloned element.");
|
||||
}
|
||||
}
|
||||
|
||||
function verifyElement(result, resultAll, expect) {
|
||||
if (expect.length > 0) {
|
||||
assert_not_equals(result, null, "The method should return a match.")
|
||||
assert_equals(found.getAttribute("id"), e[0], "The method should return the first match.");
|
||||
assert_equals(result, resultAll[0], "The result should match the first item from querySelectorAll.");
|
||||
assert_false(found.hasAttribute("data-clone"), "This should not be annotated as a cloned element.");
|
||||
} else {
|
||||
assert_equals(result, null, "The method should not match anything.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue