Bug 1611682 - Fix show DOM properties. r=rcaliman.

This patch work around the fact that the `inspect` command
is used for different purpose:
- open the evaluated element in the inspector/debugger
- expand a given object in the console

In order to do that, a second parameter is added to indicate
which usage we do want.
This is not pretty, but I can't see something as straightforward
to fix this issue.
Given that there's plan to have a properties sidebar in the
inspector, it might be enough for now.

The existing test is modified to check that the object is indeed
expanded in the console.

Differential Revision: https://phabricator.services.mozilla.com/D61662

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2020-02-05 15:23:10 +00:00
Родитель 606e719987
Коммит d9ff4804c3
5 изменённых файлов: 29 добавлений и 16 удалений

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

@ -345,7 +345,7 @@ class MarkupContextMenu {
_showDOMProperties() {
this.toolbox.openSplitConsole().then(() => {
const { hud } = this.toolbox.getPanel("webconsole");
hud.ui.wrapper.dispatchEvaluateExpression("inspect($0)");
hud.ui.wrapper.dispatchEvaluateExpression("inspect($0, true)");
});
}

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

@ -2,22 +2,16 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {
getHistoryEntries,
} = require("devtools/client/webconsole/selectors/history");
// Tests for menuitem functionality that doesn't fit into any specific category
const TEST_URL = URL_ROOT + "doc_inspector_menu.html";
add_task(async function() {
const { inspector, toolbox, testActor } = await openInspectorForURL(TEST_URL);
await testShowDOMProperties();
await testDuplicateNode();
await testDeleteNode();
await testDeleteTextNode();
await testDeleteRootNode();
await testScrollIntoView();
// This needs to be last as the webconsole `inspect` command impact the selected node in
// the inspector.
await testShowDOMProperties();
async function testDuplicateNode() {
info("Testing 'Duplicate Node' menu item for normal elements.");
@ -135,12 +129,25 @@ add_task(async function() {
await consoleOpened;
const webconsoleUI = toolbox.getPanel("webconsole").hud.ui;
const messagesAdded = webconsoleUI.once("new-messages");
await messagesAdded;
info("Checking if 'inspect($0)' was evaluated");
const state = webconsoleUI.wrapper.getStore().getState();
ok(getHistoryEntries(state)[0] === "inspect($0)");
await poll(
() => {
const messages = [
...webconsoleUI.outputNode.querySelectorAll(".message"),
];
const nodeMessage = messages.find(m => m.textContent.includes("body"));
// wait for the object to be expanded
return (
nodeMessage &&
nodeMessage.querySelectorAll(".object-inspector .node").length > 10
);
},
"Waiting for the element node to be expanded",
10,
1000
);
info("Close split console");
await toolbox.toggleSplitConsole();
}

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

@ -148,7 +148,7 @@ function handleHelperResult(response) {
break;
case "inspectObject": {
const objectActor = helperResult.object;
if (hud.toolbox) {
if (hud.toolbox && !helperResult.forceExpandInConsole) {
hud.toolbox.inspectObjectActor(objectActor);
} else {
webConsoleUI.inspectObjectActor(objectActor);

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

@ -155,7 +155,8 @@ rawPackets.set(`inspect({a: 1})`, {
}
},
"actorID": "server0.conn0.child1/obj28"
}
},
"forceExpandInConsole": false
},
"input": "inspect({a: 1})",
"result": {

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

@ -629,7 +629,11 @@ WebConsoleCommands._registerOriginal("cd", function(owner, window) {
* @param object object
* Object to inspect.
*/
WebConsoleCommands._registerOriginal("inspect", function(owner, object) {
WebConsoleCommands._registerOriginal("inspect", function(
owner,
object,
forceExpandInConsole = false
) {
const dbgObj = owner.preprocessDebuggerObject(
owner.makeDebuggeeValue(object)
);
@ -639,6 +643,7 @@ WebConsoleCommands._registerOriginal("inspect", function(owner, object) {
type: "inspectObject",
input: owner.evalInput,
object: grip,
forceExpandInConsole,
};
});