function testDriveFileEntry(callback) {
  driveFileSystem.entries['/test.txt'] =
      new MockFileEntry(driveFileSystem, '/test.txt', {});

  var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
      driveSyncHandler, ui, [driveFileSystem.entries['/test.txt']]);
  var invalidated = 0;
  metadataModel.properties = {
    hosted: false,
    pinned: false
  };
  return reportPromise(model.initialize().then(function() {
    var actions = model.getActions();
    assertEquals(3, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);

    // 'Save for Offline' should be enabled.
    var saveForOfflineAction =
        actions[ActionsModel.CommonActionId.SAVE_FOR_OFFLINE];
    assertTrue(!!saveForOfflineAction);
    assertTrue(saveForOfflineAction.canExecute());

    // 'Manage in Drive' should be enabled.
    var manageInDriveAction =
        actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
    assertTrue(!!manageInDriveAction);
    assertTrue(manageInDriveAction.canExecute());

    chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
      metadataModel.properties.pinned = true;
      assertEquals(driveFileSystem.entries['/test.txt'], entry);
      assertTrue(pin);
      callback();
    };

    // For pinning, invalidating is done asynchronously, so we need to wait
    // for it with a promise.
    return new Promise(function(fulfill, reject) {
      model.addEventListener('invalidated', function() {
        invalidated++;
        fulfill();
      });
      saveForOfflineAction.execute();
    });
  }).then(function() {
    assertTrue(metadataModel.properties.pinned);
    assertEquals(1, invalidated);

    // The model is invalidated, as list of actions have changed. Recreated
    // the model and check that the actions are updated.
    model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
        driveSyncHandler, ui, [driveFileSystem.entries['/test.txt']]);
    return model.initialize();
  }).then(function() {
    var actions = model.getActions();
    assertEquals(3, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);

    // 'Offline not Necessary' should be enabled.
    var offlineNotNecessaryAction =
        actions[ActionsModel.CommonActionId.OFFLINE_NOT_NECESSARY];
    assertTrue(!!offlineNotNecessaryAction);
    assertTrue(offlineNotNecessaryAction.canExecute());

    // 'Manage in Drive' should be enabled.
    var manageInDriveAction =
        actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
    assertTrue(!!manageInDriveAction);
    assertTrue(manageInDriveAction.canExecute());

    chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
      metadataModel.properties.pinned = false;
      assertEquals(driveFileSystem.entries['/test.txt'], entry);
      assertFalse(pin);
      callback();
    };

    return new Promise(function(fulfill, reject) {
      model.addEventListener('invalidated', function() {
        invalidated++;
        fulfill();
      });
      offlineNotNecessaryAction.execute();
    });
  }).then(function() {
    assertFalse(metadataModel.properties.pinned);
    assertEquals(2, invalidated);
  }), callback);
}
/**
 * Tests that the correct actions are available for a file in Google Drive.
 */
Tests that the correct actions are available for a file in Google Drive.
Tests that the correct actions are available for a file in Google Drive .
function testDriveFileEntry(callback) {
  driveFileSystem.entries['/test.txt'] =
      new MockFileEntry(driveFileSystem, '/test.txt', {});
  var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
      driveSyncHandler, ui, [driveFileSystem.entries['/test.txt']]);
  var invalidated = 0;
  metadataModel.properties = {
    hosted: false,
    pinned: false
  };
  return reportPromise(model.initialize().then(function() {
    var actions = model.getActions();
    assertEquals(3, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
    var saveForOfflineAction =
        actions[ActionsModel.CommonActionId.SAVE_FOR_OFFLINE];
    assertTrue(!!saveForOfflineAction);
    assertTrue(saveForOfflineAction.canExecute());
    var manageInDriveAction =
        actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
    assertTrue(!!manageInDriveAction);
    assertTrue(manageInDriveAction.canExecute());
    chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
      metadataModel.properties.pinned = true;
      assertEquals(driveFileSystem.entries['/test.txt'], entry);
      assertTrue(pin);
      callback();
    };
    return new Promise(function(fulfill, reject) {
      model.addEventListener('invalidated', function() {
        invalidated++;
        fulfill();
      });
      saveForOfflineAction.execute();
    });
  }).then(function() {
    assertTrue(metadataModel.properties.pinned);
    assertEquals(1, invalidated);
    model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
        driveSyncHandler, ui, [driveFileSystem.entries['/test.txt']]);
    return model.initialize();
  }).then(function() {
    var actions = model.getActions();
    assertEquals(3, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
    var offlineNotNecessaryAction =
        actions[ActionsModel.CommonActionId.OFFLINE_NOT_NECESSARY];
    assertTrue(!!offlineNotNecessaryAction);
    assertTrue(offlineNotNecessaryAction.canExecute());
    var manageInDriveAction =
        actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
    assertTrue(!!manageInDriveAction);
    assertTrue(manageInDriveAction.canExecute());
    chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
      metadataModel.properties.pinned = false;
      assertEquals(driveFileSystem.entries['/test.txt'], entry);
      assertFalse(pin);
      callback();
    };
    return new Promise(function(fulfill, reject) {
      model.addEventListener('invalidated', function() {
        invalidated++;
        fulfill();
      });
      offlineNotNecessaryAction.execute();
    });
  }).then(function() {
    assertFalse(metadataModel.properties.pinned);
    assertEquals(2, invalidated);
  }), callback);
}
function testDriveFileEntry ( callback ) { driveFileSystem . entries [ '/test.txt' ] = new MockFileEntry ( driveFileSystem , '/test.txt' , { } ) ; var model = new ActionsModel ( volumeManager , metadataModel , shortcutsModel , driveSyncHandler , ui , [ driveFileSystem . entries [ '/test.txt' ] ] ) ; var invalidated = 0 ; metadataModel . properties = { hosted : false , pinned : false } ; return reportPromise ( model . initialize ( ) . then ( function ( ) { var actions = model . getActions ( ) ; assertEquals ( 3 , Object . keys ( actions ) . length ) ; assertTrue ( ! ! actions [ ActionsModel . CommonActionId . SHARE ] ) ; var saveForOfflineAction = actions [ ActionsModel . CommonActionId . SAVE_FOR_OFFLINE ] ; assertTrue ( ! ! saveForOfflineAction ) ; assertTrue ( saveForOfflineAction . canExecute ( ) ) ; var manageInDriveAction = actions [ ActionsModel . InternalActionId . MANAGE_IN_DRIVE ] ; assertTrue ( ! ! manageInDriveAction ) ; assertTrue ( manageInDriveAction . canExecute ( ) ) ; chrome . fileManagerPrivate . pinDriveFile = function ( entry , pin , callback ) { metadataModel . properties . pinned = true ; assertEquals ( driveFileSystem . entries [ '/test.txt' ] , entry ) ; assertTrue ( pin ) ; callback ( ) ; } ; return new Promise ( function ( fulfill , reject ) { model . addEventListener ( 'invalidated' , function ( ) { invalidated ++ ; fulfill ( ) ; } ) ; saveForOfflineAction . execute ( ) ; } ) ; } ) . then ( function ( ) { assertTrue ( metadataModel . properties . pinned ) ; assertEquals ( 1 , invalidated ) ; model = new ActionsModel ( volumeManager , metadataModel , shortcutsModel , driveSyncHandler , ui , [ driveFileSystem . entries [ '/test.txt' ] ] ) ; return model . initialize ( ) ; } ) . then ( function ( ) { var actions = model . getActions ( ) ; assertEquals ( 3 , Object . keys ( actions ) . length ) ; assertTrue ( ! ! actions [ ActionsModel . CommonActionId . SHARE ] ) ; var offlineNotNecessaryAction = actions [ ActionsModel . CommonActionId . OFFLINE_NOT_NECESSARY ] ; assertTrue ( ! ! offlineNotNecessaryAction ) ; assertTrue ( offlineNotNecessaryAction . canExecute ( ) ) ; var manageInDriveAction = actions [ ActionsModel . InternalActionId . MANAGE_IN_DRIVE ] ; assertTrue ( ! ! manageInDriveAction ) ; assertTrue ( manageInDriveAction . canExecute ( ) ) ; chrome . fileManagerPrivate . pinDriveFile = function ( entry , pin , callback ) { metadataModel . properties . pinned = false ; assertEquals ( driveFileSystem . entries [ '/test.txt' ] , entry ) ; assertFalse ( pin ) ; callback ( ) ; } ; return new Promise ( function ( fulfill , reject ) { model . addEventListener ( 'invalidated' , function ( ) { invalidated ++ ; fulfill ( ) ; } ) ; offlineNotNecessaryAction . execute ( ) ; } ) ; } ) . then ( function ( ) { assertFalse ( metadataModel . properties . pinned ) ; assertEquals ( 2 , invalidated ) ; } ) , callback ) ; }
Tests that the correct actions are available for a file in Google Drive.
Tests that the correct actions are available for a file in Google Drive .
// 'Save for Offline' should be enabled. // 'Manage in Drive' should be enabled. // For pinning, invalidating is done asynchronously, so we need to wait // for it with a promise. // The model is invalidated, as list of actions have changed. Recreated // the model and check that the actions are updated. // 'Offline not Necessary' should be enabled. // 'Manage in Drive' should be enabled.