forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1216632 - Make autocompletion work on $_ and $0; r=bgrins.
To make $0 autocompletion work, we need to pass the current selectedNode actor from the frontend, so we can retrieve the object reference later. For $_, we need the webconsole actor reference to be able to retrieve the last input result. Since the list of parameters of JsPropertyProviders was getting a bit long, we transform them in an object so it's more legible on the consumer side. Mochitests are added for both helpers to ensure this work as expected. Differential Revision: https://phabricator.services.mozilla.com/D11866 --HG-- extra : moz-landing-system : lando
- Loading branch information
Showing
11 changed files
with
226 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
devtools/client/webconsole/test/mochitest/browser_jsterm_completion_dollar_underscore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* -*- 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/ */ | ||
|
||
// Tests that code completion works properly on $_. | ||
|
||
"use strict"; | ||
|
||
const TEST_URI = `data:text/html;charset=utf8,<p>test code completion on $_`; | ||
|
||
add_task(async function() { | ||
// Run test with legacy JsTerm | ||
await pushPref("devtools.webconsole.jsterm.codeMirror", false); | ||
await performTests(); | ||
// And then run it with the CodeMirror-powered one. | ||
await pushPref("devtools.webconsole.jsterm.codeMirror", true); | ||
await performTests(); | ||
}); | ||
|
||
async function performTests() { | ||
const {jsterm} = await openNewTabAndConsole(TEST_URI); | ||
const {autocompletePopup} = jsterm; | ||
|
||
info("Test that there's no issue when trying to do an autocompletion without last " + | ||
"evaluation result"); | ||
await setInputValueForAutocompletion(jsterm, "$_."); | ||
is(autocompletePopup.items.length, 0, "autocomplete popup has no items"); | ||
is(autocompletePopup.isOpen, false, "autocomplete popup is not open"); | ||
|
||
info("Populate $_ by executing a command"); | ||
await jsterm.execute(`Object.create(null, Object.getOwnPropertyDescriptors({ | ||
x: 1, | ||
y: "hello" | ||
}))`); | ||
|
||
await setInputValueForAutocompletion(jsterm, "$_."); | ||
checkJsTermCompletionValue(jsterm, " x", "'$_.' completion (completeNode)"); | ||
is(getAutocompletePopupLabels(autocompletePopup).join("|"), "x|y", | ||
"autocomplete popup has expected items"); | ||
is(autocompletePopup.isOpen, true, "autocomplete popup is open"); | ||
|
||
await setInputValueForAutocompletion(jsterm, "$_.x."); | ||
is(autocompletePopup.isOpen, true, "autocomplete popup is open"); | ||
is(getAutocompletePopupLabels(autocompletePopup).includes("toExponential"), true, | ||
"autocomplete popup has expected items"); | ||
|
||
await setInputValueForAutocompletion(jsterm, "$_.y."); | ||
is(autocompletePopup.isOpen, true, "autocomplete popup is open"); | ||
is(getAutocompletePopupLabels(autocompletePopup).includes("trim"), true, | ||
"autocomplete popup has expected items"); | ||
} | ||
|
||
function getAutocompletePopupLabels(autocompletePopup) { | ||
return autocompletePopup.items.map(i => i.label); | ||
} |
57 changes: 57 additions & 0 deletions
57
devtools/client/webconsole/test/mochitest/browser_jsterm_completion_dollar_zero.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* -*- 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/ */ | ||
|
||
// Tests that code completion works properly on $0. | ||
|
||
"use strict"; | ||
|
||
const TEST_URI = `data:text/html;charset=utf-8, | ||
<head> | ||
<title>$0 completion test</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>$0 completion test</h1> | ||
<p>This is some example text</p> | ||
</div> | ||
</body>`; | ||
|
||
add_task(async function() { | ||
// Run test with legacy JsTerm | ||
await pushPref("devtools.webconsole.jsterm.codeMirror", false); | ||
await performTests(); | ||
// And then run it with the CodeMirror-powered one. | ||
await pushPref("devtools.webconsole.jsterm.codeMirror", true); | ||
await performTests(); | ||
}); | ||
|
||
async function performTests() { | ||
const toolbox = await openNewTabAndToolbox(TEST_URI, "inspector"); | ||
await registerTestActor(toolbox.target.client); | ||
const testActor = await getTestActor(toolbox); | ||
await selectNodeWithPicker(toolbox, testActor, "h1"); | ||
|
||
info("Picker mode stopped, <h1> selected, now switching to the console"); | ||
const hud = await openConsole(); | ||
const {jsterm} = hud; | ||
|
||
hud.ui.clearOutput(); | ||
|
||
const {autocompletePopup} = jsterm; | ||
|
||
await setInputValueForAutocompletion(jsterm, "$0."); | ||
is(getAutocompletePopupLabels(autocompletePopup).includes("attributes"), true, | ||
"autocomplete popup has expected items"); | ||
is(autocompletePopup.isOpen, true, "autocomplete popup is open"); | ||
|
||
await setInputValueForAutocompletion(jsterm, "$0.attributes."); | ||
is(autocompletePopup.isOpen, true, "autocomplete popup is open"); | ||
is(getAutocompletePopupLabels(autocompletePopup).includes("getNamedItem"), true, | ||
"autocomplete popup has expected items"); | ||
} | ||
|
||
function getAutocompletePopupLabels(autocompletePopup) { | ||
return autocompletePopup.items.map(i => i.label); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.