Skip to content

Commit 82c07f1

Browse files
author
rbpotter
committed
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 <[email protected]> Commit-Queue: Rebekah Potter <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#599291}(cherry picked from commit aa73099) Reviewed-on: https://chromium-review.googlesource.com/c/1284056 Reviewed-by: Rebekah Potter <[email protected]> Cr-Commit-Position: refs/branch-heads/3578@{#52} Cr-Branched-From: 4226ddf-refs/heads/master@{#599034}
1 parent 23eaedb commit 82c07f1

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

chrome/browser/resources/print_preview/new/pages_settings.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,17 @@ Polymer({
354354
* @param {!KeyboardEvent} e The keyboard event
355355
*/
356356
onKeydown_: function(e) {
357-
e.stopPropagation();
358-
if (e.key == 'Enter') {
357+
if (e.key === 'Escape')
358+
return;
359+
360+
if (e.key === 'Enter') {
359361
this.resetAndUpdate();
360362
this.resetIfEmpty_();
361-
} else if (e.shiftKey && e.key == 'Tab') {
363+
return;
364+
}
365+
366+
e.stopPropagation();
367+
if (e.shiftKey && e.key === 'Tab') {
362368
this.$.customRadioButton.focus();
363369
e.preventDefault();
364370
}

chrome/test/data/webui/print_preview/pages_settings_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cr.define('pages_settings_test', function() {
1313
ClickingCustomFocusesInput: 'clicking custom focuses input',
1414
InputNotDisabledOnValidityChange: 'input not disabled on validity change',
1515
IgnoreInputKeyEvents: 'ignore input key events',
16+
EnterOnInputTriggersPrint: 'enter on input triggers print',
1617
};
1718

1819
const suiteName = 'PagesSettingsTest';
@@ -501,6 +502,49 @@ cr.define('pages_settings_test', function() {
501502
});
502503

503504
});
505+
506+
// Verifies that the enter key event is bubbled to the pages settings
507+
// element, so that it will be bubbled to the print preview app to trigger a
508+
// print.
509+
test(assert(TestNames.EnterOnInputTriggersPrint), function() {
510+
const input = pagesSection.$.pageSettingsCustomInput.inputElement;
511+
const radioGroup = pagesSection.$$('paper-radio-group');
512+
const whenPrintReceived =
513+
test_util.eventToPromise('keydown', pagesSection);
514+
515+
// Setup an empty input by clicking on the custom radio button.
516+
const inputFocused = test_util.eventToPromise('focus', input);
517+
pagesSection.$.customRadioButton.click();
518+
return inputFocused
519+
.then(function() {
520+
assertEquals(
521+
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
522+
MockInteractions.keyEventOn(input, 'keydown', 13, [], 'Enter');
523+
return whenPrintReceived;
524+
})
525+
// All gets automatically selected
526+
.then(function() {
527+
assertEquals(pagesSection.pagesValueEnum_.ALL, radioGroup.selected);
528+
// Refocus the radio group to reset the focused button to "all".
529+
// Normally, enter results in print, so this does not need to
530+
// happen.
531+
radioGroup.focus();
532+
return setupInput('1', 3);
533+
})
534+
// Re-select custom and print again.
535+
.then(function() {
536+
assertEquals(
537+
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
538+
const whenPrintReceived =
539+
test_util.eventToPromise('keydown', pagesSection);
540+
MockInteractions.keyEventOn(input, 'keydown', 13, [], 'Enter');
541+
return whenPrintReceived;
542+
})
543+
.then(function() {
544+
assertEquals(
545+
pagesSection.pagesValueEnum_.CUSTOM, radioGroup.selected);
546+
});
547+
});
504548
});
505549

506550
return {

chrome/test/data/webui/print_preview/print_preview_interactive_ui_tests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ TEST_F('PrintPreviewPagesSettingsTest', 'IgnoreInputKeyEvents', function() {
159159
this.runMochaTest(pages_settings_test.TestNames.IgnoreInputKeyEvents);
160160
});
161161

162+
TEST_F(
163+
'PrintPreviewPagesSettingsTest', 'EnterOnInputTriggersPrint', function() {
164+
this.runMochaTest(
165+
pages_settings_test.TestNames.EnterOnInputTriggersPrint);
166+
});
167+
162168
PrintPreviewNumberSettingsSectionInteractiveTest =
163169
class extends PrintPreviewInteractiveUITest {
164170
/** @override */

0 commit comments

Comments
 (0)