function testCopyInParallel(callback) {
  var fileSystemA = createTestFileSystem('volumeA', {
    '/': DIRECTORY_SIZE,
    '/test.txt': 10
  });
  var fileSystemB = createTestFileSystem('volumeB', {
    '/': DIRECTORY_SIZE,
  });
  var fileSystems = [fileSystemA, fileSystemB];

  window.webkitResolveLocalFileSystemURL = function(url, success, failure) {
    return resolveTestFileSystemURL(
        getFileSystemForURL(fileSystems, url), url, success, failure);
  };

  var blockableFakeStartCopy = new BlockableFakeStartCopy(
      'filesystem:volumeB/',
      fileSystemA.entries['/test.txt'],
      fileSystems);
  chrome.fileManagerPrivate.startCopy =
      blockableFakeStartCopy.startCopyFunc.bind(blockableFakeStartCopy);

  volumeManager = new FakeVolumeManager();
  fileOperationManager = new FileOperationManager();

  var eventLogger = new EventLogger(fileOperationManager);

  // Copy test.txt from volume A to volume B.
  fileOperationManager.paste([fileSystemA.entries['/test.txt']],
      fileSystemB.entries['/'],
      false);

  var firstOperationTaskId;
  reportPromise(waitUntil(function() {
    return blockableFakeStartCopy.resolveBlockedOperationCallback !== null;
  }).then(function() {
    assertEquals(1, eventLogger.events.length);
    assertEquals('BEGIN', eventLogger.events[0].reason);
    firstOperationTaskId = eventLogger.events[0].taskId;

    // Copy test.txt from volume A to volume A. This should not be blocked by
    // the previous operation.
    fileOperationManager.paste([fileSystemA.entries['/test.txt']],
        fileSystemA.entries['/'],
        false);

    // Wait until the second operation is completed.
    return waitUntil(function() {
      return eventLogger.numberOfSuccessEvents === 1;
    });
  }).then(function() {
    // Resolve the blocked operation.
    blockableFakeStartCopy.resolveBlockedOperationCallback();

    // Wait until the blocked operation is completed.
    return waitUntil(function() {
      return eventLogger.numberOfSuccessEvents === 2;
    });
  }).then(function() {
    // Events should be following.
    // BEGIN: first operation
    // BEGIN: second operation
    // SUCCESS: second operation
    // SUCCESS: first operation
    var events = eventLogger.events;
    assertEquals(4, events.length);
    assertEquals('BEGIN', events[0].reason);
    assertEquals(firstOperationTaskId, events[0].taskId);
    assertEquals('BEGIN', events[1].reason);
    assertTrue(firstOperationTaskId !== events[1].taskId);
    assertEquals('SUCCESS', events[2].reason);
    assertEquals(events[1].taskId, events[2].taskId);
    assertEquals('SUCCESS', events[3].reason);
    assertEquals(firstOperationTaskId, events[3].taskId);
  }), callback);
}
/**
 * Tests the fileOperationUtil.paste for copying files in paralell. When
 * destination volumes are different, copy operations can run in paralell.
 */
Tests the fileOperationUtil.paste for copying files in paralell. When
destination volumes are different, copy operations can run in paralell.
Tests the fileOperationUtil . paste for copying files in paralell . When destination volumes are different copy operations can run in paralell .
function testCopyInParallel(callback) {
  var fileSystemA = createTestFileSystem('volumeA', {
    '/': DIRECTORY_SIZE,
    '/test.txt': 10
  });
  var fileSystemB = createTestFileSystem('volumeB', {
    '/': DIRECTORY_SIZE,
  });
  var fileSystems = [fileSystemA, fileSystemB];
  window.webkitResolveLocalFileSystemURL = function(url, success, failure) {
    return resolveTestFileSystemURL(
        getFileSystemForURL(fileSystems, url), url, success, failure);
  };
  var blockableFakeStartCopy = new BlockableFakeStartCopy(
      'filesystem:volumeB/',
      fileSystemA.entries['/test.txt'],
      fileSystems);
  chrome.fileManagerPrivate.startCopy =
      blockableFakeStartCopy.startCopyFunc.bind(blockableFakeStartCopy);
  volumeManager = new FakeVolumeManager();
  fileOperationManager = new FileOperationManager();
  var eventLogger = new EventLogger(fileOperationManager);
  fileOperationManager.paste([fileSystemA.entries['/test.txt']],
      fileSystemB.entries['/'],
      false);
  var firstOperationTaskId;
  reportPromise(waitUntil(function() {
    return blockableFakeStartCopy.resolveBlockedOperationCallback !== null;
  }).then(function() {
    assertEquals(1, eventLogger.events.length);
    assertEquals('BEGIN', eventLogger.events[0].reason);
    firstOperationTaskId = eventLogger.events[0].taskId;
    fileOperationManager.paste([fileSystemA.entries['/test.txt']],
        fileSystemA.entries['/'],
        false);
    return waitUntil(function() {
      return eventLogger.numberOfSuccessEvents === 1;
    });
  }).then(function() {
    blockableFakeStartCopy.resolveBlockedOperationCallback();
    return waitUntil(function() {
      return eventLogger.numberOfSuccessEvents === 2;
    });
  }).then(function() {
    var events = eventLogger.events;
    assertEquals(4, events.length);
    assertEquals('BEGIN', events[0].reason);
    assertEquals(firstOperationTaskId, events[0].taskId);
    assertEquals('BEGIN', events[1].reason);
    assertTrue(firstOperationTaskId !== events[1].taskId);
    assertEquals('SUCCESS', events[2].reason);
    assertEquals(events[1].taskId, events[2].taskId);
    assertEquals('SUCCESS', events[3].reason);
    assertEquals(firstOperationTaskId, events[3].taskId);
  }), callback);
}
function testCopyInParallel ( callback ) { var fileSystemA = createTestFileSystem ( 'volumeA' , { '/' : DIRECTORY_SIZE , '/test.txt' : 10 } ) ; var fileSystemB = createTestFileSystem ( 'volumeB' , { '/' : DIRECTORY_SIZE , } ) ; var fileSystems = [ fileSystemA , fileSystemB ] ; window . webkitResolveLocalFileSystemURL = function ( url , success , failure ) { return resolveTestFileSystemURL ( getFileSystemForURL ( fileSystems , url ) , url , success , failure ) ; } ; var blockableFakeStartCopy = new BlockableFakeStartCopy ( 'filesystem:volumeB/' , fileSystemA . entries [ '/test.txt' ] , fileSystems ) ; chrome . fileManagerPrivate . startCopy = blockableFakeStartCopy . startCopyFunc . bind ( blockableFakeStartCopy ) ; volumeManager = new FakeVolumeManager ( ) ; fileOperationManager = new FileOperationManager ( ) ; var eventLogger = new EventLogger ( fileOperationManager ) ; fileOperationManager . paste ( [ fileSystemA . entries [ '/test.txt' ] ] , fileSystemB . entries [ '/' ] , false ) ; var firstOperationTaskId ; reportPromise ( waitUntil ( function ( ) { return blockableFakeStartCopy . resolveBlockedOperationCallback !== null ; } ) . then ( function ( ) { assertEquals ( 1 , eventLogger . events . length ) ; assertEquals ( 'BEGIN' , eventLogger . events [ 0 ] . reason ) ; firstOperationTaskId = eventLogger . events [ 0 ] . taskId ; fileOperationManager . paste ( [ fileSystemA . entries [ '/test.txt' ] ] , fileSystemA . entries [ '/' ] , false ) ; return waitUntil ( function ( ) { return eventLogger . numberOfSuccessEvents === 1 ; } ) ; } ) . then ( function ( ) { blockableFakeStartCopy . resolveBlockedOperationCallback ( ) ; return waitUntil ( function ( ) { return eventLogger . numberOfSuccessEvents === 2 ; } ) ; } ) . then ( function ( ) { var events = eventLogger . events ; assertEquals ( 4 , events . length ) ; assertEquals ( 'BEGIN' , events [ 0 ] . reason ) ; assertEquals ( firstOperationTaskId , events [ 0 ] . taskId ) ; assertEquals ( 'BEGIN' , events [ 1 ] . reason ) ; assertTrue ( firstOperationTaskId !== events [ 1 ] . taskId ) ; assertEquals ( 'SUCCESS' , events [ 2 ] . reason ) ; assertEquals ( events [ 1 ] . taskId , events [ 2 ] . taskId ) ; assertEquals ( 'SUCCESS' , events [ 3 ] . reason ) ; assertEquals ( firstOperationTaskId , events [ 3 ] . taskId ) ; } ) , callback ) ; }
Tests the fileOperationUtil.paste for copying files in paralell.
Tests the fileOperationUtil . paste for copying files in paralell .
// Copy test.txt from volume A to volume B. // Copy test.txt from volume A to volume A. This should not be blocked by // the previous operation. // Wait until the second operation is completed. // Resolve the blocked operation. // Wait until the blocked operation is completed. // Events should be following. // BEGIN: first operation // BEGIN: second operation // SUCCESS: second operation // SUCCESS: first operation