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

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

    // 'Share' should be disabled in offline mode.
    var shareAction = actions[ActionsModel.CommonActionId.SHARE];
    assertTrue(!!shareAction);
    volumeManager.driveConnectionState = {
      type: VolumeManagerCommon.DriveConnectionType.OFFLINE
    };
    assertFalse(shareAction.canExecute());

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

    // 'Create Shortcut' should be enabled, until it's executed, then disabled.
    var createFolderShortcutAction =
        actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
    assertTrue(!!createFolderShortcutAction);
    assertTrue(createFolderShortcutAction.canExecute());
    createFolderShortcutAction.execute();
    assertFalse(createFolderShortcutAction.canExecute());
    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']]);
    model.addEventListener('invalidated', function() {
      invalidated++;
    });
    return model.initialize();
  }).then(function() {
    var actions = model.getActions();
    assertEquals(4, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
    assertTrue(!!actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE]);
    assertTrue(!!actions[ActionsModel.InternalActionId.REMOVE_FOLDER_SHORTCUT]);

    // 'Create shortcut' should be disabled.
    var createFolderShortcutAction =
        actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
    assertTrue(!!createFolderShortcutAction);
    assertFalse(createFolderShortcutAction.canExecute());
    assertEquals(1, invalidated);
  }), callback);
}
/**
 * Tests that the correct actions are available for a directory in Google Drive.
 */
Tests that the correct actions are available for a directory in Google Drive.
Tests that the correct actions are available for a directory in Google Drive .
function testDriveDirectoryEntry(callback) {
  driveFileSystem.entries['/test'] =
      new MockDirectoryEntry(driveFileSystem, '/test', {});
  var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
      driveSyncHandler, ui, [driveFileSystem.entries['/test']]);
  var invalidated = 0;
  model.addEventListener('invalidated', function() {
    invalidated++;
  });
  return reportPromise(model.initialize().then(function() {
    var actions = model.getActions();
    assertEquals(3, Object.keys(actions).length);
    var shareAction = actions[ActionsModel.CommonActionId.SHARE];
    assertTrue(!!shareAction);
    volumeManager.driveConnectionState = {
      type: VolumeManagerCommon.DriveConnectionType.OFFLINE
    };
    assertFalse(shareAction.canExecute());
    var manageInDriveAction =
        actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
    assertTrue(!!manageInDriveAction);
    assertFalse(manageInDriveAction.canExecute());
    var createFolderShortcutAction =
        actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
    assertTrue(!!createFolderShortcutAction);
    assertTrue(createFolderShortcutAction.canExecute());
    createFolderShortcutAction.execute();
    assertFalse(createFolderShortcutAction.canExecute());
    assertEquals(1, invalidated);
    model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
        driveSyncHandler, ui, [driveFileSystem.entries['/test']]);
    model.addEventListener('invalidated', function() {
      invalidated++;
    });
    return model.initialize();
  }).then(function() {
    var actions = model.getActions();
    assertEquals(4, Object.keys(actions).length);
    assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
    assertTrue(!!actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE]);
    assertTrue(!!actions[ActionsModel.InternalActionId.REMOVE_FOLDER_SHORTCUT]);
    var createFolderShortcutAction =
        actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
    assertTrue(!!createFolderShortcutAction);
    assertFalse(createFolderShortcutAction.canExecute());
    assertEquals(1, invalidated);
  }), callback);
}
function testDriveDirectoryEntry ( callback ) { driveFileSystem . entries [ '/test' ] = new MockDirectoryEntry ( driveFileSystem , '/test' , { } ) ; var model = new ActionsModel ( volumeManager , metadataModel , shortcutsModel , driveSyncHandler , ui , [ driveFileSystem . entries [ '/test' ] ] ) ; var invalidated = 0 ; model . addEventListener ( 'invalidated' , function ( ) { invalidated ++ ; } ) ; return reportPromise ( model . initialize ( ) . then ( function ( ) { var actions = model . getActions ( ) ; assertEquals ( 3 , Object . keys ( actions ) . length ) ; var shareAction = actions [ ActionsModel . CommonActionId . SHARE ] ; assertTrue ( ! ! shareAction ) ; volumeManager . driveConnectionState = { type : VolumeManagerCommon . DriveConnectionType . OFFLINE } ; assertFalse ( shareAction . canExecute ( ) ) ; var manageInDriveAction = actions [ ActionsModel . InternalActionId . MANAGE_IN_DRIVE ] ; assertTrue ( ! ! manageInDriveAction ) ; assertFalse ( manageInDriveAction . canExecute ( ) ) ; var createFolderShortcutAction = actions [ ActionsModel . InternalActionId . CREATE_FOLDER_SHORTCUT ] ; assertTrue ( ! ! createFolderShortcutAction ) ; assertTrue ( createFolderShortcutAction . canExecute ( ) ) ; createFolderShortcutAction . execute ( ) ; assertFalse ( createFolderShortcutAction . canExecute ( ) ) ; assertEquals ( 1 , invalidated ) ; model = new ActionsModel ( volumeManager , metadataModel , shortcutsModel , driveSyncHandler , ui , [ driveFileSystem . entries [ '/test' ] ] ) ; model . addEventListener ( 'invalidated' , function ( ) { invalidated ++ ; } ) ; return model . initialize ( ) ; } ) . then ( function ( ) { var actions = model . getActions ( ) ; assertEquals ( 4 , Object . keys ( actions ) . length ) ; assertTrue ( ! ! actions [ ActionsModel . CommonActionId . SHARE ] ) ; assertTrue ( ! ! actions [ ActionsModel . InternalActionId . MANAGE_IN_DRIVE ] ) ; assertTrue ( ! ! actions [ ActionsModel . InternalActionId . REMOVE_FOLDER_SHORTCUT ] ) ; var createFolderShortcutAction = actions [ ActionsModel . InternalActionId . CREATE_FOLDER_SHORTCUT ] ; assertTrue ( ! ! createFolderShortcutAction ) ; assertFalse ( createFolderShortcutAction . canExecute ( ) ) ; assertEquals ( 1 , invalidated ) ; } ) , callback ) ; }
Tests that the correct actions are available for a directory in Google Drive.
Tests that the correct actions are available for a directory in Google Drive .
// 'Share' should be disabled in offline mode. // 'Manage in Drive' should be disabled in offline mode. // 'Create Shortcut' should be enabled, until it's executed, then disabled. // The model is invalidated, as list of actions have changed. Recreated // the model and check that the actions are updated. // 'Create shortcut' should be disabled.