Bug 1607741 - [devtools] Remove webconsole cd command. r=ladybenko.

The command is removed and the test that were using it
are either removed or updated.

Differential Revision: https://phabricator.services.mozilla.com/D101928
This commit is contained in:
Nicolas Chevobbe 2021-01-18 17:02:14 +00:00
Родитель 3b365915dc
Коммит a862e95663
13 изменённых файлов: 8 добавлений и 431 удалений

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

@ -96,10 +96,6 @@ messageRepeats.tooltip2=#1 repeat;#1 repeats
# output
openNodeInInspector=Click to select the node in the inspector
# LOCALIZATION NOTE (cdFunctionInvalidArgument): the text that is displayed when
# cd() is invoked with an invalid argument.
cdFunctionInvalidArgument=Cannot cd() to the given window. Invalid argument.
# LOCALIZATION NOTE (selfxss.msg): the text that is displayed when
# a new user of the developer tools pastes code into the console
# %1 is the text of selfxss.okstring

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

@ -19,8 +19,6 @@ support-files =
test_hsts-invalid-headers.sjs
test-batching.html
test-console-trace-duplicates.html
test-cd-iframe-child.html
test-cd-iframe-parent.html
test-console-api-iframe.html
test-console-api.html
test-csp-violation.html
@ -186,7 +184,6 @@ tags = mcb
[browser_webconsole_cached_messages_cross_domain_iframe.js]
[browser_webconsole_cached_messages_no_duplicate.js]
[browser_webconsole_cached_messages.js]
[browser_webconsole_cd_iframe.js]
[browser_webconsole_certificate_messages.js]
[browser_webconsole_checkloaduri_errors.js]
[browser_webconsole_clear_cache.js]

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

@ -13,7 +13,6 @@ const HELPERS = [
"$$",
"$0",
"$x",
"cd",
"clear",
"clearHistory",
"copy",

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

@ -1,81 +0,0 @@
/* 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";
const TEST_URI =
"http://example.com/browser/devtools/client/webconsole/" +
"test/browser/test-cd-iframe-parent.html";
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
info("Test initial state");
await executeWindowTest(hud, "parent");
info("cd() into the iframe using a selector");
execute(hud, `cd("iframe")`);
await executeWindowTest(hud, "child");
info("cd() out of the iframe, reset to default window");
execute(hud, "cd()");
await executeWindowTest(hud, "parent");
info("cd() into the iframe using an iframe DOM element");
execute(hud, `cd($("iframe"))`);
await executeWindowTest(hud, "child");
info("cd(window.parent)");
execute(hud, "cd(window.parent)");
await executeWindowTest(hud, "parent");
info("call cd() with unexpected arguments");
let onCdErrorMessage = waitForMessage(hud, "Cannot cd()");
execute(hud, "cd(document)");
let cdErrorMessage = await onCdErrorMessage;
ok(
cdErrorMessage.node.classList.contains("error"),
"An error message is shown when calling the cd command with `document`"
);
onCdErrorMessage = waitForMessage(hud, "Cannot cd()");
execute(hud, `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"
);
});
async function executeWindowTest(hud, iframeRole) {
const BASE_TEXT = "Test for the cd() command (bug 609872) - iframe";
const onMessages = waitForMessages({
hud,
messages: [
{
text: `${BASE_TEXT} ${iframeRole}`,
},
{
text: `p: ${BASE_TEXT} ${iframeRole}`,
},
{
text: `obj: ${iframeRole}!`,
},
],
});
execute(hud, `document.title`);
execute(hud, `"p: " + document.querySelector("p").textContent`);
execute(hud, `"obj: " + window.foobar`);
const messages = await onMessages;
ok(
messages,
`Expected evaluation result messages are shown in ${iframeRole} iframe`
);
// Clear the output so we don't pollute the next assertions.
await clearOutput(hud);
}

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

@ -75,7 +75,6 @@ function getCommands() {
"asdf()",
"1 + @",
"inspect({a: 1})",
"cd(document)",
"undefined",
];

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

@ -1,16 +0,0 @@
<!-- 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>
"use strict";
window.foobar = "child!";
</script>
</body>
</html>

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

@ -1,17 +0,0 @@
<!-- 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>
"use strict";
window.foobar = "parent!";
</script>
<iframe src="test-cd-iframe-child.html"></iframe>
</body>
</html>

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

@ -245,15 +245,6 @@ 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();

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

@ -177,21 +177,6 @@ rawPackets.set(`inspect({a: 1})`, {
"timestamp": 1572867483805
});
rawPackets.set(`cd(document)`, {
"resultID": "1573832025125-4",
"hasException": false,
"helperResult": {
"type": "error",
"message": "cdFunctionInvalidArgument"
},
"input": "cd(document)",
"result": {
"type": "undefined"
},
"startTime": 1572867483805,
"timestamp": 1572867483805
});
rawPackets.set(`undefined`, {
"resultID": "1573832025127-5",
"hasException": false,

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

@ -4,7 +4,7 @@
"use strict";
const { Ci, Cu, Cc } = require("chrome");
const { Cu } = require("chrome");
// Note that this is only used in WebConsoleCommands, see $0 and screenshot.
if (!isWorker) {
@ -518,63 +518,6 @@ WebConsoleCommands._registerOriginal("help", function(owner) {
owner.helperResult = { type: "help" };
});
/**
* Change the JS evaluation scope.
*
* @param DOMElement|string|window window
* The window object to use for eval scope. This can be a string that
* is used to perform document.querySelector(), to find the iframe that
* you want to cd() to. A DOMElement can be given as well, the
* .contentWindow property is used. Lastly, you can directly pass
* a window object. If you call cd() with no arguments, the current
* eval scope is cleared back to its default (the top window).
*/
WebConsoleCommands._registerOriginal("cd", function(owner, window) {
// Log a deprecation warning.
const scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
const scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
const deprecationMessage =
"The `cd` command will be disabled in a future release. " +
"See https://bugzilla.mozilla.org/show_bug.cgi?id=1605327 for more information.";
scriptError.initWithWindowID(
deprecationMessage,
null,
null,
0,
0,
1,
"content javascript",
owner.window.windowGlobalChild.innerWindowId
);
const Services = require("Services");
Services.console.logMessage(scriptError);
if (!window) {
owner.consoleActor.evalGlobal = null;
owner.helperResult = { type: "cd" };
return;
}
if (typeof window == "string") {
window = owner.window.document.querySelector(window);
}
if (Element.isInstance(window) && window.contentWindow) {
window = window.contentWindow;
}
if (!(window instanceof Ci.nsIDOMWindow)) {
owner.helperResult = {
type: "error",
message: "cdFunctionInvalidArgument",
};
return;
}
owner.consoleActor.evalGlobal = window;
owner.helperResult = { type: "cd" };
});
/**
* Inspects the passed object. This is done by opening the PropertyPanel.
*

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

@ -26,7 +26,6 @@ support-files =
[test_file_uri.html]
[test_jsterm.html]
[test_jsterm_autocomplete.html]
[test_jsterm_cd_iframe.html]
[test_jsterm_last_result.html]
[test_jsterm_queryselector.html]
[test_network_get.html]

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

@ -447,7 +447,7 @@
async function doAutocompleteCommands(webConsoleFront) {
info("test autocomplete for 'c'");
let matches = (await webConsoleFront.autocomplete("c")).matches;
ok(matches.includes("cd") && matches.includes("clear"), "commands are returned");
ok(matches.includes("clear"), "commands are returned");
info("test autocomplete for 's'");
matches = (await webConsoleFront.autocomplete("s")).matches;
@ -459,27 +459,27 @@
info("test autocomplete for 'window.c'");
matches = (await webConsoleFront.autocomplete("window.c")).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
info("test autocomplete for 'window[c'");
matches = (await webConsoleFront.autocomplete("window[c")).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
info(`test autocomplete for 'window["c'`);
matches = (await webConsoleFront.autocomplete(`window["c`)).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
info(`test autocomplete for 'window["c'`);
matches = (await webConsoleFront.autocomplete(`window["c`)).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
info(`test autocomplete for 'window[";c'`);
matches = (await webConsoleFront.autocomplete(`window[";c`)).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
info(`test autocomplete for 'window[;c'`);
matches = (await webConsoleFront.autocomplete(`window[;c`)).matches;
ok(!matches.includes("cd") && !matches.includes("clear"), "commands are not returned");
ok(!matches.includes("clear"), "commands are not returned");
}
async function doAutocompleteAfterOperator(webConsoleFront) {

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

@ -1,218 +0,0 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the cd() function</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 the cd() function</p>
<iframe id="content-iframe" src="http://example.com/chrome/devtools/shared/webconsole/test/chrome/sandboxed_iframe.html"></iframe>
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let gState;
async function startTest()
{
removeEventListener("load", startTest);
const {state} = await attachConsoleToTab([]);
onAttach(state);
}
function onAttach(aState)
{
top.foobarObject = Object.create(null);
top.foobarObject.bug609872 = "parent";
window.foobarObject = Object.create(null);
window.foobarObject.bug609872 = "child";
gState = aState;
const tests = [doCheckParent, doCdIframe, doCheckIframe,
doCdContentIframe,
doCdSandboxedIframe, doCheckSandboxedIframe,
doCdParent,
doCdParent,
doCheckParent2];
runTests(tests, testEnd);
}
function doCheckParent()
{
info("check parent window");
gState.webConsoleFront.evaluateJSAsync("window.foobarObject.bug609872")
.then(onFooObjectFromParent);
}
function onFooObjectFromParent(aResponse)
{
checkObject(aResponse, {
input: "window.foobarObject.bug609872",
result: "parent",
});
ok(!aResponse.exception, "no eval exception");
ok(!aResponse.helperResult, "no helper result");
nextTest();
}
function doCdIframe()
{
info("test cd('iframe')");
gState.webConsoleFront.evaluateJSAsync("cd('iframe')").then(onCdIframe);
}
function onCdIframe(aResponse)
{
checkObject(aResponse, {
input: "cd('iframe')",
result: { type: "undefined" },
helperResult: { type: "cd" },
});
ok(!aResponse.exception, "no eval exception");
nextTest();
}
function doCheckIframe()
{
info("check foobarObject from the iframe");
gState.webConsoleFront.evaluateJSAsync("window.foobarObject.bug609872")
.then(onFooObjectFromIframe);
}
function onFooObjectFromIframe(aResponse)
{
checkObject(aResponse, {
input: "window.foobarObject.bug609872",
result: "child",
});
ok(!aResponse.exception, "no js eval exception");
ok(!aResponse.helperResult, "no helper result");
nextTest();
}
function doCdContentIframe()
{
info("test cd('#content-iframe')");
gState.webConsoleFront.evaluateJSAsync("cd('#content-iframe')").then(onCdContentIframe);
}
function onCdContentIframe(aResponse)
{
checkObject(aResponse, {
input: "cd('#content-iframe')",
result: { type: "undefined" },
helperResult: { type: "cd" },
});
ok(!aResponse.exception, "no eval exception");
nextTest();
}
function doCdSandboxedIframe()
{
// Don't use string to ensure we don't get security exception
// when passing a content window reference.
const cmd = "cd(document.getElementById('sandboxed-iframe').contentWindow)";
info("test " + cmd);
gState.webConsoleFront.evaluateJSAsync(cmd).then(onCdSandboxedIframe.bind(null, cmd));
}
function onCdSandboxedIframe(cmd, aResponse)
{
checkObject(aResponse, {
input: cmd,
result: { type: "undefined" },
helperResult: { type: "cd" },
});
ok(!aResponse.exception, "no eval exception");
nextTest();
}
function doCheckSandboxedIframe()
{
info("check foobarObject from the sandboxed iframe");
gState.webConsoleFront.evaluateJSAsync("window.foobarObject.bug1051224")
.then(onFooObjectFromSandboxedIframe);
}
function onFooObjectFromSandboxedIframe(aResponse)
{
checkObject(aResponse, {
input: "window.foobarObject.bug1051224",
result: "sandboxed",
});
ok(!aResponse.exception, "no js eval exception");
ok(!aResponse.helperResult, "no helper result");
nextTest();
}
function doCdParent()
{
info("test cd() back to parent");
gState.webConsoleFront.evaluateJSAsync("cd()").then(onCdParent);
}
function onCdParent(aResponse)
{
checkObject(aResponse, {
input: "cd()",
result: { type: "undefined" },
helperResult: { type: "cd" },
});
ok(!aResponse.exception, "no eval exception");
nextTest();
}
function doCheckParent2()
{
gState.webConsoleFront.evaluateJSAsync("window.foobarObject.bug609872")
.then(onFooObjectFromParent2);
}
function onFooObjectFromParent2(aResponse)
{
checkObject(aResponse, {
input: "window.foobarObject.bug609872",
result: "parent",
});
ok(!aResponse.exception, "no eval exception");
ok(!aResponse.helperResult, "no helper result");
nextTest();
}
function testEnd()
{
closeDebugger(gState, function() {
gState = null;
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>