Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: ui/file_manager/file_manager/background/js/media_import_handler_unittest.js

Issue 964533003: Files.app: Fix task cancellation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2311
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/background/js/media_import_handler_unittest.js
diff --git a/ui/file_manager/file_manager/background/js/media_import_handler_unittest.js b/ui/file_manager/file_manager/background/js/media_import_handler_unittest.js
index 35886a7b1fccbe863fec90af08181b898c3a1f06..3d0a374f71e2b5e5525e9aa2529fce3e5ed612e8 100644
--- a/ui/file_manager/file_manager/background/js/media_import_handler_unittest.js
+++ b/ui/file_manager/file_manager/background/js/media_import_handler_unittest.js
@@ -115,7 +115,7 @@ function testImportMedia(callback) {
*/
function(updateType, task) {
switch (updateType) {
- case importer.TaskQueue.UpdateType.SUCCESS:
+ case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
@@ -162,7 +162,7 @@ function testImportMediaWithDuplicateFilenames(callback) {
*/
function(updateType, task) {
switch (updateType) {
- case importer.TaskQueue.UpdateType.SUCCESS:
+ case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
@@ -210,7 +210,7 @@ function testKeepAwakeDuringImport(callback) {
// Assert that keepAwake is set while the task is active.
assertTrue(chrome.power.requestKeepAwakeStatus);
switch (updateType) {
- case importer.TaskQueue.UpdateType.SUCCESS:
+ case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
@@ -253,7 +253,7 @@ function testUpdatesHistoryAfterImport(callback) {
*/
function(updateType, task) {
switch (updateType) {
- case importer.TaskQueue.UpdateType.SUCCESS:
+ case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
@@ -361,7 +361,7 @@ function testImportWithDuplicates(callback) {
*/
function(updateType, task) {
switch (updateType) {
- case importer.TaskQueue.UpdateType.SUCCESS:
+ case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
@@ -395,6 +395,62 @@ function testImportWithDuplicates(callback) {
scanResult.finalize();
}
+function testImportWithErrors(callback) {
+ var media = setupFileSystem([
+ '/DCIM/photos0/IMG00001.jpg',
+ '/DCIM/photos0/IMG00002.jpg',
+ '/DCIM/photos0/IMG00003.jpg',
+ '/DCIM/photos1/IMG00004.jpg',
+ '/DCIM/photos1/IMG00005.jpg',
+ '/DCIM/photos1/IMG00006.jpg'
+ ]);
+
+ /** @const {number} */
+ var EXPECTED_COPY_COUNT = 5;
+
+ var scanResult = new TestScanResult(media);
+ var importTask = mediaImporter.importFromScanResult(
+ scanResult,
+ importer.Destination.GOOGLE_DRIVE,
+ destinationFactory);
+ var whenImportDone = new Promise(
+ function(resolve, reject) {
+ importTask.addObserver(
+ /**
+ * @param {!importer.TaskQueue.UpdateType} updateType
+ * @param {!importer.TaskQueue.Task} task
+ */
+ function(updateType, task) {
+ if (updateType === importer.TaskQueue.UpdateType.COMPLETE) {
+ resolve();
+ }
+ });
+ });
+
+ // Simulate an error after 3 imports.
+ var copyCount = 0;
+ importTask.addObserver(function(updateType) {
+ if (updateType ===
+ importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED) {
+ copyCount++;
+ if (copyCount === 3) {
+ mockCopier.simulateOneError();
+ }
+ }
+ });
+
+ // Verify that the error didn't result in only 3 files being imported.
+ reportPromise(
+ whenImportDone.then(
+ function() {
+ var copiedEntries = destinationFileSystem.root.getAllChildren();
+ assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
+ }),
+ callback);
+
+ scanResult.finalize();
+}
+
/**
* @param {!Array.<string>} fileNames
* @return {!Array.<!Entry>}
@@ -421,6 +477,8 @@ function MockCopyTo() {
// Replace with test function.
fileOperationUtil.copyTo = this.copyTo_.bind(this);
+ this.simulateError_ = false;
+
this.entryChangedCallback_ = null;
this.progressCallback_ = null;
this.successCallback_ = null;
@@ -437,6 +495,13 @@ function MockCopyTo() {
MockCopyTo.CopyInfo;
/**
+ * Makes the mock copier simulate an error the next time copyTo_ is called.
+ */
+MockCopyTo.prototype.simulateOneError = function() {
+ this.simulateError_ = true;
+};
+
+/**
* A mock to replace fileOperationUtil.copyTo. See the original for details.
* @param {Entry} source
* @param {DirectoryEntry} parent
@@ -454,6 +519,12 @@ MockCopyTo.prototype.copyTo_ = function(source, parent, newName,
this.successCallback_ = successCallback;
this.errorCallback_ = errorCallback;
+ if (this.simulateError_) {
+ this.simulateError_ = false;
+ this.errorCallback_(new Error('test error'));
+ return;
+ }
+
// Log the copy, then copy the file.
this.copiedFiles.push({
source: source,

Powered by Google App Engine
This is Rietveld 408576698