function testProvidedEntry(callback) {
  providedFileSystem.entries['/test'] =
      new MockDirectoryEntry(providedFileSystem, '/test', {});

  chrome.fileManagerPrivate.getCustomActions = function(entries, callback) {
    assertEquals(1, entries.length);
    assertEquals(providedFileSystem.entries['/test'], entries[0]);
    callback([
      {
        id: ActionsModel.CommonActionId.SHARE,
        title: 'Share it!'
      },
      {
        id: 'some-custom-id',
        title: 'Turn into chocolate!'
      }
    ]);
  };

  var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
      driveSyncHandler, ui, [providedFileSystem.entries['/test']]);
  var invalidated = 0;
  model.addEventListener('invalidated', function() {
    invalidated++;
  });
  return reportPromise(model.initialize().then(function() {
    var actions = model.getActions();
    assertEquals(2, Object.keys(actions).length);

    var shareAction = actions[ActionsModel.CommonActionId.SHARE];
    assertTrue(!!shareAction);
    // Sharing on FSP is possible even if Drive is offline. Custom actions are
    // always executable, as we don't know the actions implementation.
    volumeManager.driveConnectionState = {
      type: VolumeManagerCommon.DriveConnectionType.OFFLINE
    };
    assertTrue(shareAction.canExecute());
    assertEquals('Share it!', shareAction.getTitle());

    chrome.fileManagerPrivate.executeCustomAction = function(entries, actionId,
        callback) {
      assertEquals(1, entries.length);
      assertEquals(providedFileSystem.entries['/test'], entries[0]);
      assertEquals(ActionsModel.CommonActionId.SHARE, actionId);
      callback();
    };
    shareAction.execute();
    assertEquals(1, invalidated);

    assertTrue(!!actions['some-custom-id']);
    assertTrue(actions['some-custom-id'].canExecute());
    assertEquals('Turn into chocolate!',
        actions['some-custom-id'].getTitle());

    chrome.fileManagerPrivate.executeCustomAction = function(entries, actionId,
        callback) {
      assertEquals(1, entries.length);
      assertEquals(providedFileSystem.entries['/test'], entries[0]);
      assertEquals('some-custom-id', actionId);
      callback();
    };

    actions['some-custom-id'].execute();
    assertEquals(2, invalidated);
  }), callback);
}
/**
 * Tests that if actions are provided with getCustomActions(), they appear
 * correctly for the file.
 */
Tests that if actions are provided with getCustomActions(), they appear
correctly for the file.
Tests that if actions are provided with getCustomActions () they appear correctly for the file .
function testProvidedEntry(callback) {
  providedFileSystem.entries['/test'] =
      new MockDirectoryEntry(providedFileSystem, '/test', {});
  chrome.fileManagerPrivate.getCustomActions = function(entries, callback) {
    assertEquals(1, entries.length);
    assertEquals(providedFileSystem.entries['/test'], entries[0]);
    callback([
      {
        id: ActionsModel.CommonActionId.SHARE,
        title: 'Share it!'
      },
      {
        id: 'some-custom-id',
        title: 'Turn into chocolate!'
      }
    ]);
  };
  var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
      driveSyncHandler, ui, [providedFileSystem.entries['/test']]);
  var invalidated = 0;
  model.addEventListener('invalidated', function() {
    invalidated++;
  });
  return reportPromise(model.initialize().then(function() {
    var actions = model.getActions();
    assertEquals(2, Object.keys(actions).length);
    var shareAction = actions[ActionsModel.CommonActionId.SHARE];
    assertTrue(!!shareAction);
    volumeManager.driveConnectionState = {
      type: VolumeManagerCommon.DriveConnectionType.OFFLINE
    };
    assertTrue(shareAction.canExecute());
    assertEquals('Share it!', shareAction.getTitle());
    chrome.fileManagerPrivate.executeCustomAction = function(entries, actionId,
        callback) {
      assertEquals(1, entries.length);
      assertEquals(providedFileSystem.entries['/test'], entries[0]);
      assertEquals(ActionsModel.CommonActionId.SHARE, actionId);
      callback();
    };
    shareAction.execute();
    assertEquals(1, invalidated);
    assertTrue(!!actions['some-custom-id']);
    assertTrue(actions['some-custom-id'].canExecute());
    assertEquals('Turn into chocolate!',
        actions['some-custom-id'].getTitle());
    chrome.fileManagerPrivate.executeCustomAction = function(entries, actionId,
        callback) {
      assertEquals(1, entries.length);
      assertEquals(providedFileSystem.entries['/test'], entries[0]);
      assertEquals('some-custom-id', actionId);
      callback();
    };
    actions['some-custom-id'].execute();
    assertEquals(2, invalidated);
  }), callback);
}
function testProvidedEntry ( callback ) { providedFileSystem . entries [ '/test' ] = new MockDirectoryEntry ( providedFileSystem , '/test' , { } ) ; chrome . fileManagerPrivate . getCustomActions = function ( entries , callback ) { assertEquals ( 1 , entries . length ) ; assertEquals ( providedFileSystem . entries [ '/test' ] , entries [ 0 ] ) ; callback ( [ { id : ActionsModel . CommonActionId . SHARE , title : 'Share it!' } , { id : 'some-custom-id' , title : 'Turn into chocolate!' } ] ) ; } ; var model = new ActionsModel ( volumeManager , metadataModel , shortcutsModel , driveSyncHandler , ui , [ providedFileSystem . entries [ '/test' ] ] ) ; var invalidated = 0 ; model . addEventListener ( 'invalidated' , function ( ) { invalidated ++ ; } ) ; return reportPromise ( model . initialize ( ) . then ( function ( ) { var actions = model . getActions ( ) ; assertEquals ( 2 , Object . keys ( actions ) . length ) ; var shareAction = actions [ ActionsModel . CommonActionId . SHARE ] ; assertTrue ( ! ! shareAction ) ; volumeManager . driveConnectionState = { type : VolumeManagerCommon . DriveConnectionType . OFFLINE } ; assertTrue ( shareAction . canExecute ( ) ) ; assertEquals ( 'Share it!' , shareAction . getTitle ( ) ) ; chrome . fileManagerPrivate . executeCustomAction = function ( entries , actionId , callback ) { assertEquals ( 1 , entries . length ) ; assertEquals ( providedFileSystem . entries [ '/test' ] , entries [ 0 ] ) ; assertEquals ( ActionsModel . CommonActionId . SHARE , actionId ) ; callback ( ) ; } ; shareAction . execute ( ) ; assertEquals ( 1 , invalidated ) ; assertTrue ( ! ! actions [ 'some-custom-id' ] ) ; assertTrue ( actions [ 'some-custom-id' ] . canExecute ( ) ) ; assertEquals ( 'Turn into chocolate!' , actions [ 'some-custom-id' ] . getTitle ( ) ) ; chrome . fileManagerPrivate . executeCustomAction = function ( entries , actionId , callback ) { assertEquals ( 1 , entries . length ) ; assertEquals ( providedFileSystem . entries [ '/test' ] , entries [ 0 ] ) ; assertEquals ( 'some-custom-id' , actionId ) ; callback ( ) ; } ; actions [ 'some-custom-id' ] . execute ( ) ; assertEquals ( 2 , invalidated ) ; } ) , callback ) ; }
Tests that if actions are provided with getCustomActions(), they appear
 correctly for the file.
Tests that if actions are provided with getCustomActions () they appear correctly for the file .
// Sharing on FSP is possible even if Drive is offline. Custom actions are // always executable, as we don't know the actions implementation.