Commit 0fc95e9d authored by yoshiki's avatar yoshiki Committed by Commit bot

[Files.app] Added a tabindex test for save file dialog

BUG=469061
TEST=run newly added test

Review URL: https://codereview.chromium.org/1092573002

Cr-Commit-Position: refs/heads/master@{#327230}
parent 529b2d0c
......@@ -1169,6 +1169,14 @@ INSTANTIATE_TEST_CASE_P(
TestParameter(NOT_IN_GUEST_MODE, "tabindexOpenDialogDownloads"),
TestParameter(IN_GUEST_MODE, "tabindexOpenDialogDownloads")));
INSTANTIATE_TEST_CASE_P(
TabindexSaveFileDialog,
FileManagerBrowserTest,
::testing::Values(
TestParameter(NOT_IN_GUEST_MODE, "tabindexSaveFileDialogDrive"),
TestParameter(NOT_IN_GUEST_MODE, "tabindexSaveFileDialogDownloads"),
TestParameter(IN_GUEST_MODE, "tabindexSaveFileDialogDownloads")));
// Fails on official build. http://crbug.com/429294
// Disabled under MSAN as well. http://crbug.com/468980.
#if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
......
......@@ -496,8 +496,8 @@
</button>
<div id="filename-input-box" visibleif="saveas-file">
<paper-input-decorator i18n-values="label:FILENAME_LABEL">
<input is="core-input" class="entry-name" type="text"
spellcheck="false" tabindex="4">
<input id="filename-input-textbox" is="core-input" tabindex="4"
class="entry-name" type="text" spellcheck="false">
</paper-input-decorator>
</div>
<div class="preparing-label" i18n-content="PREPARING_LABEL"></div>
......
......@@ -227,6 +227,58 @@ function openNewWindow(appState, initialRoot, opt_callback) {
opt_callback);
}
/**
* Opens a file dialog and waits for closing it.
*
* @param {Object} dialogParams Dialog parameters to be passed to chrome.
* fileSystem.chooseEntry() API.
* @param {string} volumeName Volume name passed to the selectVolume remote
* funciton.
* @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries.
* @param {function(windowId:string):Promise} closeDialog Function to close the
* dialog.
* @return {Promise} Promise to be fulfilled with the result entry of the
* dialog.
*/
function openAndWaitForClosingDialog(
dialogParams, volumeName, expectedSet, closeDialog) {
var resultPromise = new Promise(function(fulfill) {
chrome.fileSystem.chooseEntry(
dialogParams,
function(entry) { fulfill(entry); });
chrome.test.assertTrue(!chrome.runtime.lastError, 'chooseEntry failed.');
});
return remoteCall.waitForWindow('dialog#').then(function(windowId) {
return remoteCall.waitForElement(windowId, '#file-list').
then(function() {
// Wait for initialization of Files.app.
return remoteCall.waitForFiles(
windowId, TestEntryInfo.getExpectedRows(BASIC_LOCAL_ENTRY_SET));
}).
then(function() {
return remoteCall.callRemoteTestUtil(
'selectVolume', windowId, [volumeName]);
}).
then(function() {
var expectedRows = TestEntryInfo.getExpectedRows(expectedSet);
return remoteCall.waitForFiles(windowId, expectedRows);
}).
then(closeDialog.bind(null, windowId)).
then(function() {
return repeatUntil(function() {
return remoteCall.callRemoteTestUtil('getWindows', null, []).
then(function(windows) {
if (windows[windowId])
return pending('Window %s does not hide.', windowId);
else
return resultPromise;
});
});
});
});
}
/**
* Opens a Files.app's main window and waits until it is initialized. Fills
* the window with initial files. Should be called for the first window only.
......
......@@ -4,58 +4,6 @@
'use strict';
/**
* Opens a file dialog and waits for closing it.
*
* @param {string} volumeName Volume name passed to the selectVolume remote
* funciton.
* @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries.
* @param {function(windowId:string):Promise} closeDialog Function to close the
* dialog.
* @return {Promise} Promise to be fulfilled with the result entry of the
* dialog.
*/
function openAndWaitForClosingDialog(volumeName, expectedSet, closeDialog) {
var resultPromise = new Promise(function(fulfill) {
chrome.fileSystem.chooseEntry(
{type: 'openFile'},
function(entry) { fulfill(entry); });
});
return remoteCall.waitForWindow('dialog#').then(function(windowId) {
return remoteCall.waitForElement(windowId, '#file-list').
then(function() {
// Wait for initialization of Files.app.
return remoteCall.waitForFiles(
windowId, TestEntryInfo.getExpectedRows(BASIC_LOCAL_ENTRY_SET));
}).
then(function() {
return remoteCall.callRemoteTestUtil(
'selectVolume', windowId, [volumeName]);
}).
then(function() {
var expectedRows = TestEntryInfo.getExpectedRows(expectedSet);
return remoteCall.waitForFiles(windowId, expectedRows);
}).
then(function() {
return remoteCall.callRemoteTestUtil(
'selectFile', windowId, ['hello.txt']);
}).
then(closeDialog.bind(null, windowId)).
then(function() {
return repeatUntil(function() {
return remoteCall.callRemoteTestUtil('getWindows', null, []).
then(function(windows) {
if (windows[windowId])
return pending('Window %s does not hide.', windowId);
else
return resultPromise;
});
});
});
});
}
/**
* Tests to open and cancel the file dialog.
*
......@@ -72,12 +20,16 @@ function openFileDialog(volumeName, expectedSet) {
var closeByCancelButtonPromise = setupPromise.then(function() {
return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName,
expectedSet,
function(windowId) {
return remoteCall.callRemoteTestUtil(
'selectFile', windowId, ['hello.txt']
).then(function() {
return remoteCall.waitForElement(windowId,
'.button-panel button.cancel').
then(function() {
'.button-panel button.cancel');
}).then(function() {
return remoteCall.callRemoteTestUtil(
'fakeEvent',
windowId,
......@@ -91,14 +43,19 @@ function openFileDialog(volumeName, expectedSet) {
var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() {
return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName,
expectedSet,
function(windowId) {
return remoteCall.callRemoteTestUtil(
'selectFile', windowId, ['hello.txt']
).then(function() {
return remoteCall.callRemoteTestUtil(
'fakeKeyDown',
windowId,
['#file-list', 'U+001B', false]);
});
});
}).then(function(result) {
// Undefined means the dialog is canceled.
chrome.test.assertEq(undefined, result);
......@@ -106,12 +63,16 @@ function openFileDialog(volumeName, expectedSet) {
var closeByOkButtonPromise = closeByEscKeyPromise.then(function() {
return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName,
expectedSet,
function(windowId) {
return remoteCall.callRemoteTestUtil(
'selectFile', windowId, ['hello.txt']
).then(function() {
return remoteCall.waitForElement(windowId,
'.button-panel button.ok').
then(function() {
'.button-panel button.ok');
}).then(function() {
return remoteCall.callRemoteTestUtil(
'fakeEvent',
windowId,
......
......@@ -191,21 +191,41 @@ testcase.tabindexFocusDirectorySelected = function() {
/**
* Tests the tab focus in the dialog and closes the dialog.
*
* @param {Object} dialogParams Dialog parameters to be passed to
* chrome.fileSystem.chooseEntry.
* @param {string} volumeName Volume name passed to the selectVolume remote
* function.
* @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries.
* @param {boolean} selectFile True to select 'hello.txt' before the tab order
* check, false do not select any file before the check.
* @param {string} initialElement Selector of the element which shows ready.
* @param {Array.<string>} expectedTabOrder Array with the IDs of the element
* with the corresponding order of expected tab-indexes.
*/
function tabindexFocus(volumeName, expectedSet, expectedTabOrder) {
function tabindexFocus(dialogParams, volumeName, expectedSet, selectFile,
initialElement, expectedTabOrder) {
var localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET);
var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET);
var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]);
var checkAndClose = function(appId) {
var promise = remoteCall.callRemoteTestUtil('getActiveElement', appId, []);
var selectAndCheckAndClose = function(appId) {
var promise = Promise.resolve();
if (selectFile) {
promise = promise.then(function() {
return remoteCall.callRemoteTestUtil(
'selectFile', appId, ['hello.txt']);
});
}
promise = promise.then(function() {
return remoteCall.waitForElement(appId, ['#ok-button:not([disabled])']);
return remoteCall.callRemoteTestUtil('getActiveElement', appId, []);
});
// Checks initial focus.
// Waits for the initial element.
promise = promise.then(function() {
return remoteCall.waitForElement(appId, ['#file-list:focus']);
return remoteCall.waitForElement(appId, [initialElement]);
});
// Checks tabfocus.
......@@ -220,16 +240,15 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) {
promise = promise.then(function() {
// Closes the window by pressing Enter.
return remoteCall.callRemoteTestUtil(
'fakeKeyDown',
appId,
['#file-list', 'Enter', false]);
'fakeKeyDown', appId, ['#file-list', 'Enter', false]);
});
return promise;
};
return setupPromise.then(function() {
return openAndWaitForClosingDialog(volumeName, expectedSet, checkAndClose);
return openAndWaitForClosingDialog(
dialogParams, volumeName, expectedSet, selectAndCheckAndClose);
});
}
......@@ -238,7 +257,8 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) {
*/
testcase.tabindexOpenDialogDownloads = function() {
testPromise(tabindexFocus(
'downloads', BASIC_LOCAL_ENTRY_SET,
{type: 'openFile'}, 'downloads', BASIC_LOCAL_ENTRY_SET, true,
'#ok-button:not([disabled])',
['ok-button', 'cancel-button', 'search-button', 'view-button',
'gear-button', 'directory-tree', 'file-list']));
};
......@@ -248,7 +268,40 @@ testcase.tabindexOpenDialogDownloads = function() {
*/
testcase.tabindexOpenDialogDrive = function() {
testPromise(tabindexFocus(
'drive', BASIC_DRIVE_ENTRY_SET,
{type: 'openFile'}, 'drive', BASIC_DRIVE_ENTRY_SET, true,
'#ok-button:not([disabled])',
['ok-button', 'cancel-button', 'search-button', 'view-button',
'gear-button', 'directory-tree', 'file-list']));
};
/**
* Tests the tab focus behavior of Save File Dialog (Downloads).
*/
testcase.tabindexSaveFileDialogDownloads = function() {
testPromise(tabindexFocus(
{
type: 'saveFile',
suggestedName: 'hoge.txt' // Prevent showing a override prompt
},
'downloads', BASIC_LOCAL_ENTRY_SET, false,
'#ok-button:not([disabled])',
['ok-button', 'cancel-button', 'search-button', 'view-button',
'gear-button', 'directory-tree', 'file-list', 'new-folder-button',
'filename-input-textbox']));
};
/**
* Tests the tab focus behavior of Save File Dialog (Drive).
*/
testcase.tabindexSaveFileDialogDrive = function() {
testPromise(tabindexFocus(
{
type: 'saveFile',
suggestedName: 'hoge.txt' // Prevent showing a override prompt
},
'drive', BASIC_DRIVE_ENTRY_SET, false,
'#ok-button:not([disabled])',
['ok-button', 'cancel-button', 'search-button', 'view-button',
'gear-button', 'directory-tree', 'file-list', 'new-folder-button',
'filename-input-textbox']));
};
......@@ -36,7 +36,7 @@
]
},
"permissions": [
"fileSystem",
{"fileSystem": ["write"]},
"tabs",
"commandLinePrivate",
"chrome-extension://oobinhbdbiehknkpbpejbbpdbkdjmoco/*",
......
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