Commit fad80abf authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Add keyboard operations tests for file list

Follow up of CL:1475315.

Change-Id: Ia6d4e8ab329fb93826182025f6f6c221d4471266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506922
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638466}
parent 7ea5df4c
......@@ -79,6 +79,10 @@ function ctrlAndKey(keyName) {
bubbles: true,
composed: true,
key: keyName,
// Get keyCode for key like A, B but not for Escape, Arrow, etc.
// A==65, B==66, etc.
keyCode: (keyName && keyName.length === 1) ? keyName.charCodeAt(0) :
undefined,
};
}
......@@ -136,7 +140,7 @@ function testMultipleSelectionWithKeyboard() {
assertFalse(item.id === tableList.getAttribute('aria-activedescendant'));
}
}
// FileTableList always allows multiple selection.
assertEquals('true', tableList.getAttribute('aria-multiselectable'));
......@@ -173,10 +177,10 @@ function testMultipleSelectionWithKeyboard() {
// listItem2 should be focused but not selected.
assertItemIsTheLead(listItem2);
assertItemIsSelected(listItem2, false);
// Only one item is selected: multiple selection should be inactive.
assertFalse(sm.getCheckSelectMode());
// Ctrl+Space selects the focused item.
tableList.dispatchEvent(new KeyboardEvent('keydown', ctrlAndKey(' ')));
// Multiple selection mode should now be activated.
......@@ -214,3 +218,82 @@ function testMultipleSelectionWithKeyboard() {
'item ' + i + ' should not have selected attr');
}
}
function testKeyboardOperations() {
// Render the FileTable on |element|.
const fullPage = true;
FileTable.decorate(
element, metadataModel, volumeManager, historyLoader, fullPage);
// Overwrite the selectionModel of the FileTable class (since events
// would be handled by cr.ui.ListSelectionModel otherwise).
const sm = new FileListSelectionModel();
const table = /** @type {FileTable} */ (element);
table.selectionModel = sm;
// Add FileTableList file entries, then draw and focus the table list.
const entries = [
new FakeEntry('entry1-label', VolumeManagerCommon.RootType.CROSTINI),
new FakeEntry('entry2-label', VolumeManagerCommon.RootType.CROSTINI),
new FakeEntry('entry3-label', VolumeManagerCommon.RootType.CROSTINI),
];
const dataModel = new FileListModel(metadataModel);
dataModel.splice(0, 0, ...entries);
const tableList = /** @type {FileTableList} */ (element.list);
tableList.dataModel = dataModel;
tableList.redraw();
tableList.focus();
// Home key selects the first item (index 0).
tableList.dispatchEvent(new KeyboardEvent('keydown', key('Home')));
// Only 1 item selected.
assertEquals(1, sm.selectedIndexes.length);
// Index 0 should be selected and focused.
assertEquals(0, sm.selectedIndexes[0]);
// End key selects the last item (index 2).
tableList.dispatchEvent(new KeyboardEvent('keydown', key('End')));
// Only 1 item selected.
assertEquals(1, sm.selectedIndexes.length);
// Index 2 should be selected and focused.
assertEquals(2, sm.selectedIndexes[0]);
// Ctrl+A key selects all items.
tableList.dispatchEvent(new KeyboardEvent('keydown', ctrlAndKey('A')));
// All 3 items are selected.
assertEquals(3, sm.selectedIndexes.length);
assertEquals(0, sm.selectedIndexes[0]);
assertEquals(1, sm.selectedIndexes[1]);
assertEquals(2, sm.selectedIndexes[2]);
// Escape key selects all items.
tableList.dispatchEvent(new KeyboardEvent('keydown', key('Escape')));
// All 3 items are selected.
assertEquals(0, sm.selectedIndexes.length);
// Home key selects the first item (index 0).
tableList.dispatchEvent(new KeyboardEvent('keydown', key('Home')));
assertEquals(1, sm.selectedIndexes.length);
assertEquals(0, sm.selectedIndexes[0]);
// ArrowDown moves and selects next item.
tableList.dispatchEvent(new KeyboardEvent('keydown', key('ArrowDown')));
// Only index 1 should be selected.
assertEquals(1, sm.selectedIndexes.length);
assertEquals(1, sm.selectedIndexes[0]);
// ArrowUp moves and selects previous item.
tableList.dispatchEvent(new KeyboardEvent('keydown', key('ArrowUp')));
// Only index 0 should be selected.
assertEquals(1, sm.selectedIndexes.length);
assertEquals(0, sm.selectedIndexes[0]);
// ArrowLeft and ArrowRight aren't really implemented.
tableList.dispatchEvent(new KeyboardEvent('keydown', key('ArrowLeft')));
// Selected item remains the same.
assertEquals(1, sm.selectedIndexes.length);
assertEquals(0, sm.selectedIndexes[0]);
tableList.dispatchEvent(new KeyboardEvent('keydown', key('ArrowRight')));
assertEquals(1, sm.selectedIndexes.length);
assertEquals(0, sm.selectedIndexes[0]);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment