Bug 1669732, add error message for invalid number of copies r=mstriemer,fluent-reviewers
authorEmma Malysz <emalysz@mozilla.com>
Thu, 18 Feb 2021 16:23:54 +0000
changeset 567990 7a68819b7e59eaae460ef05446ab0307d01fb739
parent 567989 07b414a0a3e221090cac841aafe6ec7ede2bac15
child 567991 b6a8e6a09dca1867ca511ae4cb7720907c26814d
push id38216
push userdluca@mozilla.com
push dateThu, 18 Feb 2021 21:46:37 +0000
treeherdermozilla-central@b82bd51a119e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, fluent-reviewers
bugs1669732
milestone87.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1669732, add error message for invalid number of copies r=mstriemer,fluent-reviewers Differential Revision: https://phabricator.services.mozilla.com/D103385
toolkit/components/printing/content/print.html
toolkit/components/printing/content/print.js
toolkit/components/printing/tests/browser_print_copies.js
toolkit/locales/en-US/toolkit/printing/printUI.ftl
--- a/toolkit/components/printing/content/print.html
+++ b/toolkit/components/printing/content/print.html
@@ -59,16 +59,21 @@
               aria-errormessage="error-invalid-scale"
               disabled required>
           </span>
         </label>
         <p id="error-invalid-scale" hidden data-l10n-id="printui-error-invalid-scale" class="error-message" role="alert"></p>
       </div>
     </template>
 
+    <template id="copy-template">
+      <input id="copies-count" is="setting-number" data-setting-name="numCopies" min="1" max="10000" class="copy-count-input photon-number" aria-errormessage="error-invalid-copies" required>
+      <p id="error-invalid-copies" hidden data-l10n-id="printui-error-invalid-copies" class="error-message" role="alert"></p>
+    </template>
+
     <template id="margins-template">
       <label for="margins-picker" class="block-label" data-l10n-id="printui-margins"></label>
       <select is="margins-select" id="margins-picker" name="margin-type" class="row" data-setting-name="margins">
         <option value="default" data-l10n-id="printui-margins-default"></option>
         <option value="minimum" data-l10n-id="printui-margins-min"></option>
         <option value="none" data-l10n-id="printui-margins-none"></option>
         <option value="custom" data-l10n-id="printui-margins-custom-inches"></option>
       </select>
@@ -126,17 +131,17 @@
           <label for="printer-picker" class="block-label" data-l10n-id="printui-destination-label"></label>
           <div class="printer-picker-wrapper">
             <select is="destination-picker" id="printer-picker" data-setting-name="printerName" iconic></select>
           </div>
         </section>
         <section id="settings">
           <section id="copies" class="section-block">
             <label for="copies-count" class="block-label" data-l10n-id="printui-copies-label"></label>
-            <input id="copies-count" is="setting-number" data-setting-name="numCopies" min="1" max="10000" class="copy-count-input photon-number" required>
+            <copy-count-input></copy-count-input>
           </section>
 
           <section id="orientation" class="section-block">
             <label id="orientation-label" class="block-label" data-l10n-id="printui-orientation"></label>
             <div is="orientation-input" class="toggle-group" role="radiogroup" aria-labelledby="orientation-label"></div>
           </section>
 
           <section id="pages" class="section-block">
--- a/toolkit/components/printing/content/print.js
+++ b/toolkit/components/printing/content/print.js
@@ -1587,18 +1587,16 @@ class PrintUIForm extends PrintUIControl
   update(settings) {
     // If there are no default system printers available and we are not on mac,
     // we should hide the system dialog because it won't be populated with
     // the correct settings. Mac and Gtk support save to pdf functionality
     // in the native dialog, so it can be shown regardless.
     this.querySelector("#system-print").hidden =
       AppConstants.platform === "win" && !settings.defaultSystemPrinter;
 
-    this.querySelector("#copies").hidden = settings.willSaveToFile;
-
     this.querySelector("#two-sided-printing").hidden = !settings.supportsDuplex;
   }
 
   enable() {
     let isValid = this.checkValidity();
     document.body.toggleAttribute("invalid", !isValid);
     if (isValid) {
       for (let element of this.elements) {
@@ -1891,16 +1889,39 @@ class OrientationInput extends PrintUICo
   handleEvent(e) {
     this.dispatchSettingsChange({
       orientation: e.target.value,
     });
   }
 }
 customElements.define("orientation-input", OrientationInput);
 
+class CopiesInput extends PrintUIControlMixin(HTMLElement) {
+  get templateId() {
+    return "copy-template";
+  }
+
+  initialize() {
+    super.initialize();
+    this._copiesSection = this.closest(".section-block");
+    this._copiesInput = this.querySelector("#copies-count");
+    this._copiesError = this.querySelector("#error-invalid-copies");
+  }
+
+  update(settings) {
+    this._copiesSection.hidden = settings.willSaveToFile;
+    this._copiesError.hidden = true;
+  }
+
+  handleEvent(e) {
+    this._copiesError.hidden = this._copiesInput.checkValidity();
+  }
+}
+customElements.define("copy-count-input", CopiesInput);
+
 class ScaleInput extends PrintUIControlMixin(HTMLElement) {
   get templateId() {
     return "scale-template";
   }
 
   initialize() {
     super.initialize();
 
--- a/toolkit/components/printing/tests/browser_print_copies.js
+++ b/toolkit/components/printing/tests/browser_print_copies.js
@@ -9,33 +9,45 @@ add_task(async function testCopyError() 
     await SpecialPowers.pushPrefEnv({
       set: [["print_printer", "A printer"]],
     });
 
     await helper.startPrint();
 
     let copyInput = helper.get("copies-count");
     let destinationPicker = helper.get("printer-picker");
+    let copyError = helper.get("error-invalid-copies");
 
     await helper.assertSettingsChanged(
       { numCopies: 1 },
       { numCopies: 10000 },
       async () => {
-        helper.text(copyInput, "10000000000");
+        await helper.waitForSettingsEvent(() => {
+          helper.text(copyInput, "10000");
+        });
+
+        is(copyError.hidden, true, "Copy error is hidden");
+        EventUtils.sendChar("0", helper.win);
 
         // Initially, the copies will be more than the max.
         is(copyInput.checkValidity(), false, "Copy count is invalid");
+        await BrowserTestUtils.waitForAttributeRemoval("hidden", copyError);
+        is(copyError.hidden, false, "Copy error is showing");
         is(
           destinationPicker.disabled,
           false,
           "Destination picker is still enabled"
         );
 
-        // When the settings event happens, copies resolves to max.
+        helper.text(copyInput, "10000");
         await helper.waitForSettingsEvent();
         is(copyInput.value, "10000", "Copies gets set to max value");
         is(copyInput.checkValidity(), true, "Copy count is valid again");
+        await BrowserTestUtils.waitForCondition(
+          () => copyError.hidden,
+          "Wait for copy error to be hidden"
+        );
       }
     );
 
     await helper.closeDialog();
   });
 });
--- a/toolkit/locales/en-US/toolkit/printing/printUI.ftl
+++ b/toolkit/locales/en-US/toolkit/printing/printUI.ftl
@@ -113,13 +113,14 @@ printui-paper-jis-b4 = JIS-B4
 printui-paper-letter = US Letter
 printui-paper-legal = US Legal
 printui-paper-tabloid = Tabloid
 
 ## Error messages shown when a user has an invalid input
 
 printui-error-invalid-scale = Scale must be a number between 10 and 200.
 printui-error-invalid-margin = Please enter a valid margin for the selected paper size.
+printui-error-invalid-copies = Copies must be a number between 1 and 10000.
 
 # Variables
 # $numPages (integer) - Number of pages
 printui-error-invalid-range = Range must be a number between 1 and { $numPages }.
 printui-error-invalid-start-overflow = The “from” page number must be smaller than the “to” page number.