Bug 1617540 - Add `hasPopupLabels` helpers for webconsole tests r=nchevobbe

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
agamvrinos 2020-02-28 16:41:45 +00:00
Родитель 280d5a112d
Коммит 7de12065d0
18 изменённых файлов: 140 добавлений и 143 удалений

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

@ -25,10 +25,8 @@ add_task(async function() {
await onPopUpOpen;
const popupItems = getAutocompletePopupLabels(popup);
is(
popupItems.includes("0"),
false,
ok(
!hasPopupLabel(popup, "0"),
"Completing on an array doesn't show numbers."
);

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

@ -36,7 +36,7 @@ add_task(async function() {
EventUtils.synthesizeKey("d");
await onUpdated;
ok(
!getAutocompletePopupLabels(popup).includes("docfoobar"),
!hasPopupLabel(popup, "docfoobar"),
"autocomplete popup does not contain docfoobar. List has not been updated"
);
@ -45,7 +45,7 @@ add_task(async function() {
EventUtils.synthesizeKey("o");
await onUpdated;
ok(
!getAutocompletePopupLabels(popup).includes("docfoobar"),
!hasPopupLabel(popup, "docfoobar"),
"autocomplete popup does not contain docfoobar. List has not been updated"
);
@ -54,7 +54,7 @@ add_task(async function() {
EventUtils.synthesizeKey("KEY_Backspace");
await onUpdated;
ok(
!getAutocompletePopupLabels(popup).includes("docfoobar"),
!hasPopupLabel(popup, "docfoobar"),
"autocomplete cached results do not contain docfoobar. list has not been updated"
);
@ -66,7 +66,7 @@ add_task(async function() {
await jstermComplete("window.");
await jstermComplete("window.getC");
ok(
getAutocompletePopupLabels(popup).includes("getComputedStyle"),
hasPopupLabel(popup, "getComputedStyle"),
"autocomplete results do contain getComputedStyle"
);
@ -92,7 +92,7 @@ add_task(async function() {
await onUpdated;
ok(
!getAutocompletePopupLabels(popup).includes("docfoobar"),
!hasPopupLabel(popup, "docfoobar"),
"autocomplete cached results do not contain docfoobar. list has not been updated"
);
@ -108,27 +108,24 @@ add_task(async function() {
);
await jstermComplete("window.testObject.");
await jstermComplete("window.testObject.z");
is(
getAutocompletePopupLabels(popup).join("-"),
"zz-zzz-zzzz",
ok(
hasExactPopupLabels(popup, ["zz", "zzz", "zzzz"]),
"results are the expected ones"
);
onUpdated = jsterm.once("autocomplete-updated");
EventUtils.sendString("z");
await onUpdated;
is(
getAutocompletePopupLabels(popup).join("-"),
"zz-zzz-zzzz",
ok(
hasExactPopupLabels(popup, ["zz", "zzz", "zzzz"]),
"filtering from the cache works - step 1"
);
onUpdated = jsterm.once("autocomplete-updated");
EventUtils.sendString("z");
await onUpdated;
is(
getAutocompletePopupLabels(popup).join("-"),
"zzz-zzzz",
ok(
hasExactPopupLabels(popup, ["zzz", "zzzz"]),
"filtering from the cache works - step 2"
);
});

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

@ -21,9 +21,8 @@ add_task(async function() {
await onPopUpOpen;
const expectedCommands = [":help", ":screenshot"];
is(
getAutocompletePopupLabels(autocompletePopup).join("\n"),
expectedCommands.join("\n"),
ok(
hasExactPopupLabels(autocompletePopup, expectedCommands),
"popup contains expected commands"
);

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

@ -27,9 +27,8 @@ add_task(async function() {
test`
);
is(
getAutocompletePopupLabels(autocompletePopup).join("\n"),
[
ok(
hasExactPopupLabels(autocompletePopup, [
"testClass",
"testConst",
"testDeconstruct1",
@ -43,7 +42,7 @@ add_task(async function() {
"testParamRest",
"testParamRestFirst",
"testVar",
].join("\n"),
]),
"Autocomplete popup displays both global and local variables"
);
});

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

@ -55,9 +55,8 @@ add_task(async function() {
EventUtils.synthesizeKey("KEY_Tab");
await onPopUpOpen;
ok(autocompletePopup.isOpen, "popup is open after Tab");
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
"baz-bloop",
ok(
hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
"popup has expected items"
);
checkInputValueAndCursorPosition(hud, "foo.bar.|");
@ -74,9 +73,8 @@ add_task(async function() {
onPopUpOpen = autocompletePopup.once("popup-opened");
EventUtils.synthesizeKey(" ", { ctrlKey: true });
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
"baz-bloop",
ok(
hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
"popup has expected items"
);
checkInputValueAndCursorPosition(hud, "foo.bar.|");
@ -89,9 +87,8 @@ add_task(async function() {
EventUtils.synthesizeKey(" ");
await onAutocompleteUpdate;
is(autocompletePopup.isOpen, true, "Autocomplete popup is still opened");
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
"baz-bloop",
ok(
hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
"popup has expected items"
);
@ -99,9 +96,8 @@ add_task(async function() {
EventUtils.synthesizeKey("KEY_Backspace");
await onAutocompleteUpdate;
is(autocompletePopup.isOpen, true, "Autocomplete popup is still opened");
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
"baz-bloop",
ok(
hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
"popup has expected items"
);

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

@ -60,9 +60,8 @@ add_task(async function() {
EventUtils.synthesizeKey("KEY_Tab");
await onPopUpOpen;
ok(autocompletePopup.isOpen, "popup is open after Tab");
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
"baz-bloop",
ok(
hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
"popup has expected items"
);
checkInputValueAndCursorPosition(hud, "window.foo.bar.|");
@ -94,9 +93,8 @@ add_task(async function() {
EventUtils.synthesizeKey("KEY_Tab");
await onPopUpOpen;
ok(autocompletePopup.isOpen, "popup is open after Tab");
is(
getAutocompletePopupLabels(autocompletePopup).join("-"),
`"hello"-"world"`,
ok(
hasExactPopupLabels(autocompletePopup, [`"hello"`, `"world"`]),
"popup has expected items"
);
checkInputValueAndCursorPosition(hud, "window.foo.bar.baz[|");
@ -113,7 +111,7 @@ add_task(async function() {
await onPopUpOpen;
ok(autocompletePopup.isOpen, "got items of getter result");
ok(
getAutocompletePopupLabels(autocompletePopup).includes("toExponential"),
hasPopupLabel(autocompletePopup, "toExponential"),
"popup has expected items"
);
@ -140,7 +138,7 @@ add_task(async function() {
"popup is open after clicking on the confirm button"
);
ok(
getAutocompletePopupLabels(autocompletePopup).includes("startsWith"),
hasPopupLabel(autocompletePopup, "startsWith"),
"popup has expected items"
);
checkInputValueAndCursorPosition(hud, "window.foo.rab.|");

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

@ -37,25 +37,23 @@ add_task(async function() {
// Test if 'foo' gives 'foo1' but not 'foo2' or 'foo3'
await jstermComplete("foo");
is(
getAutocompletePopupLabels(popup).join("-"),
"foo1-foo1Obj",
ok(
hasExactPopupLabels(popup, ["foo1", "foo1Obj"]),
`"foo" gave the expected suggestions`
);
// Test if 'foo1Obj.' gives 'prop1' and 'prop2'
await jstermComplete("foo1Obj.");
checkInputCompletionValue(hud, "prop1", "foo1Obj completion");
is(
getAutocompletePopupLabels(popup).join("-"),
"prop1-prop2",
ok(
hasExactPopupLabels(popup, ["prop1", "prop2"]),
`"foo1Obj." gave the expected suggestions`
);
// Test if 'foo1Obj.prop2.' gives 'prop21'
await jstermComplete("foo1Obj.prop2.");
ok(
getAutocompletePopupLabels(popup).includes("prop21"),
hasPopupLabel(popup, "prop21"),
`"foo1Obj.prop2." gave the expected suggestions`
);
@ -73,10 +71,9 @@ add_task(async function() {
// Test if 'foo' gives 'foo3' and 'foo1' but not 'foo2', since we are paused in
// the `secondCall` function (called by `firstCall`, which we call in `pauseDebugger`).
await jstermComplete("foo");
is(
getAutocompletePopupLabels(popup).join("-"),
"foo1-foo1Obj-foo3-foo3Obj",
`"foo" gave the expected suggestions`
ok(
hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo3", "foo3Obj"]),
`"foo." gave the expected suggestions`
);
await openDebugger();
@ -90,32 +87,22 @@ add_task(async function() {
// Test if 'foo' gives 'foo2' and 'foo1' but not 'foo3', since we are now in the
// `firstCall` frame.
await jstermComplete("foo");
is(
getAutocompletePopupLabels(popup).join("-"),
"foo1-foo1Obj-foo2-foo2Obj",
ok(
hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo2", "foo2Obj"]),
`"foo" gave the expected suggestions`
);
// Test if 'foo2Obj.' gives 'prop1'
await jstermComplete("foo2Obj.");
ok(
getAutocompletePopupLabels(popup).includes("prop1"),
`"foo2Obj." returns "prop1"`
);
ok(hasPopupLabel(popup, "prop1"), `"foo2Obj." returns "prop1"`);
// Test if 'foo2Obj.prop1.' gives 'prop11'
await jstermComplete("foo2Obj.prop1.");
ok(
getAutocompletePopupLabels(popup).includes("prop11"),
`"foo2Obj.prop1" returns "prop11"`
);
ok(hasPopupLabel(popup, "prop11"), `"foo2Obj.prop1" returns "prop11"`);
// Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string,i.e. 'length'
await jstermComplete("foo2Obj.prop1.prop11.");
ok(
getAutocompletePopupLabels(popup).includes("length"),
`results do contain "length"`
);
ok(hasPopupLabel(popup, "length"), `results do contain "length"`);
// Test if 'foo2Obj[0].' throws no errors.
await jstermComplete("foo2Obj[0].");

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

@ -50,11 +50,8 @@ add_task(async function() {
is(popup.selectedIndex, 1, "popup.selectedIndex is correct");
ok(!getInputCompletionValue(hud), "completeNode.value is empty");
const items = getAutocompletePopupLabels(popup);
const expectedItems = ["testBugAA", "testBugBB"];
is(
items.join("-"),
expectedItems.join("-"),
ok(
hasExactPopupLabels(popup, ["testBugAA", "testBugBB"]),
"getItems returns the items we expect"
);

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

@ -39,13 +39,9 @@ add_task(async function() {
ok(popup.isOpen, "popup is open");
const popupItems = getAutocompletePopupLabels(popup);
const expectedPopupItems = ["item00", "item1", "item2", "item3"];
is(popup.itemCount, expectedPopupItems.length, "popup.itemCount is correct");
is(
popupItems.join("-"),
expectedPopupItems.join("-"),
ok(
hasExactPopupLabels(popup, expectedPopupItems),
"getItems returns the items we expect"
);
is(popup.selectedIndex, 0, "Index of the first item is selected.");

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

@ -28,9 +28,8 @@ add_task(async function() {
await onPopUpOpen;
ok(popup.isOpen, "popup is open");
const expectedPopupItems = ["null", "nullVar"];
is(
getAutocompletePopupLabels(popup).join("-"),
expectedPopupItems.join("-"),
ok(
hasExactPopupLabels(popup, expectedPopupItems),
"popup has expected items"
);

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

@ -30,9 +30,8 @@ add_task(async function() {
ok(popup.isOpen, "popup is open");
const expectedPopupItems = ["xx", "xxx"];
is(
getAutocompletePopupLabels(popup).join("-"),
expectedPopupItems.join("-"),
ok(
hasExactPopupLabels(popup, expectedPopupItems),
"popup has expected items"
);

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

@ -146,9 +146,8 @@ async function testInput(
EventUtils.sendString(input);
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
expectedItems.join("|"),
ok(
hasExactPopupLabels(autocompletePopup, expectedItems),
`${description} - popup has expected item, in expected order`
);
checkInputCompletionValue(
@ -183,9 +182,12 @@ async function testCompletionTextUpdateOnPopupNavigate(hud) {
EventUtils.sendString(input);
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
`"data-test"|"dataTest"|"DATA-TEST"`,
ok(
hasExactPopupLabels(autocompletePopup, [
`"data-test"`,
`"dataTest"`,
`"DATA-TEST"`,
]),
`popup has expected items, in expected order`
);
checkInputCompletionValue(hud, `-test"]`, `completeNode has expected value`);
@ -218,9 +220,8 @@ async function testAcceptCompletionExistingClosingBracket(hud) {
const onPopUpOpen = autocompletePopup.once("popup-opened");
EventUtils.sendString("b");
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
`"bar"`,
ok(
hasExactPopupLabels(autocompletePopup, [`"bar"`]),
`popup has expected item`
);

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

@ -92,11 +92,11 @@ add_task(async function() {
EventUtils.sendString(test.initialInput);
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
test.expectedItems.join("|"),
ok(
hasExactPopupLabels(autocompletePopup, test.expectedItems),
`popup has expected items, in expected order`
);
checkInputCompletionValue(
hud,
test.expectedCompletionText,
@ -111,9 +111,8 @@ add_task(async function() {
EventUtils.sendString(char);
await onPopupUpdate;
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
expectedItems.join("|"),
ok(
hasExactPopupLabels(autocompletePopup, expectedItems),
`popup has expected items, in expected order`
);
checkInputCompletionValue(

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

@ -29,11 +29,11 @@ add_task(async function() {
EventUtils.sendString("foob");
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"fooBar - FooBar",
ok(
hasExactPopupLabels(autocompletePopup, ["fooBar", "FooBar"]),
"popup has expected item, in expected order"
);
checkInputCompletionValue(hud, "ar", "completeNode has expected value");
info("Check that filtering the autocomplete cache is also case insensitive");
@ -43,9 +43,8 @@ add_task(async function() {
await onAutoCompleteUpdated;
checkInput("fooba|");
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"fooBar - FooBar",
ok(
hasExactPopupLabels(autocompletePopup, ["fooBar", "FooBar"]),
"popup cache filtering is also case-insensitive"
);
checkInputCompletionValue(hud, "r", "completeNode has expected value");
@ -68,9 +67,8 @@ add_task(async function() {
// to display the popup so the user knows that we are matching "Foo" and not "foo".
checkInput("fooBar.f|");
ok(true, "The popup was opened even if there's 1 item matching");
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"Foo",
ok(
hasExactPopupLabels(autocompletePopup, ["Foo"]),
"popup has expected item"
);
checkInputCompletionValue(hud, "oo", "completeNode has expected value");
@ -88,9 +86,8 @@ add_task(async function() {
EventUtils.sendString("func");
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"function - Function",
ok(
hasExactPopupLabels(autocompletePopup, ["function", "Function"]),
"popup has expected item"
);
checkInputCompletionValue(hud, "tion", "completeNode has expected value");
@ -107,18 +104,16 @@ add_task(async function() {
onPopUpOpen = autocompletePopup.once("popup-opened");
EventUtils.sendString("fooBar.");
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"test - Foo - Test - TEST",
"popup has expected items"
ok(
hasExactPopupLabels(autocompletePopup, ["test", "Foo", "Test", "TEST"]),
"popup has expected item"
);
onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
EventUtils.sendString("T");
await onAutoCompleteUpdated;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"Test - TEST",
ok(
hasExactPopupLabels(autocompletePopup, ["Test", "TEST"]),
"popup was filtered case-sensitively, as expected"
);
});

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

@ -32,26 +32,23 @@ add_task(async function() {
await setInputValueForAutocompletion(hud, "$_.");
checkInputCompletionValue(hud, "x", "'$_.' completion (completeNode)");
is(
getAutocompletePopupLabels(autocompletePopup).join("|"),
"x|y",
ok(
hasExactPopupLabels(autocompletePopup, ["x", "y"]),
"autocomplete popup has expected items"
);
is(autocompletePopup.isOpen, true, "autocomplete popup is open");
await setInputValueForAutocompletion(hud, "$_.x.");
is(autocompletePopup.isOpen, true, "autocomplete popup is open");
is(
getAutocompletePopupLabels(autocompletePopup).includes("toExponential"),
true,
ok(
hasPopupLabel(autocompletePopup, "toExponential"),
"autocomplete popup has expected items"
);
await setInputValueForAutocompletion(hud, "$_.y.");
is(autocompletePopup.isOpen, true, "autocomplete popup is open");
is(
getAutocompletePopupLabels(autocompletePopup).includes("trim"),
true,
ok(
hasPopupLabel(autocompletePopup, "trim"),
"autocomplete popup has expected items"
);
});

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

@ -31,18 +31,16 @@ add_task(async function() {
const { autocompletePopup } = jsterm;
await setInputValueForAutocompletion(hud, "$0.");
is(
getAutocompletePopupLabels(autocompletePopup).includes("attributes"),
true,
ok(
hasPopupLabel(autocompletePopup, "attributes"),
"autocomplete popup has expected items"
);
is(autocompletePopup.isOpen, true, "autocomplete popup is open");
await setInputValueForAutocompletion(hud, "$0.attributes.");
is(autocompletePopup.isOpen, true, "autocomplete popup is open");
is(
getAutocompletePopupLabels(autocompletePopup).includes("getNamedItem"),
true,
ok(
hasPopupLabel(autocompletePopup, "getNamedItem"),
"autocomplete popup has expected items"
);
});

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

@ -24,18 +24,16 @@ add_task(async function() {
const onPopUpOpen = autocompletePopup.once("popup-opened");
EventUtils.sendString("x.");
await onPopUpOpen;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"foo - foO - fOo - fOO",
ok(
hasExactPopupLabels(autocompletePopup, ["foo", "foO", "fOo", "fOO"]),
"popup has expected item, in expected order"
);
const onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
EventUtils.sendString("foO");
await onAutoCompleteUpdated;
is(
getAutocompletePopupLabels(autocompletePopup).join(" - "),
"foO - foo - fOo - fOO",
ok(
hasExactPopupLabels(autocompletePopup, ["foO", "foo", "fOo", "fOO"]),
"popup has expected item, in expected order"
);
});

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

@ -1334,6 +1334,50 @@ function getAutocompletePopupLabels(popup) {
return popup.getItems().map(item => item.label);
}
/**
* Check if the retrieved list of autocomplete labels of the specific popup
* includes all of the expected labels.
*
* @param {AutocompletPopup} popup
* @param {Array<String>} expected the array of expected labels
*/
function hasExactPopupLabels(popup, expected) {
return hasPopupLabels(popup, expected, true);
}
/**
* Check if the expected label is included in the list of autocomplete labels
* of the specific popup.
*
* @param {AutocompletPopup} popup
* @param {String} label the label to check
*/
function hasPopupLabel(popup, label) {
return hasPopupLabels(popup, [label]);
}
/**
* Validate the expected labels against the autocomplete labels.
*
* @param {AutocompletPopup} popup
* @param {Array<String>} expectedLabels
* @param {Boolean} checkAll
*/
function hasPopupLabels(popup, expectedLabels, checkAll = false) {
const autocompleteLabels = getAutocompletePopupLabels(popup);
if (checkAll) {
return (
autocompleteLabels.length === expectedLabels.length &&
autocompleteLabels.every((autoLabel, idx) => {
return expectedLabels.indexOf(autoLabel) === idx;
})
);
}
return expectedLabels.every(expectedLabel => {
return autocompleteLabels.includes(expectedLabel);
});
}
/**
* Return the "Confirm Dialog" element.
*