Bug 1406030 - Enable browser_webconsole_cd_iframe.js in new frontend; r=Honza.
Once the test was migrated, it was failing because we did not show
error messages for invalid cd() calls.
There was a missing part in the evaluation result prepare message, which
this patch fixes. A stub and a mocha test were added to make sure we do
display those kind of messages.
MozReview-Commit-ID: FcTsP2pr3vD
--- a/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js
+++ b/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js
@@ -51,16 +51,24 @@ describe("EvaluationResult component:",
it("renders an inspect command result", () => {
const message = stubPreparedMessages.get("inspect({a: 1})");
const wrapper = render(EvaluationResult({ message, serviceContainer }));
expect(wrapper.find(".message-body").text()).toBe("Object { a: 1 }");
});
+ it("renders an jsterm command error result", () => {
+ const message = stubPreparedMessages.get("cd(document)");
+ const wrapper = render(EvaluationResult({ message, serviceContainer }));
+
+ expect(wrapper.find(".message-body").text())
+ .toBe("Cannot cd() to the given window. Invalid argument.");
+ });
+
it("displays a [Learn more] link", () => {
const store = setupStore([]);
const message = stubPreparedMessages.get("asdf()");
serviceContainer.openLink = sinon.spy();
const wrapper = mount(Provider({store},
EvaluationResult({message, serviceContainer})
--- a/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js
@@ -150,17 +150,18 @@ p {
}
`);
// Evaluation Result
const evaluationResultCommands = [
"new Date(0)",
"asdf()",
"1 + @",
- "inspect({a: 1})"
+ "inspect({a: 1})",
+ "cd(document)"
];
let evaluationResult = new Map(evaluationResultCommands.map(cmd => [cmd, cmd]));
evaluationResult.set("longString message Error",
`throw new Error("Long error ".repeat(10000))`);
// Network Event
--- a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/evaluationResult.js
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/evaluationResult.js
@@ -138,16 +138,39 @@ stubPreparedMessages.set("inspect({a: 1}
"stacktrace": null,
"frame": null,
"groupId": null,
"userProvidedStyles": null,
"notes": null,
"indent": 0
}));
+stubPreparedMessages.set("cd(document)", new ConsoleMessage({
+ "id": "1",
+ "allowRepeating": true,
+ "source": "javascript",
+ "timeStamp": 1510650094657,
+ "type": "result",
+ "helperType": "error",
+ "level": "error",
+ "messageText": "Cannot cd() to the given window. Invalid argument.",
+ "parameters": [
+ {
+ "type": "undefined"
+ }
+ ],
+ "repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"Cannot cd() to the given window. Invalid argument.\",\"parameters\":[{\"type\":\"undefined\"}],\"source\":\"javascript\",\"type\":\"result\",\"userProvidedStyles\":null}",
+ "stacktrace": null,
+ "frame": null,
+ "groupId": null,
+ "userProvidedStyles": null,
+ "notes": null,
+ "indent": 0
+}));
+
stubPreparedMessages.set("longString message Error", new ConsoleMessage({
"id": "1",
"allowRepeating": true,
"source": "javascript",
"timeStamp": 1493108241073,
"type": "result",
"helperType": null,
"level": "error",
@@ -300,16 +323,32 @@ stubPackets.set("inspect({a: 1})", {
"ownSymbolsLength": 0,
"safeGetterValues": {}
}
}
},
"notes": null
});
+stubPackets.set("cd(document)", {
+ "from": "server1.conn0.child1/consoleActor2",
+ "input": "cd(document)",
+ "result": {
+ "type": "undefined"
+ },
+ "timestamp": 1510650094657,
+ "exception": null,
+ "frame": null,
+ "helperResult": {
+ "type": "error",
+ "message": "cdFunctionInvalidArgument"
+ },
+ "notes": null
+});
+
stubPackets.set("longString message Error", {
"from": "server1.conn0.child1/consoleActor2",
"input": "throw new Error(\"Long error \".repeat(10000))",
"result": {
"type": "undefined"
},
"timestamp": 1493108241073,
"exception": {
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -57,18 +57,18 @@ support-files =
test-bug-597756-reopen-closed-tab.html
test-bug-599725-response-headers.sjs
test-bug-600183-charset.html
test-bug-600183-charset.html^headers^
test-bug-601177-log-levels.html
test-bug-601177-log-levels.js
test-bug-603750-websocket.html
test-bug-603750-websocket.js
- test-bug-609872-cd-iframe-child.html
- test-bug-609872-cd-iframe-parent.html
+ test-cd-iframe-child.html
+ test-cd-iframe-parent.html
test-bug-613013-console-api-iframe.html
test-bug-618078-network-exceptions.html
test-bug-630733-response-redirect-headers.sjs
test-bug-632275-getters.html
test-bug-632347-iterators-generators.html
test-bug-644419-log-limits.html
test-bug-646025-console-file-location.html
test-bug-658368-time-methods.html
@@ -224,17 +224,16 @@ subsuite = clipboard
[browser_netmonitor_shows_reqs_in_webconsole.js]
[browser_webconsole_allow_mixedcontent_securityerrors.js]
tags = mcb
[browser_webconsole_batching.js]
[browser_webconsole_block_mixedcontent_securityerrors.js]
tags = mcb
[browser_webconsole_cached_messages.js]
[browser_webconsole_cd_iframe.js]
-skip-if = true # Bug 1406030
[browser_webconsole_certificate_messages.js]
[browser_webconsole_charset.js]
skip-if = true # Bug 1404400
[browser_webconsole_click_function_to_source.js]
skip-if = true # Bug 1406038
[browser_webconsole_clickable_urls.js]
[browser_webconsole_closing_after_completion.js]
skip-if = true # Bug 1408927
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_cd_iframe.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_cd_iframe.js
@@ -2,114 +2,70 @@
/* 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/ */
// Test that the cd() jsterm helper function works as expected. See bug 609872.
"use strict";
-function test() {
- let hud;
-
- const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
- "test/test-bug-609872-cd-iframe-parent.html";
+const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
+ "new-console-output/test/mochitest/test-cd-iframe-parent.html";
- const parentMessages = [{
- name: "document.title in parent iframe",
- text: "bug 609872 - iframe parent",
- category: CATEGORY_OUTPUT,
- }, {
- name: "paragraph content",
- text: "p: test for bug 609872 - iframe parent",
- category: CATEGORY_OUTPUT,
- }, {
- name: "object content",
- text: "obj: parent!",
- category: CATEGORY_OUTPUT,
- }];
+add_task(async function () {
+ const hud = await openNewTabAndConsole(TEST_URI);
+
+ info("Test initial state");
+ await executeWindowTest(hud, "parent");
- const childMessages = [{
- name: "document.title in child iframe",
- text: "bug 609872 - iframe child",
- category: CATEGORY_OUTPUT,
- }, {
- name: "paragraph content",
- text: "p: test for bug 609872 - iframe child",
- category: CATEGORY_OUTPUT,
- }, {
- name: "object content",
- text: "obj: child!",
- category: CATEGORY_OUTPUT,
- }];
+ info("cd() into the iframe using a selector");
+ await hud.jsterm.execute(`cd("iframe")`);
+ await executeWindowTest(hud, "child");
+
+ info("cd() out of the iframe, reset to default window");
+ await hud.jsterm.execute("cd()");
+ await executeWindowTest(hud, "parent");
- Task.spawn(runner).then(finishTest);
-
- function* runner() {
- const {tab} = yield loadTab(TEST_URI);
- hud = yield openConsole(tab);
-
- yield executeWindowTest();
+ info("cd() into the iframe using an iframe DOM element");
+ await hud.jsterm.execute(`cd($("iframe"))`);
+ await executeWindowTest(hud, "child");
- yield waitForMessages({ webconsole: hud, messages: parentMessages });
-
- info("cd() into the iframe using a selector");
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd('iframe')");
- yield executeWindowTest();
-
- yield waitForMessages({ webconsole: hud, messages: childMessages });
+ info("cd(window.parent)");
+ await hud.jsterm.execute("cd(window.parent)");
+ await executeWindowTest(hud, "parent");
- info("cd() out of the iframe, reset to default window");
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd()");
- yield executeWindowTest();
-
- yield waitForMessages({ webconsole: hud, messages: parentMessages });
-
- info("call cd() with unexpected arguments");
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd(document)");
+ info("call cd() with unexpected arguments");
+ let onCdErrorMessage = waitForMessage(hud, "Cannot cd()");
+ hud.jsterm.execute("cd(document)");
+ let cdErrorMessage = await onCdErrorMessage;
+ ok(cdErrorMessage.node.classList.contains("error"),
+ "An error message is shown when calling the cd command with `document`");
- yield waitForMessages({
- webconsole: hud,
- messages: [{
- text: "Cannot cd()",
- category: CATEGORY_OUTPUT,
- severity: SEVERITY_ERROR,
- }],
- });
-
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd('p')");
+ onCdErrorMessage = waitForMessage(hud, "Cannot cd()");
+ hud.jsterm.execute(`cd("p")`);
+ cdErrorMessage = await onCdErrorMessage;
+ ok(cdErrorMessage.node.classList.contains("error"),
+ "An error message is shown when calling the cd command with a non iframe selector");
+});
- yield waitForMessages({
- webconsole: hud,
- messages: [{
- text: "Cannot cd()",
- category: CATEGORY_OUTPUT,
- severity: SEVERITY_ERROR,
- }],
- });
-
- info("cd() into the iframe using an iframe DOM element");
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd($('iframe'))");
- yield executeWindowTest();
-
- yield waitForMessages({ webconsole: hud, messages: childMessages });
+async function executeWindowTest(hud, iframeRole) {
+ const BASE_TEXT = "Test for the cd() command (bug 609872) - iframe";
+ let onMessages = waitForMessages({
+ hud,
+ messages: [{
+ text: `${BASE_TEXT} ${iframeRole}`
+ }, {
+ text: `p: ${BASE_TEXT} ${iframeRole}`
+ }, {
+ text: `obj: ${iframeRole}!`
+ }]
+ });
- info("cd(window.parent)");
- hud.jsterm.clearOutput();
- yield hud.jsterm.execute("cd(window.parent)");
- yield executeWindowTest();
-
- yield waitForMessages({ webconsole: hud, messages: parentMessages });
+ hud.jsterm.execute(`document.title`);
+ hud.jsterm.execute(`"p: " + document.querySelector("p").textContent`);
+ hud.jsterm.execute(`"obj: " + window.foobar`);
- yield closeConsole(tab);
- }
+ const messages = await onMessages;
+ ok(messages, `Expected evaluation result messages are shown in ${iframeRole} iframe`);
- function* executeWindowTest() {
- yield hud.jsterm.execute("document.title");
- yield hud.jsterm.execute("'p: ' + document.querySelector('p').textContent");
- yield hud.jsterm.execute("'obj: ' + window.foobarBug609872");
- }
+ // Clear the output so we don't pollute the next assertions.
+ hud.jsterm.clearOutput();
}
rename from devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-child.html
rename to devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-child.html
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-child.html
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-child.html
@@ -1,13 +1,13 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
- <title>test for bug 609872 - iframe child</title>
- <!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
+ <title>Test for the cd() command (bug 609872) - iframe child</title>
</head>
<body>
- <p>test for bug 609872 - iframe child</p>
- <script>window.foobarBug609872 = 'child!';</script>
+ <p>Test for the cd() command (bug 609872) - iframe child</p>
+ <script>window.foobar = "child!";</script>
</body>
</html>
rename from devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-parent.html
rename to devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-parent.html
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-parent.html
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-parent.html
@@ -1,14 +1,14 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
- <title>test for bug 609872 - iframe parent</title>
- <!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
+ <title>Test for the cd() command (bug 609872) - iframe parent</title>
</head>
<body>
- <p>test for bug 609872 - iframe parent</p>
- <script>window.foobarBug609872 = 'parent!';</script>
- <iframe src="test-bug-609872-cd-iframe-child.html"></iframe>
+ <p>Test for the cd() command (bug 609872) - iframe parent</p>
+ <script>window.foobar = "parent!";</script>
+ <iframe src="test-cd-iframe-child.html"></iframe>
</body>
</html>
--- a/devtools/client/webconsole/new-console-output/utils/messages.js
+++ b/devtools/client/webconsole/new-console-output/utils/messages.js
@@ -251,16 +251,24 @@ function transformEvaluationResultPacket
timestamp: timeStamp,
notes,
} = packet;
const parameter = helperResult && helperResult.object
? helperResult.object
: result;
+ if (helperResult && helperResult.type === "error") {
+ try {
+ messageText = l10n.getStr(helperResult.message);
+ } catch (ex) {
+ messageText = helperResult.message;
+ }
+ }
+
const level = messageText ? MESSAGE_LEVEL.ERROR : MESSAGE_LEVEL.LOG;
return new ConsoleMessage({
source: MESSAGE_SOURCE.JAVASCRIPT,
type: MESSAGE_TYPE.RESULT,
helperType: helperResult ? helperResult.type : null,
level,
messageText,
parameters: [parameter],