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