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 @@
*
* @interface
*/
function Crostini() {}
class Crostini {
/**
* Initialize enabled settings.
* Must be done after loadTimeData is available.
*/
initEnabled() {}
/**
* Initialize enabled settings.
* Must be done after loadTimeData is available.
*/
Crostini.prototype.initEnabled = function() {};
/**
* Initialize Volume Manager.
* @param {!VolumeManager} volumeManager
*/
initVolumeManager(volumeManager) {}
/**
* Initialize Volume Manager.
* @param {!VolumeManager} volumeManager
*/
Crostini.prototype.initVolumeManager = function(volumeManager) {};
/**
* Register for any shared path changes.
*/
listen() {}
/**
* Register for any shared path changes.
*/
Crostini.prototype.listen = function() {};
/**
* Set whether the specified VM is enabled.
* @param {string} vmName
* @param {boolean} enabled
*/
setEnabled(vmName, enabled) {}
/**
* Set whether the specified VM is enabled.
* @param {string} vmName
* @param {boolean} enabled
*/
Crostini.prototype.setEnabled = function(vmName, enabled) {};
/**
* Returns true if the specified VM is enabled.
* @param {string} vmName
* @return {boolean}
*/
isEnabled(vmName) {}
/**
* Returns true if the specified VM is enabled.
* @param {string} vmName
* @return {boolean}
*/
Crostini.prototype.isEnabled = function(vmName) {};
/**
* Set whether the specified VM allows root access.
* @param {string} vmName
* @param {boolean} allowed
*/
setRootAccessAllowed(vmName, allowed) {}
/**
* Set whether the specified VM allows root access.
* @param {string} vmName
* @param {boolean} allowed
*/
Crostini.prototype.setRootAccessAllowed = function(vmName, allowed) {};
/**
* Returns true if root access to specified VM is allowed.
* @param {string} vmName
* @return {boolean}
*/
isRootAccessAllowed(vmName) {}
/**
* Returns true if root access to specified VM is allowed.
* @param {string} vmName
* @return {boolean}
*/
Crostini.prototype.isRootAccessAllowed = function(vmName) {};
/**
* Registers an entry as a shared path for the specified VM.
* @param {string} vmName
* @param {!Entry} entry
*/
registerSharedPath(vmName, entry) {}
/**
* Registers an entry as a shared path for the specified VM.
* @param {string} vmName
* @param {!Entry} entry
*/
Crostini.prototype.registerSharedPath = function(vmName, entry) {};
/**
* Unregisters entry as a shared path from the specified VM.
* @param {string} vmName
* @param {!Entry} entry
*/
unregisterSharedPath(vmName, entry) {}
/**
* Unregisters entry as a shared path from the specified VM.
* @param {string} vmName
* @param {!Entry} entry
*/
Crostini.prototype.unregisterSharedPath = function(vmName, entry) {};
/**
* Returns true if entry is shared with the specified VM.
* @param {string} vmName
* @param {!Entry} entry
* @return {boolean} True if path is shared either by a direct
* share or from one of its ancestor directories.
*/
isPathShared(vmName, entry) {}
/**
* Returns true if entry is shared with the specified VM.
* @param {string} vmName
* @param {!Entry} entry
* @return {boolean} True if path is shared either by a direct
* share or from one of its ancestor directories.
*/
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) {};
/**
* 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.
*/
canSharePath(vmName, entry, persist) {}
}
......@@ -37,116 +37,117 @@ mockChrome.fileManagerPrivate = {
/**
* Logs copy-progress events from a file operation manager.
* @param {!FileOperationManager} fileOperationManager The target file
* operation manager.
* @constructor
* @struct
*/
function EventLogger(fileOperationManager) {
this.events = [];
this.numberOfBeginEvents = 0;
this.numberOfErrorEvents = 0;
this.numberOfSuccessEvents = 0;
fileOperationManager.addEventListener(
'copy-progress', this.onCopyProgress_.bind(this));
}
/**
* Log file operation manager copy-progress event details.
* @param {Event} event An event.
* @private
*/
EventLogger.prototype.onCopyProgress_ = function(event) {
event = /** @type {FileOperationProgressEvent} */ (event);
if (event.reason === 'BEGIN') {
this.events.push(event);
this.numberOfBeginEvents++;
class EventLogger {
/**
* @param {!FileOperationManager} fileOperationManager The target file
* operation manager.
*/
constructor(fileOperationManager) {
this.events = [];
this.numberOfBeginEvents = 0;
this.numberOfErrorEvents = 0;
this.numberOfSuccessEvents = 0;
fileOperationManager.addEventListener(
'copy-progress', this.onCopyProgress_.bind(this));
}
if (event.reason === 'ERROR') {
this.events.push(event);
this.numberOfErrorEvents++;
}
if (event.reason === 'SUCCESS') {
this.events.push(event);
this.numberOfSuccessEvents++;
/**
* Log file operation manager copy-progress event details.
* @param {Event} event An event.
* @private
*/
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.
* @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) {
this.resolveBlockedOperationCallback = null;
this.blockedDestination_ = blockedDestination;
this.sourceEntry_ = sourceEntry;
this.fileSystems_ = fileSystems;
this.startCopyId_ = 0;
}
class BlockableFakeStartCopy {
/**
* @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(blockedDestination, sourceEntry, fileSystems) {
this.resolveBlockedOperationCallback = null;
this.blockedDestination_ = blockedDestination;
this.sourceEntry_ = sourceEntry;
this.fileSystems_ = fileSystems;
this.startCopyId_ = 0;
}
/**
* Fake implementation of startCopy function.
* @param {!Entry} source
* @param {!Entry} destination
* @param {string} newName
* @param {function(number)} callback
*/
BlockableFakeStartCopy.prototype.startCopyFunc = function(
source, destination, newName, callback) {
const makeStatus = type => {
return {
type: type,
sourceUrl: source.toURL(),
destinationUrl: destination.toURL()
/**
* Fake implementation of startCopy function.
* @param {!Entry} source
* @param {!Entry} destination
* @param {string} newName
* @param {function(number)} callback
*/
startCopyFunc(source, destination, newName, callback) {
const makeStatus = type => {
return {
type: type,
sourceUrl: source.toURL(),
destinationUrl: destination.toURL()
};
};
};
const completeCopyOperation = copyId => {
const newPath = joinPath('/', newName);
const fileSystem =
getFileSystemForURL(this.fileSystems_, destination.toURL());
const mockEntry = /** @type {!MockEntry} */ (this.sourceEntry_);
fileSystem.entries[newPath] =
/** @type {!MockEntry} */ (mockEntry.clone(newPath));
listener(copyId, makeStatus('end_copy_entry'));
listener(copyId, makeStatus('success'));
};
const completeCopyOperation = copyId => {
const newPath = joinPath('/', newName);
const fileSystem =
getFileSystemForURL(this.fileSystems_, destination.toURL());
const mockEntry = /** @type {!MockEntry} */ (this.sourceEntry_);
fileSystem.entries[newPath] =
/** @type {!MockEntry} */ (mockEntry.clone(newPath));
listener(copyId, makeStatus('end_copy_entry'));
listener(copyId, makeStatus('success'));
};
this.startCopyId_++;
this.startCopyId_++;
callback(this.startCopyId_);
var listener = mockChrome.fileManagerPrivate.onCopyProgress.listener_;
listener(this.startCopyId_, makeStatus('begin_copy_entry'));
listener(this.startCopyId_, makeStatus('progress'));
callback(this.startCopyId_);
var listener = mockChrome.fileManagerPrivate.onCopyProgress.listener_;
listener(this.startCopyId_, makeStatus('begin_copy_entry'));
listener(this.startCopyId_, makeStatus('progress'));
if (destination.toURL() === this.blockedDestination_) {
this.resolveBlockedOperationCallback =
completeCopyOperation.bind(this, this.startCopyId_);
} else {
completeCopyOperation(this.startCopyId_);
if (destination.toURL() === this.blockedDestination_) {
this.resolveBlockedOperationCallback =
completeCopyOperation.bind(this, this.startCopyId_);
} else {
completeCopyOperation(this.startCopyId_);
}
}
};
}
/**
* Fake volume manager.
* @constructor
* @struct
*/
function FakeVolumeManager() {}
/**
* Returns fake volume info.
* @param {!Entry} entry
* @return {!Object}
*/
FakeVolumeManager.prototype.getVolumeInfo = function(entry) {
return {volumeId: entry.filesystem.name};
};
class FakeVolumeManager {
/**
* Returns fake volume info.
* @param {!Entry} entry
* @return {!Object}
*/
getVolumeInfo(entry) {
return {volumeId: entry.filesystem.name};
}
}
/**
* 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