Commit 80223a4b authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert file_display.js to use async-await.

Bug: 909056
Change-Id: Ic5a91cccb89c55d65217e6e55444878e4ab623cd
Reviewed-on: https://chromium-review.googlesource.com/c/1354733Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612085}
parent 8e96110f
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; 'use strict';
/** /**
...@@ -11,146 +10,101 @@ ...@@ -11,146 +10,101 @@
* @param {string} path Path to be tested, Downloads or Drive. * @param {string} path Path to be tested, Downloads or Drive.
* @param {Array<TestEntryInfo>} defaultEntries Default file entries. * @param {Array<TestEntryInfo>} defaultEntries Default file entries.
*/ */
function fileDisplay(path, defaultEntries) { async function fileDisplay(path, defaultEntries) {
var appId;
const defaultList = TestEntryInfo.getExpectedRows(defaultEntries).sort(); const defaultList = TestEntryInfo.getExpectedRows(defaultEntries).sort();
StepsRunner.run([ // Open Files app on the given |path| with default file entries.
// Open Files app on the given |path| with default file entries. const {appId, fileList} = await setupAndWaitUntilReady(null, path, null);
function() {
setupAndWaitUntilReady(null, path, this.next); // Verify the default file list is present in |result|.
}, chrome.test.assertEq(defaultList, fileList);
// Verify the default file list is present in |result|.
function(result) { // Add new file entries.
appId = result.windowId; await addEntries(['local', 'drive'], [ENTRIES.newlyAdded]);
chrome.test.assertEq(defaultList, result.fileList);
this.next(); // Verify the newly added entries appear in the file list.
}, const expectedList =
// Add new file entries. defaultList.concat([ENTRIES.newlyAdded.getExpectedRow()]);
function() { await remoteCall.waitForFiles(appId, expectedList);
addEntries(['local', 'drive'], [ENTRIES.newlyAdded], this.next);
},
// Verify the newly added entries appear in the file list.
function() {
const expectedList =
defaultList.concat([ENTRIES.newlyAdded.getExpectedRow()]);
remoteCall.waitForFiles(appId, expectedList).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
* Tests files display in Downloads. * Tests files display in Downloads.
*/ */
testcase.fileDisplayDownloads = function() { testcase.fileDisplayDownloads = function() {
fileDisplay(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET); return fileDisplay(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET);
}; };
/** /**
* Tests files display in Google Drive. * Tests files display in Google Drive.
*/ */
testcase.fileDisplayDrive = function() { testcase.fileDisplayDrive = function() {
fileDisplay(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET); return fileDisplay(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET);
}; };
/** /**
* Tests file display rendering in offline Google Drive. * Tests file display rendering in offline Google Drive.
*/ */
testcase.fileDisplayDriveOffline = function() { testcase.fileDisplayDriveOffline = async function() {
var appId;
const driveFiles = const driveFiles =
[ENTRIES.hello, ENTRIES.pinned, ENTRIES.photos, ENTRIES.testDocument]; [ENTRIES.hello, ENTRIES.pinned, ENTRIES.photos, ENTRIES.testDocument];
StepsRunner.run([ // Open Files app on Drive with the given test files.
// Open Files app on Drive with the given test files. const {appId} =
function() { await setupAndWaitUntilReady(null, RootPath.DRIVE, null, [], driveFiles);
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next, [], driveFiles);
}, // Retrieve all file list entries that could be rendered 'offline'.
// Retrieve all file list entries that could be rendered 'offline'. const offlineEntry = '#file-list .table-row.file.dim-offline';
function(result) { let elements = await remoteCall.callRemoteTestUtil(
appId = result.windowId; 'queryAllElements', appId, [offlineEntry, ['opacity']]);
const offlineEntry = '#file-list .table-row.file.dim-offline';
remoteCall.callRemoteTestUtil( // Check: the hello.txt file only should be rendered 'offline'.
'queryAllElements', appId, [offlineEntry, ['opacity']], this.next); chrome.test.assertEq(1, elements.length);
}, chrome.test.assertEq(0, elements[0].text.indexOf('hello.txt'));
// Check: the hello.txt file only should be rendered 'offline'.
function(elements) { // Check: hello.txt must have 'offline' CSS render style (opacity).
chrome.test.assertEq(1, elements.length); chrome.test.assertEq('0.4', elements[0].styles.opacity);
chrome.test.assertEq(0, elements[0].text.indexOf('hello.txt'));
this.next(elements[0].styles); // Retrieve file entries that are 'available offline' (not dimmed).
}, const availableEntry = '#file-list .table-row:not(.dim-offline)';
// Check: hello.txt must have 'offline' CSS render style (opacity). elements = await remoteCall.callRemoteTestUtil(
function(style) { 'queryAllElements', appId, [availableEntry, ['opacity']]);
chrome.test.assertEq('0.4', style.opacity);
this.next(); // Check: these files should have 'available offline' CSS style.
}, chrome.test.assertEq(3, elements.length);
// Retrieve file entries that are 'available offline' (not dimmed).
function() { function checkRenderedInAvailableOfflineStyle(element, fileName) {
const availableEntry = '#file-list .table-row:not(.dim-offline)'; chrome.test.assertEq(0, element.text.indexOf(fileName));
remoteCall.callRemoteTestUtil( chrome.test.assertEq('1', element.styles.opacity);
'queryAllElements', appId, [availableEntry, ['opacity']], this.next); }
},
// Check: these files should have 'available offline' CSS style. // Directories are shown as 'available offline'.
function(elements) { checkRenderedInAvailableOfflineStyle(elements[0], 'photos');
chrome.test.assertEq(3, elements.length);
// Hosted documents are shown as 'available offline'.
function checkRenderedInAvailableOfflineStyle(element, fileName) { checkRenderedInAvailableOfflineStyle(elements[1], 'Test Document.gdoc');
chrome.test.assertEq(0, element.text.indexOf(fileName));
chrome.test.assertEq('1', element.styles.opacity); // Pinned files are shown as 'available offline'.
} checkRenderedInAvailableOfflineStyle(elements[2], 'pinned');
// Directories are shown as 'available offline'.
checkRenderedInAvailableOfflineStyle(elements[0], 'photos');
// Hosted documents are shown as 'available offline'.
checkRenderedInAvailableOfflineStyle(elements[1], 'Test Document.gdoc');
// Pinned files are shown as 'available offline'.
checkRenderedInAvailableOfflineStyle(elements[2], 'pinned');
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Tests file display rendering in online Google Drive. * Tests file display rendering in online Google Drive.
*/ */
testcase.fileDisplayDriveOnline = function() { testcase.fileDisplayDriveOnline = async function() {
var appId; // Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DRIVE, null, [], BASIC_DRIVE_ENTRY_SET);
// Open Files app on Drive.
function() { // Retrieve all file list row entries.
setupAndWaitUntilReady( const fileEntry = '#file-list .table-row';
null, RootPath.DRIVE, this.next, [], BASIC_DRIVE_ENTRY_SET); const elements = await remoteCall.callRemoteTestUtil(
}, 'queryAllElements', appId, [fileEntry, ['opacity']]);
// Retrieve all file list row entries.
function(result) { // Check: all files must have 'online' CSS style (not dimmed).
appId = result.windowId; chrome.test.assertEq(BASIC_DRIVE_ENTRY_SET.length, elements.length);
const fileEntry = '#file-list .table-row'; for (let i = 0; i < elements.length; ++i)
remoteCall.callRemoteTestUtil( chrome.test.assertEq('1', elements[i].styles.opacity);
'queryAllElements', appId, [fileEntry, ['opacity']], this.next);
},
// Check: all files must have 'online' CSS style (not dimmed).
function(elements) {
chrome.test.assertEq(BASIC_DRIVE_ENTRY_SET.length, elements.length);
for (let i = 0; i < elements.length; ++i)
chrome.test.assertEq('1', elements[i].styles.opacity);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
...@@ -158,119 +112,70 @@ testcase.fileDisplayDriveOnline = function() { ...@@ -158,119 +112,70 @@ testcase.fileDisplayDriveOnline = function() {
* we can navigate to folders inside /Computers also has the side effect of * we can navigate to folders inside /Computers also has the side effect of
* testing that the breadcrumbs are working. * testing that the breadcrumbs are working.
*/ */
testcase.fileDisplayComputers = function() { testcase.fileDisplayComputers = async function() {
let appId; // Open Files app on Drive with Computers registered.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DRIVE, null, [], COMPUTERS_ENTRY_SET);
// Open Files app on Drive with Computers registered.
function() { // Navigate to Comuter Grand Root.
setupAndWaitUntilReady( await remoteCall.navigateWithDirectoryTree(appId, '/Computers', 'Computers');
null, RootPath.DRIVE, this.next, [], COMPUTERS_ENTRY_SET);
}, // Navigiate to a Computer Root.
function(result) { await remoteCall.navigateWithDirectoryTree(
appId = result.windowId; appId, '/Computers/Computer A', 'Computers');
// Navigate to Comuter Grand Root.
return remoteCall // Navigiate to a subdirectory under a Computer Root.
.navigateWithDirectoryTree(appId, '/Computers', 'Computers') await remoteCall.navigateWithDirectoryTree(
.then(this.next); appId, '/Computers/Computer A/A', 'Computers');
},
function() {
// Navigiate to a Computer Root.
return remoteCall
.navigateWithDirectoryTree(
appId, '/Computers/Computer A', 'Computers')
.then(this.next);
},
function() {
// Navigiate to a subdirectory under a Computer Root.
return remoteCall
.navigateWithDirectoryTree(
appId, '/Computers/Computer A/A', 'Computers')
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests files display in an MTP volume. * Tests files display in an MTP volume.
*/ */
testcase.fileDisplayMtp = function() { testcase.fileDisplayMtp = async function() {
var appId;
const MTP_VOLUME_QUERY = '#directory-tree [volume-type-icon="mtp"]'; const MTP_VOLUME_QUERY = '#directory-tree [volume-type-icon="mtp"]';
StepsRunner.run([ // Open Files app on local downloads.
// Open Files app on local downloads. const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); // Mount MTP volume in the Downloads window.
}, await sendTestMessage({name: 'mountFakeMtp'});
// Mount MTP volume in the Downloads window.
function(results) { // Wait for the MTP mount.
appId = results.windowId; await remoteCall.waitForElement(appId, MTP_VOLUME_QUERY);
sendTestMessage({name: 'mountFakeMtp'}).then(this.next);
}, // Click to open the MTP volume.
// Wait for the MTP mount. await remoteCall.callRemoteTestUtil(
function() { 'fakeMouseClick', appId, [MTP_VOLUME_QUERY]);
remoteCall.waitForElement(appId, MTP_VOLUME_QUERY).then(this.next);
}, // Verify the MTP file list.
// Click to open the MTP volume. const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
function() { await remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true});
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [MTP_VOLUME_QUERY], this.next);
},
// Verify the MTP file list.
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true})
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Tests files display in a removable USB volume. * Tests files display in a removable USB volume.
*/ */
testcase.fileDisplayUsb = function() { testcase.fileDisplayUsb = async function() {
var appId;
const USB_VOLUME_QUERY = '#directory-tree [volume-type-icon="removable"]'; const USB_VOLUME_QUERY = '#directory-tree [volume-type-icon="removable"]';
StepsRunner.run([ // Open Files app on local downloads.
// Open Files app on local downloads. const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); // Mount USB volume in the Downloads window.
}, await sendTestMessage({name: 'mountFakeUsb'});
// Mount USB volume in the Downloads window.
function(results) { // Wait for the USB mount.
appId = results.windowId; await remoteCall.waitForElement(appId, USB_VOLUME_QUERY);
sendTestMessage({name: 'mountFakeUsb'}).then(this.next);
}, // Click to open the USB volume.
// Wait for the USB mount. await remoteCall.callRemoteTestUtil(
function() { 'fakeMouseClick', appId, [USB_VOLUME_QUERY]);
remoteCall.waitForElement(appId, USB_VOLUME_QUERY).then(this.next);
}, // Verify the USB file list.
// Click to open the USB volume. const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
function() { await remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true});
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [USB_VOLUME_QUERY], this.next);
},
// Verify the USB file list.
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true})
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
...@@ -281,178 +186,115 @@ testcase.fileDisplayUsb = function() { ...@@ -281,178 +186,115 @@ testcase.fileDisplayUsb = function() {
* @param {Array<Object>} expectedResults The results set. * @param {Array<Object>} expectedResults The results set.
* *
*/ */
function searchDownloads(searchTerm, expectedResults) { async function searchDownloads(searchTerm, expectedResults) {
var appId; // Open Files app on local downloads.
const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
StepsRunner.run([
// Open Files app on local downloads. // Focus the search box.
function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); 'fakeEvent', appId, ['#search-box cr-input', 'focus']));
},
// Focus the search box. // Input a text.
function(results) { await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'inputText', appId, ['#search-box cr-input', searchTerm]);
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next); // Notify the element of the input.
}, chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
// Input a text. 'fakeEvent', appId, ['#search-box cr-input', 'input']));
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil( await remoteCall.waitForFiles(
'inputText', appId, ['#search-box cr-input', searchTerm], this.next); appId, TestEntryInfo.getExpectedRows(expectedResults));
},
// Notify the element of the input.
function() {
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next);
},
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForFiles(appId, TestEntryInfo.getExpectedRows(expectedResults))
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
* Tests case-senstive search for an entry in Downloads. * Tests case-senstive search for an entry in Downloads.
*/ */
testcase.fileSearch = function() { testcase.fileSearch = function() {
searchDownloads('hello', [ENTRIES.hello]); return searchDownloads('hello', [ENTRIES.hello]);
}; };
/** /**
* Tests case-insenstive search for an entry in Downloads. * Tests case-insenstive search for an entry in Downloads.
*/ */
testcase.fileSearchCaseInsensitive = function() { testcase.fileSearchCaseInsensitive = function() {
searchDownloads('HELLO', [ENTRIES.hello]); return searchDownloads('HELLO', [ENTRIES.hello]);
}; };
/** /**
* Tests searching for a string doesn't match anything in Downloads and that * Tests searching for a string doesn't match anything in Downloads and that
* there are no displayed items that match the search string. * there are no displayed items that match the search string.
*/ */
testcase.fileSearchNotFound = function() { testcase.fileSearchNotFound = async function() {
var appId;
var searchTerm = 'blahblah'; var searchTerm = 'blahblah';
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); // Focus the search box.
}, chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
// Focus the search box. 'fakeEvent', appId, ['#search-box cr-input', 'focus']));
function(results) {
appId = results.windowId; // Input a text.
remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next); 'inputText', appId, ['#search-box cr-input', searchTerm]);
},
// Input a text. // Notify the element of the input.
function(result) { await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(result); 'fakeEvent', appId, ['#search-box cr-input', 'input']);
remoteCall.callRemoteTestUtil( const element =
'inputText', appId, ['#search-box cr-input', searchTerm], this.next); await remoteCall.waitForElement(appId, ['#empty-folder-label b']);
}, chrome.test.assertEq(element.text, '\"' + searchTerm + '\"');
// Notify the element of the input.
function() {
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next);
},
function(result) {
remoteCall.waitForElement(appId, ['#empty-folder-label b']).
then(this.next);
},
function(element) {
chrome.test.assertEq(element.text, '\"' + searchTerm + '\"');
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Tests Files app opening without errors when there isn't Downloads which is * Tests Files app opening without errors when there isn't Downloads which is
* the default volume. * the default volume.
*/ */
testcase.fileDisplayWithoutDownloadsVolume = function() { testcase.fileDisplayWithoutDownloadsVolume = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount Downloads volume which the default volume.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountDownloads'});
.then(this.next);
}, // Wait until all volumes are removed.
// Unmount Downloads volume which the default volume. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 2, args);
sendTestMessage({name: 'unmountDownloads'}).then(this.next);
}, // Open Files app without specifying the initial directory/root.
// Wait until all volumes are removed. const appId = await openNewWindow(null, null);
function() { chrome.test.assertTrue(!!appId, 'failed to open new window');
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Wait for Files app to finish loading.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 2, args) await remoteCall.waitFor('isFileManagerLoaded', appId, true);
.then(this.next);
},
// Open Files app without specifying the initial directory/root.
function() {
openNewWindow(null, null, this.next);
},
// Wait for Files app to finish loading.
function(result) {
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result;
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests Files app opening without errors when there are no volumes at all. * Tests Files app opening without errors when there are no volumes at all.
*/ */
testcase.fileDisplayWithoutVolumes = function() { testcase.fileDisplayWithoutVolumes = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount all default volumes.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountAllVolumes'});
.then(this.next);
}, // Wait until all volumes are removed.
// Unmount all default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 0, args);
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
}, // Open Files app without specifying the initial directory/root.
// Wait until all volumes are removed. const appId = await openNewWindow(null, null);
function() { chrome.test.assertTrue(!!appId, 'failed to open new window');
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Wait for Files app to finish loading.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args) await remoteCall.waitFor('isFileManagerLoaded', appId, true);
.then(this.next);
},
// Open Files app without specifying the initial directory/root.
function() {
openNewWindow(null, null, this.next);
},
// Wait for Files app to finish loading.
function(result) {
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result;
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
...@@ -460,60 +302,37 @@ testcase.fileDisplayWithoutVolumes = function() { ...@@ -460,60 +302,37 @@ testcase.fileDisplayWithoutVolumes = function() {
* then mounting Downloads volume which should appear and be able to display its * then mounting Downloads volume which should appear and be able to display its
* files. * files.
*/ */
testcase.fileDisplayWithoutVolumesThenMountDownloads = function() { testcase.fileDisplayWithoutVolumesThenMountDownloads = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount all default volumes.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountAllVolumes'});
.then(this.next);
}, // Wait until all volumes are removed.
// Unmount all default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 0, args);
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
}, // Open Files app without specifying the initial directory/root.
// Wait until all volumes are removed. const appId = await openNewWindow(null, null);
function() { chrome.test.assertTrue(!!appId, 'failed to open new window');
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Wait for Files app to finish loading.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args) await remoteCall.waitFor('isFileManagerLoaded', appId, true);
.then(this.next);
}, // Remount Downloads.
// Open Files app without specifying the initial directory/root. await sendTestMessage({name: 'mountDownloads'});
function() {
openNewWindow(null, null, this.next); // Downloads should appear in My files in the directory tree.
}, await remoteCall.waitForElement(appId, '[volume-type-icon="downloads"]');
// Wait for Files app to finish loading. const downloadsRow = ['Downloads', '--', 'Folder'];
function(result) { const crostiniRow = ['Linux files', '--', 'Folder'];
chrome.test.assertTrue(!!result, 'failed to open new window'); await remoteCall.waitForFiles(
appId = result; appId, [downloadsRow, crostiniRow],
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next); {ignoreFileSize: true, ignoreLastModifiedTime: true});
},
// Remount Downloads.
function() {
sendTestMessage({name: 'mountDownloads'}).then(this.next);
},
// Downloads should appear in My files in the directory tree.
function() {
remoteCall.waitForElement(appId, '[volume-type-icon="downloads"]')
.then(this.next);
},
function() {
const downloadsRow = ['Downloads', '--', 'Folder'];
const crostiniRow = ['Linux files', '--', 'Folder'];
remoteCall
.waitForFiles(
appId, [downloadsRow, crostiniRow],
{ignoreFileSize: true, ignoreLastModifiedTime: true})
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
...@@ -521,322 +340,202 @@ testcase.fileDisplayWithoutVolumesThenMountDownloads = function() { ...@@ -521,322 +340,202 @@ testcase.fileDisplayWithoutVolumesThenMountDownloads = function() {
* then mounting Drive volume which should appear and be able to display its * then mounting Drive volume which should appear and be able to display its
* files. * files.
*/ */
testcase.fileDisplayWithoutVolumesThenMountDrive = function() { testcase.fileDisplayWithoutVolumesThenMountDrive = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount all default volumes.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountAllVolumes'});
.then(this.next);
}, // Wait until all volumes are removed.
// Unmount all default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 0, args);
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
}, // Open Files app without specifying the initial directory/root.
// Wait until all volumes are removed. const appId = await openNewWindow(null, null);
function() { chrome.test.assertTrue(!!appId, 'failed to open new window');
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Wait for Files app to finish loading.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args) await remoteCall.waitFor('isFileManagerLoaded', appId, true);
.then(this.next);
}, // Navigate to the Drive FakeItem.
// Open Files app without specifying the initial directory/root. await remoteCall.callRemoteTestUtil(
function() { 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
openNewWindow(null, null, this.next);
}, // The fake Google Drive should be empty.
// Wait for Files app to finish loading. await remoteCall.waitForFiles(appId, []);
function(result) {
chrome.test.assertTrue(!!result, 'failed to open new window'); // Remount Drive. The curent directory should be changed from the Google
appId = result; // Drive FakeItem to My Drive.
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next); await sendTestMessage({name: 'mountDrive'});
},
// Navigate to the Drive FakeItem. // Add an entry to Drive.
function() { await addEntries(['drive'], [ENTRIES.newlyAdded]);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next); // Wait for "My Drive" files to display in the file list.
}, await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
// The fake Google Drive should be empty.
function() {
remoteCall.waitForFiles(appId, []).then(this.next);
},
// Remount Drive. The curent directory should be changed from the Google
// Drive FakeItem to My Drive.
function() {
sendTestMessage({name: 'mountDrive'}).then(this.next);
},
// Add an entry to Drive.
function() {
addEntries(['drive'], [ENTRIES.newlyAdded], this.next);
},
// Wait for "My Drive" files to display in the file list.
function() {
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests Files app opening without Drive mounted. * Tests Files app opening without Drive mounted.
*/ */
testcase.fileDisplayWithoutDrive = function() { testcase.fileDisplayWithoutDrive = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount all default volumes.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountAllVolumes'});
.then(this.next);
}, // Remount Downloads.
// Unmount all default volumes. await sendTestMessage({name: 'mountDownloads'});
function() {
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next); // Wait until downloads is re-added
}, await remoteCall.waitFor(
// Remount Downloads. 'getVolumesCount', null, (count) => count === 1, args);
function() {
sendTestMessage({name: 'mountDownloads'}).then(this.next); // Open the files app.
}, const {appId} = await setupAndWaitUntilReady(
// Wait until downloads is re-added null, RootPath.DOWNLOADS, null, [ENTRIES.newlyAdded], []);
function() {
const args = []; // Wait for the loading indicator blink to finish.
// appId is still null, but isn't needed for getVolumesCount. await remoteCall.waitForElement(
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 1, args) appId, '#list-container paper-progress[hidden]');
.then(this.next);
}, // Navigate to Drive.
// Open the files app. await remoteCall.callRemoteTestUtil(
function() { 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
setupAndWaitUntilReady( await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Google Drive');
null, RootPath.DOWNLOADS, this.next, [ENTRIES.newlyAdded], []);
}, // The fake Google Drive should be empty.
// Wait for the loading indicator blink to finish. await remoteCall.waitForFiles(appId, []);
function(result) {
appId = result.windowId; // The loading indicator should be visible and remain visible forever.
remoteCall.waitForElement(appId, '#list-container paper-progress[hidden]') await remoteCall.waitForElement(
.then(this.next); appId, '#list-container paper-progress:not([hidden])');
},
// Navigate to Drive.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next);
},
function() {
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Google Drive')
.then(this.next);
},
// The fake Google Drive should be empty.
function() {
remoteCall.waitForFiles(appId, []).then(this.next);
},
// The loading indicator should be visible and remain visible forever.
function() {
remoteCall
.waitForElement(appId, '#list-container paper-progress:not([hidden])')
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests Files app opening without Drive mounted and then disabling and * Tests Files app opening without Drive mounted and then disabling and
* re-enabling Drive. * re-enabling Drive.
*/ */
testcase.fileDisplayWithoutDriveThenDisable = function() { testcase.fileDisplayWithoutDriveThenDisable = async function() {
let appId = null; // Wait for the Files app background page to mount the default volumes.
const args = [];
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. await remoteCall.waitFor(
function() { 'getVolumesCount', null, (count) => count === 3, args);
const args = [];
// appId is still null, but isn't needed for getVolumesCount. // Unmount all default volumes.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await sendTestMessage({name: 'unmountAllVolumes'});
.then(this.next);
}, // Remount Downloads.
// Unmount all default volumes. await sendTestMessage({name: 'mountDownloads'});
function() {
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next); // Add a file to Downloads.
}, await addEntries(['local'], [ENTRIES.newlyAdded]);
// Remount Downloads.
function() { // Wait until all volumes are removed.
sendTestMessage({name: 'mountDownloads'}).then(this.next); await remoteCall.waitFor(
}, 'getVolumesCount', null, (count) => count === 1, args);
// Add a file to Downloads.
function() { // Open Files app without specifying the initial directory/root.
addEntries(['local'], [ENTRIES.newlyAdded], this.next); const appId = await openNewWindow(null, null);
}, chrome.test.assertTrue(!!appId, 'failed to open new window');
// Wait until all volumes are removed.
function() { // Wait for Files app to finish loading.
const args = []; await remoteCall.waitFor('isFileManagerLoaded', appId, true);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 1, args) // Ensure Downloads has loaded.
.then(this.next); await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
},
// Open Files app without specifying the initial directory/root. // Navigate to Drive.
function() { await remoteCall.callRemoteTestUtil(
openNewWindow(null, null, this.next); 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
},
// Wait for Files app to finish loading. // The fake Google Drive should be empty.
function(result) { await remoteCall.waitForFiles(appId, []);
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result; // Disable Drive.
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next); await sendTestMessage({name: 'setDriveEnabled', enabled: false});
},
// Ensure Downloads has loaded. // The current directory should change to the default (Downloads).
function() { await remoteCall.waitUntilCurrentDirectoryIsChanged(
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]) appId, '/My files/Downloads');
.then(this.next);
}, // Ensure Downloads has loaded.
// Navigate to Drive. await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
function() {
remoteCall.callRemoteTestUtil( // Re-enabled Drive.
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next); await sendTestMessage({name: 'setDriveEnabled', enabled: true});
},
// The fake Google Drive should be empty. // Wait for the fake drive to reappear.
function() { await remoteCall.waitForElement(appId, ['[root-type-icon=\'drive\']']);
remoteCall.waitForFiles(appId, []).then(this.next);
},
// Disable Drive.
function() {
sendTestMessage({name: 'setDriveEnabled', enabled: false})
.then(this.next);
},
// The current directory should change to the default (Downloads).
function() {
remoteCall
.waitUntilCurrentDirectoryIsChanged(appId, '/My files/Downloads')
.then(this.next);
},
// Ensure Downloads has loaded.
function() {
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
// Re-enabled Drive.
function() {
sendTestMessage({name: 'setDriveEnabled', enabled: true}).then(this.next);
},
// Wait for the fake drive to reappear.
function() {
remoteCall.waitForElement(appId, ['[root-type-icon=\'drive\']'])
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests Files app resisting the urge to switch to Downloads when mounts change. * Tests Files app resisting the urge to switch to Downloads when mounts change.
* re-enabling Drive. * re-enabling Drive.
*/ */
testcase.fileDisplayMountWithFakeItemSelected = function() { testcase.fileDisplayMountWithFakeItemSelected = async function() {
let appId = null; // Open Files app on Drive with the given test files.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DOWNLOADS, null, [ENTRIES.newlyAdded], []);
// Open Files app on Drive with the given test files.
function() { // Ensure Downloads has loaded.
setupAndWaitUntilReady( await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.newlyAdded], []);
}, // Navigate to My files.
// Ensure Downloads has loaded. await remoteCall.callRemoteTestUtil(
function(result) { 'fakeMouseClick', appId, ['[root-type-icon=\'my_files\']']);
appId = result.windowId;
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]) // Wait for the navigation to complete.
.then(this.next); await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files');
},
// Navigate to My files. // Mount a USB drive.
function() { await sendTestMessage({name: 'mountFakeUsbEmpty'});
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['[root-type-icon=\'my_files\']'], // Wait for the mount to appear.
this.next); await remoteCall.waitForElement(
}, appId, ['#directory-tree [volume-type-icon="removable"]']);
// Wait for the navigation to complete. chrome.test.assertEq(
function() { '/My files',
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files') await remoteCall.callRemoteTestUtil('getBreadcrumbPath', appId, []));
.then(this.next);
},
// Mount a USB drive.
function() {
sendTestMessage({name: 'mountFakeUsbEmpty'}).then(this.next);
},
// Wait for the mount to appear.
function() {
remoteCall
.waitForElement(
appId, ['#directory-tree [volume-type-icon="removable"]'])
.then(this.next);
},
function() {
remoteCall.callRemoteTestUtil('getBreadcrumbPath', appId, [])
.then(this.next);
},
function(path) {
chrome.test.assertEq('/My files', path);
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests Files app switching away from Drive virtual folders when Drive is * Tests Files app switching away from Drive virtual folders when Drive is
* unmounted. * unmounted.
*/ */
testcase.fileDisplayUnmountDriveWithSharedWithMeSelected = function() { testcase.fileDisplayUnmountDriveWithSharedWithMeSelected = async function() {
let appId = null; // Open Files app on Drive with the given test files.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DRIVE, null, [ENTRIES.newlyAdded],
// Open Files app on Drive with the given test files. [ENTRIES.testSharedDocument, ENTRIES.hello]);
function() {
setupAndWaitUntilReady( // Navigate to Shared with me.
null, RootPath.DRIVE, this.next, [ENTRIES.newlyAdded], await remoteCall.callRemoteTestUtil(
[ENTRIES.testSharedDocument, ENTRIES.hello]); 'fakeMouseClick', appId, ['[volume-type-icon=\'drive_shared_with_me\']']);
},
// Navigate to Shared with me. // Wait for the navigation to complete.
function(result) { await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Shared with me');
appId = result.windowId;
remoteCall.callRemoteTestUtil( // Check that the file is visible.
'fakeMouseClick', appId, await remoteCall.waitForFiles(
['[volume-type-icon=\'drive_shared_with_me\']'], this.next); appId, [ENTRIES.testSharedDocument.getExpectedRow()]);
},
// Wait for the navigation to complete. // Unmount drive.
function() { await sendTestMessage({name: 'unmountDrive'});
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Shared with me')
.then(this.next); // We should navigate to Downloads.
}, await remoteCall.waitUntilCurrentDirectoryIsChanged(
// Check that the file is visible. appId, '/My files/Downloads');
function() {
remoteCall // Which should contain a file.
.waitForFiles(appId, [ENTRIES.testSharedDocument.getExpectedRow()]) await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
.then(this.next);
},
// Unmount drive.
function() {
sendTestMessage({name: 'unmountDrive'}).then(this.next);
},
// We should navigate to Downloads.
function() {
remoteCall
.waitUntilCurrentDirectoryIsChanged(appId, '/My files/Downloads')
.then(this.next);
},
// Which should contain a file.
function() {
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
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