Skip to content

Commit

Permalink
Print Preview Refresh: Fix enter key blocked in pages input
Browse files Browse the repository at this point in the history
Bug: 894350
Change-Id: Ic5cde2aef449e745e1301ee0c09b6e9ad50308e3
Reviewed-on: https://chromium-review.googlesource.com/c/1278534
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599291}
  • Loading branch information
rbpotter authored and Commit Bot committed Oct 12, 2018
1 parent dc74851 commit aa73099
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
12 changes: 9 additions & 3 deletions chrome/browser/resources/print_preview/new/pages_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,17 @@ Polymer({
* @param {!KeyboardEvent} e The keyboard event
*/
onKeydown_: function(e) {
e.stopPropagation();
if (e.key == 'Enter') {
if (e.key === 'Escape')
return;

if (e.key === 'Enter') {
this.resetAndUpdate();
this.resetIfEmpty_();
} else if (e.shiftKey && e.key == 'Tab') {
return;
}

e.stopPropagation();
if (e.shiftKey && e.key === 'Tab') {
this.$.customRadioButton.focus();
e.preventDefault();
}
Expand Down
44 changes: 44 additions & 0 deletions chrome/test/data/webui/print_preview/pages_settings_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cr.define('pages_settings_test', function() {
ClickingCustomFocusesInput: 'clicking custom focuses input',
InputNotDisabledOnValidityChange: 'input not disabled on validity change',
IgnoreInputKeyEvents: 'ignore input key events',
EnterOnInputTriggersPrint: 'enter on input triggers print',
};

const suiteName = 'PagesSettingsTest';
Expand Down Expand Up @@ -501,6 +502,49 @@ cr.define('pages_settings_test', function() {
});

});

// Verifies that the enter key event is bubbled to the pages settings
// element, so that it will be bubbled to the print preview app to trigger a
// print.
test(assert(TestNames.EnterOnInputTriggersPrint), function() {
const input = pagesSection.$.pageSettingsCustomInput.inputElement;
const radioGroup = pagesSection.$$('paper-radio-group');
const whenPrintReceived =
test_util.eventToPromise('keydown', pagesSection);

// Setup an empty input by clicking on the custom radio button.
const inputFocused = test_util.eventToPromise('focus', input);
pagesSection.$.customRadioButton.click();
return inputFocused
.then(function() {
assertEquals(
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
MockInteractions.keyEventOn(input, 'keydown', 13, [], 'Enter');
return whenPrintReceived;
})
// All gets automatically selected
.then(function() {
assertEquals(pagesSection.pagesValueEnum_.ALL, radioGroup.selected);
// Refocus the radio group to reset the focused button to "all".
// Normally, enter results in print, so this does not need to
// happen.
radioGroup.focus();
return setupInput('1', 3);
})
// Re-select custom and print again.
.then(function() {
assertEquals(
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
const whenPrintReceived =
test_util.eventToPromise('keydown', pagesSection);
MockInteractions.keyEventOn(input, 'keydown', 13, [], 'Enter');
return whenPrintReceived;
})
.then(function() {
assertEquals(
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
});
});
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ TEST_F('PrintPreviewPagesSettingsTest', 'IgnoreInputKeyEvents', function() {
this.runMochaTest(pages_settings_test.TestNames.IgnoreInputKeyEvents);
});

TEST_F(
'PrintPreviewPagesSettingsTest', 'EnterOnInputTriggersPrint', function() {
this.runMochaTest(
pages_settings_test.TestNames.EnterOnInputTriggersPrint);
});

PrintPreviewNumberSettingsSectionInteractiveTest =
class extends PrintPreviewInteractiveUITest {
/** @override */
Expand Down

0 comments on commit aa73099

Please sign in to comment.