Files
firefox/devtools/shared/webconsole/test/test_jsterm.html
T
Brendan Dahl 135bc8a754 Bug 1550801 - Replace expected XULDocument with HTMLDocument in devtools tests. r=nchevobbe
test_bug819670_getter_throws.html:
Previously, the document context inspected in the console was the test
harness XULDocument, but now it will be an HTMLDocument. Update the
checks to make sure the inspected object has the same own properties as
the test documents own properties.

other tests:
Simply replace the expected document type.

Differential Revision: https://phabricator.services.mozilla.com/D38695
2019-07-22 06:34:05 +00:00

282 lines
6.9 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for JavaScript terminal functionality</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 JavaScript terminal functionality</p>
<iframe id="content-iframe" src="http://example.com/chrome/devtools/shared/webconsole/test/sandboxed_iframe.html"></iframe>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
let gState;
let {MAX_AUTOCOMPLETE_ATTEMPTS,MAX_AUTOCOMPLETIONS} = require("devtools/shared/webconsole/js-property-provider");
// This test runs all of its assertions twice - once with
// evaluateJS and once with evaluateJSAsync.
let evaluatingSync = true;
function evaluateJS(input, options = {}) {
if (evaluatingSync) {
return gState.client.evaluateJS(input, options);
} else {
return gState.client.evaluateJSAsync(input, options);
}
}
function startTest()
{
removeEventListener("load", startTest);
attachConsoleToTab(["PageError"], onAttach);
}
function onAttach(aState, aResponse)
{
top.foobarObject = Object.create(null);
top.foobarObject.foo = 1;
top.foobarObject.foobar = 2;
top.foobarObject.foobaz = 3;
top.foobarObject.omg = 4;
top.foobarObject.omgfoo = 5;
top.foobarObject.strfoo = "foobarz";
top.foobarObject.omgstr = "foobarz" +
(new Array(DebuggerServer.LONG_STRING_LENGTH * 2)).join("abb");
top.largeObject1 = Object.create(null);
for (let i = 0; i < MAX_AUTOCOMPLETE_ATTEMPTS + 1; i++) {
top.largeObject1['a' + i] = i;
}
top.largeObject2 = Object.create(null);
for (let i = 0; i < MAX_AUTOCOMPLETIONS * 2; i++) {
top.largeObject2['a' + i] = i;
}
gState = aState;
let tests = [doSimpleEval, doWindowEval, doEvalWithException,
doEvalWithHelper, doEvalString, doEvalLongString,
doEvalWithBinding, doEvalWithBindingFrame,
forceLexicalInit];
runTests(tests, testEnd);
}
async function doSimpleEval() {
info("test eval '2+2'");
let response = await evaluateJS("2+2");
checkObject(response, {
input: "2+2",
result: 4,
});
ok(!response.exception, "no eval exception");
ok(!response.helperResult, "no helper result");
nextTest();
}
async function doWindowEval() {
info("test eval 'document'");
let response = await evaluateJS("document");
checkObject(response, {
input: "document",
result: {
type: "object",
class: "HTMLDocument",
actor: /[a-z]/,
},
});
ok(!response.exception, "no eval exception");
ok(!response.helperResult, "no helper result");
nextTest();
}
async function doEvalWithException() {
info("test eval with exception");
let response = await evaluateJS("window.doTheImpossible()");
checkObject(response, {
input: "window.doTheImpossible()",
result: {
type: "undefined",
},
exceptionMessage: /doTheImpossible/,
});
ok(response.exception, "js eval exception");
ok(!response.helperResult, "no helper result");
nextTest();
}
async function doEvalWithHelper() {
info("test eval with helper");
let response = await evaluateJS("clear()");
checkObject(response, {
input: "clear()",
result: {
type: "undefined",
},
helperResult: { type: "clearOutput" },
});
ok(!response.exception, "no eval exception");
nextTest();
}
async function doEvalString() {
let response = await evaluateJS("window.foobarObject.strfoo");
checkObject(response, {
input: "window.foobarObject.strfoo",
result: "foobarz",
});
nextTest();
}
async function doEvalLongString() {
let response = await evaluateJS("window.foobarObject.omgstr");
let str = top.foobarObject.omgstr;
let initial = str.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH);
checkObject(response, {
input: "window.foobarObject.omgstr",
result: {
type: "longString",
initial: initial,
length: str.length,
},
});
nextTest();
}
async function doEvalWithBinding() {
let response = await evaluateJS("document;");
let documentActor = response.result.actor;
info("running a command with _self as document using selectedObjectActor");
let selectedObjectSame = await evaluateJS("_self === document", {
selectedObjectActor: documentActor
});
checkObject(selectedObjectSame, {
result: true
});
nextTest();
}
async function doEvalWithBindingFrame() {
let frameWin = top.document.querySelector("iframe").contentWindow;
frameWin.fooFrame = { bar: 1 };
let response = await evaluateJS(
"document.querySelector('iframe').contentWindow.fooFrame"
);
let iframeObjectActor = response.result.actor;
ok(iframeObjectActor, "There is an actor associated with the response");
let selectedObjectGlobal = await evaluateJS("this.temp1 = _self;", {
selectedObjectActor: iframeObjectActor
});
ok(top.temp1 && top.temp1.bar === 1,
"Global matches the top global with bindObjectActor");
ok(!frameWin.temp1,
"Global doesn't match the object's global with bindObjectActor");
nextTest()
}
async function forceLexicalInit() {
info("test that failed let/const bindings are initialized to undefined");
const testData = [
{
stmt: "let foopie = wubbalubadubdub",
vars: ["foopie"]
},
{
stmt: "let {z, w={n}=null} = {}",
vars: ["z", "w"]
},
{
stmt: "let [a, b, c] = null",
vars: ["a", "b", "c"]
},
{
stmt: "const nein1 = rofl, nein2 = copter",
vars: ["nein1", "nein2"]
},
{
stmt: "const {ha} = null",
vars: ["ha"]
},
{
stmt: "const [haw=[lame]=null] = []",
vars: ["haw"]
},
{
stmt: "const [rawr, wat=[lame]=null] = []",
vars: ["rawr", "haw"]
},
{
stmt: "let {zzz: xyz=99, zwz: wb} = nexistepas()",
vars: ["xyz", "wb"]
},
{
stmt: "let {c3pdoh=101} = null",
vars: ["c3pdoh"]
}
];
for (let data of testData) {
let response = await evaluateJS(data.stmt);
checkObject(response, {
input: data.stmt,
result: undefined,
});
ok(response.exception, "expected exception");
for (let varName of data.vars) {
let response2 = await evaluateJS(varName);
checkObject(response2, {
input: varName,
result: undefined,
});
ok(!response2.exception, "unexpected exception");
}
}
nextTest();
}
function testEnd()
{
// If this is the first run, reload the page and do it again.
// Otherwise, end the test.
closeDebugger(gState, function() {
gState = null;
if (evaluatingSync) {
evaluatingSync = false;
startTest();
} else {
SimpleTest.finish();
}
});
}
addEventListener("load", startTest);
</script>
</body>
</html>