Commit 7fe9b01c authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile file_operation_manager and its mock file

 - add these files to the BUILD file, fix all closure errors
 - change externs FileOperationManager to be an @interface
 - rename FileOperationManager to FileOperationManagerImpl,
   and use it as the implementation in FilesApp
 - remove FileOperationManager.DELETE_TIMEOUT, it is unused
 - update class MockFileOperationManager, an implementation
   of FileOperationManager for tests, and add missing base
   class methods needed to Closure compile it.
 - re-order file_operation_handler_unittest.html scripts: the
   simple scripts first, the unittest-related scripts last.
 - make util.addEventListenerToBackgroundComponent have an
   EventTarget to satisfy Closure compile now EventTarget is
   used to define the externs FileOperationManager @interface

No change in test behavior, no new tests.

Bug: 908299
Change-Id: I5b03596b6beb3e6bce3bd8a140525fff4cb30d2d
Reviewed-on: https://chromium-review.googlesource.com/c/1350447
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610810}
parent 22428dfe
......@@ -3,28 +3,17 @@
// found in the LICENSE file.
/**
* @constructor
* @struct
* @extends {cr.EventTarget}
* FileOperationManager: manager of file operations. Implementations of this
* interface must @extends {cr.EventTarget}.
*
* @interface
* @extends {EventTarget}
*/
function FileOperationManager() {}
/**
* Adds an event listener for the tasks.
* @param {string} type The name of the event.
* @param {EventListenerType} handler The handler for the event. This is called
* when the event is dispatched.
* @override
*/
FileOperationManager.prototype.addEventListener = function(type, handler) {};
/**
* Removes an event listener for the tasks.
* @param {string} type The name of the event.
* @param {EventListenerType} handler The handler to be removed.
* @override
*/
FileOperationManager.prototype.removeEventListener = function(type, handler) {};
FileOperationManager.prototype = /** @struct */ {
__proto__: EventTarget.prototype,
};
/**
* Says if there are any tasks in the queue.
......
......@@ -67,6 +67,7 @@ js_type_check("test_support_type_check") {
testonly = true
deps = [
":mock_drive_sync_handler",
":mock_file_operation_manager",
":mock_media_scanner",
":mock_progress_center",
":mock_volume_manager",
......@@ -81,6 +82,7 @@ js_library("closure_compile_externs") {
"../../../externs/background/drive_sync_handler.js",
"../../../externs/background/file_browser_background.js",
"../../../externs/background/file_browser_background_full.js",
"../../../externs/background/file_operation_manager.js",
"../../../externs/background/import_history.js",
"../../../externs/background/import_runner.js",
"../../../externs/background/media_scanner.js",
......@@ -216,11 +218,20 @@ js_library("file_operation_handler") {
]
}
js_library("mock_file_operation_manager") {
testonly = true
deps = [
":file_operation_manager",
]
externs_list = [ "../../../externs/background/file_operation_manager.js" ]
}
js_library("file_operation_manager") {
deps = [
":file_operation_util",
":volume_manager_factory",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js/cr:event_target",
]
}
......
......@@ -115,7 +115,7 @@ function FileBrowserBackgroundImpl() {
this.crostini.listen();
}.bind(this));
this.fileOperationManager = new FileOperationManager();
this.fileOperationManager = new FileOperationManagerImpl();
this.fileOperationHandler_ = new FileOperationHandler(
this.fileOperationManager, this.progressCenter);
}.bind(this));
......
......@@ -12,14 +12,14 @@
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="file_operation_handler.js"></script>
<script src="file_operation_util.js"></script>
<script src="../../common/js/progress_center_common.js"></script>
<script src="../../common/js/util.js"></script>
<script src="mock_file_operation_manager.js"></script>
<script src="mock_progress_center.js"></script>
<script src="file_operation_util.js"></script>
<script src="file_operation_handler.js"></script>
<script src="file_operation_handler_unittest.js"></script>
</body>
......
......@@ -3,11 +3,14 @@
// found in the LICENSE file.
/**
* FileOperationManagerImpl: implementation of {FileOperationManager}.
*
* @constructor
* @struct
* @implements {FileOperationManager}
* @extends {cr.EventTarget}
*/
function FileOperationManager() {
function FileOperationManagerImpl() {
/**
* @private {VolumeManager}
*/
......@@ -44,14 +47,6 @@ function FileOperationManager() {
this.eventRouter_ = new fileOperationUtil.EventRouter();
}
/**
* Returns pending copy tasks for testing.
* @return {!Array<!fileOperationUtil.Task>} Pending copy tasks.
*/
FileOperationManager.prototype.getPendingCopyTasksForTesting = function() {
return this.pendingCopyTasks_;
};
/**
* Adds an event listener for the tasks.
* @param {string} type The name of the event.
......@@ -59,7 +54,7 @@ FileOperationManager.prototype.getPendingCopyTasksForTesting = function() {
* when the event is dispatched.
* @override
*/
FileOperationManager.prototype.addEventListener = function(type, handler) {
FileOperationManagerImpl.prototype.addEventListener = function(type, handler) {
this.eventRouter_.addEventListener(type, handler);
};
......@@ -69,25 +64,34 @@ FileOperationManager.prototype.addEventListener = function(type, handler) {
* @param {EventListenerType} handler The handler to be removed.
* @override
*/
FileOperationManager.prototype.removeEventListener = function(type, handler) {
FileOperationManagerImpl.prototype.removeEventListener = function(
type, handler) {
this.eventRouter_.removeEventListener(type, handler);
};
/**
* Says if there are any tasks in the queue.
* Checks if there are any tasks in the queue.
* @return {boolean} True, if there are any tasks.
*/
FileOperationManager.prototype.hasQueuedTasks = function() {
FileOperationManagerImpl.prototype.hasQueuedTasks = function() {
return Object.keys(this.runningCopyTasks_).length > 0 ||
this.pendingCopyTasks_.length > 0 ||
this.deleteTasks_.length > 0;
};
/**
* Returns pending copy tasks for testing.
* @return {!Array<!fileOperationUtil.Task>} Pending copy tasks.
*/
FileOperationManagerImpl.prototype.getPendingCopyTasksForTesting = function() {
return this.pendingCopyTasks_;
};
/**
* Requests the specified task to be canceled.
* @param {string} taskId ID of task to be canceled.
*/
FileOperationManager.prototype.requestTaskCancel = function(taskId) {
FileOperationManagerImpl.prototype.requestTaskCancel = function(taskId) {
var task = null;
// If the task is not on progress, remove it immediately.
......@@ -134,7 +138,7 @@ FileOperationManager.prototype.requestTaskCancel = function(taskId) {
* @return {Promise} Promise fulfilled with the filtered entry. This is not
* rejected.
*/
FileOperationManager.prototype.filterSameDirectoryEntry = function(
FileOperationManagerImpl.prototype.filterSameDirectoryEntry = function(
sourceEntries, targetEntry, isMove) {
if (!isMove)
return Promise.resolve(sourceEntries);
......@@ -176,7 +180,7 @@ FileOperationManager.prototype.filterSameDirectoryEntry = function(
* at another places, we need to specify the ID of the item. If the
* item is not created, FileOperationManager generates new ID.
*/
FileOperationManager.prototype.paste = function(
FileOperationManagerImpl.prototype.paste = function(
sourceEntries, targetEntry, isMove, opt_taskId) {
// Do nothing if sourceEntries is empty.
if (sourceEntries.length === 0)
......@@ -201,10 +205,10 @@ FileOperationManager.prototype.paste = function(
* @param {boolean} isMove In case of move.
* @param {string=} opt_taskId If the corresponding item has already created
* at another places, we need to specify the ID of the item. If the
* item is not created, FileOperationManager generates new ID.
* item is not created, FileOperationManagerImpl generates new ID.
* @private
*/
FileOperationManager.prototype.queueCopy_ = function(
FileOperationManagerImpl.prototype.queueCopy_ = function(
targetDirEntry, entries, isMove, opt_taskId) {
var task;
var taskId = opt_taskId || this.generateTaskId();
......@@ -242,7 +246,7 @@ FileOperationManager.prototype.queueCopy_ = function(
*
* @private
*/
FileOperationManager.prototype.serviceAllTasks_ = function() {
FileOperationManagerImpl.prototype.serviceAllTasks_ = function() {
if (this.pendingCopyTasks_.length === 0 &&
Object.keys(this.runningCopyTasks_).length === 0) {
// All tasks have been serviced, clean up and exit.
......@@ -346,17 +350,12 @@ FileOperationManager.prototype.serviceAllTasks_ = function() {
nextTask.run(onEntryChanged, onTaskProgress, onTaskSuccess, onTaskError);
};
/**
* Timeout before files are really deleted (to allow undo).
*/
FileOperationManager.DELETE_TIMEOUT = 30 * 1000;
/**
* Schedules the files deletion.
*
* @param {Array<Entry>} entries The entries.
*/
FileOperationManager.prototype.deleteEntries = function(entries) {
FileOperationManagerImpl.prototype.deleteEntries = function(entries) {
var task =
/** @type {!fileOperationUtil.DeleteTask} */ (Object.preventExtensions({
entries: entries,
......@@ -404,7 +403,7 @@ FileOperationManager.prototype.deleteEntries = function(entries) {
*
* @private
*/
FileOperationManager.prototype.serviceAllDeleteTasks_ = function() {
FileOperationManagerImpl.prototype.serviceAllDeleteTasks_ = function() {
this.serviceDeleteTask_(
this.deleteTasks_[0],
function() {
......@@ -421,7 +420,8 @@ FileOperationManager.prototype.serviceAllDeleteTasks_ = function() {
* @param {function()} callback Callback run on task end.
* @private
*/
FileOperationManager.prototype.serviceDeleteTask_ = function(task, callback) {
FileOperationManagerImpl.prototype.serviceDeleteTask_ = function(
task, callback) {
var queue = new AsyncUtil.Queue();
// Delete each entry.
......@@ -471,7 +471,7 @@ FileOperationManager.prototype.serviceDeleteTask_ = function(task, callback) {
* @param {!Array<!Entry>} selectionEntries The selected entries.
* @param {!DirectoryEntry} dirEntry The directory containing the selection.
*/
FileOperationManager.prototype.zipSelection = function(
FileOperationManagerImpl.prototype.zipSelection = function(
selectionEntries, dirEntry) {
var zipTask = new fileOperationUtil.ZipTask(
this.generateTaskId(), selectionEntries, dirEntry, dirEntry);
......@@ -490,6 +490,6 @@ FileOperationManager.prototype.zipSelection = function(
*
* @return {string} New task ID.
*/
FileOperationManager.prototype.generateTaskId = function() {
FileOperationManagerImpl.prototype.generateTaskId = function() {
return 'file-operation-' + this.taskIdCounter_++;
};
......@@ -255,7 +255,7 @@ volumeManagerFactory.getInstance = function() {
/**
* Test target.
* @type {FileOperationManager}
* @type {FileOperationManagerImpl}
*/
var fileOperationManager;
......@@ -483,7 +483,7 @@ function testCopy(callback) {
};
volumeManager = new FakeVolumeManager();
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
// Observing manager's events.
var eventsPromise = waitForEvents(fileOperationManager);
......@@ -541,7 +541,7 @@ function testCopyInSequential(callback) {
blockableFakeStartCopy.startCopyFunc.bind(blockableFakeStartCopy);
volumeManager = new FakeVolumeManager();
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
var eventLogger = new EventLogger(fileOperationManager);
......@@ -626,7 +626,7 @@ function testCopyInParallel(callback) {
blockableFakeStartCopy.startCopyFunc.bind(blockableFakeStartCopy);
volumeManager = new FakeVolumeManager();
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
var eventLogger = new EventLogger(fileOperationManager);
......@@ -696,7 +696,7 @@ function testCopyFails(callback) {
return null;
}
};
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
var eventLogger = new EventLogger(fileOperationManager);
......@@ -737,7 +737,7 @@ function testMove(callback) {
resolveTestFileSystemURL.bind(null, fileSystem);
volumeManager = new FakeVolumeManager();
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
// Observing manager's events.
var eventsPromise = waitForEvents(fileOperationManager);
......@@ -836,7 +836,7 @@ function testZip(callback) {
};
volumeManager = new FakeVolumeManager();
fileOperationManager = new FileOperationManager();
fileOperationManager = new FileOperationManagerImpl();
// Observing manager's events.
reportPromise(waitForEvents(fileOperationManager).then(function(events) {
......
......@@ -5,15 +5,16 @@
'use strict';
/**
* Mock class of FileOperationManager.
* Mock implementation of {FileOperationManager} for tests.
* @constructor
* @struct
* @implements {FileOperationManager}
* @extends {cr.EventTarget}
*/
function MockFileOperationManager() {
cr.EventTarget.call(this);
/**
* Event to be dispatched when requestTaskCancel is called.
* Event to be dispatched when requestTaskCancel is called. Note: the
* unittest writes this value before calling requestTaskCancel().
* @type {Event}
*/
this.cancelEvent = null;
......@@ -25,20 +26,23 @@ function MockFileOperationManager() {
this.pasteResolver = null;
}
MockFileOperationManager.prototype = {
__proto__: cr.EventTarget.prototype
MockFileOperationManager.prototype = /** @struct */ {
__proto__: cr.EventTarget.prototype,
};
/**
* Dispatches a pre-specified cancel event.
* Dispatches a cancel event that has been specified by the unittest.
*/
MockFileOperationManager.prototype.requestTaskCancel = function() {
assert(this.cancelEvent);
this.dispatchEvent(this.cancelEvent);
};
/**
* @param {!Array<!Entry>} sourceEntries Entries of the source files.
* @param {!DirectoryEntry} targetEntry The destination entry of the target
* Kick off pasting.
*
* @param {Array<Entry>} sourceEntries Entries of the source files.
* @param {DirectoryEntry} targetEntry The destination entry of the target
* directory.
* @param {boolean} isMove True if the operation is "move", otherwise (i.e.
* if the operation is "copy") false.
......@@ -91,3 +95,11 @@ MockFileOperationManager.prototype.generateTaskId = function() {
MockFileOperationManager.prototype.isKnownTaskId = function(id) {
return this.generatedTaskIds.indexOf(id) !== -1;
};
MockFileOperationManager.prototype.hasQueuedTasks = function() {};
MockFileOperationManager.prototype.filterSameDirectoryEntry = function() {};
MockFileOperationManager.prototype.deleteEntries = function() {};
MockFileOperationManager.prototype.zipSelection = function() {};
......@@ -1363,9 +1363,9 @@ util.validateExternalDriveName = function(name, volumeInfo) {
};
/**
* Adds a foregorund listener to the background page components.
* The lisner will be removed when the foreground window is closed.
* @param {!cr.EventTarget} target
* Adds a foreground listener to the background page components.
* The listener will be removed when the foreground window is closed.
* @param {!EventTarget} target
* @param {string} type
* @param {Function} handler
*/
......
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