Bug 1580808 - Change UrlbarTestUtils.get[set]SelectedIndex to get[set]SelectedRowIndex. r=adw

Depends on D45455

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Harry Twyford 2019-09-12 21:05:22 +00:00
Родитель 1cb9dbb638
Коммит 2b19541fd2
22 изменённых файлов: 67 добавлений и 64 удалений

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

@ -191,7 +191,7 @@ var UrlbarTestUtils = {
* @param {object} win The window containing the urlbar.
* @returns {number} The selected index.
*/
getSelectedIndex(win) {
getSelectedRowIndex(win) {
return win.gURLBar.view.selectedRowIndex;
},
@ -200,7 +200,7 @@ var UrlbarTestUtils = {
* @param {object} win The window containing the urlbar.
* @param {index} index The index to select.
*/
setSelectedIndex(win, index) {
setSelectedRowIndex(win, index) {
win.gURLBar.view.selectedRowIndex = index;
},

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

@ -215,7 +215,7 @@ add_task(async function backspaceNoAutofill() {
function checkKeys(testTuples) {
for (let [key, value, selectedIndex] of testTuples) {
EventUtils.synthesizeKey(key);
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), selectedIndex);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), selectedIndex);
Assert.equal(gURLBar.untrimmedValue, value);
}
}

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

@ -18,7 +18,7 @@ function repeat(limit, func) {
function assertSelected(index) {
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
index,
"Should have selected the correct item"
);
@ -49,7 +49,7 @@ function assertSelected_one_off(index) {
// This is true because although both the listbox and the one-offs can have
// selections, the test doesn't check that.
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
-1,
"A one-off is selected, so the listbox should not have a selection"
);

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

@ -24,7 +24,7 @@ add_task(async function() {
await promiseAutocompleteResultPopup("http://example.com");
const initialIndex = UrlbarTestUtils.getSelectedIndex(window);
const initialIndex = UrlbarTestUtils.getSelectedRowIndex(window);
info("Key Down to select the next item.");
EventUtils.synthesizeKey("KEY_ArrowDown");
@ -35,7 +35,7 @@ add_task(async function() {
nextIndex
);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
nextIndex,
"Should have selected the next item"
);
@ -51,7 +51,7 @@ add_task(async function() {
let editedValue = gURLBar.value;
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
initialIndex,
"Should have selected the initialIndex again"
);

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

@ -17,7 +17,7 @@ function repeat(limit, func) {
function assertSelected(index) {
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
index,
"Should have the correct item selected"
);

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

@ -76,7 +76,7 @@ async function checkPopupOpens(key) {
checkIfKeyStartsQuery(key, true);
});
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
`${key}: Heuristic result should be selected`
);

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

@ -21,7 +21,7 @@ add_task(async function url() {
gURLBar.selectionStart = gURLBar.untrimmedValue.length;
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.promiseSearchComplete(window);
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 0);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.ok(details.autofill);
Assert.equal(details.url, "http://example.com/");
@ -35,7 +35,7 @@ add_task(async function userTyping() {
await UrlbarTestUtils.promisePopupClose(window);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.promiseSearchComplete(window);
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 0);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(details.type, UrlbarUtils.RESULT_TYPE.SEARCH);
Assert.ok(details.searchParams);
@ -49,7 +49,7 @@ add_task(async function empty() {
await UrlbarTestUtils.promisePopupClose(window);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.promiseSearchComplete(window);
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), -1);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), -1);
let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(details.url, "http://example.com/");
Assert.equal(gURLBar.value, "");

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

@ -47,7 +47,7 @@ add_task(async function() {
// First item should already be selected
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"Should have the first item selected"
);
@ -55,7 +55,7 @@ add_task(async function() {
// Select next one (important!)
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
1,
"Should have the second item selected"
);
@ -63,7 +63,7 @@ add_task(async function() {
// Re-select keyword item
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"Should have the first item selected"
);

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

@ -15,7 +15,7 @@ add_task(async function test() {
await promiseAutocompleteResultPopup("", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
-1,
"Nothing selected"
);
@ -27,7 +27,7 @@ add_task(async function test() {
EventUtils.synthesizeKey("KEY_ArrowDown");
}
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
resultCount - 1,
"Last result selected"
);
@ -35,7 +35,7 @@ add_task(async function test() {
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
-1,
"Nothing selected"
);

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

@ -104,20 +104,20 @@ add_task(async function viewContainsStaleRows() {
// result, the stale "x" results should be selected. We should *not* enter
// the one-off search buttons at that point.
for (let i = 1; i < maxResults; i++) {
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
Assert.equal(result.element.row.result.uiIndex, i);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
// Now the first one-off should be selected.
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), -1);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), -1);
Assert.equal(gURLBar.view.oneOffSearchButtons.selectedButtonIndex, 0);
// Arrow back up through all the results.
for (let i = maxResults - 1; i >= 0; i--) {
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
}
await UrlbarTestUtils.promisePopupClose(window, () =>
@ -271,18 +271,18 @@ add_task(async function staleReplacedWithFresh() {
// should continue on to "test2". We should *not* enter the one-off search
// buttons at that point.
for (let i = 1; i < maxResults; i++) {
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
// Now the first one-off should be selected.
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), -1);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), -1);
Assert.equal(gURLBar.view.oneOffSearchButtons.selectedButtonIndex, 0);
// Arrow back up through all the results.
for (let i = maxResults - 1; i >= 0; i--) {
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
}
await UrlbarTestUtils.promisePopupClose(window, () =>

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

@ -20,13 +20,13 @@ add_task(async function init() {
add_task(async function downKey() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
for (let i = 1; i < MAX_RESULTS; i++) {
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
}
EventUtils.synthesizeKey("KEY_ArrowDown");
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
@ -35,7 +35,7 @@ add_task(async function downKey() {
EventUtils.synthesizeKey("KEY_ArrowDown");
}
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected again"
);
@ -44,7 +44,7 @@ add_task(async function downKey() {
add_task(async function upKey() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
@ -55,20 +55,23 @@ add_task(async function upKey() {
EventUtils.synthesizeKey("KEY_ArrowUp");
}
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
MAX_RESULTS - 1,
"The last result should be selected"
);
for (let i = 1; i < MAX_RESULTS; i++) {
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), MAX_RESULTS - i - 1);
Assert.equal(
UrlbarTestUtils.getSelectedRowIndex(window),
MAX_RESULTS - i - 1
);
}
});
add_task(async function pageDownKey() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
@ -76,13 +79,13 @@ add_task(async function pageDownKey() {
for (let i = 0; i < pageCount; i++) {
EventUtils.synthesizeKey("KEY_PageDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
Math.min((i + 1) * UrlbarUtils.PAGE_UP_DOWN_DELTA, MAX_RESULTS - 1)
);
}
EventUtils.synthesizeKey("KEY_PageDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"Page down at end should wrap around to first result"
);
@ -91,13 +94,13 @@ add_task(async function pageDownKey() {
add_task(async function pageUpKey() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
EventUtils.synthesizeKey("KEY_PageUp");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
MAX_RESULTS - 1,
"Page up at start should wrap around to last result"
);
@ -105,7 +108,7 @@ add_task(async function pageUpKey() {
for (let i = 0; i < pageCount; i++) {
EventUtils.synthesizeKey("KEY_PageUp");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
Math.max(MAX_RESULTS - 1 - (i + 1) * UrlbarUtils.PAGE_UP_DOWN_DELTA, 0)
);
}
@ -117,7 +120,7 @@ add_task(async function pageDownKeyShowsView() {
EventUtils.synthesizeKey("KEY_PageDown");
await UrlbarTestUtils.promiseSearchComplete(window);
Assert.ok(UrlbarTestUtils.isPopupOpen(window));
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 0);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
});
add_task(async function pageUpKeyShowsView() {
@ -126,23 +129,23 @@ add_task(async function pageUpKeyShowsView() {
EventUtils.synthesizeKey("KEY_PageUp");
await UrlbarTestUtils.promiseSearchComplete(window);
Assert.ok(UrlbarTestUtils.isPopupOpen(window));
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 0);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 0);
});
add_task(async function tabKey() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
for (let i = 1; i < MAX_RESULTS; i++) {
EventUtils.synthesizeKey("KEY_Tab");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), i);
}
EventUtils.synthesizeKey("KEY_Tab");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected again"
);
@ -151,13 +154,13 @@ add_task(async function tabKey() {
add_task(async function tabKeyReverse() {
await promiseAutocompleteResultPopup("exam", window, true);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The heuristic autofill result should be selected initially"
);
for (let i = 1; i < MAX_RESULTS; i++) {
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), MAX_RESULTS - i);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), MAX_RESULTS - i);
}
});

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

@ -24,7 +24,7 @@ add_task(async function test_switchtab_decodeuri() {
EventUtils.synthesizeKey("KEY_ArrowDown");
let result = await UrlbarTestUtils.getDetailsOfResultAt(
window,
UrlbarTestUtils.getSelectedIndex(window)
UrlbarTestUtils.getSelectedRowIndex(window)
);
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH);

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

@ -33,7 +33,7 @@ add_task(async function test_switchtab_override() {
EventUtils.synthesizeKey("KEY_ArrowDown");
let result = await UrlbarTestUtils.getDetailsOfResultAt(
window,
UrlbarTestUtils.getSelectedIndex(window)
UrlbarTestUtils.getSelectedRowIndex(window)
);
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH);

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

@ -89,7 +89,7 @@ async function runTest(aSourceWindow, aDestWindow, aExpectSwitch, aCallback) {
info(`awesomebar popup appeared. aExpectSwitch: ${aExpectSwitch}`);
// Make sure the last match is selected.
while (
UrlbarTestUtils.getSelectedIndex(aDestWindow) <
UrlbarTestUtils.getSelectedRowIndex(aDestWindow) <
UrlbarTestUtils.getResultCount(aDestWindow) - 1
) {
info("handling key navigation for DOM_VK_DOWN key");

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

@ -100,7 +100,7 @@ add_task(async function tipIsSecondResult() {
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"The first result should be selected."
);
@ -113,7 +113,7 @@ add_task(async function tipIsSecondResult() {
"The selected element should be the tip button."
);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
1,
"getSelectedIndex should return 1 even though the tip button is selected."
);
@ -126,14 +126,14 @@ add_task(async function tipIsSecondResult() {
"The selected element should be the tip help button."
);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
1,
"getSelectedIndex should return 1 even though the help button is selected."
);
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
2,
"The third result should be selected."
);
@ -194,7 +194,7 @@ add_task(async function tipIsOnlyResult() {
"The selected element should be the tip button."
);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"getSelectedIndex should return 0."
);
@ -207,14 +207,14 @@ add_task(async function tipIsOnlyResult() {
"The selected element should be the tip help button."
);
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
0,
"getSelectedIndex should return 0."
);
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
-1,
"There should be no selection."
);

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

@ -63,7 +63,7 @@ add_task(async function actionURILosslessDecode() {
// moz-action.
do {
EventUtils.synthesizeKey("KEY_ArrowDown");
} while (UrlbarTestUtils.getSelectedIndex(window) != 0);
} while (UrlbarTestUtils.getSelectedRowIndex(window) != 0);
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);

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

@ -22,7 +22,7 @@ async function promiseAutoComplete(inputText) {
function assertSelected(index) {
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
index,
"Should have the correct index selected"
);
@ -56,7 +56,7 @@ add_task(async function() {
"Should have got the correct amount of results"
);
let initiallySelected = UrlbarTestUtils.getSelectedIndex(window);
let initiallySelected = UrlbarTestUtils.getSelectedRowIndex(window);
info("Key Down to select the next item");
EventUtils.synthesizeKey("KEY_ArrowDown");

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

@ -257,7 +257,7 @@ add_task(async function hiddenWhenUsingSearchAlias() {
function assertState(result, oneOff, textValue = undefined) {
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
result,
"Expected result should be selected"
);

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

@ -194,7 +194,7 @@ add_task(async function overridden_engine_not_reused() {
function assertState(result, oneOff, textValue = undefined) {
Assert.equal(
UrlbarTestUtils.getSelectedIndex(window),
UrlbarTestUtils.getSelectedRowIndex(window),
result,
"Expected result should be selected"
);

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

@ -23,7 +23,7 @@ add_task(async function test_remove_history() {
let expectedResultCount = UrlbarTestUtils.getResultCount(window) - 1;
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 1);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 1);
EventUtils.synthesizeKey("KEY_Delete", { shiftKey: true });
await promiseVisitRemoved;
await TestUtils.waitForCondition(
@ -61,7 +61,7 @@ add_task(async function test_remove_bookmark_doesnt() {
Assert.equal(result.url, TEST_URL, "Found the expected result");
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(UrlbarTestUtils.getSelectedIndex(window), 1);
Assert.equal(UrlbarTestUtils.getSelectedRowIndex(window), 1);
EventUtils.synthesizeKey("KEY_Delete", { shiftKey: true });
// We don't have an easy way of determining if the event was process or not,

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

@ -740,7 +740,7 @@ add_task(async function test_suggestion_enterSelection() {
let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await searchInAwesomebar("query");
info("Select the second result and press Return.");
UrlbarTestUtils.setSelectedIndex(window, 1);
UrlbarTestUtils.setSelectedRowIndex(window, 1);
EventUtils.synthesizeKey("KEY_Enter");
await p;

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

@ -123,7 +123,7 @@ add_task(async function test_popup_url() {
);
// Set the selected attribute to true to test the highlight popup properties
UrlbarTestUtils.setSelectedIndex(window, 1);
UrlbarTestUtils.setSelectedRowIndex(window, 1);
let actionResult = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
let urlResult = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
let resultCS = window.getComputedStyle(urlResult.element.row);
@ -142,7 +142,7 @@ add_task(async function test_popup_url() {
// Now set the index to somewhere not on the first two, so that we can test both
// url and action text colors.
UrlbarTestUtils.setSelectedIndex(window, 2);
UrlbarTestUtils.setSelectedRowIndex(window, 2);
Assert.equal(
window.getComputedStyle(urlResult.element.url).color,