Bug 1206133 - Fix browser_popupNotification_checkbox.js, which was broken by the popuppositioned patch. r=jhofmann
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 26 Sep 2016 11:39:56 -0700
changeset 315940 4a6f6c64ae89d18931c50286076f8a0030c75095
parent 315939 b0e0213a3b2bd5f0e449a41984414e7a64a45a8a
child 315941 b19e10ea4577c4ecc1cd0db76f76ff3f24b01e17
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhofmann
bugs1206133
milestone52.0a1
Bug 1206133 - Fix browser_popupNotification_checkbox.js, which was broken by the popuppositioned patch. r=jhofmann MozReview-Commit-ID: DEp1ZAHcPqT
browser/base/content/test/popupNotifications/browser_popupNotification_checkbox.js
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_checkbox.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_checkbox.js
@@ -20,16 +20,24 @@ function checkCheckbox(checkbox, label, 
 
 function checkMainAction(notification, disabled=false) {
   let mainAction = notification.button;
   let warningLabel = document.getAnonymousElementByAttribute(notification, "class", "popup-notification-warning");
   is(warningLabel.hidden, !disabled, "Warning label should be shown");
   is(mainAction.disabled, disabled, "MainAction should be disabled");
 }
 
+function promiseElementVisible(element) {
+  // HTMLElement.offsetParent is null when the element is not visisble
+  // (or if the element has |position: fixed|). See:
+  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
+  return BrowserTestUtils.waitForCondition(() => element.offsetParent !== null,
+                                          "Waiting for element to be visible");
+}
+
 var gNotification;
 
 var tests = [
   // Test that passing the checkbox field shows the checkbox.
   { id: "show_checkbox",
     run: function () {
       this.notifyObj = new BasicNotification(this.id);
       this.notifyObj.options.checkbox = {
@@ -70,21 +78,22 @@ var tests = [
     run: function () {
       this.notifyObj = new BasicNotification(this.id);
       this.notifyObj.mainAction.callback = ({checkboxChecked}) => this.mainActionChecked = checkboxChecked;
       this.notifyObj.options.checkbox = {
         label: "This is a checkbox",
       };
       gNotification = showNotification(this.notifyObj);
     },
-    onShown: function (popup) {
+    onShown: function* (popup) {
       checkPopup(popup, this.notifyObj);
       let notification = popup.childNodes[0];
       let checkbox = notification.checkbox;
       checkCheckbox(checkbox, "This is a checkbox");
+      yield promiseElementVisible(checkbox);
       EventUtils.synthesizeMouseAtCenter(checkbox, {});
       checkCheckbox(checkbox, "This is a checkbox", true);
       triggerMainCommand(popup);
     },
     onHidden: function () {
       is(this.mainActionChecked, true, "mainAction callback is passed the correct checkbox value");
     }
   },
@@ -98,21 +107,22 @@ var tests = [
         accessKey: "T",
         callback: ({checkboxChecked}) => this.secondaryActionChecked = checkboxChecked,
       }];
       this.notifyObj.options.checkbox = {
         label: "This is a checkbox",
       };
       gNotification = showNotification(this.notifyObj);
     },
-    onShown: function (popup) {
+    onShown: function* (popup) {
       checkPopup(popup, this.notifyObj);
       let notification = popup.childNodes[0];
       let checkbox = notification.checkbox;
       checkCheckbox(checkbox, "This is a checkbox");
+      yield promiseElementVisible(checkbox);
       EventUtils.synthesizeMouseAtCenter(checkbox, {});
       checkCheckbox(checkbox, "This is a checkbox", true);
       triggerSecondaryCommand(popup, 0);
     },
     onHidden: function () {
       is(this.secondaryActionChecked, true, "secondaryAction callback is passed the correct checkbox value");
     }
   },
@@ -125,21 +135,22 @@ var tests = [
         label: "This is a checkbox",
         checkedState: {
           disableMainAction: true,
           warningLabel: "Testing disable",
         },
       };
       gNotification = showNotification(this.notifyObj);
     },
-    onShown: function (popup) {
+    onShown: function* (popup) {
       checkPopup(popup, this.notifyObj);
       let notification = popup.childNodes[0];
       let checkbox = notification.checkbox;
       checkCheckbox(checkbox, "This is a checkbox");
+      yield promiseElementVisible(checkbox);
       EventUtils.synthesizeMouseAtCenter(checkbox, {});
       dismissNotification(popup);
     },
     onHidden: function (popup) {
       let icon = document.getElementById("default-notification-icon");
       EventUtils.synthesizeMouseAtCenter(icon, {});
       let notification = popup.childNodes[0];
       let checkbox = notification.checkbox;
@@ -162,25 +173,26 @@ var tests = [
             checked: checked,
             [state]: {
               disableMainAction: true,
               warningLabel: "Testing disable",
             },
           };
           gNotification = showNotification(this.notifyObj);
         },
-        onShown: function (popup) {
+        onShown: function* (popup) {
           checkPopup(popup, this.notifyObj);
           let notification = popup.childNodes[0];
           let checkbox = notification.checkbox;
           let disabled = (state === "checkedState" && checked) ||
                          (state === "uncheckedState" && !checked);
 
           checkCheckbox(checkbox, "This is a checkbox", checked);
           checkMainAction(notification, disabled);
+          yield promiseElementVisible(checkbox);
           EventUtils.synthesizeMouseAtCenter(checkbox, {});
           checkCheckbox(checkbox, "This is a checkbox", !checked);
           checkMainAction(notification, !disabled);
           EventUtils.synthesizeMouseAtCenter(checkbox, {});
           checkCheckbox(checkbox, "This is a checkbox", checked);
           checkMainAction(notification, disabled);
 
           // Unblock the main command if it's currently disabled.