diff --git a/chrome/browser/resources/print_preview/new/pages_settings.js b/chrome/browser/resources/print_preview/new/pages_settings.js index cbf808c485b6f..e4c48c84010a4 100644 --- a/chrome/browser/resources/print_preview/new/pages_settings.js +++ b/chrome/browser/resources/print_preview/new/pages_settings.js @@ -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(); } diff --git a/chrome/test/data/webui/print_preview/pages_settings_test.js b/chrome/test/data/webui/print_preview/pages_settings_test.js index eea45414302bb..72fae7ecbd32f 100644 --- a/chrome/test/data/webui/print_preview/pages_settings_test.js +++ b/chrome/test/data/webui/print_preview/pages_settings_test.js @@ -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'; @@ -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 { diff --git a/chrome/test/data/webui/print_preview/print_preview_interactive_ui_tests.js b/chrome/test/data/webui/print_preview/print_preview_interactive_ui_tests.js index a93fc7f8b24a6..cf208370b38ed 100644 --- a/chrome/test/data/webui/print_preview/print_preview_interactive_ui_tests.js +++ b/chrome/test/data/webui/print_preview/print_preview_interactive_ui_tests.js @@ -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 */