Files
firefox/devtools/shared/webconsole/test/test_jsterm_queryselector.html
T
Yoshi Huang 55fbfd1425 Bug 1381771 - Part 2: use legacy data: URI behavior to run test. r=bgrins
These two tests just creates a dummy window, however it makes the test
more difficult to write if we just simply use a seperate file for them.

Because these are chrome: tests, and they are opening a content window,
for the chrome side, it won't receive the window.onload because they are
not the same origin.

For the content side, it cannot access 'postMessage' because it looks
there's some protection when trying to read chrome object.
2017-07-24 10:00:31 +08:00

145 lines
3.8 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the querySelector / querySelectorAll helpers</title>
<script type="text/javascript" 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">
SimpleTest.waitForExplicitFinish();
let gState;
let gWin;
function evaluateJS(input) {
return new Promise((resolve) => gState.client.evaluateJS(input, resolve));
}
function startTest() {
info ("Content window opened, attaching console to it");
let 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;
let tests = [
setupWindow,
checkQuerySelector,
checkQuerySelectorAll,
checkQuerySelectorAllNotExist,
checkQuerySelectorAllException
];
runTests(tests, testEnd);
});
}
let setupWindow = Task.async(function*() {
info ("Shimming window functions for the content privileged tab");
yield evaluateJS("document.querySelector = function() { throw 'should not call qS'; }");
yield evaluateJS("document.querySelectorAll = function() { throw 'should not call qSA'; }");
nextTest();
});
let checkQuerySelector = Task.async(function*() {
info ("$ returns an DOMNode");
let response = yield evaluateJS("$('body')");
basicResultCheck(response, "$('body')", {
type: "object",
class: "HTMLBodyElement",
preview: {
kind: "DOMNode",
nodeName: "body"
}
});
nextTest();
});
let checkQuerySelectorAll = Task.async(function*() {
info ("$$ returns an array");
let response = yield evaluateJS("$$('body')");
basicResultCheck(response, "$$('body')", {
type: "object",
class: "Array",
preview: {
length: 1
}
});
nextTest();
});
let checkQuerySelectorAllNotExist = Task.async(function*() {
info ("$$ returns an array even if query yields no results");
let response = yield evaluateJS("$$('foobar')");
basicResultCheck(response, "$$('foobar')", {
type: "object",
class: "Array",
preview: {
length: 0
}
});
nextTest();
});
let checkQuerySelectorAllException = Task.async(function*() {
info ("$$ returns an exception if an invalid selector was provided");
let response = yield evaluateJS("$$(':foo')");
checkObject(response, {
input: "$$(':foo')",
exceptionMessage: "SyntaxError: ':foo' is not a valid selector",
exception: {
preview: {
kind: "DOMException",
name: "SyntaxError",
message: "':foo' is not a valid selector"
}
}
});
nextTest();
});
function basicResultCheck(response, input, output) {
checkObject(response, {
from: gState.actor,
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();
});
}
let load = Task.async(function*() {
removeEventListener("load", load);
yield 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>