Commit 0c155df8 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert some more smaller files app tests to use async-await.

Convert:
- open_image_files.js
- restore_geometry.js
- restore_prefs.js

Bug: 909056
Change-Id: Idc4c7636b0192878d62aa455ef096a032afed610
Reviewed-on: https://chromium-review.googlesource.com/c/1353067
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612142}
parent 21f4d4cc
......@@ -11,46 +11,25 @@
*
* @param {string} path Directory path (Downloads or Drive).
*/
function imageOpen(path) {
let appId;
let galleryAppId;
StepsRunner.run([
async function imageOpen(path) {
// Open Files.App on |path|, add image3 to Downloads and Drive.
function() {
setupAndWaitUntilReady(
null, path, this.next, [ENTRIES.image3], [ENTRIES.image3]);
},
const {appId} = await setupAndWaitUntilReady(
null, path, null, [ENTRIES.image3], [ENTRIES.image3]);
// Open the image file in Files app.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.image3.targetPath], this.next);
},
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.image3.targetPath]));
// Check: the Gallery window should open.
function(result) {
chrome.test.assertTrue(result);
galleryApp.waitForWindow('gallery.html').then(this.next);
},
const galleryAppId = await galleryApp.waitForWindow('gallery.html');
// Check: the image should appear in the Gallery window.
function(windowId) {
galleryAppId = windowId;
galleryApp.waitForSlideImage(
galleryAppId, 640, 480, 'image3').then(this.next);
},
await galleryApp.waitForSlideImage(galleryAppId, 640, 480, 'image3');
// Close the Gallery window.
function() {
galleryApp.closeWindowAndWait(galleryAppId).then(this.next);
},
// Check: the Gallery window should close.
function(result) {
chrome.test.assertTrue(result, 'Failed to close Gallery window');
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
chrome.test.assertTrue(
await galleryApp.closeWindowAndWait(galleryAppId),
'Failed to close Gallery window');
}
/**
......@@ -59,80 +38,57 @@ function imageOpen(path) {
*
* @param {string} path Directory path (Downloads or Drive).
*/
function imageOpenGalleryOpen(path) {
let appId;
let galleryAppId;
async function imageOpenGalleryOpen(path) {
const testImages = [ENTRIES.image3, ENTRIES.desktop];
StepsRunner.run([
// Open Files.App on |path|, add test images to Downloads and Drive.
function() {
setupAndWaitUntilReady(null, path, this.next, testImages, testImages);
},
const {appId} =
await setupAndWaitUntilReady(null, path, null, testImages, testImages);
// Open an image file in Files app.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.image3.targetPath], this.next);
},
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.image3.targetPath]));
// Wait a11y-msg to have some text.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '#a11y-msg:not(:empty)').then(this.next);
},
await remoteCall.waitForElement(appId, '#a11y-msg:not(:empty)');
// Fetch A11y messages.
function() {
remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, [])
.then(this.next);
},
const a11yMessages =
await remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []);
// Check that opening the file was announced to screen reader.
function(a11yMessages) {
chrome.test.assertTrue(a11yMessages instanceof Array);
chrome.test.assertEq(1, a11yMessages.length);
chrome.test.assertEq('Opening file image3.jpg.', a11yMessages[0]);
this.next();
},
// Check: the Gallery window should open.
function() {
galleryApp.waitForWindow('gallery.html').then(this.next);
},
const galleryAppId = await galleryApp.waitForWindow('gallery.html');
// Check: the image should appear in the Gallery window.
function(windowId) {
galleryAppId = windowId;
galleryApp.waitForSlideImage(
galleryAppId, 640, 480, 'image3').then(this.next);
},
await galleryApp.waitForSlideImage(galleryAppId, 640, 480, 'image3');
// Now open a different image file in Files app.
function() {
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.desktop.targetPath], this.next);
},
await remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.desktop.targetPath]);
// Check: the new image should appear in the Gallery window.
function() {
galleryApp.waitForSlideImage(
galleryAppId, 800, 600, 'My Desktop Background').then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await galleryApp.waitForSlideImage(
galleryAppId, 800, 600, 'My Desktop Background');
}
testcase.imageOpenDownloads = function() {
imageOpen(RootPath.DOWNLOADS);
return imageOpen(RootPath.DOWNLOADS);
};
testcase.imageOpenDrive = function() {
imageOpen(RootPath.DRIVE);
return imageOpen(RootPath.DRIVE);
};
testcase.imageOpenGalleryOpenDownloads = function() {
imageOpenGalleryOpen(RootPath.DOWNLOADS);
return imageOpenGalleryOpen(RootPath.DOWNLOADS);
};
testcase.imageOpenGalleryOpenDrive = function() {
imageOpenGalleryOpen(RootPath.DRIVE);
return imageOpenGalleryOpen(RootPath.DRIVE);
};
})();
......@@ -7,101 +7,60 @@
/**
* Tests restoring window geometry of the Files app.
*/
testcase.restoreGeometry = function() {
var appId;
var appId2;
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
testcase.restoreGeometry = async function() {
// Set up Files app.
let {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Resize the window to minimal dimensions.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'resizeWindow', appId, [640, 480], this.next);
},
await remoteCall.callRemoteTestUtil('resizeWindow', appId, [640, 480]);
// Check the current window's size.
function() {
remoteCall.waitForWindowGeometry(appId, 640, 480).then(this.next);
},
await remoteCall.waitForWindowGeometry(appId, 640, 480);
// Enlarge the window by 10 pixels.
function(result) {
remoteCall.callRemoteTestUtil(
'resizeWindow', appId, [650, 490], this.next);
},
await remoteCall.callRemoteTestUtil('resizeWindow', appId, [650, 490]);
// Check the current window's size.
function() {
remoteCall.waitForWindowGeometry(appId, 650, 490).then(this.next);
},
await remoteCall.waitForWindowGeometry(appId, 650, 490);
// Open another window, where the current view is restored.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
// Check the next window's size.
function(results) {
appId2 = results.windowId;
remoteCall.waitForWindowGeometry(appId2, 650, 490).then(this.next);
},
// Check for errors.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await remoteCall.waitForWindowGeometry(appId, 650, 490);
};
/**
* Tests restoring a maximized Files app window.
*/
testcase.restoreGeometryMaximized = function() {
var appId;
var appId2;
testcase.restoreGeometryMaximized = async function() {
var caller = getCaller();
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Set up Files app.
let {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Maximize the window
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil('maximizeWindow', appId, [], this.next);
},
await remoteCall.callRemoteTestUtil('maximizeWindow', appId, []);
// Check that the first window is maximized.
function() {
return repeatUntil(function() {
return remoteCall.callRemoteTestUtil('isWindowMaximized', appId, [])
.then(function(isMaximized) {
if (isMaximized)
await repeatUntil(async function() {
if (await remoteCall.callRemoteTestUtil('isWindowMaximized', appId, [])) {
return true;
else
}
return pending(caller, 'Waiting window maximized...');
});
}).then(this.next);
},
// Close the window.
function() {
remoteCall.closeWindowAndWait(appId).then(this.next);
},
await remoteCall.closeWindowAndWait(appId);
// Open a Files app window again.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
// Check that the newly opened window is maximized initially.
function(results) {
appId2 = results.windowId;
return repeatUntil(function() {
return remoteCall.callRemoteTestUtil('isWindowMaximized', appId2, [])
.then(function(isMaximized) {
if (isMaximized)
await repeatUntil(async function() {
if (await remoteCall.callRemoteTestUtil('isWindowMaximized', appId, [])) {
return true;
else
}
return pending(caller, 'Waiting window maximized...');
});
}).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
};
......@@ -7,8 +7,7 @@
/**
* Tests restoring the sorting order.
*/
testcase.restoreSortColumn = function() {
var appId;
testcase.restoreSortColumn = async function() {
var EXPECTED_FILES = TestEntryInfo.getExpectedRows([
ENTRIES.photos, // 'photos' (directory)
ENTRIES.world, // 'world.ogv', 59943 bytes
......@@ -16,104 +15,57 @@ testcase.restoreSortColumn = function() {
ENTRIES.desktop, // 'My Desktop Background.png', 272 bytes
ENTRIES.hello, // 'hello.txt', 51 bytes
]);
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Set up Files app.
let {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Sort by name.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil('fakeMouseClick',
appId,
['.table-header-cell:nth-of-type(1)'],
this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['.table-header-cell:nth-of-type(1)']);
// Check the sorted style of the header.
function() {
remoteCall.waitForElement(appId, '.table-header-sort-image-asc').
then(this.next);
},
await remoteCall.waitForElement(appId, '.table-header-sort-image-asc');
// Sort by size (in descending order).
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick',
appId,
['.table-header-cell:nth-of-type(2)'],
this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['.table-header-cell:nth-of-type(2)']);
// Check the sorted style of the header.
function() {
remoteCall.waitForElement(appId, '.table-header-sort-image-desc').
then(this.next);
},
await remoteCall.waitForElement(appId, '.table-header-sort-image-desc');
// Check the sorted files.
function() {
remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true}).
then(this.next);
},
await remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true});
// Open another window, where the sorted column should be restored.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
// Check the sorted style of the header.
function(results) {
appId = results.windowId;
remoteCall.waitForElement(appId, '.table-header-sort-image-desc').
then(this.next);
},
await remoteCall.waitForElement(appId, '.table-header-sort-image-desc');
// Check the sorted files.
function() {
remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true}).
then(this.next);
},
// Check the error.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true});
};
/**
* Tests restoring the current view (the file list or the thumbnail grid).
*/
testcase.restoreCurrentView = function() {
var appId;
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
testcase.restoreCurrentView = async function() {
// Set up Files app.
const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Check the initial view.
function(results) {
appId = results.windowId;
remoteCall.waitForElement(appId, '.thumbnail-grid[hidden]').
then(this.next);
},
await remoteCall.waitForElement(appId, '.thumbnail-grid[hidden]');
// Change the current view.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick',
appId,
['#view-button'],
this.next);
},
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#view-button']));
// Check the new current view.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '.detail-table[hidden]').
then(this.next);
},
await remoteCall.waitForElement(appId, '.detail-table[hidden]');
// Open another window, where the current view is restored.
function() {
openNewWindow(null, RootPath.DOWNLOADS, this.next);
},
const appId2 = await openNewWindow(null, RootPath.DOWNLOADS);
// Check the current view.
function(inAppId) {
appId = inAppId;
remoteCall.waitForElement(appId, '.detail-table[hidden]').then(this.next);
},
// Check the error.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await remoteCall.waitForElement(appId2, '.detail-table[hidden]');
};
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