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,92 +10,67 @@ ...@@ -11,92 +10,67 @@
* @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.
function() { const {appId, fileList} = await setupAndWaitUntilReady(null, path, null);
setupAndWaitUntilReady(null, path, this.next);
},
// Verify the default file list is present in |result|. // Verify the default file list is present in |result|.
function(result) { chrome.test.assertEq(defaultList, fileList);
appId = result.windowId;
chrome.test.assertEq(defaultList, result.fileList);
this.next();
},
// Add new file entries. // Add new file entries.
function() { await addEntries(['local', 'drive'], [ENTRIES.newlyAdded]);
addEntries(['local', 'drive'], [ENTRIES.newlyAdded], this.next);
},
// Verify the newly added entries appear in the file list. // Verify the newly added entries appear in the file list.
function() {
const expectedList = const expectedList =
defaultList.concat([ENTRIES.newlyAdded.getExpectedRow()]); defaultList.concat([ENTRIES.newlyAdded.getExpectedRow()]);
remoteCall.waitForFiles(appId, expectedList).then(this.next); await remoteCall.waitForFiles(appId, expectedList);
},
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.
function() { const {appId} =
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next, [], driveFiles); await setupAndWaitUntilReady(null, RootPath.DRIVE, null, [], driveFiles);
},
// Retrieve all file list entries that could be rendered 'offline'. // Retrieve all file list entries that could be rendered 'offline'.
function(result) {
appId = result.windowId;
const offlineEntry = '#file-list .table-row.file.dim-offline'; const offlineEntry = '#file-list .table-row.file.dim-offline';
remoteCall.callRemoteTestUtil( let elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, [offlineEntry, ['opacity']], this.next); 'queryAllElements', appId, [offlineEntry, ['opacity']]);
},
// Check: the hello.txt file only should be rendered 'offline'. // Check: the hello.txt file only should be rendered 'offline'.
function(elements) {
chrome.test.assertEq(1, elements.length); chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('hello.txt')); chrome.test.assertEq(0, elements[0].text.indexOf('hello.txt'));
this.next(elements[0].styles);
},
// Check: hello.txt must have 'offline' CSS render style (opacity). // Check: hello.txt must have 'offline' CSS render style (opacity).
function(style) { chrome.test.assertEq('0.4', elements[0].styles.opacity);
chrome.test.assertEq('0.4', style.opacity);
this.next();
},
// Retrieve file entries that are 'available offline' (not dimmed). // Retrieve file entries that are 'available offline' (not dimmed).
function() {
const availableEntry = '#file-list .table-row:not(.dim-offline)'; const availableEntry = '#file-list .table-row:not(.dim-offline)';
remoteCall.callRemoteTestUtil( elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, [availableEntry, ['opacity']], this.next); 'queryAllElements', appId, [availableEntry, ['opacity']]);
},
// Check: these files should have 'available offline' CSS style. // Check: these files should have 'available offline' CSS style.
function(elements) {
chrome.test.assertEq(3, elements.length); chrome.test.assertEq(3, elements.length);
function checkRenderedInAvailableOfflineStyle(element, fileName) { function checkRenderedInAvailableOfflineStyle(element, fileName) {
...@@ -112,45 +86,25 @@ testcase.fileDisplayDriveOffline = function() { ...@@ -112,45 +86,25 @@ testcase.fileDisplayDriveOffline = function() {
// Pinned files are shown as 'available offline'. // Pinned files are shown as 'available offline'.
checkRenderedInAvailableOfflineStyle(elements[2], 'pinned'); 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;
StepsRunner.run([
// Open Files app on Drive. // Open Files app on Drive.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DRIVE, null, [], BASIC_DRIVE_ENTRY_SET);
null, RootPath.DRIVE, this.next, [], BASIC_DRIVE_ENTRY_SET);
},
// Retrieve all file list row entries. // Retrieve all file list row entries.
function(result) {
appId = result.windowId;
const fileEntry = '#file-list .table-row'; const fileEntry = '#file-list .table-row';
remoteCall.callRemoteTestUtil( const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, [fileEntry, ['opacity']], this.next); 'queryAllElements', appId, [fileEntry, ['opacity']]);
},
// Check: all files must have 'online' CSS style (not dimmed). // Check: all files must have 'online' CSS style (not dimmed).
function(elements) {
chrome.test.assertEq(BASIC_DRIVE_ENTRY_SET.length, elements.length); chrome.test.assertEq(BASIC_DRIVE_ENTRY_SET.length, elements.length);
for (let i = 0; i < elements.length; ++i) for (let i = 0; i < elements.length; ++i)
chrome.test.assertEq('1', elements[i].styles.opacity); 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;
StepsRunner.run([
// Open Files app on Drive with Computers registered. // Open Files app on Drive with Computers registered.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DRIVE, null, [], COMPUTERS_ENTRY_SET);
null, RootPath.DRIVE, this.next, [], COMPUTERS_ENTRY_SET);
},
function(result) {
appId = result.windowId;
// Navigate to Comuter Grand Root. // Navigate to Comuter Grand Root.
return remoteCall await remoteCall.navigateWithDirectoryTree(appId, '/Computers', 'Computers');
.navigateWithDirectoryTree(appId, '/Computers', 'Computers')
.then(this.next);
},
function() {
// Navigiate to a Computer Root. // Navigiate to a Computer Root.
return remoteCall await remoteCall.navigateWithDirectoryTree(
.navigateWithDirectoryTree( appId, '/Computers/Computer A', 'Computers');
appId, '/Computers/Computer A', 'Computers')
.then(this.next);
},
function() {
// Navigiate to a subdirectory under a Computer Root. // Navigiate to a subdirectory under a Computer Root.
return remoteCall await remoteCall.navigateWithDirectoryTree(
.navigateWithDirectoryTree( appId, '/Computers/Computer A/A', 'Computers');
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.
function() { const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Mount MTP volume in the Downloads window. // Mount MTP volume in the Downloads window.
function(results) { await sendTestMessage({name: 'mountFakeMtp'});
appId = results.windowId;
sendTestMessage({name: 'mountFakeMtp'}).then(this.next);
},
// Wait for the MTP mount. // Wait for the MTP mount.
function() { await remoteCall.waitForElement(appId, MTP_VOLUME_QUERY);
remoteCall.waitForElement(appId, MTP_VOLUME_QUERY).then(this.next);
},
// Click to open the MTP volume. // Click to open the MTP volume.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, [MTP_VOLUME_QUERY]);
'fakeMouseClick', appId, [MTP_VOLUME_QUERY], this.next);
},
// Verify the MTP file list. // Verify the MTP file list.
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET); const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true}) await 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.
function() { const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Mount USB volume in the Downloads window. // Mount USB volume in the Downloads window.
function(results) { await sendTestMessage({name: 'mountFakeUsb'});
appId = results.windowId;
sendTestMessage({name: 'mountFakeUsb'}).then(this.next);
},
// Wait for the USB mount. // Wait for the USB mount.
function() { await remoteCall.waitForElement(appId, USB_VOLUME_QUERY);
remoteCall.waitForElement(appId, USB_VOLUME_QUERY).then(this.next);
},
// Click to open the USB volume. // Click to open the USB volume.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, [USB_VOLUME_QUERY]);
'fakeMouseClick', appId, [USB_VOLUME_QUERY], this.next);
},
// Verify the USB file list. // Verify the USB file list.
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET); const files = TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET);
remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true}) await 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;
StepsRunner.run([
// Open Files app on local downloads. // Open Files app on local downloads.
function() { const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Focus the search box. // Focus the search box.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'fakeEvent', appId, ['#search-box cr-input', 'focus']));
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next);
},
// Input a text. // Input a text.
function(result) { await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(result); 'inputText', appId, ['#search-box cr-input', searchTerm]);
remoteCall.callRemoteTestUtil(
'inputText', appId, ['#search-box cr-input', searchTerm], this.next);
},
// Notify the element of the input. // Notify the element of the input.
function() { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeEvent', appId, ['#search-box cr-input', 'input']));
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next);
},
function(result) { await remoteCall.waitForFiles(
chrome.test.assertTrue(!!result); appId, TestEntryInfo.getExpectedRows(expectedResults));
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. // Focus the search box.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'fakeEvent', appId, ['#search-box cr-input', 'focus']));
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next);
},
// Input a text. // Input a text.
function(result) { await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(result); 'inputText', appId, ['#search-box cr-input', searchTerm]);
remoteCall.callRemoteTestUtil(
'inputText', appId, ['#search-box cr-input', searchTerm], this.next);
},
// Notify the element of the input. // Notify the element of the input.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeEvent', appId, ['#search-box cr-input', 'input']);
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next); const element =
}, await remoteCall.waitForElement(appId, ['#empty-folder-label b']);
function(result) {
remoteCall.waitForElement(appId, ['#empty-folder-label b']).
then(this.next);
},
function(element) {
chrome.test.assertEq(element.text, '\"' + searchTerm + '\"'); 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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount Downloads volume which the default volume. // Unmount Downloads volume which the default volume.
function() { await sendTestMessage({name: 'unmountDownloads'});
sendTestMessage({name: 'unmountDownloads'}).then(this.next);
},
// Wait until all volumes are removed. // Wait until all volumes are removed.
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 2, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 2, args)
.then(this.next);
},
// Open Files app without specifying the initial directory/root. // Open Files app without specifying the initial directory/root.
function() { const appId = await openNewWindow(null, null);
openNewWindow(null, null, this.next); chrome.test.assertTrue(!!appId, 'failed to open new window');
},
// Wait for Files app to finish loading. // Wait for Files app to finish loading.
function(result) { await remoteCall.waitFor('isFileManagerLoaded', appId, true);
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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount all default volumes. // Unmount all default volumes.
function() { await sendTestMessage({name: 'unmountAllVolumes'});
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
},
// Wait until all volumes are removed. // Wait until all volumes are removed.
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 0, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args)
.then(this.next);
},
// Open Files app without specifying the initial directory/root. // Open Files app without specifying the initial directory/root.
function() { const appId = await openNewWindow(null, null);
openNewWindow(null, null, this.next); chrome.test.assertTrue(!!appId, 'failed to open new window');
},
// Wait for Files app to finish loading. // Wait for Files app to finish loading.
function(result) { await remoteCall.waitFor('isFileManagerLoaded', appId, true);
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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount all default volumes. // Unmount all default volumes.
function() { await sendTestMessage({name: 'unmountAllVolumes'});
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
},
// Wait until all volumes are removed. // Wait until all volumes are removed.
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 0, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args)
.then(this.next);
},
// Open Files app without specifying the initial directory/root. // Open Files app without specifying the initial directory/root.
function() { const appId = await openNewWindow(null, null);
openNewWindow(null, null, this.next); chrome.test.assertTrue(!!appId, 'failed to open new window');
},
// Wait for Files app to finish loading. // Wait for Files app to finish loading.
function(result) { await remoteCall.waitFor('isFileManagerLoaded', appId, true);
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result;
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next);
},
// Remount Downloads. // Remount Downloads.
function() { await sendTestMessage({name: 'mountDownloads'});
sendTestMessage({name: 'mountDownloads'}).then(this.next);
},
// Downloads should appear in My files in the directory tree. // Downloads should appear in My files in the directory tree.
function() { await remoteCall.waitForElement(appId, '[volume-type-icon="downloads"]');
remoteCall.waitForElement(appId, '[volume-type-icon="downloads"]')
.then(this.next);
},
function() {
const downloadsRow = ['Downloads', '--', 'Folder']; const downloadsRow = ['Downloads', '--', 'Folder'];
const crostiniRow = ['Linux files', '--', 'Folder']; const crostiniRow = ['Linux files', '--', 'Folder'];
remoteCall await remoteCall.waitForFiles(
.waitForFiles(
appId, [downloadsRow, crostiniRow], appId, [downloadsRow, crostiniRow],
{ignoreFileSize: true, ignoreLastModifiedTime: true}) {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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount all default volumes. // Unmount all default volumes.
function() { await sendTestMessage({name: 'unmountAllVolumes'});
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
},
// Wait until all volumes are removed. // Wait until all volumes are removed.
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 0, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 0, args)
.then(this.next);
},
// Open Files app without specifying the initial directory/root. // Open Files app without specifying the initial directory/root.
function() { const appId = await openNewWindow(null, null);
openNewWindow(null, null, this.next); chrome.test.assertTrue(!!appId, 'failed to open new window');
},
// Wait for Files app to finish loading. // Wait for Files app to finish loading.
function(result) { await remoteCall.waitFor('isFileManagerLoaded', appId, true);
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result;
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next);
},
// Navigate to the Drive FakeItem. // Navigate to the Drive FakeItem.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next);
},
// The fake Google Drive should be empty. // The fake Google Drive should be empty.
function() { await remoteCall.waitForFiles(appId, []);
remoteCall.waitForFiles(appId, []).then(this.next);
},
// Remount Drive. The curent directory should be changed from the Google // Remount Drive. The curent directory should be changed from the Google
// Drive FakeItem to My Drive. // Drive FakeItem to My Drive.
function() { await sendTestMessage({name: 'mountDrive'});
sendTestMessage({name: 'mountDrive'}).then(this.next);
},
// Add an entry to Drive. // Add an entry to Drive.
function() { await addEntries(['drive'], [ENTRIES.newlyAdded]);
addEntries(['drive'], [ENTRIES.newlyAdded], this.next);
},
// Wait for "My Drive" files to display in the file list. // Wait for "My Drive" files to display in the file list.
function() { await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount all default volumes. // Unmount all default volumes.
function() { await sendTestMessage({name: 'unmountAllVolumes'});
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
},
// Remount Downloads. // Remount Downloads.
function() { await sendTestMessage({name: 'mountDownloads'});
sendTestMessage({name: 'mountDownloads'}).then(this.next);
},
// Wait until downloads is re-added // Wait until downloads is re-added
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 1, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 1, args)
.then(this.next);
},
// Open the files app. // Open the files app.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.newlyAdded], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.newlyAdded], []);
},
// Wait for the loading indicator blink to finish. // Wait for the loading indicator blink to finish.
function(result) { await remoteCall.waitForElement(
appId = result.windowId; appId, '#list-container paper-progress[hidden]');
remoteCall.waitForElement(appId, '#list-container paper-progress[hidden]')
.then(this.next);
},
// Navigate to Drive. // Navigate to Drive.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next); await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Google Drive');
},
function() {
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Google Drive')
.then(this.next);
},
// The fake Google Drive should be empty. // The fake Google Drive should be empty.
function() { await remoteCall.waitForFiles(appId, []);
remoteCall.waitForFiles(appId, []).then(this.next);
},
// The loading indicator should be visible and remain visible forever. // The loading indicator should be visible and remain visible forever.
function() { await remoteCall.waitForElement(
remoteCall appId, '#list-container paper-progress:not([hidden])');
.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;
StepsRunner.run([
// Wait for the Files app background page to mount the default volumes. // Wait for the Files app background page to mount the default volumes.
function() {
const args = []; const args = [];
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 3, args) await remoteCall.waitFor(
.then(this.next); 'getVolumesCount', null, (count) => count === 3, args);
},
// Unmount all default volumes. // Unmount all default volumes.
function() { await sendTestMessage({name: 'unmountAllVolumes'});
sendTestMessage({name: 'unmountAllVolumes'}).then(this.next);
},
// Remount Downloads. // Remount Downloads.
function() { await sendTestMessage({name: 'mountDownloads'});
sendTestMessage({name: 'mountDownloads'}).then(this.next);
},
// Add a file to Downloads. // Add a file to Downloads.
function() { await addEntries(['local'], [ENTRIES.newlyAdded]);
addEntries(['local'], [ENTRIES.newlyAdded], this.next);
},
// Wait until all volumes are removed. // Wait until all volumes are removed.
function() { await remoteCall.waitFor(
const args = []; 'getVolumesCount', null, (count) => count === 1, args);
// appId is still null, but isn't needed for getVolumesCount.
remoteCall.waitFor('getVolumesCount', appId, (count) => count === 1, args)
.then(this.next);
},
// Open Files app without specifying the initial directory/root. // Open Files app without specifying the initial directory/root.
function() { const appId = await openNewWindow(null, null);
openNewWindow(null, null, this.next); chrome.test.assertTrue(!!appId, 'failed to open new window');
},
// Wait for Files app to finish loading. // Wait for Files app to finish loading.
function(result) { await remoteCall.waitFor('isFileManagerLoaded', appId, true);
chrome.test.assertTrue(!!result, 'failed to open new window');
appId = result;
remoteCall.waitFor('isFileManagerLoaded', appId, true).then(this.next);
},
// Ensure Downloads has loaded. // Ensure Downloads has loaded.
function() { await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
// Navigate to Drive. // Navigate to Drive.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['[root-type-icon=\'drive\']']);
'fakeMouseClick', appId, ['[root-type-icon=\'drive\']'], this.next);
},
// The fake Google Drive should be empty. // The fake Google Drive should be empty.
function() { await remoteCall.waitForFiles(appId, []);
remoteCall.waitForFiles(appId, []).then(this.next);
},
// Disable Drive. // Disable Drive.
function() { await sendTestMessage({name: 'setDriveEnabled', enabled: false});
sendTestMessage({name: 'setDriveEnabled', enabled: false})
.then(this.next);
},
// The current directory should change to the default (Downloads). // The current directory should change to the default (Downloads).
function() { await remoteCall.waitUntilCurrentDirectoryIsChanged(
remoteCall appId, '/My files/Downloads');
.waitUntilCurrentDirectoryIsChanged(appId, '/My files/Downloads')
.then(this.next);
},
// Ensure Downloads has loaded. // Ensure Downloads has loaded.
function() { await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
// Re-enabled Drive. // Re-enabled Drive.
function() { await sendTestMessage({name: 'setDriveEnabled', enabled: true});
sendTestMessage({name: 'setDriveEnabled', enabled: true}).then(this.next);
},
// Wait for the fake drive to reappear. // Wait for the fake drive to reappear.
function() { await remoteCall.waitForElement(appId, ['[root-type-icon=\'drive\']']);
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;
StepsRunner.run([
// Open Files app on Drive with the given test files. // Open Files app on Drive with the given test files.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.newlyAdded], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.newlyAdded], []);
},
// Ensure Downloads has loaded. // Ensure Downloads has loaded.
function(result) { await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
appId = result.windowId;
remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()])
.then(this.next);
},
// Navigate to My files. // Navigate to My files.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['[root-type-icon=\'my_files\']']);
'fakeMouseClick', appId, ['[root-type-icon=\'my_files\']'],
this.next);
},
// Wait for the navigation to complete. // Wait for the navigation to complete.
function() { await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files');
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files')
.then(this.next);
},
// Mount a USB drive. // Mount a USB drive.
function() { await sendTestMessage({name: 'mountFakeUsbEmpty'});
sendTestMessage({name: 'mountFakeUsbEmpty'}).then(this.next);
},
// Wait for the mount to appear. // Wait for the mount to appear.
function() { await remoteCall.waitForElement(
remoteCall appId, ['#directory-tree [volume-type-icon="removable"]']);
.waitForElement( chrome.test.assertEq(
appId, ['#directory-tree [volume-type-icon="removable"]']) '/My files',
.then(this.next); await remoteCall.callRemoteTestUtil('getBreadcrumbPath', appId, []));
},
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;
StepsRunner.run([
// Open Files app on Drive with the given test files. // Open Files app on Drive with the given test files.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DRIVE, null, [ENTRIES.newlyAdded],
null, RootPath.DRIVE, this.next, [ENTRIES.newlyAdded],
[ENTRIES.testSharedDocument, ENTRIES.hello]); [ENTRIES.testSharedDocument, ENTRIES.hello]);
},
// Navigate to Shared with me. // Navigate to Shared with me.
function(result) { await remoteCall.callRemoteTestUtil(
appId = result.windowId; 'fakeMouseClick', appId, ['[volume-type-icon=\'drive_shared_with_me\']']);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['[volume-type-icon=\'drive_shared_with_me\']'], this.next);
},
// Wait for the navigation to complete. // Wait for the navigation to complete.
function() { await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Shared with me');
remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Shared with me')
.then(this.next);
},
// Check that the file is visible. // Check that the file is visible.
function() { await remoteCall.waitForFiles(
remoteCall appId, [ENTRIES.testSharedDocument.getExpectedRow()]);
.waitForFiles(appId, [ENTRIES.testSharedDocument.getExpectedRow()])
.then(this.next);
},
// Unmount drive. // Unmount drive.
function() { await sendTestMessage({name: 'unmountDrive'});
sendTestMessage({name: 'unmountDrive'}).then(this.next);
},
// We should navigate to Downloads. // We should navigate to Downloads.
function() { await remoteCall.waitUntilCurrentDirectoryIsChanged(
remoteCall appId, '/My files/Downloads');
.waitUntilCurrentDirectoryIsChanged(appId, '/My files/Downloads')
.then(this.next);
},
// Which should contain a file. // Which should contain a file.
function() { await remoteCall.waitForFiles(appId, [ENTRIES.newlyAdded.getExpectedRow()]);
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