Commit 96b6c563 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert tab_index.js to use async-await.

Bug: 909056
Change-Id: I8fbfc11a3076c014cf20d711d82fea36183c0792
Reviewed-on: https://chromium-review.googlesource.com/c/1356171
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612557}
parent 42cc8e6f
...@@ -7,221 +7,137 @@ ...@@ -7,221 +7,137 @@
/** /**
* Tests the focus behavior of the search box. * Tests the focus behavior of the search box.
*/ */
testcase.tabindexSearchBoxFocus = function() { testcase.tabindexSearchBoxFocus = async function() {
var appId; // Open Files app on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DRIVE, null);
// Set up File Manager.
function() { // Check that the file list has the focus on launch.
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next); await remoteCall.waitForElement(appId, ['#file-list:focus']);
},
// Check that the file list has the focus on launch. // Press the Ctrl-F key.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'fakeKeyDown', appId, ['body', 'f', true, false, false]));
remoteCall.waitForElement(appId, ['#file-list:focus']).then(this.next);
}, // Check that the search box has the focus.
// Press the Ctrl-F key. await remoteCall.waitForElement(appId, ['#search-box cr-input:focus-within']);
function(element) {
remoteCall.callRemoteTestUtil( // Press the Esc key.
'fakeKeyDown', appId, ['body', 'f', true, false, false], this.next); chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
}, 'fakeKeyDown', appId,
// Check that the search box has the focus. ['#search-box cr-input', 'Escape', false, false, false]));
function(result) {
chrome.test.assertTrue(result); // Check that the file list has the focus.
remoteCall.waitForElement(appId, ['#search-box cr-input:focus-within']) chrome.test.assertTrue(
.then(this.next); await remoteCall.checkNextTabFocus(appId, 'file-list'));
},
// Press the Esc key.
function(element) {
remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId,
['#search-box cr-input', 'Escape', false, false, false], this.next);
},
// Check that the file list has the focus.
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
},
// Check for errors.
function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Tests the tab focus behavior of the Files app when no file is selected. * Tests the tab focus behavior of the Files app when no file is selected.
*/ */
testcase.tabindexFocus = function() { testcase.tabindexFocus = async function() {
var appId; // Open Files app on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DRIVE, null);
// Set up File Manager.
function() { // Check that the file list has the focus on launch.
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next); await remoteCall.waitForElement(appId, ['#file-list:focus']);
}, await remoteCall.waitForElement(appId, ['#drive-welcome-link']);
// Check that the file list has the focus on launch. const element =
function(results) { await remoteCall.callRemoteTestUtil('getActiveElement', appId, []);
appId = results.windowId; chrome.test.assertEq('list', element.attributes['class']);
remoteCall.waitForElement(appId, ['#file-list:focus']).then(this.next);
}, // Send Tab key events to cycle through the tabable elements.
function(element) { chrome.test.assertTrue(
remoteCall.waitForElement(appId, ['#drive-welcome-link']).then(this.next); await remoteCall.checkNextTabFocus(appId, 'search-button'));
}, chrome.test.assertTrue(
function(element) { await remoteCall.checkNextTabFocus(appId, 'view-button'));
remoteCall.callRemoteTestUtil('getActiveElement', appId, [], this.next); chrome.test.assertTrue(
// Press the Tab key. await remoteCall.checkNextTabFocus(appId, 'sort-button'));
}, function(element) { chrome.test.assertTrue(
chrome.test.assertEq('list', element.attributes['class']); await remoteCall.checkNextTabFocus(appId, 'gear-button'));
remoteCall.checkNextTabFocus(appId, 'search-button').then(this.next); chrome.test.assertTrue(
}, function(result) { await remoteCall.checkNextTabFocus(appId, 'directory-tree'));
chrome.test.assertTrue(result); chrome.test.assertTrue(
remoteCall.checkNextTabFocus(appId, 'view-button').then(this.next); await remoteCall.checkNextTabFocus(appId, 'drive-welcome-link'));
}, function(result) { chrome.test.assertTrue(
chrome.test.assertTrue(result); await remoteCall.checkNextTabFocus(appId, 'file-list'));
remoteCall.checkNextTabFocus(appId, 'sort-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'gear-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'directory-tree').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'drive-welcome-link').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Tests the tab focus behavior of the Files app when no file is selected in * Tests the tab focus behavior of the Files app when no file is selected in
* Downloads directory. * Downloads directory.
*/ */
testcase.tabindexFocusDownloads = function() { testcase.tabindexFocusDownloads = async function() {
var appId; // Open Files app on Downloads.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Check that the file list has the focus on launch.
function(results) {
appId = results.windowId;
remoteCall.waitForElement(appId, ['#file-list:focus']).then(this.next);
}, function(element) {
remoteCall.callRemoteTestUtil('getActiveElement', appId, [], this.next);
}, function(element) {
chrome.test.assertEq('list', element.attributes['class']);
remoteCall.checkNextTabFocus(appId, 'breadcrumb-path-0').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'search-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'view-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'sort-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'gear-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'directory-tree').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]);
};
// Check that the file list has the focus on launch.
await remoteCall.waitForElement(appId, ['#file-list:focus']);
const element =
await remoteCall.callRemoteTestUtil('getActiveElement', appId, []);
chrome.test.assertEq('list', element.attributes['class']);
// Send Tab key events to cycle through the tabable elements.
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'breadcrumb-path-0'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'search-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'view-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'sort-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'gear-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'directory-tree'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'file-list'));
};
/** /**
* Tests the tab focus behavior of the Files app when a directory is selected. * Tests the tab focus behavior of the Files app when a directory is selected.
*/ */
testcase.tabindexFocusDirectorySelected = function() { testcase.tabindexFocusDirectorySelected = async function() {
var appId; // Open Files app on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DRIVE, null);
// Set up File Manager.
function() { // Check that the file list has the focus on launch.
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next); await Promise.all([
}, remoteCall.waitForElement(appId, ['#file-list:focus']),
// Check that the file list has the focus on launch. remoteCall.waitForElement(appId, ['#drive-welcome-link']),
function(results) { ]);
appId = results.windowId; const element =
Promise.all([ await remoteCall.callRemoteTestUtil('getActiveElement', appId, []);
remoteCall.waitForElement(appId, ['#file-list:focus']), chrome.test.assertEq('list', element.attributes['class']);
remoteCall.waitForElement(appId, ['#drive-welcome-link']),
]).then(this.next); // Select the directory named 'photos'.
}, chrome.test.assertTrue(
function(elements) { await remoteCall.callRemoteTestUtil('selectFile', appId, ['photos']));
remoteCall.callRemoteTestUtil('getActiveElement', appId, [], this.next);
}, await Promise.all([
function(element) { remoteCall.waitForElement(
chrome.test.assertEq('list', element.attributes['class']); appId, ['#share-menu-button:not([hidden]):not([disabled])']),
// Select the directory named 'photos'. remoteCall.waitForElement(
remoteCall.callRemoteTestUtil( appId, ['#delete-button:not([hidden]):not([disabled])']),
'selectFile', appId, ['photos']).then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
Promise
.all([
remoteCall.waitForElement(
appId, ['#share-menu-button:not([hidden]):not([disabled])']),
remoteCall.waitForElement(
appId, ['#delete-button:not([hidden]):not([disabled])']),
])
.then(this.next);
// Press the Tab key.
},
function(elements) {
remoteCall.checkNextTabFocus(appId, 'share-menu-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'delete-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'search-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'view-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'sort-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'gear-button').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'directory-tree').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'drive-welcome-link').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]); ]);
// Send Tab key events to cycle through the tabable elements.
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'share-menu-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'delete-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'search-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'view-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'sort-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'gear-button'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'directory-tree'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'drive-welcome-link'));
chrome.test.assertTrue(
await remoteCall.checkNextTabFocus(appId, 'file-list'));
}; };
/** /**
...@@ -241,98 +157,82 @@ testcase.tabindexFocusDirectorySelected = function() { ...@@ -241,98 +157,82 @@ testcase.tabindexFocusDirectorySelected = function() {
* @param {Array<string>} expectedTabOrder Array with the IDs of the element * @param {Array<string>} expectedTabOrder Array with the IDs of the element
* with the corresponding order of expected tab-indexes. * with the corresponding order of expected tab-indexes.
*/ */
function tabindexFocus(dialogParams, volumeName, expectedSet, initialize, async function tabindexFocus(
initialElements, expectedTabOrder) { dialogParams, volumeName, expectedSet, initialize, initialElements,
var localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET); expectedTabOrder) {
var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET); await Promise.all([
var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]); addEntries(['local'], BASIC_LOCAL_ENTRY_SET),
addEntries(['drive'], BASIC_DRIVE_ENTRY_SET)
var selectAndCheckAndClose = function(appId) { ]);
var promise = Promise.resolve();
const selectAndCheckAndClose = async (appId) => {
if (dialogParams.type === 'saveFile') { if (dialogParams.type === 'saveFile') {
promise = promise.then(function() { await remoteCall.waitForElement(
return remoteCall.waitForElement( appId, ['#filename-input-textbox:focus-within']);
appId, ['#filename-input-textbox:focus-within']);
});
} else { } else {
promise = promise.then(function() { await remoteCall.waitForElement(appId, ['#file-list:focus']);
return remoteCall.waitForElement(appId, ['#file-list:focus']);
});
} }
if (initialize) if (initialize) {
promise = promise.then(initialize.bind(null, appId)); await initialize(appId);
}
// Waits for the initial element. // Wait for the initial element.
promise = promise.then(function() { await Promise.all(initialElements.map((selector) => {
return Promise.all(initialElements.map(function(selector) { return remoteCall.waitForElement(appId, [selector]);
return remoteCall.waitForElement(appId, [selector]); }));
}));
});
// Checks tabfocus. // Checks tabfocus.
expectedTabOrder.forEach(function(className) { for (const className of expectedTabOrder) {
promise = promise.then(function() { chrome.test.assertTrue(
return remoteCall.checkNextTabFocus(appId, className); await remoteCall.checkNextTabFocus(appId, className), className);
}).then(function(result) { }
chrome.test.assertTrue(result);
});
});
promise = promise.then(function() {
// Closes the window by pressing Enter.
return remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId, ['#file-list', 'Enter', false, false, false]);
});
return promise; // Closes the window by pressing Enter.
await remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId, ['#file-list', 'Enter', false, false, false]);
}; };
return setupPromise.then(function() { await openAndWaitForClosingDialog(
return openAndWaitForClosingDialog( dialogParams, volumeName, expectedSet, selectAndCheckAndClose);
dialogParams, volumeName, expectedSet, selectAndCheckAndClose);
});
} }
/** /**
* Tests the tab focus behavior of Open Dialog (Downloads). * Tests the tab focus behavior of Open Dialog (Downloads).
*/ */
testcase.tabindexOpenDialogDownloads = function() { testcase.tabindexOpenDialogDownloads = async function() {
testPromise(tabindexFocus( return tabindexFocus(
{type: 'openFile'}, 'downloads', BASIC_LOCAL_ENTRY_SET, {type: 'openFile'}, 'downloads', BASIC_LOCAL_ENTRY_SET,
function(appId) { async (appId) => {
return remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil('selectFile', appId, ['hello.txt']);
'selectFile', appId, ['hello.txt']);
}, },
['#ok-button:not([disabled])'], [ ['#ok-button:not([disabled])'], [
'cancel-button', 'ok-button', 'breadcrumb-path-0', 'search-button', 'cancel-button', 'ok-button', 'breadcrumb-path-0', 'search-button',
'view-button', 'sort-button', 'gear-button', 'directory-tree', 'view-button', 'sort-button', 'gear-button', 'directory-tree',
'file-list' 'file-list'
])); ]);
}; };
/** /**
* Tests the tab focus behavior of Open Dialog (Drive). * Tests the tab focus behavior of Open Dialog (Drive).
*/ */
testcase.tabindexOpenDialogDrive = function() { testcase.tabindexOpenDialogDrive = async function() {
testPromise(tabindexFocus( return tabindexFocus(
{type: 'openFile'}, 'drive', BASIC_DRIVE_ENTRY_SET, {type: 'openFile'}, 'drive', BASIC_DRIVE_ENTRY_SET,
function(appId) { async (appId) => {
return remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil('selectFile', appId, ['hello.txt']);
'selectFile', appId, ['hello.txt']);
}, },
['#ok-button:not([disabled])'], [ ['#ok-button:not([disabled])'], [
'cancel-button', 'ok-button', 'search-button', 'view-button', 'cancel-button', 'ok-button', 'search-button', 'view-button',
'sort-button', 'gear-button', 'directory-tree', 'file-list' 'sort-button', 'gear-button', 'directory-tree', 'file-list'
])); ]);
}; };
/** /**
* Tests the tab focus behavior of Save File Dialog (Downloads). * Tests the tab focus behavior of Save File Dialog (Downloads).
*/ */
testcase.tabindexSaveFileDialogDownloads = function() { testcase.tabindexSaveFileDialogDownloads = async function() {
testPromise(tabindexFocus( return tabindexFocus(
{ {
type: 'saveFile', type: 'saveFile',
suggestedName: 'hoge.txt' // Prevent showing a override prompt suggestedName: 'hoge.txt' // Prevent showing a override prompt
...@@ -342,14 +242,14 @@ testcase.tabindexSaveFileDialogDownloads = function() { ...@@ -342,14 +242,14 @@ testcase.tabindexSaveFileDialogDownloads = function() {
'cancel-button', 'ok-button', 'breadcrumb-path-0', 'search-button', 'cancel-button', 'ok-button', 'breadcrumb-path-0', 'search-button',
'view-button', 'sort-button', 'gear-button', 'directory-tree', 'view-button', 'sort-button', 'gear-button', 'directory-tree',
'file-list', 'new-folder-button', 'filename-input-textbox' 'file-list', 'new-folder-button', 'filename-input-textbox'
])); ]);
}; };
/** /**
* Tests the tab focus behavior of Save File Dialog (Drive). * Tests the tab focus behavior of Save File Dialog (Drive).
*/ */
testcase.tabindexSaveFileDialogDrive = function() { testcase.tabindexSaveFileDialogDrive = async function() {
testPromise(tabindexFocus( return tabindexFocus(
{ {
type: 'saveFile', type: 'saveFile',
suggestedName: 'hoge.txt' // Prevent showing a override prompt suggestedName: 'hoge.txt' // Prevent showing a override prompt
...@@ -358,5 +258,5 @@ testcase.tabindexSaveFileDialogDrive = function() { ...@@ -358,5 +258,5 @@ testcase.tabindexSaveFileDialogDrive = function() {
'cancel-button', 'ok-button', 'search-button', 'view-button', 'cancel-button', 'ok-button', 'search-button', 'view-button',
'sort-button', 'gear-button', 'directory-tree', 'file-list', 'sort-button', 'gear-button', 'directory-tree', 'file-list',
'new-folder-button', 'filename-input-textbox' 'new-folder-button', 'filename-input-textbox'
])); ]);
}; };
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