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; // Open Files.App on |path|, add image3 to Downloads and Drive.
let galleryAppId; const {appId} = await setupAndWaitUntilReady(
null, path, null, [ENTRIES.image3], [ENTRIES.image3]);
StepsRunner.run([
// Open Files.App on |path|, add image3 to Downloads and Drive. // Open the image file in Files app.
function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
setupAndWaitUntilReady( 'openFile', appId, [ENTRIES.image3.targetPath]));
null, path, this.next, [ENTRIES.image3], [ENTRIES.image3]);
}, // Check: the Gallery window should open.
// Open the image file in Files app. const galleryAppId = await galleryApp.waitForWindow('gallery.html');
function(results) {
appId = results.windowId; // Check: the image should appear in the Gallery window.
remoteCall.callRemoteTestUtil( await galleryApp.waitForSlideImage(galleryAppId, 640, 480, 'image3');
'openFile', appId, [ENTRIES.image3.targetPath], this.next);
}, // Close the Gallery window.
// Check: the Gallery window should open. chrome.test.assertTrue(
function(result) { await galleryApp.closeWindowAndWait(galleryAppId),
chrome.test.assertTrue(result); 'Failed to close Gallery window');
galleryApp.waitForWindow('gallery.html').then(this.next);
},
// Check: the image should appear in the Gallery window.
function(windowId) {
galleryAppId = windowId;
galleryApp.waitForSlideImage(
galleryAppId, 640, 480, 'image3').then(this.next);
},
// 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);
}
]);
} }
/** /**
...@@ -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. const {appId} =
function() { await setupAndWaitUntilReady(null, path, null, testImages, testImages);
setupAndWaitUntilReady(null, path, this.next, testImages, testImages);
}, // Open an image file in Files app.
// Open an image file in Files app. chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
function(results) { 'openFile', appId, [ENTRIES.image3.targetPath]));
appId = results.windowId;
remoteCall.callRemoteTestUtil( // Wait a11y-msg to have some text.
'openFile', appId, [ENTRIES.image3.targetPath], this.next); await remoteCall.waitForElement(appId, '#a11y-msg:not(:empty)');
},
// Wait a11y-msg to have some text. // Fetch A11y messages.
function(result) { const a11yMessages =
chrome.test.assertTrue(result); await remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []);
remoteCall.waitForElement(appId, '#a11y-msg:not(:empty)').then(this.next);
}, // Check that opening the file was announced to screen reader.
// Fetch A11y messages. chrome.test.assertTrue(a11yMessages instanceof Array);
function() { chrome.test.assertEq(1, a11yMessages.length);
remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []) chrome.test.assertEq('Opening file image3.jpg.', a11yMessages[0]);
.then(this.next);
}, // Check: the Gallery window should open.
// Check that opening the file was announced to screen reader. const galleryAppId = await galleryApp.waitForWindow('gallery.html');
function(a11yMessages) {
chrome.test.assertTrue(a11yMessages instanceof Array); // Check: the image should appear in the Gallery window.
chrome.test.assertEq(1, a11yMessages.length); await galleryApp.waitForSlideImage(galleryAppId, 640, 480, 'image3');
chrome.test.assertEq('Opening file image3.jpg.', a11yMessages[0]);
this.next(); // Now open a different image file in Files app.
}, await remoteCall.callRemoteTestUtil(
// Check: the Gallery window should open. 'openFile', appId, [ENTRIES.desktop.targetPath]);
function() {
galleryApp.waitForWindow('gallery.html').then(this.next); // Check: the new image should appear in the Gallery window.
}, await galleryApp.waitForSlideImage(
// Check: the image should appear in the Gallery window. galleryAppId, 800, 600, 'My Desktop Background');
function(windowId) {
galleryAppId = windowId;
galleryApp.waitForSlideImage(
galleryAppId, 640, 480, 'image3').then(this.next);
},
// Now open a different image file in Files app.
function() {
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.desktop.targetPath], this.next);
},
// 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);
}
]);
} }
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. // Resize the window to minimal dimensions.
function() { await remoteCall.callRemoteTestUtil('resizeWindow', appId, [640, 480]);
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
}, // Check the current window's size.
// Resize the window to minimal dimensions. await remoteCall.waitForWindowGeometry(appId, 640, 480);
function(results) {
appId = results.windowId; // Enlarge the window by 10 pixels.
remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil('resizeWindow', appId, [650, 490]);
'resizeWindow', appId, [640, 480], this.next);
}, // Check the current window's size.
// Check the current window's size. await remoteCall.waitForWindowGeometry(appId, 650, 490);
function() {
remoteCall.waitForWindowGeometry(appId, 640, 480).then(this.next); // Open another window, where the current view is restored.
}, ({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
// Enlarge the window by 10 pixels.
function(result) { // Check the next window's size.
remoteCall.callRemoteTestUtil( await remoteCall.waitForWindowGeometry(appId, 650, 490);
'resizeWindow', appId, [650, 490], this.next);
},
// Check the current window's size.
function() {
remoteCall.waitForWindowGeometry(appId, 650, 490).then(this.next);
},
// Open another window, where the current view is restored.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// 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);
}
]);
}; };
/** /**
* 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 await remoteCall.callRemoteTestUtil('maximizeWindow', appId, []);
function(results) {
appId = results.windowId; // Check that the first window is maximized.
remoteCall.callRemoteTestUtil('maximizeWindow', appId, [], this.next); await repeatUntil(async function() {
}, if (await remoteCall.callRemoteTestUtil('isWindowMaximized', appId, [])) {
// Check that the first window is maximized. return true;
function() { }
return repeatUntil(function() { return pending(caller, 'Waiting window maximized...');
return remoteCall.callRemoteTestUtil('isWindowMaximized', appId, []) });
.then(function(isMaximized) {
if (isMaximized) // Close the window.
return true; await remoteCall.closeWindowAndWait(appId);
else
return pending(caller, 'Waiting window maximized...'); // Open a Files app window again.
}); ({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
}).then(this.next);
}, // Check that the newly opened window is maximized initially.
// Close the window. await repeatUntil(async function() {
function() { if (await remoteCall.callRemoteTestUtil('isWindowMaximized', appId, [])) {
remoteCall.closeWindowAndWait(appId).then(this.next); return true;
},
// Open a Files app window again.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// 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)
return true;
else
return pending(caller, 'Waiting window maximized...');
});
}).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
} }
]); return pending(caller, 'Waiting window maximized...');
});
}; };
...@@ -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. await remoteCall.callRemoteTestUtil(
function(results) { 'fakeMouseClick', appId, ['.table-header-cell:nth-of-type(1)']);
appId = results.windowId;
remoteCall.callRemoteTestUtil('fakeMouseClick', // Check the sorted style of the header.
appId, await remoteCall.waitForElement(appId, '.table-header-sort-image-asc');
['.table-header-cell:nth-of-type(1)'],
this.next); // Sort by size (in descending order).
}, await remoteCall.callRemoteTestUtil(
// Check the sorted style of the header. 'fakeMouseClick', appId, ['.table-header-cell:nth-of-type(2)']);
function() {
remoteCall.waitForElement(appId, '.table-header-sort-image-asc'). // Check the sorted style of the header.
then(this.next); await remoteCall.waitForElement(appId, '.table-header-sort-image-desc');
},
// Sort by size (in descending order). // Check the sorted files.
function() { await remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true});
remoteCall.callRemoteTestUtil('fakeMouseClick',
appId, // Open another window, where the sorted column should be restored.
['.table-header-cell:nth-of-type(2)'], ({appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS));
this.next);
}, // Check the sorted style of the header.
// Check the sorted style of the header. await remoteCall.waitForElement(appId, '.table-header-sort-image-desc');
function() {
remoteCall.waitForElement(appId, '.table-header-sort-image-desc'). // Check the sorted files.
then(this.next); await remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true});
},
// Check the sorted files.
function() {
remoteCall.waitForFiles(appId, EXPECTED_FILES, {orderCheck: true}).
then(this.next);
},
// Open another window, where the sorted column should be restored.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Check the sorted style of the header.
function(results) {
appId = results.windowId;
remoteCall.waitForElement(appId, '.table-header-sort-image-desc').
then(this.next);
},
// Check the sorted files.
function() {
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() { // Check the initial view.
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); await remoteCall.waitForElement(appId, '.thumbnail-grid[hidden]');
},
// Check the initial view. // Change the current view.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'fakeMouseClick', appId, ['#view-button']));
remoteCall.waitForElement(appId, '.thumbnail-grid[hidden]').
then(this.next); // Check the new current view.
}, await remoteCall.waitForElement(appId, '.detail-table[hidden]');
// Change the current view.
function() { // Open another window, where the current view is restored.
remoteCall.callRemoteTestUtil('fakeMouseClick', const appId2 = await openNewWindow(null, RootPath.DOWNLOADS);
appId,
['#view-button'], // Check the current view.
this.next); await remoteCall.waitForElement(appId2, '.detail-table[hidden]');
},
// Check the new current view.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '.detail-table[hidden]').
then(this.next);
},
// Open another window, where the current view is restored.
function() {
openNewWindow(null, RootPath.DOWNLOADS, this.next);
},
// Check the current view.
function(inAppId) {
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