Bug 1727653 - wait for resize event before testing restoration of persisted sizes. r=niklas, a=RyanVM FIREFOX_91_11_0esr_BUILD1
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 15 Jun 2022 22:50:32 +0000
changeset 657840 cec32c7ec3acf7e8f2afa89ee287b2c6f5e6db81
parent 657839 a183595253d282a7ee0b760e9445b99a4ff2cc58
child 657841 255124d762161f7bcb8841ea4cbb4da6bcd8b226
push id282
push userryanvm@gmail.com
push dateFri, 17 Jun 2022 19:31:24 +0000
treeherdermozilla-esr91@cec32c7ec3ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersniklas, RyanVM
bugs1727653
milestone91.11.0
Bug 1727653 - wait for resize event before testing restoration of persisted sizes. r=niklas, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D149329
toolkit/content/tests/chrome/test_navigate_persist.html
--- a/toolkit/content/tests/chrome/test_navigate_persist.html
+++ b/toolkit/content/tests/chrome/test_navigate_persist.html
@@ -20,25 +20,32 @@ https://bugzilla.mozilla.org/show_bug.cg
           document.addEventListener("DOMContentLoaded", () => {
             resolve();
           }, { once: true } );
         }, "document-element-inserted");
         win.location = url;
       });
     }
 
-    function resize(win, size) {
-      let resizePromise = new Promise(resolve => {
-        if (win.outerWidth === size && win.outerHeight === size) {
+    function promiseMaybeResizeEvent(win, expectedSize) {
+      return new Promise(resolve => {
+        // If the size is already as expected, then there may be no resize
+        // event.
+        if (win.outerWidth === expectedSize
+            && win.outerHeight === expectedSize) {
           resolve();
         }
         win.addEventListener("resize", () => {
           resolve();
         }, {once: true});
       });
+    }
+
+    function resize(win, size) {
+      const resizePromise = promiseMaybeResizeEvent(win, size);
       win.resizeTo(size, size);
       return resizePromise;
     }
 
     async function runTest() {
       // Test that persisted window attributes are loaded when a top level
       // window is navigated. This mimics the behavior of early first paint by
       // first loading about:blank and then navigating to window_navigate_persist.html.
@@ -55,16 +62,17 @@ https://bugzilla.mozilla.org/show_bug.cg
       // Now mimic early first paint.
       win = window.browsingContext.topChromeWindow
                   .openDialog("about:blank", "_blank", `chrome,all,dialog=no`);
       await SimpleTest.promiseFocus(win, true);
       isnot(win.outerWidth, PERSIST_SIZE, "Initial window width is not the persisted size");
       isnot(win.outerHeight, PERSIST_SIZE, "Initial window height is not the persisted size");
 
       await navigateWindowTo(win, "window_navigate_persist.html");
+      await promiseMaybeResizeEvent(win, PERSIST_SIZE);
       is(win.outerWidth, PERSIST_SIZE, "Window width is persisted");
       is(win.outerHeight, PERSIST_SIZE, "Window height is persisted");
       win.close();
       SimpleTest.finish();
     }
 
   </script>
 </head>