function defaultTaskDialog(expectedTaskId, windowId) {
  // Prepare expected labels.
  var expectedLabels = [
    'DummyTask1 (default)',
    'DummyTask2'
  ];

  // Select file.
  var selectFilePromise =
      remoteCall.callRemoteTestUtil('selectFile', windowId, ['hello.txt']);

  // Click the change default menu.
  var menuClickedPromise = selectFilePromise.
      then(function() {
        return remoteCall.waitForElement(windowId, '#tasks[multiple]');
      }).
      then(function() {
        return remoteCall.waitForElement(
            windowId, '#tasks-menu .change-default');
      }).
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent', windowId, ['#tasks', 'select', {
              item: {type: 'ChangeDefaultTask'}
            }]);
      }).
      then(function(result) {
        chrome.test.assertTrue(result);
      });

  var caller = getCaller();
  // Wait for the list of menu item is added as expected.
  var menuPreparedPromise = menuClickedPromise.then(function() {
    return repeatUntil(function() {
      // Obtains menu items.
      var menuItemsPromise = remoteCall.callRemoteTestUtil(
          'queryAllElements',
          windowId,
          ['#default-task-dialog #default-tasks-list li']);

      // Compare the contents of items.
      return menuItemsPromise.then(function(items) {
        var actualLabels = items.map(function(item) { return item.text; });
        if (chrome.test.checkDeepEq(expectedLabels, actualLabels)) {
          return true;
        } else {
          return pending(
              caller, 'Tasks do not match, expected: %j, actual: %j.',
              expectedLabels, actualLabels);
        }
      });
    });
  });

  // Click the non default item.
  var itemClickedPromise = menuPreparedPromise.
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent',
            windowId,
            [
              '#default-task-dialog #default-tasks-list li:nth-of-type(2)',
              'mousedown',
              {bubbles: true, button: 0}
            ]);
      }).
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent',
            windowId,
            [
              '#default-task-dialog #default-tasks-list li:nth-of-type(2)',
              'click',
              {bubbles: true}
            ]);
      }).
      then(function(result) {
        chrome.test.assertTrue(result);
      });

  // Wait for the dialog hidden, and the task is executed.
  var dialogHiddenPromise = itemClickedPromise.then(function() {
    return remoteCall.waitForElementLost(
        windowId, '#default-task-dialog', null);
  });

  // Execute the new default task.
  var taskButtonClicked =
      dialogHiddenPromise
          .then(function() {
            // Click on "Open ▼" button.
            remoteCall.callRemoteTestUtil(
                'fakeMouseClick', windowId, ['#tasks']);
            // Wait for dropdown menu to show.
            return remoteCall.waitForElement(
                windowId, '#tasks-menu cr-menu-item');
          })
          .then(function(result) {
            // Click on first menu item.
            remoteCall.callRemoteTestUtil(
                'fakeMouseClick', windowId,
                ['#tasks-menu cr-menu-item:nth-child(1)']);
            // Wait dropdown menu to hide.
            return remoteCall.waitForElement(windowId, '#tasks-menu[hidden]');
          })
          .then(function(result) {
            chrome.test.assertTrue(!!result);
          });

  // Check the executed tasks.
  return taskButtonClicked.then(function() {
    return remoteCall.waitUntilTaskExecutes(windowId, expectedTaskId);
  });
}
/**
 * Tests to specify default task via the default task dialog.
 *
 * @param {string} expectedTaskId Task ID to be expected to newly specify as
 *     default.
 * @param {string} windowId Window ID.
 * @return {Promise} Promise to be fulfilled/rejected depends on the test
 *     result.
 */
Tests to specify default task via the default task dialog.
@param {string} expectedTaskId Task ID to be expected to newly specify as
default.
@param {string} windowId Window ID.
@return {Promise} Promise to be fulfilled/rejected depends on the test
result.
Tests to specify default task via the default task dialog . @param { string } expectedTaskId Task ID to be expected to newly specify as default . @param { string } windowId Window ID . @return { Promise } Promise to be fulfilled / rejected depends on the test result .
function defaultTaskDialog(expectedTaskId, windowId) {
  var expectedLabels = [
    'DummyTask1 (default)',
    'DummyTask2'
  ];
  var selectFilePromise =
      remoteCall.callRemoteTestUtil('selectFile', windowId, ['hello.txt']);
  var menuClickedPromise = selectFilePromise.
      then(function() {
        return remoteCall.waitForElement(windowId, '#tasks[multiple]');
      }).
      then(function() {
        return remoteCall.waitForElement(
            windowId, '#tasks-menu .change-default');
      }).
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent', windowId, ['#tasks', 'select', {
              item: {type: 'ChangeDefaultTask'}
            }]);
      }).
      then(function(result) {
        chrome.test.assertTrue(result);
      });
  var caller = getCaller();
  var menuPreparedPromise = menuClickedPromise.then(function() {
    return repeatUntil(function() {
      var menuItemsPromise = remoteCall.callRemoteTestUtil(
          'queryAllElements',
          windowId,
          ['#default-task-dialog #default-tasks-list li']);
      return menuItemsPromise.then(function(items) {
        var actualLabels = items.map(function(item) { return item.text; });
        if (chrome.test.checkDeepEq(expectedLabels, actualLabels)) {
          return true;
        } else {
          return pending(
              caller, 'Tasks do not match, expected: %j, actual: %j.',
              expectedLabels, actualLabels);
        }
      });
    });
  });
  var itemClickedPromise = menuPreparedPromise.
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent',
            windowId,
            [
              '#default-task-dialog #default-tasks-list li:nth-of-type(2)',
              'mousedown',
              {bubbles: true, button: 0}
            ]);
      }).
      then(function() {
        return remoteCall.callRemoteTestUtil(
            'fakeEvent',
            windowId,
            [
              '#default-task-dialog #default-tasks-list li:nth-of-type(2)',
              'click',
              {bubbles: true}
            ]);
      }).
      then(function(result) {
        chrome.test.assertTrue(result);
      });
  var dialogHiddenPromise = itemClickedPromise.then(function() {
    return remoteCall.waitForElementLost(
        windowId, '#default-task-dialog', null);
  });
  var taskButtonClicked =
      dialogHiddenPromise
          .then(function() {
            remoteCall.callRemoteTestUtil(
                'fakeMouseClick', windowId, ['#tasks']);
            return remoteCall.waitForElement(
                windowId, '#tasks-menu cr-menu-item');
          })
          .then(function(result) {
            remoteCall.callRemoteTestUtil(
                'fakeMouseClick', windowId,
                ['#tasks-menu cr-menu-item:nth-child(1)']);
            return remoteCall.waitForElement(windowId, '#tasks-menu[hidden]');
          })
          .then(function(result) {
            chrome.test.assertTrue(!!result);
          });
  return taskButtonClicked.then(function() {
    return remoteCall.waitUntilTaskExecutes(windowId, expectedTaskId);
  });
}
function defaultTaskDialog ( expectedTaskId , windowId ) { var expectedLabels = [ 'DummyTask1 (default)' , 'DummyTask2' ] ; var selectFilePromise = remoteCall . callRemoteTestUtil ( 'selectFile' , windowId , [ 'hello.txt' ] ) ; var menuClickedPromise = selectFilePromise . then ( function ( ) { return remoteCall . waitForElement ( windowId , '#tasks[multiple]' ) ; } ) . then ( function ( ) { return remoteCall . waitForElement ( windowId , '#tasks-menu .change-default' ) ; } ) . then ( function ( ) { return remoteCall . callRemoteTestUtil ( 'fakeEvent' , windowId , [ '#tasks' , 'select' , { item : { type : 'ChangeDefaultTask' } } ] ) ; } ) . then ( function ( result ) { chrome . test . assertTrue ( result ) ; } ) ; var caller = getCaller ( ) ; var menuPreparedPromise = menuClickedPromise . then ( function ( ) { return repeatUntil ( function ( ) { var menuItemsPromise = remoteCall . callRemoteTestUtil ( 'queryAllElements' , windowId , [ '#default-task-dialog #default-tasks-list li' ] ) ; return menuItemsPromise . then ( function ( items ) { var actualLabels = items . map ( function ( item ) { return item . text ; } ) ; if ( chrome . test . checkDeepEq ( expectedLabels , actualLabels ) ) { return true ; } else { return pending ( caller , 'Tasks do not match, expected: %j, actual: %j.' , expectedLabels , actualLabels ) ; } } ) ; } ) ; } ) ; var itemClickedPromise = menuPreparedPromise . then ( function ( ) { return remoteCall . callRemoteTestUtil ( 'fakeEvent' , windowId , [ '#default-task-dialog #default-tasks-list li:nth-of-type(2)' , 'mousedown' , { bubbles : true , button : 0 } ] ) ; } ) . then ( function ( ) { return remoteCall . callRemoteTestUtil ( 'fakeEvent' , windowId , [ '#default-task-dialog #default-tasks-list li:nth-of-type(2)' , 'click' , { bubbles : true } ] ) ; } ) . then ( function ( result ) { chrome . test . assertTrue ( result ) ; } ) ; var dialogHiddenPromise = itemClickedPromise . then ( function ( ) { return remoteCall . waitForElementLost ( windowId , '#default-task-dialog' , null ) ; } ) ; var taskButtonClicked = dialogHiddenPromise . then ( function ( ) { remoteCall . callRemoteTestUtil ( 'fakeMouseClick' , windowId , [ '#tasks' ] ) ; return remoteCall . waitForElement ( windowId , '#tasks-menu cr-menu-item' ) ; } ) . then ( function ( result ) { remoteCall . callRemoteTestUtil ( 'fakeMouseClick' , windowId , [ '#tasks-menu cr-menu-item:nth-child(1)' ] ) ; return remoteCall . waitForElement ( windowId , '#tasks-menu[hidden]' ) ; } ) . then ( function ( result ) { chrome . test . assertTrue ( ! ! result ) ; } ) ; return taskButtonClicked . then ( function ( ) { return remoteCall . waitUntilTaskExecutes ( windowId , expectedTaskId ) ; } ) ; }
Tests to specify default task via the default task dialog.
Tests to specify default task via the default task dialog .
// Prepare expected labels. // Select file. // Click the change default menu. // Wait for the list of menu item is added as expected. // Obtains menu items. // Compare the contents of items. // Click the non default item. // Wait for the dialog hidden, and the task is executed. // Execute the new default task. // Click on "Open ▼" button. // Wait for dropdown menu to show. // Click on first menu item. // Wait dropdown menu to hide. // Check the executed tasks.