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

Side by Side Diff: ui/file_manager/file_manager/background/js/media_import_handler_unittest.js

Issue 980603003: Move content deduplication into the scan process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review comments. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @type {!MockFileOperationManager} */ 5 /** @type {!MockFileOperationManager} */
6 var progressCenter; 6 var progressCenter;
7 7
8 /** @type {!TestMediaScanner} */ 8 /** @type {!TestMediaScanner} */
9 var mediaScanner; 9 var mediaScanner;
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 importHistory = new importer.TestImportHistory(); 75 importHistory = new importer.TestImportHistory();
76 mediaScanner = new TestMediaScanner(); 76 mediaScanner = new TestMediaScanner();
77 destinationFileSystem = new MockFileSystem('googleDriveFilesystem'); 77 destinationFileSystem = new MockFileSystem('googleDriveFilesystem');
78 destinationFactory = Promise.resolve(destinationFileSystem.root); 78 destinationFactory = Promise.resolve(destinationFileSystem.root);
79 duplicateFinderFactory = new importer.TestDuplicateFinder.Factory(); 79 duplicateFinderFactory = new importer.TestDuplicateFinder.Factory();
80 80
81 mediaImporter = new importer.MediaImportHandler( 81 mediaImporter = new importer.MediaImportHandler(
82 progressCenter, 82 progressCenter,
83 importHistory, 83 importHistory,
84 duplicateFinderFactory,
85 new TestTracker()); 84 new TestTracker());
86 } 85 }
87 86
88 function testImportMedia(callback) { 87 function testImportMedia(callback) {
89 var media = setupFileSystem([ 88 var media = setupFileSystem([
90 '/DCIM/photos0/IMG00001.jpg', 89 '/DCIM/photos0/IMG00001.jpg',
91 '/DCIM/photos0/IMG00002.jpg', 90 '/DCIM/photos0/IMG00002.jpg',
92 '/DCIM/photos0/IMG00003.jpg', 91 '/DCIM/photos0/IMG00003.jpg',
93 '/DCIM/photos1/IMG00004.jpg', 92 '/DCIM/photos1/IMG00004.jpg',
94 '/DCIM/photos1/IMG00005.jpg', 93 '/DCIM/photos1/IMG00005.jpg',
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 whenImportCancelled.then( 363 whenImportCancelled.then(
365 function() { 364 function() {
366 var copiedEntries = destinationFileSystem.root.getAllChildren(); 365 var copiedEntries = destinationFileSystem.root.getAllChildren();
367 assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length); 366 assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
368 }), 367 }),
369 callback); 368 callback);
370 369
371 scanResult.finalize(); 370 scanResult.finalize();
372 } 371 }
373 372
374 function testImportWithDuplicates(callback) {
375 var media = setupFileSystem([
376 '/DCIM/photos0/IMG00001.jpg',
377 '/DCIM/photos0/IMG00002.jpg',
378 '/DCIM/photos0/IMG00003.jpg',
379 '/DCIM/photos1/IMG00004.jpg',
380 '/DCIM/photos1/IMG00005.jpg',
381 '/DCIM/photos1/IMG00006.jpg'
382 ]);
383
384 /** @const {number} */
385 var EXPECTED_COPY_COUNT = 3;
386
387 var scanResult = new TestScanResult(media);
388 var importTask = mediaImporter.importFromScanResult(
389 scanResult,
390 importer.Destination.GOOGLE_DRIVE,
391 destinationFactory);
392 var whenImportDone = new Promise(
393 function(resolve, reject) {
394 importTask.addObserver(
395 /**
396 * @param {!importer.TaskQueue.UpdateType} updateType
397 * @param {!importer.TaskQueue.Task} task
398 */
399 function(updateType, task) {
400 switch (updateType) {
401 case importer.TaskQueue.UpdateType.COMPLETE:
402 resolve();
403 break;
404 case importer.TaskQueue.UpdateType.ERROR:
405 reject(new Error(importer.TaskQueue.UpdateType.ERROR));
406 break;
407 }
408 });
409 });
410
411 // Simulate a known number of new imports followed by a bunch of duplicate
412 // imports.
413 var copyCount = 0;
414 importTask.addObserver(function(updateType) {
415 if (updateType ===
416 importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED) {
417 copyCount++;
418 if (copyCount === EXPECTED_COPY_COUNT) {
419 duplicateFinderFactory.instances[0].returnValue = true;
420 }
421 }
422 });
423
424 reportPromise(
425 whenImportDone.then(
426 function() {
427 var copiedEntries = destinationFileSystem.root.getAllChildren();
428 assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
429 }),
430 callback);
431
432 scanResult.finalize();
433 }
434
435 function testImportWithErrors(callback) { 373 function testImportWithErrors(callback) {
436 374
437 // Quiet the logger just in this test where we expect errors. 375 // Quiet the logger just in this test where we expect errors.
438 // Elsewhere, it's better for errors to be seen by test authors. 376 // Elsewhere, it's better for errors to be seen by test authors.
439 importer.setupTestLogger().quiet(); 377 importer.setupTestLogger().quiet();
440 378
441 var media = setupFileSystem([ 379 var media = setupFileSystem([
442 '/DCIM/photos0/IMG00001.jpg', 380 '/DCIM/photos0/IMG00001.jpg',
443 '/DCIM/photos0/IMG00002.jpg', 381 '/DCIM/photos0/IMG00002.jpg',
444 '/DCIM/photos0/IMG00003.jpg', 382 '/DCIM/photos0/IMG00003.jpg',
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 }); 513 });
576 source.copyTo( 514 source.copyTo(
577 parent, 515 parent,
578 newName, 516 newName,
579 function(newEntry) { 517 function(newEntry) {
580 this.entryChangedCallback_(source.toURL(), parent); 518 this.entryChangedCallback_(source.toURL(), parent);
581 this.successCallback_(newEntry); 519 this.successCallback_(newEntry);
582 }.bind(this), 520 }.bind(this),
583 this.errorCallback_.bind(this)); 521 this.errorCallback_.bind(this));
584 }; 522 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698