Commit dea3b9e5 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Closure compile mocks in //file_manager/foreground/js.

This just gets the mocks to be closure compiled, there will
likely be more changes when we start taking direct dependencies.

Bug: 860355
Change-Id: I7ddfe6f82830a3d2e5b0858596dba80f921e5534
Reviewed-on: https://chromium-review.googlesource.com/c/1304036Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Stuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603420}
parent 84338104
......@@ -296,14 +296,19 @@ MockFileEntry.prototype.asMock = function() {
* @param {FileSystem} filesystem File system where the entry is localed.
* @param {string} fullPath Full path for the entry.
* @param {Metadata=} opt_metadata Metadata.
* @extends {MockEntry}
* @extends {DirectoryEntry} MockDirectoryEntry is used to mock the implement
* DirectoryEntry for testing.
* @implements {MockEntryInterface}
* @constructor
*/
function MockDirectoryEntry(filesystem, fullPath, opt_metadata) {
var metadata = opt_metadata || /** @type {!Metadata} */ ({});
metadata.size = metadata.size || 0;
metadata.modificationTime = metadata.modificationTime || new Date();
MockEntry.call(this, filesystem, fullPath, metadata);
filesystem.entries[fullPath] = this;
this.filesystem = filesystem;
this.fullPath = fullPath;
this.metadata = opt_metadata || /** @type {!Metadata} */ ({});
this.metadata.size = this.metadata.size || 0;
this.metadata.modificationTime = this.metadata.modificationTime || new Date();
this.removed_ = false;
this.isFile = false;
this.isDirectory = true;
}
......@@ -329,12 +334,16 @@ MockDirectoryEntry.prototype.getAllChildren = function() {
* Returns a file under the directory.
*
* @param {string} path Path.
* @param {Object} option Option.
* @param {function(!FileEntry)} onSuccess Success callback.
* @param {function(!FileError)} onError Failure callback;
* @param {!FileSystemFlags=} option Options
* @param {function(!FileEntry)=} onSuccess Success callback.
* @param {function(!FileError)=} onError Failure callback;
*/
MockDirectoryEntry.prototype.getFile = function(
path, option, onSuccess, onError) {
// As onSuccess and onError are optional, if they are not supplied we default
// them to be no-ops to save on checking their validity later.
onSuccess = onSuccess || (entry => {}); // no-op
onError = onError || (error => {}); // no-op
var fullPath = path[0] === '/' ? path : joinPath(this.fullPath, path);
if (!this.filesystem.entries[fullPath])
onError(/** @type {!FileError} */ ({name: util.FileError.NOT_FOUND_ERR}));
......@@ -349,24 +358,30 @@ MockDirectoryEntry.prototype.getFile = function(
* Returns a directory under the directory.
*
* @param {string} path Path.
* @param {Object} option Option.
* @param {function(!MockDirectoryEntry)} onSuccess Success callback.
* @param {function(Object)} onError Failure callback;
* @param {!FileSystemFlags=} option Options
* @param {function(!DirectoryEntry)=} onSuccess Success callback.
* @param {function(!FileError)=} onError Failure callback;
*/
MockDirectoryEntry.prototype.getDirectory =
function(path, option, onSuccess, onError) {
MockDirectoryEntry.prototype.getDirectory = function(
path, option, onSuccess, onError) {
// As onSuccess and onError are optional, if they are not supplied we default
// them to be no-ops to save on checking their validity later.
onSuccess = onSuccess || (entry => {}); // no-op
onError = onError || (error => {}); // no-op
var fullPath = path[0] === '/' ? path : joinPath(this.fullPath, path);
var result = this.filesystem.entries[fullPath];
if (result) {
if (!(result instanceof MockDirectoryEntry))
onError({name: util.FileError.TYPE_MISMATCH_ERR});
onError(
/** @type {!FileError} */ ({name: util.FileError.TYPE_MISMATCH_ERR}));
else if (option['create'] && option['exclusive'])
onError({name: util.FileError.PATH_EXISTS_ERR});
onError(
/** @type {!FileError} */ ({name: util.FileError.PATH_EXISTS_ERR}));
else
onSuccess(result);
} else {
if (!option['create']) {
onError({name: util.FileError.NOT_FOUND_ERR});
onError(/** @type {!FileError} */ ({name: util.FileError.NOT_FOUND_ERR}));
} else {
var newEntry = new MockDirectoryEntry(this.filesystem, fullPath);
this.filesystem.entries[fullPath] = newEntry;
......
......@@ -111,6 +111,10 @@ js_type_check("test_support_type_check") {
testonly = true
deps = [
":mock_actions_model",
":mock_directory_model",
":mock_folder_shortcut_data_model",
":mock_navigation_list_model",
":mock_thumbnail_loader",
]
}
......@@ -147,6 +151,37 @@ js_library("mock_actions_model") {
]
}
js_library("mock_directory_model") {
testonly = true
deps = [
":directory_contents",
":directory_model",
"//ui/file_manager/file_manager/common/js:mock_entry",
"//ui/file_manager/file_manager/common/js:util",
]
}
js_library("mock_folder_shortcut_data_model") {
testonly = true
deps = [
"//ui/file_manager/file_manager/common/js:mock_entry",
]
}
js_library("mock_navigation_list_model") {
testonly = true
deps = [
":navigation_list_model",
]
}
js_library("mock_thumbnail_loader") {
testonly = true
deps = [
":thumbnail_loader",
]
}
js_library("app_state_controller") {
deps = [
":dialog_type",
......
......@@ -5,7 +5,7 @@
/**
* Mock class for DirectoryModel.
* @constructor
* @extends {cr.EventTarget}
* @extends {DirectoryModel}
*/
function MockDirectoryModel() {
/**
......@@ -48,8 +48,8 @@ MockDirectoryModel.prototype.navigateToMockEntry = function(entry) {
var event = new Event('directory-changed');
event.previousDirEntry = this.currentEntry_;
event.newDirEntry = entry;
event.volumeChanged = this.currentEntry_ &&
util.isSameFileSystem(this.currentEntry_, entry);
event.volumeChanged =
this.currentEntry_ && util.isSameEntry(this.currentEntry_, entry);
this.currentEntry_ = entry;
this.dispatchEvent(event);
resolve();
......@@ -59,7 +59,7 @@ MockDirectoryModel.prototype.navigateToMockEntry = function(entry) {
/**
* Mock class for FileFilter.
* @constructor
* @extends {cr.EventTarget}
* @extends {FileFilter}
*/
function MockFileFilter() {}
......
......@@ -11,6 +11,7 @@
* @param {string=} opt_mediaType Media type.
* @param {Array<ThumbnailLoader.LoadTarget>=} opt_loadTargets Load targets.
* @param {number=} opt_priority Priority.
* @constructor
*/
function MockThumbnailLoader(entry, opt_loaderType, opt_metadata, opt_mediaType,
opt_loadTargets, opt_priority) {
......@@ -19,7 +20,7 @@ function MockThumbnailLoader(entry, opt_loaderType, opt_metadata, opt_mediaType,
/**
* Data url of test image.
* @private {string}
* @private {?string}
*/
MockThumbnailLoader.testImageDataUrl = null;
......@@ -44,8 +45,8 @@ MockThumbnailLoader.errorUrls = [];
/**
* Loads thumbnail as data url.
*
* @return {!Promise<{data:string, width:number, height:number}>} A promise
* which is resolved with data url.
* @return {!Promise<{data:?string, width:number, height:number}>} A
* promise which is resolved with data url.
*/
MockThumbnailLoader.prototype.loadAsDataUrl = function() {
if (MockThumbnailLoader.errorUrls.indexOf(this.entry_.toURL()) !== -1)
......
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