forked from mirrors/gecko-dev
Differential Revision: https://phabricator.services.mozilla.com/D51090 --HG-- extra : moz-landing-system : lando
167 lines
4.3 KiB
HTML
167 lines
4.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf8">
|
|
<title>Test for the querySelector / querySelectorAll helpers</title>
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="text/javascript" src="common.js"></script>
|
|
<!-- Any copyright is dedicated to the Public Domain.
|
|
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
|
</head>
|
|
<body>
|
|
<p>Test for the querySelector / querySelectorAll helpers</p>
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
"use strict";
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
let gState;
|
|
let gWin;
|
|
|
|
function evaluateJS(input) {
|
|
return gState.webConsoleFront.evaluateJSAsync(input);
|
|
}
|
|
|
|
function startTest() {
|
|
info ("Content window opened, attaching console to it");
|
|
|
|
const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
|
|
ok (!gWin.document.nodePrincipal.equals(systemPrincipal),
|
|
"The test document is not using the system principal");
|
|
|
|
attachConsoleToTab([], state => {
|
|
gState = state;
|
|
const tests = [
|
|
setupWindow,
|
|
checkQuerySelector,
|
|
checkQuerySelectorAll,
|
|
checkQuerySelectorAllNotExist,
|
|
checkQuerySelectorException,
|
|
checkQuerySelectorAllException
|
|
];
|
|
runTests(tests, testEnd);
|
|
});
|
|
}
|
|
|
|
const setupWindow = async function () {
|
|
info ("Shimming window functions for the content privileged tab");
|
|
await evaluateJS("document.querySelector = function() { throw 'should not call qS'; }");
|
|
await evaluateJS("document.querySelectorAll = function() { throw 'should not call qSA'; }");
|
|
nextTest();
|
|
};
|
|
|
|
const checkQuerySelector = async function () {
|
|
info ("$ returns an DOMNode");
|
|
const response = await evaluateJS("$('body')");
|
|
basicResultCheck(response, "$('body')", {
|
|
type: "object",
|
|
class: "HTMLBodyElement",
|
|
preview: {
|
|
kind: "DOMNode",
|
|
nodeName: "body"
|
|
}
|
|
});
|
|
nextTest();
|
|
};
|
|
|
|
const checkQuerySelectorAll = async function () {
|
|
info ("$$ returns an array");
|
|
const response = await evaluateJS("$$('body')");
|
|
basicResultCheck(response, "$$('body')", {
|
|
type: "object",
|
|
class: "Array",
|
|
preview: {
|
|
length: 1
|
|
}
|
|
});
|
|
nextTest();
|
|
};
|
|
|
|
const checkQuerySelectorAllNotExist = async function () {
|
|
info ("$$ returns an array even if query yields no results");
|
|
const response = await evaluateJS("$$('foobar')");
|
|
basicResultCheck(response, "$$('foobar')", {
|
|
type: "object",
|
|
class: "Array",
|
|
preview: {
|
|
length: 0
|
|
}
|
|
});
|
|
nextTest();
|
|
};
|
|
|
|
const checkQuerySelectorException = async function () {
|
|
info ("$ returns an exception if an invalid selector was provided");
|
|
const response = await evaluateJS("$(':foo')");
|
|
checkObject(response, {
|
|
input: "$(':foo')",
|
|
exceptionMessage: "SyntaxError: ':foo' is not a valid selector",
|
|
exception: {
|
|
type: "object",
|
|
class: "DOMException",
|
|
preview: {
|
|
kind: "DOMException",
|
|
name: "SyntaxError",
|
|
message: "':foo' is not a valid selector"
|
|
}
|
|
}
|
|
});
|
|
nextTest();
|
|
};
|
|
|
|
const checkQuerySelectorAllException = async function () {
|
|
info ("$$ returns an exception if an invalid selector was provided");
|
|
const response = await evaluateJS("$$(':foo')");
|
|
checkObject(response, {
|
|
input: "$$(':foo')",
|
|
exceptionMessage: "SyntaxError: ':foo' is not a valid selector",
|
|
exception: {
|
|
type: "object",
|
|
class: "DOMException",
|
|
preview: {
|
|
kind: "DOMException",
|
|
name: "SyntaxError",
|
|
message: "':foo' is not a valid selector"
|
|
}
|
|
}
|
|
});
|
|
nextTest();
|
|
};
|
|
|
|
function basicResultCheck(response, input, output) {
|
|
checkObject(response, {
|
|
input: input,
|
|
result: output,
|
|
});
|
|
ok(!response.exception, "no eval exception");
|
|
ok(!response.helperResult, "no helper result");
|
|
}
|
|
|
|
function testEnd() {
|
|
gWin.close();
|
|
gWin = null;
|
|
closeDebugger(gState, function() {
|
|
gState = null;
|
|
SimpleTest.finish();
|
|
});
|
|
}
|
|
|
|
const load = async function () {
|
|
removeEventListener("load", load);
|
|
|
|
await new Promise(resolve => {
|
|
SpecialPowers.pushPrefEnv({"set": [
|
|
["security.data_uri.unique_opaque_origin", false],
|
|
]}, resolve);
|
|
});
|
|
|
|
// Open a content window to test XRay functionality on built in functions.
|
|
gWin = window.open("data:text/html,");
|
|
info ("Waiting for content window to load");
|
|
gWin.onload = startTest;
|
|
};
|
|
addEventListener("load", load);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|