Bug 1405352 - Split browser_webconsole_jsterm.js in multiple tests; r=Honza.

The test was doing a lot of things and was hard to follow.
Here we split it so we can have dedicated tests for each helpers.

MozReview-Commit-ID: 6YGR3aq6jYn

--HG--
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_document_no_xray.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_error_docs.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_error_outside_valid_range.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_dollar.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_dollar_dollar.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_dollar_x.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_help.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_keys_values.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_helper_pprint.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_instance_of.js
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_jsterm.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_null_undefined.js
extra : rebase_source : dafa772bcbc6b379fd6ec1137c07ba24e794fc71
This commit is contained in:
Nicolas Chevobbe 2018-01-24 11:34:30 +01:00
Родитель 2983f74a62
Коммит da3e572a83
13 изменённых файлов: 337 добавлений и 197 удалений

Просмотреть файл

@ -213,17 +213,28 @@ skip-if = true # Bug 1403188
[browser_jsterm_ctrl_a_select_all.js]
[browser_jsterm_ctrl_key_nav.js]
skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only
[browser_jsterm_document_no_xray.js]
[browser_jsterm_dollar.js]
[browser_jsterm_error_docs.js]
[browser_jsterm_error_outside_valid_range.js]
[browser_jsterm_helper_clear.js]
[browser_jsterm_helper_dollar_dollar.js]
[browser_jsterm_helper_dollar_x.js]
[browser_jsterm_helper_dollar.js]
[browser_jsterm_helper_help.js]
[browser_jsterm_helper_keys_values.js]
[browser_jsterm_helper_pprint.js]
[browser_jsterm_history.js]
[browser_jsterm_history_persist.js]
[browser_jsterm_history_nav.js]
[browser_jsterm_input_expansion.js]
[browser_jsterm_inspect.js]
[browser_jsterm_instance_of.js]
[browser_jsterm_multiline.js]
[browser_jsterm_no_autocompletion_on_defined_variables.js]
[browser_jsterm_no_input_and_tab_key_pressed.js]
[browser_jsterm_no_input_change_and_tab_key_pressed.js]
[browser_jsterm_null_undefined.js]
[browser_jsterm_popup_close_on_tab_switch.js]
[browser_jsterm_popup.js]
[browser_jsterm_selfxss.js]
@ -292,9 +303,6 @@ skip-if = true # Bug 1405343
[browser_webconsole_insecure_passwords_web_console_warning.js]
[browser_webconsole_inspect_cross_domain_object.js]
[browser_webconsole_js_input_expansion.js]
[browser_webconsole_jsterm.js]
skip-if = true # Bug 1405352
# old console skip-if = e10s # Bug 1042253 - webconsole e10s tests (Linux debug timeout)
[browser_webconsole_keyboard_accessibility.js]
[browser_webconsole_location_debugger_link.js]
[browser_webconsole_location_scratchpad_link.js]

Просмотреть файл

@ -0,0 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = "data:text/html,Test evaluating document";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
// check for occurrences of Object XRayWrapper, bug 604430
const onMessage = waitForMessage(hud, "HTMLDocument");
jsterm.execute("document");
const {node} = await onMessage;
is(node.textContent.includes("xray"), false, "document - no XrayWrapper");
});

Просмотреть файл

@ -0,0 +1,33 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = "data:text/html,Test error documentation";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
// Check that errors with entries in errordocs.js display links next to their messages.
const ErrorDocs = require("devtools/server/actors/errordocs");
const ErrorDocStatements = {
"JSMSG_BAD_RADIX": "(42).toString(0);",
"JSMSG_BAD_ARRAY_LENGTH": "([]).length = -1",
"JSMSG_NEGATIVE_REPETITION_COUNT": "'abc'.repeat(-1);",
"JSMSG_PRECISION_RANGE": "77.1234.toExponential(-1);",
};
for (let [errorMessageName, expression] of Object.entries(ErrorDocStatements)) {
let title = ErrorDocs.GetURL({ errorMessageName }).split("?")[0];
jsterm.clearOutput();
const onMessage = waitForMessage(hud, "RangeError:")
jsterm.execute(expression);
const {node} = await onMessage;
const learnMoreLink = node.querySelector(".learn-more-link");
ok(learnMoreLink, `There is a [Learn More] link for "${errorMessageName}" error`);
is(learnMoreLink.title, title, `The link has the expected "${title}" title`);
}
});

Просмотреть файл

@ -0,0 +1,21 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Ensure that dom errors, with error numbers outside of the range
// of valid js.msg errors, don't cause crashes (See Bug 1270721).
const TEST_URI = "data:text/html,Test error documentation";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
const text = "TypeError: 'redirect' member of RequestInit 'foo' is not a valid value " +
"for enumeration RequestRedirect";
const onErrorMessage = waitForMessage(hud, text, ".message.error");
jsterm.execute("new Request('',{redirect:'foo'})");
await onErrorMessage;
ok(true, "Error message displayed as expected, without crashing the console.");
});

Просмотреть файл

@ -0,0 +1,41 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = `data:text/html,
<main>
<ul>
<li>First</li>
<li>Second</li>
</ul>
<aside>Sidebar</aside>
</main>
`;
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
let onMessage = waitForMessage(hud, "<main>");
jsterm.execute("$('main')");
let message = await onMessage;
ok(message, "`$('main')` worked");
onMessage = waitForMessage(hud, "<li>");
jsterm.execute("$('main > ul > li')");
message = await onMessage;
ok(message, "`$('main > ul > li')` worked");
onMessage = waitForMessage(hud, "LI");
jsterm.execute("$('main > ul > li').tagName");
message = await onMessage;
ok(message, "`$` result can be used right away");
onMessage = waitForMessage(hud, "null");
jsterm.execute("$('div')");
message = await onMessage;
ok(message, "`$('div')` does return null");
});

Просмотреть файл

@ -0,0 +1,41 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = `data:text/html,
<main>
<ul>
<li>First</li>
<li>Second</li>
</ul>
<aside>Sidebar</aside>
</main>
`;
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
let onMessage = waitForMessage(hud, "Array [ main ]");
jsterm.execute("$$('main')");
let message = await onMessage;
ok(message, "`$$('main')` worked");
onMessage = waitForMessage(hud, "Array [ li, li ]");
jsterm.execute("$$('main > ul > li')");
message = await onMessage;
ok(message, "`$$('main > ul > li')` worked");
onMessage = waitForMessage(hud, "LI - LI");
jsterm.execute("$$('main > ul > li').map(el => el.tagName).join(' - ')");
message = await onMessage;
ok(message, "`$$` result can be used right away");
onMessage = waitForMessage(hud, "Array []");
jsterm.execute("$$('div')");
message = await onMessage;
ok(message, "`$$('div')` returns an empty array");
});

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = `data:text/html,
<main>
<ul>
<li>First</li>
<li>Second</li>
</ul>
<aside>Sidebar</aside>
</main>
`;
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
let onMessage = waitForMessage(hud, "Array [ li, li ]");
jsterm.execute("$x('.//li')");
let message = await onMessage;
ok(message, "`$x` worked");
onMessage = waitForMessage(hud, "<li>");
jsterm.execute("$x('.//li', document.body)[0]");
message = await onMessage;
ok(message, "`$x()` result can be used right away");
});

Просмотреть файл

@ -0,0 +1,31 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = "data:text/html,Test <code>help()</code> jsterm helper";
const HELP_URL = "https://developer.mozilla.org/docs/Tools/Web_Console/Helpers";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
let openedLinks = 0;
let oldOpenLink = hud.openLink;
hud.openLink = (url) => {
if (url == HELP_URL) {
openedLinks++;
}
};
jsterm.clearOutput();
await jsterm.execute("help()");
await jsterm.execute("help");
await jsterm.execute("?");
let messages = Array.from(jsterm.outputNode.querySelectorAll(".message"));
ok(messages.every(msg => msg.classList.contains("command")),
"There is no results shown for the help commands");
is(openedLinks, 3, "correct number of pages opened by the help calls");
hud.openLink = oldOpenLink;
});

Просмотреть файл

@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI =
"data:text/html,Test <code>keys()</code> & <code>values()</code> jsterm helper";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
let onMessage = waitForMessage(hud, `Array [ "a", "b" ]`);
jsterm.execute("keys({a: 2, b:1})");
let message = await onMessage;
ok(message, "`keys()` worked");
onMessage = waitForMessage(hud, "Array [ 2, 1 ]");
jsterm.execute("values({a: 2, b:1})");
message = await onMessage;
ok(message, "`values()` worked");
onMessage = waitForMessage(hud, "Array");
jsterm.execute("keys(window)");
message = await onMessage;
ok(message, "`keys(window)` worked");
});

Просмотреть файл

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = "data:text/html,Test <code>pprint()</code> jsterm helper";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
let onMessage = waitForMessage(hud, `" b: 2\n a: 1"`);
jsterm.execute("pprint({b:2, a:1})");
let message = await onMessage;
ok(message, "`pprint()` worked");
// check that pprint(window) does not throw (see Bug 608358).
onMessage = waitForMessage(hud, `window:`);
jsterm.execute("pprint(window)");
message = await onMessage;
ok(message, "`pprint(window)` worked");
// check that calling pprint with a string does not throw (See Bug 614561).
onMessage = waitForMessage(hud, `" 0: \\"h\\"\n 1: \\"i\\""`);
jsterm.execute("pprint('hi')");
message = await onMessage;
ok(message, "`pprint('hi')` worked");
// check that pprint(function) shows function source (See Bug 618344).
onMessage = waitForMessage(hud, `"function() { var someCanaryValue = 42; }`);
jsterm.execute("pprint(function() { var someCanaryValue = 42; })");
message = await onMessage;
ok(message, "`pprint(function)` shows function source");
});

Просмотреть файл

@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Check instanceof correctness. See Bug 599940.
const TEST_URI = "data:text/html,Test <code>instanceof</code> evaluation";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
let onMessage = waitForMessage(hud, "true");
jsterm.execute("[] instanceof Array");
let message = await onMessage;
ok(message, "`instanceof Array` is correct");
onMessage = waitForMessage(hud, "true");
jsterm.execute("({}) instanceof Object");
message = await onMessage;
ok(message, "`instanceof Object` is correct");
onMessage = waitForMessage(hud, "false");
jsterm.execute("({}) instanceof Array");
message = await onMessage;
ok(message, "`instanceof Array` has expected result");
});

Просмотреть файл

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI =
"data:text/html,Test evaluating null and undefined";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const jsterm = hud.jsterm;
// Check that an evaluated null produces "null". See Bug 650780.
let onMessage = waitForMessage(hud, `null`);
jsterm.execute("null");
let message = await onMessage;
ok(message, "`null` returned the expected value");
onMessage = waitForMessage(hud, "undefined");
jsterm.execute("undefined");
message = await onMessage;
ok(message, "`undefined` returned the expected value");
});

Просмотреть файл

@ -1,194 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/test-console.html";
var jsterm;
add_task(function* () {
yield loadTab(TEST_URI);
let hud = yield openConsole();
jsterm = hud.jsterm;
yield testJSTerm(hud);
jsterm = null;
});
function checkResult(msg, desc) {
let def = defer();
waitForMessages({
webconsole: jsterm.hud.owner,
messages: [{
name: desc,
category: CATEGORY_OUTPUT,
}],
}).then(([result]) => {
let node = [...result.matched][0].querySelector(".message-body");
if (typeof msg == "string") {
is(node.textContent.trim(), msg,
"correct message shown for " + desc);
} else if (typeof msg == "function") {
ok(msg(node), "correct message shown for " + desc);
}
def.resolve();
});
return def.promise;
}
function* testJSTerm(hud) {
const HELP_URL = "https://developer.mozilla.org/docs/Tools/" +
"Web_Console/Helpers";
jsterm.clearOutput();
yield jsterm.execute("$('#header').getAttribute('id')");
yield checkResult('"header"', "$() worked");
jsterm.clearOutput();
yield jsterm.execute("$$('h1').length");
yield checkResult("1", "$$() worked");
jsterm.clearOutput();
yield jsterm.execute("$x('.//*', document.body)[0] == $$('h1')[0]");
yield checkResult("true", "$x() worked");
// no jsterm.clearOutput() here as we clear the output using the clear() fn.
yield jsterm.execute("clear()");
yield waitForSuccess({
name: "clear() worked",
validator: function () {
return jsterm.outputNode.childNodes.length == 0;
}
});
jsterm.clearOutput();
yield jsterm.execute("keys({b:1})[0] == 'b'");
yield checkResult("true", "keys() worked", 1);
jsterm.clearOutput();
yield jsterm.execute("values({b:1})[0] == 1");
yield checkResult("true", "values() worked", 1);
jsterm.clearOutput();
let openedLinks = 0;
let oldOpenLink = hud.openLink;
hud.openLink = (url) => {
if (url == HELP_URL) {
openedLinks++;
}
};
yield jsterm.execute("help()");
yield jsterm.execute("help");
yield jsterm.execute("?");
let output = jsterm.outputNode.querySelector(".message[category='output']");
ok(!output, "no output for help() calls");
is(openedLinks, 3, "correct number of pages opened by the help calls");
hud.openLink = oldOpenLink;
jsterm.clearOutput();
yield jsterm.execute("pprint({b:2, a:1})");
yield checkResult("\" b: 2\n a: 1\"", "pprint()");
// check instanceof correctness, bug 599940
jsterm.clearOutput();
yield jsterm.execute("[] instanceof Array");
yield checkResult("true", "[] instanceof Array == true");
jsterm.clearOutput();
yield jsterm.execute("({}) instanceof Object");
yield checkResult("true", "({}) instanceof Object == true");
// check for occurrences of Object XRayWrapper, bug 604430
jsterm.clearOutput();
yield jsterm.execute("document");
yield checkResult(function (node) {
return node.textContent.search(/\[object xraywrapper/i) == -1;
}, "document - no XrayWrapper");
// check that pprint(window) and keys(window) don't throw, bug 608358
jsterm.clearOutput();
yield jsterm.execute("pprint(window)");
yield checkResult(null, "pprint(window)");
jsterm.clearOutput();
yield jsterm.execute("keys(window)");
yield checkResult(null, "keys(window)");
// bug 614561
jsterm.clearOutput();
yield jsterm.execute("pprint('hi')");
yield checkResult("\" 0: \"h\"\n 1: \"i\"\"", "pprint('hi')");
// check that pprint(function) shows function source, bug 618344
jsterm.clearOutput();
yield jsterm.execute("pprint(function() { var someCanaryValue = 42; })");
yield checkResult(function (node) {
return node.textContent.indexOf("someCanaryValue") > -1;
}, "pprint(function) shows source");
// check that an evaluated null produces "null", bug 650780
jsterm.clearOutput();
yield jsterm.execute("null");
yield checkResult("null", "null is null");
jsterm.clearOutput();
yield jsterm.execute("undefined");
yield checkResult("undefined", "undefined is printed");
// check that thrown strings produce error messages,
// and the message text matches that of a stringified error object
// bug 1099071
jsterm.clearOutput();
yield jsterm.execute("throw '';");
yield checkResult((node) => {
return node.closest(".message").getAttribute("severity") === "error" &&
node.textContent === new Error("").toString();
}, "thrown empty string generates error message");
jsterm.clearOutput();
yield jsterm.execute("throw 'tomatoes';");
yield checkResult((node) => {
return node.closest(".message").getAttribute("severity") === "error" &&
node.textContent === new Error("tomatoes").toString();
}, "thrown non-empty string generates error message");
jsterm.clearOutput();
yield jsterm.execute("throw { foo: 'bar' };");
yield checkResult((node) => {
return node.closest(".message").getAttribute("severity") === "error" &&
node.textContent === Object.prototype.toString();
}, "thrown object generates error message");
// check that errors with entires in errordocs.js display links
// alongside their messages.
const ErrorDocs = require("devtools/server/actors/errordocs");
const ErrorDocStatements = {
"JSMSG_BAD_RADIX": "(42).toString(0);",
"JSMSG_BAD_ARRAY_LENGTH": "([]).length = -1",
"JSMSG_NEGATIVE_REPETITION_COUNT": "'abc'.repeat(-1);",
"JSMSG_PRECISION_RANGE": "77.1234.toExponential(-1);",
};
for (let errorMessageName of Object.keys(ErrorDocStatements)) {
let title = ErrorDocs.GetURL({ errorMessageName }).split("?")[0];
jsterm.clearOutput();
yield jsterm.execute(ErrorDocStatements[errorMessageName]);
yield checkResult((node) => {
return node.parentNode.getElementsByTagName("a")[0].title == title;
}, `error links to ${title}`);
}
// Ensure that dom errors, with error numbers outside of the range
// of valid js.msg errors, don't cause crashes (bug 1270721).
yield jsterm.execute("new Request('',{redirect:'foo'})");
}