Bug 1628889 - Try to fix preferences tests that fail to scroll when opening the preferences tab. r=mkmelin a=wsmwk
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 15 Apr 2020 20:38:19 +1200
changeset 38520 931823eeff65b826ca34af4b2ab378c94234004d
parent 38519 c8ac1cc10b1a088953b1973a544cbd0856e58c66
child 38521 e431355d0d285ec02da2478c106c00c5f524c1d7
push id2625
push userthunderbird@calypsoblue.org
push dateFri, 19 Jun 2020 19:52:35 +0000
treeherdercomm-beta@1346aaf4d966 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, wsmwk
bugs1628889
Bug 1628889 - Try to fix preferences tests that fail to scroll when opening the preferences tab. r=mkmelin a=wsmwk
calendar/test/browser/preferences/head.js
mail/components/preferences/preferencesTab.js
mail/components/preferences/test/browser/head.js
--- a/calendar/test/browser/preferences/head.js
+++ b/calendar/test/browser/preferences/head.js
@@ -36,16 +36,23 @@ async function openNewPrefsTab(paneID, s
     // If we don't wait here for other scripts to run, they
     // could be in a bad state if our test closes the tab.
     await new Promise(resolve => prefsWindow.setTimeout(resolve));
   }
 
   registerCleanupOnce();
 
   await new Promise(resolve => prefsWindow.setTimeout(resolve));
+  if (scrollPaneTo) {
+    Assert.greater(
+      prefsDocument.getElementById("preferencesContainer").scrollTop,
+      0,
+      "Prefs page did scroll when it was supposed to"
+    );
+  }
   return { prefsDocument, prefsWindow };
 }
 
 function registerCleanupOnce() {
   if (registerCleanupOnce.alreadyRegistered) {
     return;
   }
   registerCleanupFunction(closePrefsTab);
--- a/mail/components/preferences/preferencesTab.js
+++ b/mail/components/preferences/preferencesTab.js
@@ -112,17 +112,17 @@ var preferencesTabType = {
       "paneSelected",
       function(event) {
         aTab.pageLoading = false;
         aTab.pageLoaded = true;
 
         if ("onLoad" in aArgs) {
           // Let selection of the initial pane complete before selecting another.
           // Otherwise we can end up with two panes selected at once.
-          setTimeout(() => {
+          aTab.browser.contentWindow.setTimeout(() => {
             // By now, the tab could already be closed. Check that it isn't.
             if (aTab.panel) {
               aArgs.onLoad(event, aTab.browser);
             }
           }, 0);
         }
       },
       { once: true }
--- a/mail/components/preferences/test/browser/head.js
+++ b/mail/components/preferences/test/browser/head.js
@@ -9,17 +9,17 @@ async function openNewPrefsTab(paneID, s
   let prefsTabMode = tabmail.tabModes.preferencesTab;
 
   is(prefsTabMode.tabs.length, 0, "Prefs tab is not open");
 
   let prefsDocument = await new Promise(resolve => {
     Services.obs.addObserver(function documentLoaded(subject) {
       if (subject.URL == "about:preferences") {
         Services.obs.removeObserver(documentLoaded, "chrome-document-loaded");
-        resolve(subject);
+        subject.ownerGlobal.setTimeout(() => resolve(subject));
       }
     }, "chrome-document-loaded");
     openPreferencesTab(paneID, scrollPaneTo, otherArgs);
   });
   ok(prefsDocument.URL == "about:preferences", "Prefs tab is open");
 
   let prefsWindow = prefsDocument.ownerGlobal;
   if (paneID) {
@@ -36,16 +36,23 @@ async function openNewPrefsTab(paneID, s
     // If we don't wait here for other scripts to run, they
     // could be in a bad state if our test closes the tab.
     await new Promise(resolve => prefsWindow.setTimeout(resolve));
   }
 
   registerCleanupOnce();
 
   await new Promise(resolve => prefsWindow.setTimeout(resolve));
+  if (scrollPaneTo) {
+    Assert.greater(
+      prefsDocument.getElementById("preferencesContainer").scrollTop,
+      0,
+      "Prefs page did scroll when it was supposed to"
+    );
+  }
   return { prefsDocument, prefsWindow };
 }
 
 async function openExistingPrefsTab(paneID, scrollPaneTo, otherArgs) {
   let tabmail = document.getElementById("tabmail");
   let prefsTabMode = tabmail.tabModes.preferencesTab;
 
   is(prefsTabMode.tabs.length, 1, "Prefs tab is open");
@@ -60,16 +67,24 @@ async function openExistingPrefsTab(pane
     });
   } else {
     openPreferencesTab(paneID, scrollPaneTo, otherArgs);
   }
 
   await new Promise(resolve => prefsWindow.setTimeout(resolve));
   is(prefsWindow.getCurrentPaneID(), paneID, `Selected pane is ${paneID}`);
 
+  if (scrollPaneTo) {
+    Assert.greater(
+      prefsDocument.getElementById("preferencesContainer").scrollTop,
+      0,
+      "Prefs page did scroll when it was supposed to"
+    );
+  }
+
   registerCleanupOnce();
 
   return { prefsDocument, prefsWindow };
 }
 
 function registerCleanupOnce() {
   if (registerCleanupOnce.alreadyRegistered) {
     return;
@@ -216,17 +231,17 @@ async function testRadioButtons(paneID, 
         scrollPaneTo
       );
 
       let testUIState = function(currentState) {
         info(`Testing with ${pref} set to ${currentState.prefValue}`);
         for (let state of states) {
           let isCurrentState = state == currentState;
           let radio = prefsDocument.getElementById(state.id);
-          is(radio.selected, isCurrentState);
+          is(radio.selected, isCurrentState, `${state.id}.selected`);
 
           if (state.enabledElements) {
             for (let selector of state.enabledElements) {
               let elements = prefsDocument.querySelectorAll(selector);
               ok(
                 elements.length >= 1,
                 `At least one element matched '${selector}'`
               );