Bug 1674106, delete custom margins from userChangedSettings when updating an invalid margin after a paper size switch r=mstriemer
authorEmma Malysz <emalysz@mozilla.com>
Wed, 02 Dec 2020 16:58:23 +0000
changeset 559099 36f51561645e8cde7b14242a181f503b1873a27a
parent 559098 3d2b3bba6fdba126b4a1d50de7a2f9fd11d4eaba
child 559100 726f26279667b7fc4ec95d5f6f5bb216a7862da7
push id131940
push useremalysz@mozilla.com
push dateWed, 02 Dec 2020 17:01:05 +0000
treeherderautoland@36f51561645e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer
bugs1674106
milestone85.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 1674106, delete custom margins from userChangedSettings when updating an invalid margin after a paper size switch r=mstriemer Differential Revision: https://phabricator.services.mozilla.com/D98224
toolkit/components/printing/content/print.js
toolkit/components/printing/tests/browser_print_margins.js
--- a/toolkit/components/printing/content/print.js
+++ b/toolkit/components/printing/content/print.js
@@ -538,30 +538,32 @@ var PrintEventHandler = {
               paperWrapper.unwriteableMarginTop -
               paperWrapper.unwriteableMarginBottom ||
           this.viewSettings.customMargins.marginTop < 0 ||
           this.viewSettings.customMargins.marginBottom < 0
         ) {
           let { marginTop, marginBottom } = this.viewSettings.defaultMargins;
           changedSettings.marginTop = changedSettings.customMarginTop = marginTop;
           changedSettings.marginBottom = changedSettings.customMarginBottom = marginBottom;
+          delete this._userChangedSettings.customMargins;
         }
 
         if (
           parseFloat(this.viewSettings.customMargins.marginRight) +
             parseFloat(this.viewSettings.customMargins.marginLeft) >
             width -
               paperWrapper.unwriteableMarginRight -
               paperWrapper.unwriteableMarginLeft ||
           this.viewSettings.customMargins.marginLeft < 0 ||
           this.viewSettings.customMargins.marginRight < 0
         ) {
           let { marginLeft, marginRight } = this.viewSettings.defaultMargins;
           changedSettings.marginLeft = changedSettings.customMarginLeft = marginLeft;
           changedSettings.marginRight = changedSettings.customMarginRight = marginRight;
+          delete this._userChangedSettings.customMargins;
         }
       } catch (e) {
         this.reportPrintingError("PAPER_MARGINS");
         throw e;
       }
     }
 
     for (let [setting, value] of Object.entries(changedSettings)) {
--- a/toolkit/components/printing/tests/browser_print_margins.js
+++ b/toolkit/components/printing/tests/browser_print_margins.js
@@ -744,8 +744,58 @@ add_task(async function testRevalidateCu
       async () => {
         await helper.dispatchSettingsChange({ orientation: 1 });
         await helper.waitForSettingsEvent();
         ok(marginError.hidden, "Margin error is hidden");
       }
     );
   });
 });
+
+add_task(async function testResetMarginPersists() {
+  await PrintHelper.withTestPage(async helper => {
+    await setupLetterPaper();
+    await helper.startPrint();
+
+    await helper.openMoreSettings();
+    this.changeDefaultToCustom(helper);
+    await helper.awaitAnimationFrame();
+    let marginError = helper.get("error-invalid-margin");
+
+    await helper.assertSettingsChanged(
+      { marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
+      { marginTop: 0.5, marginRight: 4, marginBottom: 0.5, marginLeft: 4.5 },
+      async () => {
+        await helper.text(helper.get("custom-margin-right"), "4");
+        await helper.text(helper.get("custom-margin-left"), "4.5");
+
+        // Wait for the preview to update, the margin options delay updates by
+        // INPUT_DELAY_MS, which is 500ms.
+        await helper.waitForSettingsEvent();
+        ok(marginError.hidden, "Margin error is hidden");
+      }
+    );
+
+    await helper.assertSettingsChanged(
+      { marginTop: 0.5, marginRight: 4, marginBottom: 0.5, marginLeft: 4.5 },
+      { marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
+      async () => {
+        helper.dispatchSettingsChange({ paperId: "iso_a4" });
+
+        // Wait for the preview to update, the margin options delay updates by
+        // INPUT_DELAY_MS, which is 500ms.
+        await helper.waitForSettingsEvent();
+        ok(marginError.hidden, "Margin error is hidden");
+      }
+    );
+
+    await helper.assertSettingsNotChanged(
+      { marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
+      async () => {
+        helper.dispatchSettingsChange({ paperId: "iso_a5" });
+        await helper.waitForSettingsEvent();
+        ok(marginError.hidden, "Margin error is hidden");
+      }
+    );
+
+    await helper.closeDialog();
+  });
+});