From 82c07f1d3fa81f2eac1d9e227e9adc3e23ac162e Mon Sep 17 00:00:00 2001 From: rbpotter Date: Tue, 16 Oct 2018 18:51:01 +0000 Subject: [PATCH] Print Preview Refresh: Fix enter key blocked in pages input (M71) Bug: 894350 Change-Id: Ic5cde2aef449e745e1301ee0c09b6e9ad50308e3 Reviewed-on: https://chromium-review.googlesource.com/c/1278534 Reviewed-by: Demetrios Papadopoulos Commit-Queue: Rebekah Potter Cr-Original-Commit-Position: refs/heads/master@{#599291}(cherry picked from commit aa730994107b1bef054c04a2ee339fdfe637a55e) Reviewed-on: https://chromium-review.googlesource.com/c/1284056 Reviewed-by: Rebekah Potter Cr-Commit-Position: refs/branch-heads/3578@{#52} Cr-Branched-From: 4226ddf99103e493d7afb23a4c7902ee496108b6-refs/heads/master@{#599034} --- .../print_preview/new/pages_settings.js | 12 +++-- .../print_preview/pages_settings_test.js | 44 +++++++++++++++++++ .../print_preview_interactive_ui_tests.js | 6 +++ 3 files changed, 59 insertions(+), 3 deletions(-) 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 */