function testCopyInSequential(callback) {
  var fileSystem = createTestFileSystem('testVolume', {
    '/': DIRECTORY_SIZE,
    '/dest': DIRECTORY_SIZE,
    '/test.txt': 10
  });

  window.webkitResolveLocalFileSystemURL =
      resolveTestFileSystemURL.bind(null, fileSystem);

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

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

  var eventLogger = new EventLogger(fileOperationManager);

  // Copy test.txt to /dest. This operation will be blocked.
  fileOperationManager.paste([fileSystem.entries['/test.txt']],
      fileSystem.entries['/dest'],
      false);

  var firstOperationTaskId;
  reportPromise(waitUntil(function() {
    // Wait until the first operation is blocked.
    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 to /. This operation should be blocked.
    fileOperationManager.paste([fileSystem.entries['/test.txt']],
        fileSystem.entries['/'],
        false);

    return waitUntil(function() {
      return fileOperationManager.getPendingCopyTasksForTesting().length === 1;
    });
  }).then(function() {
    // Asserts that the second operation is added to pending copy tasks. Current
    // implementation run tasks synchronusly after adding it to pending tasks.
    // TODO(yawano) This check deeply depends on the implementation. Find a
    //     better way to test this.
    var pendingTask = fileOperationManager.getPendingCopyTasksForTesting()[0];
    assertEquals(fileSystem.entries['/'], pendingTask.targetDirEntry);

    blockableFakeStartCopy.resolveBlockedOperationCallback();

    return waitUntil(function() {
      return eventLogger.numberOfSuccessEvents === 2;
    });
  }).then(function() {
    // Events should be the following.
    // BEGIN: first operation
    // BEGIN: second operation
    // SUCCESS: first operation
    // SUCCESS: second 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(events[1].taskId !== firstOperationTaskId);
    assertEquals('SUCCESS', events[2].reason);
    assertEquals(firstOperationTaskId, events[2].taskId);
    assertEquals('SUCCESS', events[3].reason);
    assertEquals(events[1].taskId, events[3].taskId);
  }), callback);
}
/**
 * Tests the fileOperationUtil.paste for copying files in sequential. When
 * destination volumes are same, copy operations should run in sequential.
 */
Tests the fileOperationUtil.paste for copying files in sequential. When
destination volumes are same, copy operations should run in sequential.
Tests the fileOperationUtil . paste for copying files in sequential . When destination volumes are same copy operations should run in sequential .
function testCopyInSequential(callback) {
  var fileSystem = createTestFileSystem('testVolume', {
    '/': DIRECTORY_SIZE,
    '/dest': DIRECTORY_SIZE,
    '/test.txt': 10
  });
  window.webkitResolveLocalFileSystemURL =
      resolveTestFileSystemURL.bind(null, fileSystem);
  var blockableFakeStartCopy = new BlockableFakeStartCopy(
      'filesystem:testVolume/dest',
      fileSystem.entries['/test.txt'],
      [fileSystem]);
  chrome.fileManagerPrivate.startCopy =
      blockableFakeStartCopy.startCopyFunc.bind(blockableFakeStartCopy);
  volumeManager = new FakeVolumeManager();
  fileOperationManager = new FileOperationManager();
  var eventLogger = new EventLogger(fileOperationManager);
  fileOperationManager.paste([fileSystem.entries['/test.txt']],
      fileSystem.entries['/dest'],
      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([fileSystem.entries['/test.txt']],
        fileSystem.entries['/'],
        false);
    return waitUntil(function() {
      return fileOperationManager.getPendingCopyTasksForTesting().length === 1;
    });
  }).then(function() {
    var pendingTask = fileOperationManager.getPendingCopyTasksForTesting()[0];
    assertEquals(fileSystem.entries['/'], pendingTask.targetDirEntry);
    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(events[1].taskId !== firstOperationTaskId);
    assertEquals('SUCCESS', events[2].reason);
    assertEquals(firstOperationTaskId, events[2].taskId);
    assertEquals('SUCCESS', events[3].reason);
    assertEquals(events[1].taskId, events[3].taskId);
  }), callback);
}
function testCopyInSequential ( callback ) { var fileSystem = createTestFileSystem ( 'testVolume' , { '/' : DIRECTORY_SIZE , '/dest' : DIRECTORY_SIZE , '/test.txt' : 10 } ) ; window . webkitResolveLocalFileSystemURL = resolveTestFileSystemURL . bind ( null , fileSystem ) ; var blockableFakeStartCopy = new BlockableFakeStartCopy ( 'filesystem:testVolume/dest' , fileSystem . entries [ '/test.txt' ] , [ fileSystem ] ) ; chrome . fileManagerPrivate . startCopy = blockableFakeStartCopy . startCopyFunc . bind ( blockableFakeStartCopy ) ; volumeManager = new FakeVolumeManager ( ) ; fileOperationManager = new FileOperationManager ( ) ; var eventLogger = new EventLogger ( fileOperationManager ) ; fileOperationManager . paste ( [ fileSystem . entries [ '/test.txt' ] ] , fileSystem . entries [ '/dest' ] , 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 ( [ fileSystem . entries [ '/test.txt' ] ] , fileSystem . entries [ '/' ] , false ) ; return waitUntil ( function ( ) { return fileOperationManager . getPendingCopyTasksForTesting ( ) . length === 1 ; } ) ; } ) . then ( function ( ) { var pendingTask = fileOperationManager . getPendingCopyTasksForTesting ( ) [ 0 ] ; assertEquals ( fileSystem . entries [ '/' ] , pendingTask . targetDirEntry ) ; 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 ( events [ 1 ] . taskId !== firstOperationTaskId ) ; assertEquals ( 'SUCCESS' , events [ 2 ] . reason ) ; assertEquals ( firstOperationTaskId , events [ 2 ] . taskId ) ; assertEquals ( 'SUCCESS' , events [ 3 ] . reason ) ; assertEquals ( events [ 1 ] . taskId , events [ 3 ] . taskId ) ; } ) , callback ) ; }
Tests the fileOperationUtil.paste for copying files in sequential.
Tests the fileOperationUtil . paste for copying files in sequential .
// Copy test.txt to /dest. This operation will be blocked. // Wait until the first operation is blocked. // Copy test.txt to /. This operation should be blocked. // Asserts that the second operation is added to pending copy tasks. Current // implementation run tasks synchronusly after adding it to pending tasks. // TODO(yawano) This check deeply depends on the implementation. Find a //     better way to test this. // Events should be the following. // BEGIN: first operation // BEGIN: second operation // SUCCESS: first operation // SUCCESS: second operation