Commit 5e01981e authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile media_import_handler_unittest

 - remove media_inport_handler_unittest.html
 - add BUILD rules to auto-generate and compile this unittest
 - define mockChrome, install it during the unittest
 - remove unused unittest vars and JS auto-format
 - document test fixtures and test helpers
 - fix Closure compile errors (there were lots).

No change in test behavior, no new tests.

Bug: 907970
Change-Id: Id90b4b1eaf84764521fb0d77aa2c29ff56db7c07
Reviewed-on: https://chromium-review.googlesource.com/c/1356728
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612997}
parent d1df6533
......@@ -75,8 +75,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, LRUCacheTest) {
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaImportHandlerTest) {
RunTest(base::FilePath(
FILE_PATH_LITERAL("background/js/media_import_handler_unittest.html")));
RunGeneratedTest("/background/js/media_import_handler_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, TaskQueueTest) {
......
......@@ -334,6 +334,22 @@ js_library("media_import_handler") {
"../../common/js:importer_common",
"../../common/js:metrics",
]
externs_list = [ "//ui/file_manager/externs/background/import_runner.js" ]
}
js_unittest("media_import_handler_unittest") {
deps = [
":media_import_handler",
":mock_drive_sync_handler",
":mock_media_scanner",
":mock_progress_center",
":mock_volume_manager",
":test_import_history",
"//ui/file_manager/base/js:mock_chrome",
"//ui/file_manager/base/js:test_error_reporting",
"//ui/file_manager/file_manager/common/js:mock_entry",
"//ui/file_manager/file_manager/common/js:test_importer_common",
]
}
js_library("mock_media_scanner") {
......@@ -499,6 +515,7 @@ js_unit_tests("unit_tests") {
":file_operation_handler_unittest",
":file_operation_manager_unittest",
":import_history_unittest",
":media_import_handler_unittest",
":media_scanner_unittest",
":task_queue_unittest",
":volume_manager_unittest",
......
<!DOCTYPE html>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.
-->
<html>
<body>
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="../../common/js/async_util.js"></script>
<script src="../../common/js/metrics_base.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../../base/js/mock_chrome.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/files_app_entry_types.js"></script>
<script src="../../common/js/util.js"></script>
<script src="../../../base/js/volume_manager_types.js"></script>
<script src="../../common/js/importer_common.js"></script>
<script src="../../common/js/test_importer_common.js"></script>
<script src="../../common/js/progress_center_common.js"></script>
<script src="drive_sync_handler.js"></script>
<script src="entry_location_impl.js"></script>
<script src="test_import_history.js"></script>
<script src="mock_drive_sync_handler.js"></script>
<script src="mock_progress_center.js"></script>
<script src="mock_media_scanner.js"></script>
<script src="task_queue.js"></script>
<script src="media_import_handler.js"></script>
<script src="duplicate_finder.js"></script>
<script src="volume_info_impl.js"></script>
<script src="volume_info_list_impl.js"></script>
<script src="volume_manager_factory.js"></script>
<script src="volume_manager_impl.js"></script>
<script src="volume_manager_util.js"></script>
<script src="mock_volume_manager.js"></script>
<script src="file_operation_util.js"></script>
<script src="media_import_handler_unittest.js"></script>
</body>
</html>
......@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** @type {!MockFileOperationManager} */
var progressCenter;
'use strict';
/** @type {!TestMediaScanner} */
var mediaScanner;
/** @type {!MockProgressCenter} */
var progressCenter;
/** @type {!importer.MediaImportHandler} */
var mediaImporter;
......@@ -14,12 +13,9 @@ var mediaImporter;
/** @type {!importer.TestImportHistory} */
var importHistory;
/** @param {!importer.DispositionChecker.CheckerFunction} */
/** @type {!importer.DispositionChecker.CheckerFunction} */
var dispositionChecker;
/** @type {!VolumeInfo} */
var drive;
/** @type {!MockCopyTo} */
var mockCopier;
......@@ -32,8 +28,10 @@ var destinationFactory;
/** @type {!MockDriveSyncHandler} */
var driveSyncHandler;
var chrome;
/**
* Mock metrics.
* @type {!Object}
*/
window.metrics = {
recordSmallCount: function() {},
recordUserAction: function() {},
......@@ -41,63 +39,75 @@ window.metrics = {
recordBoolean: function() {},
};
/**
* Mock Chrome APIs
* @type {!Object}
*/
var mockChrome;
// Set up the test components.
function setUp() {
// Mock loadTimeData strings.
window.loadTimeData.getString = id => id;
// Set up mock chrome APIs.
chrome = {
// Setup mock chrome APIs.
mockChrome = {
power: {
requestKeepAwakeWasCalled: false,
requestKeepAwakeStatus: false,
requestKeepAwake: function() {
chrome.power.requestKeepAwakeWasCalled = true;
chrome.power.requestKeepAwakeStatus = true;
mockChrome.power.requestKeepAwakeWasCalled = true;
mockChrome.power.requestKeepAwakeStatus = true;
},
releaseKeepAwake: function() {
chrome.power.requestKeepAwakeStatus = false;
mockChrome.power.requestKeepAwakeStatus = false;
}
},
fileManagerPrivate: {
setEntryTag: function() {}
}
setEntryTag: function() {},
},
};
new MockCommandLinePrivate();
importer.setupTestLogger();
progressCenter = new MockProgressCenter();
installMockChrome(mockChrome);
new MockCommandLinePrivate();
// Replaces fileOperationUtil.copyTo with test function.
// Replace fileOperationUtil.copyTo with mock test function.
mockCopier = new MockCopyTo();
// Create and install MockVolumeManager.
var volumeManager = new MockVolumeManager();
drive = volumeManager.getCurrentProfileVolumeInfo(
VolumeManagerCommon.VolumeType.DRIVE);
// Create fake parented and non-parented roots.
drive.fileSystem.populate([
'/root/',
'/other/'
]);
MockVolumeManager.installMockSingleton(volumeManager);
importHistory = new importer.TestImportHistory();
// Add fake parented and non-parented roots: /root/ and /other/.
var driveVolumeType = VolumeManagerCommon.VolumeType.DRIVE;
var driveVolumeInfo = /** @type {!VolumeInfo} */
(volumeManager.getCurrentProfileVolumeInfo(driveVolumeType));
var driveFileSystem =
/** @type {!MockFileSystem} */ (driveVolumeInfo.fileSystem);
driveFileSystem.populate(['/root/', '/other/']);
// This is the default disposition checker used by mediaImporter.
// Tests can replace this at runtime if they want specialized behaviors.
// Setup a default disposition checker. Tests can replace it at runtime
// if they need specialized disposition check behavior.
dispositionChecker = function() {
return Promise.resolve(importer.Disposition.ORIGINAL);
};
mediaScanner = new TestMediaScanner();
destinationFileSystem = new MockFileSystem('googleDriveFilesystem');
destinationFactory = Promise.resolve(destinationFileSystem.root);
// Setup MediaImporter.
progressCenter = new MockProgressCenter();
importHistory = new importer.TestImportHistory();
driveSyncHandler = new MockDriveSyncHandler();
importer.setupTestLogger();
mediaImporter = new importer.MediaImportHandler(
progressCenter, importHistory, function(entry, destination) {
return dispositionChecker(entry, destination);
}, driveSyncHandler);
progressCenter, importHistory, dispositionChecker, driveSyncHandler);
// Setup the copy destination.
destinationFileSystem = new MockFileSystem('googleDriveFilesystem');
destinationFactory = Promise.resolve(destinationFileSystem.root);
}
/**
* Tests media imports.
*/
function testImportMedia(callback) {
var media = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -113,14 +123,14 @@ function testImportMedia(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -133,9 +143,10 @@ function testImportMedia(callback) {
});
reportPromise(
whenImportDone.then(
function() {
var copiedEntries = destinationFileSystem.root.getAllChildren();
whenImportDone.then(function() {
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(media.length, copiedEntries.length);
}),
callback);
......@@ -143,6 +154,9 @@ function testImportMedia(callback) {
scanResult.finalize();
}
/**
* Tests media import duplicate detection.
*/
function testImportMedia_skipAndMarkDuplicatedFiles(callback) {
var DUPLICATED_FILE_PATH_1 = '/DCIM/photos0/duplicated_1.jpg';
var DUPLICATED_FILE_PATH_2 = '/DCIM/photos0/duplicated_2.jpg';
......@@ -171,14 +185,14 @@ function testImportMedia_skipAndMarkDuplicatedFiles(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -194,15 +208,17 @@ function testImportMedia_skipAndMarkDuplicatedFiles(callback) {
whenImportDone.then(
function() {
// Only the new file should be copied.
var copiedEntries = destinationFileSystem.root.getAllChildren();
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(1, copiedEntries.length);
assertEquals(ORIGINAL_FILE_DEST_PATH, copiedEntries[0].fullPath);
importHistory.assertCopied(media[1],
importer.Destination.GOOGLE_DRIVE);
var mockFileEntry = /** @type {!MockFileEntry} */ (media[1]);
importHistory.assertCopied(
mockFileEntry, importer.Destination.GOOGLE_DRIVE);
// The 2 duplicated files should be marked as imported.
[media[0], media[2]].forEach(
/** @param {!FileEntry} entry */
function(entry) {
[media[0], media[2]].forEach(function(entry) {
entry = /** @type {!MockFileEntry} */ (entry);
importHistory.assertImported(
entry, importer.Destination.GOOGLE_DRIVE);
});
......@@ -211,6 +227,9 @@ function testImportMedia_skipAndMarkDuplicatedFiles(callback) {
scanResult.finalize();
}
/**
* Tests media import uses encoded URLs.
*/
function testImportMedia_EmploysEncodedUrls(callback) {
var media = setupFileSystem([
'/DCIM/photos0/Mom and Dad.jpg',
......@@ -222,26 +241,25 @@ function testImportMedia_EmploysEncodedUrls(callback) {
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var promise = new Promise(
function(resolve, reject) {
var promise =
new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve(destinationFileSystem.root.getAllChildren());
resolve(/** @type {!MockDirectoryEntry} */
(destinationFileSystem.root).getAllChildren());
break;
case importer.TaskQueue.UpdateType.ERROR:
reject('Task failed :(');
break;
}
});
})
.then(
function(copiedEntries) {
}).then(function(copiedEntries) {
var expected = 'Mom%20and%20Dad.jpg';
var url = copiedEntries[0].toURL();
assertTrue(url.length > expected.length);
......@@ -254,8 +272,10 @@ function testImportMedia_EmploysEncodedUrls(callback) {
scanResult.finalize();
}
// Verifies that when files with duplicate names are imported, that they don't
// overwrite one another.
/**
* Tests that when files with duplicate names are imported, that they don't
* overwrite one another.
*/
function testImportMediaWithDuplicateFilenames(callback) {
var media = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -271,14 +291,14 @@ function testImportMediaWithDuplicateFilenames(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -292,9 +312,10 @@ function testImportMediaWithDuplicateFilenames(callback) {
// Verify that we end up with 6, and not 3, destination entries.
reportPromise(
whenImportDone.then(
function() {
var copiedEntries = destinationFileSystem.root.getAllChildren();
whenImportDone.then(function() {
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(media.length, copiedEntries.length);
}),
callback);
......@@ -302,6 +323,9 @@ function testImportMediaWithDuplicateFilenames(callback) {
scanResult.finalize();
}
/**
* Tests that active media imports keep chrome.power awake.
*/
function testKeepAwakeDuringImport(callback) {
var media = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -317,16 +341,16 @@ function testKeepAwakeDuringImport(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
// Assert that keepAwake is set while the task is active.
assertTrue(chrome.power.requestKeepAwakeStatus);
assertTrue(mockChrome.power.requestKeepAwakeStatus);
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -339,11 +363,12 @@ function testKeepAwakeDuringImport(callback) {
});
reportPromise(
whenImportDone.then(
function() {
assertTrue(chrome.power.requestKeepAwakeWasCalled);
assertFalse(chrome.power.requestKeepAwakeStatus);
var copiedEntries = destinationFileSystem.root.getAllChildren();
whenImportDone.then(function() {
assertTrue(mockChrome.power.requestKeepAwakeWasCalled);
assertFalse(mockChrome.power.requestKeepAwakeStatus);
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(media.length, copiedEntries.length);
}),
callback);
......@@ -351,6 +376,9 @@ function testKeepAwakeDuringImport(callback) {
scanResult.finalize();
}
/**
* Tests that media imports update import history.
*/
function testUpdatesHistoryAfterImport(callback) {
var entries = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -369,14 +397,13 @@ function testUpdatesHistoryAfterImport(callback) {
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -388,19 +415,18 @@ function testUpdatesHistoryAfterImport(callback) {
});
});
var promise = whenImportDone.then(
function() {
var promise = whenImportDone.then(function() {
mockCopier.copiedFiles.forEach(
/** @param {!MockCopyTo.CopyInfo} copy */
function(copy) {
var mockFileEntry = /** @type {!MockFileEntry} */ (copy.source);
importHistory.assertCopied(
copy.source, importer.Destination.GOOGLE_DRIVE);
mockFileEntry, importer.Destination.GOOGLE_DRIVE);
});
dupeFiles.forEach(
/** @param {!FileEntry} entry */
function(entry) {
dupeFiles.forEach(function(entry) {
var mockFileEntry = /** @type {!MockFileEntry} */ (entry);
importHistory.assertImported(
entry, importer.Destination.GOOGLE_DRIVE);
mockFileEntry, importer.Destination.GOOGLE_DRIVE);
});
});
......@@ -408,6 +434,9 @@ function testUpdatesHistoryAfterImport(callback) {
reportPromise(promise, callback);
}
/**
* Tests that media imports tag entries after import.
*/
function testTagsEntriesAfterImport(callback) {
var entries = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -419,14 +448,14 @@ function testTagsEntriesAfterImport(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
......@@ -440,7 +469,7 @@ function testTagsEntriesAfterImport(callback) {
var taggedEntries = [];
// Replace chrome.fileManagerPrivate.setEntryTag with a listener.
chrome.fileManagerPrivate.setEntryTag = function(entry) {
mockChrome.fileManagerPrivate.setEntryTag = function(entry) {
taggedEntries.push(entry);
};
......@@ -454,7 +483,9 @@ function testTagsEntriesAfterImport(callback) {
scanResult.finalize();
}
// Tests that cancelling an import works properly.
/**
* Tests cancelling a media import.
*/
function testImportCancellation(callback) {
var media = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
......@@ -473,14 +504,14 @@ function testImportCancellation(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportCancelled = new Promise(
function(resolve, reject) {
var whenImportCancelled = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
if (updateType === importer.TaskQueue.UpdateType.CANCELED) {
resolve();
}
......@@ -500,9 +531,10 @@ function testImportCancellation(callback) {
});
reportPromise(
whenImportCancelled.then(
function() {
var copiedEntries = destinationFileSystem.root.getAllChildren();
whenImportCancelled.then(function() {
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
}),
callback);
......@@ -510,9 +542,11 @@ function testImportCancellation(callback) {
scanResult.finalize();
}
/**
* Tests media imports with errors.
*/
function testImportWithErrors(callback) {
// Quiet the logger just in this test where we expect errors.
// Quieten the logger just in this test, since we expect errors.
// Elsewhere, it's better for errors to be seen by test authors.
importer.setupTestLogger().quiet();
......@@ -533,14 +567,14 @@ function testImportWithErrors(callback) {
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
var whenImportDone = new Promise(function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
* @param {Object=} opt_task
*/
function(updateType, task) {
function(updateType, opt_task) {
if (updateType === importer.TaskQueue.UpdateType.COMPLETE) {
resolve();
}
......@@ -561,9 +595,10 @@ function testImportWithErrors(callback) {
// Verify that the error didn't result in some files not being copied.
reportPromise(
whenImportDone.then(
function() {
var copiedEntries = destinationFileSystem.root.getAllChildren();
whenImportDone.then(function() {
var mockDirectoryEntry =
/** @type {!MockDirectoryEntry} */ (destinationFileSystem.root);
var copiedEntries = mockDirectoryEntry.getAllChildren();
assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
}),
callback);
......@@ -572,31 +607,31 @@ function testImportWithErrors(callback) {
}
/**
* Setup a file system containing the given |fileNames| and return the file
* system's entries in an array.
*
* @param {!Array<string>} fileNames
* @return {!Array<!Entry>}
*/
function setupFileSystem(fileNames) {
// Set up a filesystem with some files.
var fileSystem = new MockFileSystem('fake-media-volume');
let fileSystem = new MockFileSystem('fake-media-volume');
fileSystem.populate(fileNames);
return fileNames.map(
function(filename) {
return fileSystem.entries[filename];
});
return fileNames.map((name) => fileSystem.entries[name]);
}
/**
* Replaces fileOperationUtil.copyTo with some mock functionality for testing.
* Replaces fileOperationUtil.copyTo with a mock for testing.
* @constructor
*/
function MockCopyTo() {
/** @type {!Array<!MockCopyTo.CopyInfo>} */
this.copiedFiles = [];
// Replace with test function.
fileOperationUtil.copyTo = this.copyTo_.bind(this);
// Replace fileOperationUtil.copyTo with our mock test function.
fileOperationUtil.copyTo =
/** @type {function(*)} */ (this.copyTo_.bind(this));
/** @private {boolean} */
this.simulateError_ = false;
this.entryChangedCallback_ = null;
......@@ -607,9 +642,9 @@ function MockCopyTo() {
/**
* @typedef {{
* source: source,
* destination: parent,
* newName: newName
* source: !Entry,
* destination: !DirectoryEntry,
* newName: string,
* }}
*/
MockCopyTo.CopyInfo;
......@@ -623,14 +658,13 @@ MockCopyTo.prototype.simulateOneError = function() {
/**
* A mock to replace fileOperationUtil.copyTo. See the original for details.
* @param {Entry} source
* @param {DirectoryEntry} parent
* @param {!Entry} source
* @param {!DirectoryEntry} parent
* @param {string} newName
* @param {function(string, Entry)} entryChangedCallback
* @param {function(string, number)} progressCallback
* @param {function(Entry)} successCallback
* @param {function(DOMError)} errorCallback
* @return {function()}
* @param {function(Error)} errorCallback
*/
MockCopyTo.prototype.copyTo_ = function(source, parent, newName,
entryChangedCallback, progressCallback, successCallback, errorCallback) {
......@@ -641,22 +675,23 @@ MockCopyTo.prototype.copyTo_ = function(source, parent, newName,
if (this.simulateError_) {
this.simulateError_ = false;
this.errorCallback_(new Error('test error'));
var error = new Error('test error');
this.errorCallback_(error);
return;
}
// Log the copy, then copy the file.
this.copiedFiles.push({
// Log the copy details.
this.copiedFiles.push(/** @type {!MockCopyTo.CopyInfo} */ ({
source: source,
destination: parent,
newName: newName
});
source.copyTo(
parent,
newName,
function(newEntry) {
newName: newName,
}));
// Copy the file.
var copyErrorCallback = /** @type {!function(FileError):*} */
(this.errorCallback_.bind(this));
source.copyTo(parent, newName, function(newEntry) {
this.entryChangedCallback_(source.toURL(), parent);
this.successCallback_(newEntry);
}.bind(this),
this.errorCallback_.bind(this));
}.bind(this), copyErrorCallback);
};
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