2010-10-20 10:39:44 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-04-15 13:10:00 -07:00
|
|
|
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
let jsterm, testDriver;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
addTab(TEST_URI);
|
2012-05-10 08:01:37 -07:00
|
|
|
browser.addEventListener("load", function onLoad() {
|
|
|
|
browser.removeEventListener("load", onLoad, true);
|
2012-05-25 03:28:47 -07:00
|
|
|
openConsole(null, function(hud) {
|
|
|
|
testDriver = testJSTerm(hud);
|
|
|
|
testDriver.next();
|
|
|
|
});
|
2012-05-10 08:01:37 -07:00
|
|
|
}, true);
|
2010-10-20 10:39:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
function nextTest() {
|
|
|
|
testDriver.next();
|
|
|
|
}
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
function checkResult(msg, desc, lines) {
|
2012-05-25 03:28:47 -07:00
|
|
|
waitForSuccess({
|
|
|
|
name: "correct number of results shown for " + desc,
|
|
|
|
validatorFn: function()
|
|
|
|
{
|
|
|
|
let nodes = jsterm.outputNode.querySelectorAll(".webconsole-msg-output");
|
|
|
|
return nodes.length == lines;
|
|
|
|
},
|
|
|
|
successFn: function()
|
|
|
|
{
|
|
|
|
let labels = jsterm.outputNode.querySelectorAll(".webconsole-msg-output");
|
|
|
|
if (typeof msg == "string") {
|
|
|
|
is(labels[lines-1].textContent.trim(), msg,
|
|
|
|
"correct message shown for " + desc);
|
|
|
|
}
|
|
|
|
else if (typeof msg == "function") {
|
|
|
|
ok(msg(labels), "correct message shown for " + desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
},
|
|
|
|
failureFn: nextTest,
|
|
|
|
});
|
2010-10-20 10:39:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-10 08:01:37 -07:00
|
|
|
function testJSTerm(hud)
|
2010-10-20 10:39:44 -07:00
|
|
|
{
|
2012-05-10 08:01:37 -07:00
|
|
|
jsterm = hud.jsterm;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
2012-08-02 02:53:00 -07:00
|
|
|
jsterm.execute("'id=' + $('#header').getAttribute('id')");
|
2010-12-14 10:51:16 -08:00
|
|
|
checkResult('"id=header"', "$() worked", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("headerQuery = $$('h1')");
|
|
|
|
jsterm.execute("'length=' + headerQuery.length");
|
2010-12-14 10:51:16 -08:00
|
|
|
checkResult('"length=1"', "$$() worked", 2);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("xpathQuery = $x('.//*', document.body);");
|
|
|
|
jsterm.execute("'headerFound=' + (xpathQuery[0] == headerQuery[0])");
|
2010-12-14 10:51:16 -08:00
|
|
|
checkResult('"headerFound=true"', "$x() worked", 2);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
// no jsterm.clearOutput() here as we clear the output using the clear() fn.
|
|
|
|
jsterm.execute("clear()");
|
2012-05-25 03:28:47 -07:00
|
|
|
|
|
|
|
waitForSuccess({
|
|
|
|
name: "clear() worked",
|
|
|
|
validatorFn: function()
|
|
|
|
{
|
|
|
|
return jsterm.outputNode.childNodes.length == 0;
|
|
|
|
},
|
|
|
|
successFn: nextTest,
|
|
|
|
failureFn: nextTest,
|
|
|
|
});
|
|
|
|
|
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("'keysResult=' + (keys({b:1})[0] == 'b')");
|
2010-12-14 10:51:16 -08:00
|
|
|
checkResult('"keysResult=true"', "keys() worked", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("'valuesResult=' + (values({b:1})[0] == 1)");
|
2010-12-14 10:51:16 -08:00
|
|
|
checkResult('"valuesResult=true"', "values() worked", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2010-11-02 05:58:37 -07:00
|
|
|
jsterm.clearOutput();
|
2012-05-25 03:28:47 -07:00
|
|
|
|
|
|
|
let tabs = gBrowser.tabs.length;
|
|
|
|
|
2010-11-02 05:58:37 -07:00
|
|
|
jsterm.execute("help()");
|
2010-12-23 07:59:19 -08:00
|
|
|
let output = jsterm.outputNode.querySelector(".webconsole-msg-output");
|
2012-05-25 03:28:47 -07:00
|
|
|
ok(!output, "help() worked");
|
2010-11-02 05:58:37 -07:00
|
|
|
|
|
|
|
jsterm.execute("help");
|
2010-12-23 07:59:19 -08:00
|
|
|
output = jsterm.outputNode.querySelector(".webconsole-msg-output");
|
2010-12-14 10:51:16 -08:00
|
|
|
ok(!output, "help worked");
|
2010-11-02 05:58:37 -07:00
|
|
|
|
|
|
|
jsterm.execute("?");
|
2010-12-23 07:59:19 -08:00
|
|
|
output = jsterm.outputNode.querySelector(".webconsole-msg-output");
|
2010-12-14 10:51:16 -08:00
|
|
|
ok(!output, "? worked");
|
2010-11-02 05:58:37 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
let foundTab = null;
|
|
|
|
waitForSuccess({
|
|
|
|
name: "help tab opened",
|
|
|
|
validatorFn: function()
|
|
|
|
{
|
|
|
|
let newTabOpen = gBrowser.tabs.length == tabs + 1;
|
|
|
|
if (!newTabOpen) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundTab = gBrowser.tabs[tabs];
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
successFn: function()
|
|
|
|
{
|
|
|
|
gBrowser.removeTab(foundTab);
|
|
|
|
nextTest();
|
|
|
|
},
|
|
|
|
failureFn: nextTest,
|
|
|
|
});
|
|
|
|
yield;
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("pprint({b:2, a:1})");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult("a: 1\n b: 2", "pprint()", 1);
|
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2010-10-28 09:01:36 -07:00
|
|
|
// check instanceof correctness, bug 599940
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("[] instanceof Array");
|
|
|
|
checkResult("true", "[] instanceof Array == true", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-28 09:01:36 -07:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("({}) instanceof Object");
|
|
|
|
checkResult("true", "({}) instanceof Object == true", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-28 09:01:36 -07:00
|
|
|
|
|
|
|
// check for occurrences of Object XRayWrapper, bug 604430
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("document");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult(function(nodes) {
|
|
|
|
return nodes[0].textContent.search(/\[object xraywrapper/i) == -1;
|
|
|
|
}, "document - no XrayWrapper", 1);
|
|
|
|
yield;
|
2010-10-28 09:01:36 -07:00
|
|
|
|
2010-11-10 08:10:25 -08:00
|
|
|
// check that pprint(window) and keys(window) don't throw, bug 608358
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("pprint(window)");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult(null, "pprint(window)", 1);
|
|
|
|
yield;
|
2010-11-10 08:10:25 -08:00
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("keys(window)");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult(null, "keys(window)", 1);
|
|
|
|
yield;
|
2010-11-10 08:10:25 -08:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
// bug 614561
|
2010-12-02 02:50:28 -08:00
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("pprint('hi')");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult('0: "h"\n 1: "i"', "pprint('hi')", 1);
|
|
|
|
yield;
|
2010-12-02 02:50:28 -08:00
|
|
|
|
2011-01-04 09:31:48 -08:00
|
|
|
// check that pprint(function) shows function source, bug 618344
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("pprint(print)");
|
2012-05-25 03:28:47 -07:00
|
|
|
checkResult(function(nodes) {
|
|
|
|
return nodes[0].textContent.indexOf("aJSTerm.") > -1;
|
|
|
|
}, "pprint(function) shows source", 1);
|
|
|
|
yield;
|
2011-01-04 09:31:48 -08:00
|
|
|
|
2011-04-21 09:22:13 -07:00
|
|
|
// check that an evaluated null produces "null", bug 650780
|
|
|
|
jsterm.clearOutput();
|
|
|
|
jsterm.execute("null");
|
|
|
|
checkResult("null", "null is null", 1);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2011-04-21 09:22:13 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
jsterm = testDriver = null;
|
2012-05-10 08:01:37 -07:00
|
|
|
executeSoon(finishTest);
|
2012-05-25 03:28:47 -07:00
|
|
|
yield;
|
2010-10-20 10:39:44 -07:00
|
|
|
}
|