Commit 8fca5822 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: ES6 class for externs/../crostini.js, crostini.js and file_operation_manager_unittest.js

Bug: 778674
Change-Id: I2f2c30a259cd1ebddaa1c15b5c754cf165025260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1763657Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689377}
parent 0a105892
...@@ -7,80 +7,80 @@ ...@@ -7,80 +7,80 @@
* *
* @interface * @interface
*/ */
function Crostini() {} class Crostini {
/**
* Initialize enabled settings.
* Must be done after loadTimeData is available.
*/
initEnabled() {}
/** /**
* Initialize enabled settings. * Initialize Volume Manager.
* Must be done after loadTimeData is available. * @param {!VolumeManager} volumeManager
*/ */
Crostini.prototype.initEnabled = function() {}; initVolumeManager(volumeManager) {}
/** /**
* Initialize Volume Manager. * Register for any shared path changes.
* @param {!VolumeManager} volumeManager */
*/ listen() {}
Crostini.prototype.initVolumeManager = function(volumeManager) {};
/** /**
* Register for any shared path changes. * Set whether the specified VM is enabled.
*/ * @param {string} vmName
Crostini.prototype.listen = function() {}; * @param {boolean} enabled
*/
setEnabled(vmName, enabled) {}
/** /**
* Set whether the specified VM is enabled. * Returns true if the specified VM is enabled.
* @param {string} vmName * @param {string} vmName
* @param {boolean} enabled * @return {boolean}
*/ */
Crostini.prototype.setEnabled = function(vmName, enabled) {}; isEnabled(vmName) {}
/** /**
* Returns true if the specified VM is enabled. * Set whether the specified VM allows root access.
* @param {string} vmName * @param {string} vmName
* @return {boolean} * @param {boolean} allowed
*/ */
Crostini.prototype.isEnabled = function(vmName) {}; setRootAccessAllowed(vmName, allowed) {}
/** /**
* Set whether the specified VM allows root access. * Returns true if root access to specified VM is allowed.
* @param {string} vmName * @param {string} vmName
* @param {boolean} allowed * @return {boolean}
*/ */
Crostini.prototype.setRootAccessAllowed = function(vmName, allowed) {}; isRootAccessAllowed(vmName) {}
/** /**
* Returns true if root access to specified VM is allowed. * Registers an entry as a shared path for the specified VM.
* @param {string} vmName * @param {string} vmName
* @return {boolean} * @param {!Entry} entry
*/ */
Crostini.prototype.isRootAccessAllowed = function(vmName) {}; registerSharedPath(vmName, entry) {}
/** /**
* Registers an entry as a shared path for the specified VM. * Unregisters entry as a shared path from the specified VM.
* @param {string} vmName * @param {string} vmName
* @param {!Entry} entry * @param {!Entry} entry
*/ */
Crostini.prototype.registerSharedPath = function(vmName, entry) {}; unregisterSharedPath(vmName, entry) {}
/** /**
* Unregisters entry as a shared path from the specified VM. * Returns true if entry is shared with the specified VM.
* @param {string} vmName * @param {string} vmName
* @param {!Entry} entry * @param {!Entry} entry
*/ * @return {boolean} True if path is shared either by a direct
Crostini.prototype.unregisterSharedPath = function(vmName, entry) {}; * share or from one of its ancestor directories.
*/
isPathShared(vmName, entry) {}
/** /**
* Returns true if entry is shared with the specified VM. * Returns true if entry can be shared with the specified VM.
* @param {string} vmName * @param {string} vmName
* @param {!Entry} entry * @param {!Entry} entry
* @return {boolean} True if path is shared either by a direct * @param {boolean} persist If path is to be persisted.
* share or from one of its ancestor directories. */
*/ canSharePath(vmName, entry, persist) {}
Crostini.prototype.isPathShared = function(vmName, entry) {}; }
/**
* Returns true if entry can be shared with the specified VM.
* @param {string} vmName
* @param {!Entry} entry
* @param {boolean} persist If path is to be persisted.
*/
Crostini.prototype.canSharePath = function(vmName, entry, persist) {};
...@@ -37,116 +37,117 @@ mockChrome.fileManagerPrivate = { ...@@ -37,116 +37,117 @@ mockChrome.fileManagerPrivate = {
/** /**
* Logs copy-progress events from a file operation manager. * Logs copy-progress events from a file operation manager.
* @param {!FileOperationManager} fileOperationManager The target file
* operation manager.
* @constructor
* @struct
*/ */
function EventLogger(fileOperationManager) { class EventLogger {
this.events = []; /**
this.numberOfBeginEvents = 0; * @param {!FileOperationManager} fileOperationManager The target file
this.numberOfErrorEvents = 0; * operation manager.
this.numberOfSuccessEvents = 0; */
fileOperationManager.addEventListener( constructor(fileOperationManager) {
'copy-progress', this.onCopyProgress_.bind(this)); this.events = [];
} this.numberOfBeginEvents = 0;
this.numberOfErrorEvents = 0;
/** this.numberOfSuccessEvents = 0;
* Log file operation manager copy-progress event details. fileOperationManager.addEventListener(
* @param {Event} event An event. 'copy-progress', this.onCopyProgress_.bind(this));
* @private
*/
EventLogger.prototype.onCopyProgress_ = function(event) {
event = /** @type {FileOperationProgressEvent} */ (event);
if (event.reason === 'BEGIN') {
this.events.push(event);
this.numberOfBeginEvents++;
} }
if (event.reason === 'ERROR') {
this.events.push(event); /**
this.numberOfErrorEvents++; * Log file operation manager copy-progress event details.
} * @param {Event} event An event.
if (event.reason === 'SUCCESS') { * @private
this.events.push(event); */
this.numberOfSuccessEvents++; onCopyProgress_(event) {
event = /** @type {FileOperationProgressEvent} */ (event);
if (event.reason === 'BEGIN') {
this.events.push(event);
this.numberOfBeginEvents++;
}
if (event.reason === 'ERROR') {
this.events.push(event);
this.numberOfErrorEvents++;
}
if (event.reason === 'SUCCESS') {
this.events.push(event);
this.numberOfSuccessEvents++;
}
} }
}; }
/** /**
* Provides fake implementation of chrome.fileManagerPrivate.startCopy. * Provides fake implementation of chrome.fileManagerPrivate.startCopy.
* @param {string} blockedDestination Destination url of an entry whose request
* should be blocked.
* @param {!Entry} sourceEntry Source entry. Single source entry is supported.
* @param {!Array<!MockFileSystem>} fileSystems File systems array.
* @constructor
* @struct
*/ */
function BlockableFakeStartCopy(blockedDestination, sourceEntry, fileSystems) { class BlockableFakeStartCopy {
this.resolveBlockedOperationCallback = null; /**
this.blockedDestination_ = blockedDestination; * @param {string} blockedDestination Destination url of an entry whose
this.sourceEntry_ = sourceEntry; * request should be blocked.
this.fileSystems_ = fileSystems; * @param {!Entry} sourceEntry Source entry. Single source entry is supported.
this.startCopyId_ = 0; * @param {!Array<!MockFileSystem>} fileSystems File systems array.
} */
constructor(blockedDestination, sourceEntry, fileSystems) {
this.resolveBlockedOperationCallback = null;
this.blockedDestination_ = blockedDestination;
this.sourceEntry_ = sourceEntry;
this.fileSystems_ = fileSystems;
this.startCopyId_ = 0;
}
/** /**
* Fake implementation of startCopy function. * Fake implementation of startCopy function.
* @param {!Entry} source * @param {!Entry} source
* @param {!Entry} destination * @param {!Entry} destination
* @param {string} newName * @param {string} newName
* @param {function(number)} callback * @param {function(number)} callback
*/ */
BlockableFakeStartCopy.prototype.startCopyFunc = function( startCopyFunc(source, destination, newName, callback) {
source, destination, newName, callback) { const makeStatus = type => {
const makeStatus = type => { return {
return { type: type,
type: type, sourceUrl: source.toURL(),
sourceUrl: source.toURL(), destinationUrl: destination.toURL()
destinationUrl: destination.toURL() };
}; };
};
const completeCopyOperation = copyId => { const completeCopyOperation = copyId => {
const newPath = joinPath('/', newName); const newPath = joinPath('/', newName);
const fileSystem = const fileSystem =
getFileSystemForURL(this.fileSystems_, destination.toURL()); getFileSystemForURL(this.fileSystems_, destination.toURL());
const mockEntry = /** @type {!MockEntry} */ (this.sourceEntry_); const mockEntry = /** @type {!MockEntry} */ (this.sourceEntry_);
fileSystem.entries[newPath] = fileSystem.entries[newPath] =
/** @type {!MockEntry} */ (mockEntry.clone(newPath)); /** @type {!MockEntry} */ (mockEntry.clone(newPath));
listener(copyId, makeStatus('end_copy_entry')); listener(copyId, makeStatus('end_copy_entry'));
listener(copyId, makeStatus('success')); listener(copyId, makeStatus('success'));
}; };
this.startCopyId_++; this.startCopyId_++;
callback(this.startCopyId_); callback(this.startCopyId_);
var listener = mockChrome.fileManagerPrivate.onCopyProgress.listener_; var listener = mockChrome.fileManagerPrivate.onCopyProgress.listener_;
listener(this.startCopyId_, makeStatus('begin_copy_entry')); listener(this.startCopyId_, makeStatus('begin_copy_entry'));
listener(this.startCopyId_, makeStatus('progress')); listener(this.startCopyId_, makeStatus('progress'));
if (destination.toURL() === this.blockedDestination_) { if (destination.toURL() === this.blockedDestination_) {
this.resolveBlockedOperationCallback = this.resolveBlockedOperationCallback =
completeCopyOperation.bind(this, this.startCopyId_); completeCopyOperation.bind(this, this.startCopyId_);
} else { } else {
completeCopyOperation(this.startCopyId_); completeCopyOperation(this.startCopyId_);
}
} }
}; }
/** /**
* Fake volume manager. * Fake volume manager.
* @constructor
* @struct
*/
function FakeVolumeManager() {}
/**
* Returns fake volume info.
* @param {!Entry} entry
* @return {!Object}
*/ */
FakeVolumeManager.prototype.getVolumeInfo = function(entry) { class FakeVolumeManager {
return {volumeId: entry.filesystem.name}; /**
}; * Returns fake volume info.
* @param {!Entry} entry
* @return {!Object}
*/
getVolumeInfo(entry) {
return {volumeId: entry.filesystem.name};
}
}
/** /**
* Returns file system of the url. * Returns file system of the url.
......
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