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