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( ...@@ -1169,6 +1169,14 @@ INSTANTIATE_TEST_CASE_P(
TestParameter(NOT_IN_GUEST_MODE, "tabindexOpenDialogDownloads"), TestParameter(NOT_IN_GUEST_MODE, "tabindexOpenDialogDownloads"),
TestParameter(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 // Fails on official build. http://crbug.com/429294
// Disabled under MSAN as well. http://crbug.com/468980. // Disabled under MSAN as well. http://crbug.com/468980.
#if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER) #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
......
...@@ -496,8 +496,8 @@ ...@@ -496,8 +496,8 @@
</button> </button>
<div id="filename-input-box" visibleif="saveas-file"> <div id="filename-input-box" visibleif="saveas-file">
<paper-input-decorator i18n-values="label:FILENAME_LABEL"> <paper-input-decorator i18n-values="label:FILENAME_LABEL">
<input is="core-input" class="entry-name" type="text" <input id="filename-input-textbox" is="core-input" tabindex="4"
spellcheck="false" tabindex="4"> class="entry-name" type="text" spellcheck="false">
</paper-input-decorator> </paper-input-decorator>
</div> </div>
<div class="preparing-label" i18n-content="PREPARING_LABEL"></div> <div class="preparing-label" i18n-content="PREPARING_LABEL"></div>
......
...@@ -227,6 +227,58 @@ function openNewWindow(appState, initialRoot, opt_callback) { ...@@ -227,6 +227,58 @@ function openNewWindow(appState, initialRoot, opt_callback) {
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 * 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. * the window with initial files. Should be called for the first window only.
......
...@@ -4,58 +4,6 @@ ...@@ -4,58 +4,6 @@
'use strict'; '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. * Tests to open and cancel the file dialog.
* *
...@@ -72,17 +20,21 @@ function openFileDialog(volumeName, expectedSet) { ...@@ -72,17 +20,21 @@ function openFileDialog(volumeName, expectedSet) {
var closeByCancelButtonPromise = setupPromise.then(function() { var closeByCancelButtonPromise = setupPromise.then(function() {
return openAndWaitForClosingDialog( return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName, volumeName,
expectedSet, expectedSet,
function(windowId) { function(windowId) {
return remoteCall.waitForElement(windowId, return remoteCall.callRemoteTestUtil(
'.button-panel button.cancel'). 'selectFile', windowId, ['hello.txt']
then(function() { ).then(function() {
return remoteCall.callRemoteTestUtil( return remoteCall.waitForElement(windowId,
'fakeEvent', '.button-panel button.cancel');
windowId, }).then(function() {
['.button-panel button.cancel', 'click']); return remoteCall.callRemoteTestUtil(
}); 'fakeEvent',
windowId,
['.button-panel button.cancel', 'click']);
});
}); });
}).then(function(result) { }).then(function(result) {
// Undefined means the dialog is canceled. // Undefined means the dialog is canceled.
...@@ -91,13 +43,18 @@ function openFileDialog(volumeName, expectedSet) { ...@@ -91,13 +43,18 @@ function openFileDialog(volumeName, expectedSet) {
var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() { var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() {
return openAndWaitForClosingDialog( return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName, volumeName,
expectedSet, expectedSet,
function(windowId) { function(windowId) {
return remoteCall.callRemoteTestUtil( return remoteCall.callRemoteTestUtil(
'fakeKeyDown', 'selectFile', windowId, ['hello.txt']
windowId, ).then(function() {
['#file-list', 'U+001B', false]); return remoteCall.callRemoteTestUtil(
'fakeKeyDown',
windowId,
['#file-list', 'U+001B', false]);
});
}); });
}).then(function(result) { }).then(function(result) {
// Undefined means the dialog is canceled. // Undefined means the dialog is canceled.
...@@ -106,17 +63,21 @@ function openFileDialog(volumeName, expectedSet) { ...@@ -106,17 +63,21 @@ function openFileDialog(volumeName, expectedSet) {
var closeByOkButtonPromise = closeByEscKeyPromise.then(function() { var closeByOkButtonPromise = closeByEscKeyPromise.then(function() {
return openAndWaitForClosingDialog( return openAndWaitForClosingDialog(
{type: 'openFile'},
volumeName, volumeName,
expectedSet, expectedSet,
function(windowId) { function(windowId) {
return remoteCall.waitForElement(windowId, return remoteCall.callRemoteTestUtil(
'.button-panel button.ok'). 'selectFile', windowId, ['hello.txt']
then(function() { ).then(function() {
return remoteCall.callRemoteTestUtil( return remoteCall.waitForElement(windowId,
'fakeEvent', '.button-panel button.ok');
windowId, }).then(function() {
['.button-panel button.ok', 'click']); return remoteCall.callRemoteTestUtil(
}); 'fakeEvent',
windowId,
['.button-panel button.ok', 'click']);
});
}); });
}).then(function(result) { }).then(function(result) {
chrome.test.assertEq('hello.txt', result.name); chrome.test.assertEq('hello.txt', result.name);
......
...@@ -191,21 +191,41 @@ testcase.tabindexFocusDirectorySelected = function() { ...@@ -191,21 +191,41 @@ testcase.tabindexFocusDirectorySelected = function() {
/** /**
* Tests the tab focus in the dialog and closes the dialog. * 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 localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET);
var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET); var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET);
var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]); var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]);
var checkAndClose = function(appId) { var selectAndCheckAndClose = function(appId) {
var promise = remoteCall.callRemoteTestUtil('getActiveElement', appId, []); var promise = Promise.resolve();
if (selectFile) {
promise = promise.then(function() {
return remoteCall.callRemoteTestUtil(
'selectFile', appId, ['hello.txt']);
});
}
promise = promise.then(function() { 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() { promise = promise.then(function() {
return remoteCall.waitForElement(appId, ['#file-list:focus']); return remoteCall.waitForElement(appId, [initialElement]);
}); });
// Checks tabfocus. // Checks tabfocus.
...@@ -220,16 +240,15 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) { ...@@ -220,16 +240,15 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) {
promise = promise.then(function() { promise = promise.then(function() {
// Closes the window by pressing Enter. // Closes the window by pressing Enter.
return remoteCall.callRemoteTestUtil( return remoteCall.callRemoteTestUtil(
'fakeKeyDown', 'fakeKeyDown', appId, ['#file-list', 'Enter', false]);
appId,
['#file-list', 'Enter', false]);
}); });
return promise; return promise;
}; };
return setupPromise.then(function() { return setupPromise.then(function() {
return openAndWaitForClosingDialog(volumeName, expectedSet, checkAndClose); return openAndWaitForClosingDialog(
dialogParams, volumeName, expectedSet, selectAndCheckAndClose);
}); });
} }
...@@ -238,9 +257,10 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) { ...@@ -238,9 +257,10 @@ function tabindexFocus(volumeName, expectedSet, expectedTabOrder) {
*/ */
testcase.tabindexOpenDialogDownloads = function() { testcase.tabindexOpenDialogDownloads = function() {
testPromise(tabindexFocus( testPromise(tabindexFocus(
'downloads', BASIC_LOCAL_ENTRY_SET, {type: 'openFile'}, 'downloads', BASIC_LOCAL_ENTRY_SET, true,
['ok-button', 'cancel-button', 'search-button', 'view-button', '#ok-button:not([disabled])',
'gear-button', 'directory-tree', 'file-list'])); ['ok-button', 'cancel-button', 'search-button', 'view-button',
'gear-button', 'directory-tree', 'file-list']));
}; };
/** /**
...@@ -248,7 +268,40 @@ testcase.tabindexOpenDialogDownloads = function() { ...@@ -248,7 +268,40 @@ testcase.tabindexOpenDialogDownloads = function() {
*/ */
testcase.tabindexOpenDialogDrive = function() { testcase.tabindexOpenDialogDrive = function() {
testPromise(tabindexFocus( testPromise(tabindexFocus(
'drive', BASIC_DRIVE_ENTRY_SET, {type: 'openFile'}, 'drive', BASIC_DRIVE_ENTRY_SET, true,
['ok-button', 'cancel-button', 'search-button', 'view-button', '#ok-button:not([disabled])',
'gear-button', 'directory-tree', 'file-list'])); ['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 @@ ...@@ -36,7 +36,7 @@
] ]
}, },
"permissions": [ "permissions": [
"fileSystem", {"fileSystem": ["write"]},
"tabs", "tabs",
"commandLinePrivate", "commandLinePrivate",
"chrome-extension://oobinhbdbiehknkpbpejbbpdbkdjmoco/*", "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