Commit 4c745fa2 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

CreateNewFolder test: improve createNewFolder helper and related

Stop using navigateWithDirectoryTree in createNewFolder helper (return
value unchecked, generally false if checked).

All tests navigate the directory tree during test setup by clicking on
subtree's expand icon. However, the createFolderNestedDownloads() test
needs to do an extra step to navigate into sub-tree 'photos'. Since it
is the only test that needs this extra step, navigateWithDirectoryTree
can be used to do it, with a post-verify step to check that #file-list
updated to the expected visual state (no files shown).

Change createNewFolder API: navigateWithDirectoryTree gone so path etc
can go. Add a tree |selector| argument so createNewFolder can check if
that folders appear in the directory tree.

Update the createNewFolder internals: focus the file list, use precise
#file-list selectors when checking for [selected] [renaming] row, more
checks to confirm that only one file-list row is [selected] [renaming]
namely the New Folder entry, and verify the New Folder is "present" in
directory tree HTML content.

After the new folder is renamed, verify that its name is shown in file
list and also in the directory tree. Finally, fully test the file-list
selection state at the end of the test (the long way).

Bug: 876267
Change-Id: I8693bdc43b95a4c3b510633697fa4b3d85e08051
Reviewed-on: https://chromium-review.googlesource.com/1186008Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585391}
parent bf31bedf
...@@ -42,92 +42,92 @@ function selectFirstFileListItem(windowId) { ...@@ -42,92 +42,92 @@ function selectFirstFileListItem(windowId) {
} }
/** /**
* Creates new folder. * Creates a new folder in the file list.
*
* @param {string} windowId The Files app windowId. * @param {string} windowId The Files app windowId.
* @param {string} path Initial path.
* @param {Array<TestEntryInfo>} initialEntrySet Initial set of entries. * @param {Array<TestEntryInfo>} initialEntrySet Initial set of entries.
* @param {string} rootLabel label path's root. * @param {string} selector Downloads or Drive directory tree item selector.
* @return {Promise} Promise to be fulfilled on success. * @return {Promise} Promise to be fulfilled on success.
*/ */
function createNewFolder(windowId, path, initialEntrySet, rootLabel) { function createNewFolder(windowId, initialEntrySet, selector) {
var caller = getCaller(); const textInput = '#file-list .table-row[renaming] input.rename';
return Promise.resolve()
.then(function() { return new Promise(function(resolve) {
return navigateWithDirectoryTree(windowId, path, rootLabel); // Focus the file-list.
}) remoteCall.callRemoteTestUtil('focus', windowId, ['#file-list'], resolve);
.then(function() { }).then(function(result) {
// Push Ctrl + E. chrome.test.assertTrue(result);
return remoteCall.callRemoteTestUtil( // Press Ctrl+E to create a new folder.
'fakeKeyDown', windowId, const key = ['#file-list', 'e', 'U+0045', true, false, false];
// Ctrl + E return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, key);
['#file-list', 'e', 'U+0045', true, false, false]); }).then(function(result) {
chrome.test.assertTrue(result);
// Check: a new folder should be shown in the file list.
const files = [['New Folder', '--', 'Folder', '']].concat(
TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles(
windowId, files, {ignoreLastModifiedTime: true});
}).then(function() { }).then(function() {
// Wait for rename text field. // Check: a new folder should be present in the directory tree.
return remoteCall.waitForElement(windowId, 'li[renaming] input.rename'); const newSubtreeChildItem = selector +
' .tree-children .tree-item[entry-label="New Folder"]';
return remoteCall.waitForElement(windowId, newSubtreeChildItem);
}).then(function() { }).then(function() {
// Check: the text input should be shown in the file list.
return remoteCall.waitForElement(windowId, textInput);
}).then(function() {
// Get all file list rows that have attribute 'renaming'.
const renamingFileListRows = ['#file-list .table-row[renaming]'];
return remoteCall.callRemoteTestUtil( return remoteCall.callRemoteTestUtil(
'queryAllElements', 'queryAllElements', windowId, renamingFileListRows);
windowId,
['div.detail-table > list > li[selected]']);
}).then(function(elements) { }).then(function(elements) {
// Ensure that only the new directory is selected and being renamed. // Check: the new folder only should be 'renaming'.
chrome.test.assertEq(1, elements.length); chrome.test.assertEq(1, elements.length);
chrome.test.assertTrue('renaming' in elements[0].attributes); chrome.test.assertEq(0, elements[0].text.indexOf('New Folder--'));
chrome.test.assertTrue('selected' in elements[0].attributes);
}).then(function() { }).then(function() {
// Check directory tree for new folder. // Get all file list rows that have attribute 'selected'.
var expectedRows = [['New Folder', '--', 'Folder', '']].concat( const selectedFileListRows = ['#file-list .table-row[selected]'];
TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles(
windowId, expectedRows, {ignoreLastModifiedTime: true});
}).then(function() {
// Type new folder name.
return remoteCall.callRemoteTestUtil( return remoteCall.callRemoteTestUtil(
'inputText', windowId, ['input.rename', 'Test Folder Name']); 'queryAllElements', windowId, selectedFileListRows);
}).then(function(elements) {
// Check: the new folder only should be 'selected'.
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('New Folder--'));
chrome.test.assertTrue('renaming' in elements[0].attributes);
}).then(function() { }).then(function() {
// Push Enter. // Type the test folder name.
return remoteCall.callRemoteTestUtil( return remoteCall.callRemoteTestUtil(
'fakeKeyDown', 'inputText', windowId, [textInput, 'Test Folder Name']);
windowId,
['input.rename', 'Enter', 'Enter', false, false, false]);
}).then(function() { }).then(function() {
// Wait until rename completes. // Press the Enter key.
return remoteCall.waitForElementLost(windowId, 'input.rename'); const key = [textInput, 'Enter', 'Enter', false, false, false];
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, key);
}).then(function(result) {
chrome.test.assertTrue(result);
// Wait until renaming is complete.
const renamingItem = ['#file-list .table-row[renaming]'];
return remoteCall.waitForElementLost(windowId, renamingItem);
}).then(function() { }).then(function() {
// A newer entry is then added for the renamed folder. // Check: the test folder should be shown in the file list.
var expectedRows = [['Test Folder Name', '--', 'Folder', '']].concat( const files = [['Test Folder Name', '--', 'Folder', '']].concat(
TestEntryInfo.getExpectedRows(initialEntrySet)); TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles( return remoteCall.waitForFiles(
windowId, expectedRows, {ignoreLastModifiedTime: true}); windowId, files, {ignoreLastModifiedTime: true});
}).then(function() { }).then(function(elements) {
var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); // Check: the test folder should be present in the directory tree.
expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']); const testSubtreeChildItem = selector +
// Wait for the new folder. ' .tree-children .tree-item[entry-label="Test Folder Name"]';
return remoteCall.waitForFiles(windowId, return remoteCall.waitForElement(windowId, testSubtreeChildItem);
expectedEntryRows, }).then(function() {
{ignoreLastModifiedTime: true}); // Get all file list rows that have attribute 'selected'.
}).then(function() { const selectedFileListRows = ['#file-list .table-row[selected]'];
// Wait until the new created folder is selected. return remoteCall.callRemoteTestUtil(
var nameSpanQuery = 'div.detail-table > list > ' + 'queryAllElements', windowId, selectedFileListRows);
'li[selected]:not([renaming]) span.entry-name'; }).then(function(elements) {
// Check: the test folder only should be 'selected'.
return repeatUntil(function() { chrome.test.assertEq(1, elements.length);
var selectedNameRetrievePromise = remoteCall.callRemoteTestUtil( chrome.test.assertEq(0, elements[0].text.indexOf('Test Folder Name--'));
'queryAllElements',
windowId,
['div.detail-table > list > li[selected] span.entry-name']);
return selectedNameRetrievePromise.then(function(elements) {
if (elements.length !== 1) {
return pending(
caller, 'Selection is not ready (elements: %j)', elements);
} else if (elements[0].text !== 'Test Folder Name') {
return pending(
caller, 'Selected item is wrong. (actual: %s)', elements[0].text);
} else {
return true;
}
});
});
}); });
} }
...@@ -172,7 +172,7 @@ testcase.selectCreateFolderDownloads = function() { ...@@ -172,7 +172,7 @@ testcase.selectCreateFolderDownloads = function() {
}).then(function() { }).then(function() {
return selectFirstFileListItem(windowId); return selectFirstFileListItem(windowId);
}).then(function() { }).then(function() {
return createNewFolder(windowId, '', BASIC_LOCAL_ENTRY_SET, 'Downloads'); return createNewFolder(windowId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
}); });
testPromise(promise); testPromise(promise);
...@@ -188,7 +188,7 @@ testcase.createFolderDownloads = function() { ...@@ -188,7 +188,7 @@ testcase.createFolderDownloads = function() {
windowId = results.windowId; windowId = results.windowId;
return expandRoot(windowId, TREEITEM_DOWNLOADS); return expandRoot(windowId, TREEITEM_DOWNLOADS);
}).then(function() { }).then(function() {
return createNewFolder(windowId, '', BASIC_LOCAL_ENTRY_SET, 'Downloads'); return createNewFolder(windowId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
}); });
testPromise(promise); testPromise(promise);
...@@ -204,8 +204,12 @@ testcase.createFolderNestedDownloads = function() { ...@@ -204,8 +204,12 @@ testcase.createFolderNestedDownloads = function() {
windowId = results.windowId; windowId = results.windowId;
return expandRoot(windowId, TREEITEM_DOWNLOADS); return expandRoot(windowId, TREEITEM_DOWNLOADS);
}).then(function() { }).then(function() {
const photosEntrySet = []; return navigateWithDirectoryTree(windowId, '/photos', 'Downloads');
return createNewFolder(windowId, '/photos', photosEntrySet, 'Downloads'); }).then(function() {
return remoteCall.waitForFiles(
windowId, [], {ignoreLastModifiedTime: true});
}).then(function() {
return createNewFolder(windowId, [], TREEITEM_DOWNLOADS);
}); });
testPromise(promise); testPromise(promise);
...@@ -221,7 +225,7 @@ testcase.createFolderDrive = function() { ...@@ -221,7 +225,7 @@ testcase.createFolderDrive = function() {
windowId = results.windowId; windowId = results.windowId;
return expandRoot(windowId, TREEITEM_DRIVE); return expandRoot(windowId, TREEITEM_DRIVE);
}).then(function() { }).then(function() {
return createNewFolder(windowId, '', BASIC_DRIVE_ENTRY_SET, 'My Drive'); return createNewFolder(windowId, BASIC_DRIVE_ENTRY_SET, TREEITEM_DRIVE);
}); });
testPromise(promise); testPromise(promise);
......
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