Commit a52aa024 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app/Audio Player: Prepare integration test harness for JS modules

Change runtime_loaded_test_util.js to avoid referring to global types or
names to prepare to run the background pages as JS modules. When running
as JS modules these global names aren't available.

Move to use an API defined in the `window.background` which is the
interface BackgroundBase.

Change the functions using getVolumeManager() to use async/await to
improve their readability.  Note that test.util.async.unmount() was
invalidly calling the volumeManager.unmount() with callback. Fix by
calling the callback after the unmount() is finished.

Change test_util_base.js to expose the required dependencies to
runtime_loaded_test_util.js because when running as JS modules those
aren't visible when loading the runtime_loaded_test_util.js.

Bug: 1133186
Change-Id: I9b5a52f6ca88cc13881862132d6e331c0dec2f57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537256
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827748}
parent 3b2fb965
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
* extension under test at runtime to populate testing functionality. * extension under test at runtime to populate testing functionality.
*/ */
/** /**
* @typedef {{ * @typedef {{
* attributes:Object<string>, * attributes:Object<string>,
...@@ -1016,32 +1015,27 @@ test.util.sync.launcherSearchOpenResult = fileURL => { ...@@ -1016,32 +1015,27 @@ test.util.sync.launcherSearchOpenResult = fileURL => {
* @param {function(*)} callback Callback function with results returned by the * @param {function(*)} callback Callback function with results returned by the
* script. * script.
*/ */
test.util.async.getFilesUnderVolume = (volumeType, names, callback) => { test.util.async.getFilesUnderVolume = async (volumeType, names, callback) => {
const displayRootPromise = const volumeManager = await window.background.getVolumeManager();
volumeManagerFactory.getInstance().then(volumeManager => { const volumeInfo = volumeManager.getCurrentProfileVolumeInfo(volumeType);
const volumeInfo = const displayRoot = await volumeInfo.resolveDisplayRoot();
volumeManager.getCurrentProfileVolumeInfo(volumeType);
return volumeInfo.resolveDisplayRoot(); const filesPromise = names.map(name => {
}); // TODO(crbug.com/880130): Remove this conditional.
if (volumeType === VolumeManagerCommon.VolumeType.DOWNLOADS) {
const retrievePromise = displayRootPromise.then(displayRoot => { name = 'Downloads/' + name;
const filesPromise = names.map(name => { }
// TODO(crbug.com/880130): Remove this conditional. return new Promise(displayRoot.getFile.bind(displayRoot, name, {}));
if (volumeType === VolumeManagerCommon.VolumeType.DOWNLOADS) {
name = 'Downloads/' + name;
}
return new Promise(displayRoot.getFile.bind(displayRoot, name, {}));
});
return Promise.all(filesPromise)
.then(aa => {
return util.entriesToURLs(aa);
})
.catch(() => {
return [];
});
}); });
retrievePromise.then(callback); try {
const urls = await Promise.all(filesPromise);
const result = util.entriesToURLs(urls);
callback(result);
} catch (error) {
console.error(error);
callback([]);
}
}; };
/** /**
...@@ -1050,14 +1044,19 @@ test.util.async.getFilesUnderVolume = (volumeType, names, callback) => { ...@@ -1050,14 +1044,19 @@ test.util.async.getFilesUnderVolume = (volumeType, names, callback) => {
* @param {VolumeManagerCommon.VolumeType} volumeType Volume type. * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
* @param {function(boolean)} callback Function receives true on success. * @param {function(boolean)} callback Function receives true on success.
*/ */
test.util.async.unmount = (volumeType, callback) => { test.util.async.unmount = async (volumeType, callback) => {
volumeManagerFactory.getInstance().then((volumeManager) => { const volumeManager = await window.background.getVolumeManager();
const volumeInfo = volumeManager.getCurrentProfileVolumeInfo(volumeType); const volumeInfo = volumeManager.getCurrentProfileVolumeInfo(volumeType);
try {
if (volumeInfo) { if (volumeInfo) {
volumeManager.unmount( await volumeManager.unmount(volumeInfo);
volumeInfo, callback.bind(null, true), callback.bind(null, false)); callback(true);
return;
} }
}); } catch (error) {
console.error(error);
}
callback(false);
}; };
/** /**
...@@ -1175,7 +1174,7 @@ test.util.sync.getA11yAnnounces = contentWindow => { ...@@ -1175,7 +1174,7 @@ test.util.sync.getA11yAnnounces = contentWindow => {
* number of volumes. * number of volumes.
*/ */
test.util.async.getVolumesCount = callback => { test.util.async.getVolumesCount = callback => {
return volumeManagerFactory.getInstance().then((volumeManager) => { return window.background.getVolumeManager().then((volumeManager) => {
callback(volumeManager.volumeInfoList.length); callback(volumeManager.volumeInfoList.length);
}); });
}; };
...@@ -1183,9 +1182,11 @@ test.util.async.getVolumesCount = callback => { ...@@ -1183,9 +1182,11 @@ test.util.async.getVolumesCount = callback => {
/** /**
* Sets/Resets a flag that causes file copy operations to always fail in test. * Sets/Resets a flag that causes file copy operations to always fail in test.
* @param {boolean} enable True to force errors. * @param {boolean} enable True to force errors.
* @suppress {checkTypes} Remove suppress when migrating Files app. This is only
* used for Files app.
*/ */
test.util.sync.forceErrorsOnFileOperations = (contentWindow, enable) => { test.util.sync.forceErrorsOnFileOperations = (contentWindow, enable) => {
fileOperationUtil.forceErrorForTest = enable; window.background.forceFileOperationErrorForTest(enable);
return enable; return enable;
}; };
...@@ -1221,6 +1222,8 @@ test.util.sync.reload = () => { ...@@ -1221,6 +1222,8 @@ test.util.sync.reload = () => {
/** /**
* Tells background page progress center to never notify a completed operation. * Tells background page progress center to never notify a completed operation.
* @suppress {checkTypes} Remove suppress when migrating Files app. This is only
* used for Files app.
*/ */
test.util.sync.progressCenterNeverNotifyCompleted = () => { test.util.sync.progressCenterNeverNotifyCompleted = () => {
window.background.progressCenter.neverNotifyCompleted(); window.background.progressCenter.neverNotifyCompleted();
......
...@@ -7,11 +7,18 @@ ...@@ -7,11 +7,18 @@
* @suppress {uselessCode} Temporary suppress because of the line exporting. * @suppress {uselessCode} Temporary suppress because of the line exporting.
*/ */
// clang-format off
// #import * as wrappedVolumeManagerCommon from '../../../base/js/volume_manager_types.m.js'; const {VolumeManagerCommon} = wrappedVolumeManagerCommon;
// #import * as wrappedUtil from '../../common/js/util.m.js'; const {util} = wrappedUtil;
// #import {assert} from 'chrome://resources/js/assert.m.js';
// clang-format on
/** /**
* Namespace for test related things. * Namespace for test related things.
*/ */
window.test = window.test || {};
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var test = test || {}; var test = window.test;
/** /**
* Namespace for test utility functions. * Namespace for test utility functions.
...@@ -89,6 +96,13 @@ test.util.registerRemoteTestUtils = () => { ...@@ -89,6 +96,13 @@ test.util.registerRemoteTestUtils = () => {
return true; return true;
} }
// Exporting the dependency for the runtime_loaded_test_util.js script.
// TODO: Remove this once runtime_loaded_test_util is a JS module and
// can import its dependencies.
window.VolumeManagerCommon = VolumeManagerCommon;
window.util = util;
window.assert = assert;
// Asynchronously load the testing functions. // Asynchronously load the testing functions.
const script = document.createElement('script'); const script = document.createElement('script');
document.body.appendChild(script); document.body.appendChild(script);
......
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