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

--HG--
rename : devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-child.html => devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-child.html
rename : devtools/client/webconsole/new-console-output/test/mochitest/test-bug-609872-cd-iframe-parent.html => devtools/client/webconsole/new-console-output/test/mochitest/test-cd-iframe-parent.html
extra : rebase_source : 8fc82b71875cebfed0e318d1eba8b5332dc650c7
This commit is contained in:
Nicolas Chevobbe 2017-11-14 10:27:12 +01:00
Родитель 72e9b053d9
Коммит 3b1a347334
10 изменённых файлов: 135 добавлений и 124 удалений

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

@ -56,6 +56,14 @@ describe("EvaluationResult component:", () => {
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([]);

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

@ -155,7 +155,8 @@ const evaluationResultCommands = [
"new Date(0)",
"asdf()",
"1 + @",
"inspect({a: 1})"
"inspect({a: 1})",
"cd(document)"
];
let evaluationResult = new Map(evaluationResultCommands.map(cmd => [cmd, cmd]));

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

@ -143,6 +143,29 @@ stubPreparedMessages.set("inspect({a: 1})", new ConsoleMessage({
"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,
@ -305,6 +328,22 @@ stubPackets.set("inspect({a: 1})", {
"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))",

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

@ -62,8 +62,8 @@ support-files =
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
@ -229,7 +229,6 @@ tags = mcb
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

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

@ -7,109 +7,65 @@
"use strict";
function test() {
let hud;
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"new-console-output/test/mochitest/test-cd-iframe-parent.html";
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/test-bug-609872-cd-iframe-parent.html";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
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,
}];
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");
Task.spawn(runner).then(finishTest);
info("cd() out of the iframe, reset to default window");
await hud.jsterm.execute("cd()");
await executeWindowTest(hud, "parent");
function* runner() {
const {tab} = yield loadTab(TEST_URI);
hud = yield openConsole(tab);
info("cd() into the iframe using an iframe DOM element");
await hud.jsterm.execute(`cd($("iframe"))`);
await executeWindowTest(hud, "child");
yield executeWindowTest();
info("cd(window.parent)");
await hud.jsterm.execute("cd(window.parent)");
await executeWindowTest(hud, "parent");
yield waitForMessages({ webconsole: hud, messages: parentMessages });
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`");
info("cd() into the iframe using a selector");
hud.jsterm.clearOutput();
yield hud.jsterm.execute("cd('iframe')");
yield executeWindowTest();
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: 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() out of the iframe, reset to default window");
hud.jsterm.clearOutput();
yield hud.jsterm.execute("cd()");
yield executeWindowTest();
hud.jsterm.execute(`document.title`);
hud.jsterm.execute(`"p: " + document.querySelector("p").textContent`);
hud.jsterm.execute(`"obj: " + window.foobar`);
yield waitForMessages({ webconsole: hud, messages: parentMessages });
const messages = await onMessages;
ok(messages, `Expected evaluation result messages are shown in ${iframeRole} iframe`);
info("call cd() with unexpected arguments");
hud.jsterm.clearOutput();
yield hud.jsterm.execute("cd(document)");
yield waitForMessages({
webconsole: hud,
messages: [{
text: "Cannot cd()",
category: CATEGORY_OUTPUT,
severity: SEVERITY_ERROR,
}],
});
hud.jsterm.clearOutput();
yield hud.jsterm.execute("cd('p')");
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 });
info("cd(window.parent)");
hud.jsterm.clearOutput();
yield hud.jsterm.execute("cd(window.parent)");
yield executeWindowTest();
yield waitForMessages({ webconsole: hud, messages: parentMessages });
yield closeConsole(tab);
}
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();
}

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

@ -1,13 +0,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/ -->
</head>
<body>
<p>test for bug 609872 - iframe child</p>
<script>window.foobarBug609872 = 'child!';</script>
</body>
</html>

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

@ -1,14 +0,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/ -->
</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>
</body>
</html>

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

@ -0,0 +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 the cd() command (bug 609872) - iframe child</title>
</head>
<body>
<p>Test for the cd() command (bug 609872) - iframe child</p>
<script>window.foobar = "child!";</script>
</body>
</html>

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

@ -0,0 +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 the cd() command (bug 609872) - iframe parent</title>
</head>
<body>
<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>

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

@ -256,6 +256,14 @@ function transformEvaluationResultPacket(packet) {
? 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,