function testImportCancellation(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 = 3;

  var scanResult = new TestScanResult(media);
  var importTask = mediaImporter.importFromScanResult(
      scanResult,
      importer.Destination.GOOGLE_DRIVE,
      destinationFactory);
  var whenImportCancelled = 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.CANCELED) {
                resolve();
              }
            });
      });

  // Simulate cancellation after the expected number of copies is done.
  var copyCount = 0;
  importTask.addObserver(function(updateType) {
    if (updateType ===
        importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED) {
      copyCount++;
      if (copyCount === EXPECTED_COPY_COUNT) {
        importTask.requestCancel();
      }
    }
  });

  reportPromise(
      whenImportCancelled.then(
        function() {
          var copiedEntries = destinationFileSystem.root.getAllChildren();
          assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
        }),
      callback);

  scanResult.finalize();
}
// Tests that cancelling an import works properly.
Tests that cancelling an import works properly.
Tests that cancelling an import works properly .
function testImportCancellation(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'
  ]);
  var EXPECTED_COPY_COUNT = 3;
  var scanResult = new TestScanResult(media);
  var importTask = mediaImporter.importFromScanResult(
      scanResult,
      importer.Destination.GOOGLE_DRIVE,
      destinationFactory);
  var whenImportCancelled = new Promise(
      function(resolve, reject) {
        importTask.addObserver(
            function(updateType, task) {
              if (updateType === importer.TaskQueue.UpdateType.CANCELED) {
                resolve();
              }
            });
      });
  var copyCount = 0;
  importTask.addObserver(function(updateType) {
    if (updateType ===
        importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED) {
      copyCount++;
      if (copyCount === EXPECTED_COPY_COUNT) {
        importTask.requestCancel();
      }
    }
  });
  reportPromise(
      whenImportCancelled.then(
        function() {
          var copiedEntries = destinationFileSystem.root.getAllChildren();
          assertEquals(EXPECTED_COPY_COUNT, copiedEntries.length);
        }),
      callback);
  scanResult.finalize();
}
function testImportCancellation ( 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' ] ) ; var EXPECTED_COPY_COUNT = 3 ; var scanResult = new TestScanResult ( media ) ; var importTask = mediaImporter . importFromScanResult ( scanResult , importer . Destination . GOOGLE_DRIVE , destinationFactory ) ; var whenImportCancelled = new Promise ( function ( resolve , reject ) { importTask . addObserver ( function ( updateType , task ) { if ( updateType === importer . TaskQueue . UpdateType . CANCELED ) { resolve ( ) ; } } ) ; } ) ; var copyCount = 0 ; importTask . addObserver ( function ( updateType ) { if ( updateType === importer . MediaImportHandler . ImportTask . UpdateType . ENTRY_CHANGED ) { copyCount ++ ; if ( copyCount === EXPECTED_COPY_COUNT ) { importTask . requestCancel ( ) ; } } } ) ; reportPromise ( whenImportCancelled . then ( function ( ) { var copiedEntries = destinationFileSystem . root . getAllChildren ( ) ; assertEquals ( EXPECTED_COPY_COUNT , copiedEntries . length ) ; } ) , callback ) ; scanResult . finalize ( ) ; }
Tests that cancelling an import works properly.
Tests that cancelling an import works properly .
/** @const {number} */ /**
             * @param {!importer.TaskQueue.UpdateType} updateType
             * @param {!importer.TaskQueue.Task} task
             */ // Simulate cancellation after the expected number of copies is done.