Bug 1189630 - Make browser_translation_exceptions.js wait for infobar to finish animating; r=florian
authorBrian Birtles <birtles@gmail.com>
Fri, 07 Aug 2015 09:01:09 +0900
changeset 288372 a01bf3016c0824cc48f301c95507358d3bbdc5eb
parent 288371 d7734e7adeb21c316cae38b88b83c411488e0563
child 288373 94a07b627f21a086015e45941b33ea4f8280dead
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1189630
milestone42.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 1189630 - Make browser_translation_exceptions.js wait for infobar to finish animating; r=florian
browser/components/translation/test/browser_translation_exceptions.js
--- a/browser/components/translation/test/browser_translation_exceptions.js
+++ b/browser/components/translation/test/browser_translation_exceptions.js
@@ -53,17 +53,29 @@ function getDomainExceptions() {
         perm.capability == Services.perms.DENY_ACTION)
       results.push(perm.principal);
   }
 
   return results;
 }
 
 function getInfoBar() {
-  return gBrowser.getNotificationBox().getNotificationWithValue("translation");
+  let deferred = Promise.defer();
+  let infobar =
+    gBrowser.getNotificationBox().getNotificationWithValue("translation");
+
+  if (!infobar) {
+    deferred.resolve();
+  } else {
+    // Wait for all animations to finish
+    Promise.all(infobar.getAnimations().map(animation => animation.finished))
+      .then(() => deferred.resolve(infobar));
+  }
+
+  return deferred.promise;
 }
 
 function openPopup(aPopup) {
   let deferred = Promise.defer();
 
   aPopup.addEventListener("popupshown", function popupShown() {
     aPopup.removeEventListener("popupshown", popupShown);
     deferred.resolve();
@@ -104,17 +116,17 @@ let gTests = [
 {
   desc: "never for language",
   run: function* checkNeverForLanguage() {
     // Show the infobar for example.com and fr.
     Translation.documentStateReceived(gBrowser.selectedBrowser,
                                       {state: Translation.STATE_OFFER,
                                        originalShown: true,
                                        detectedLanguage: "fr"});
-    let notif = getInfoBar();
+    let notif = yield getInfoBar();
     ok(notif, "the infobar is visible");
     let ui = gBrowser.selectedBrowser.translationUI;
     let uri = gBrowser.selectedBrowser.currentURI;
     ok(ui.shouldShowInfoBar(uri, "fr"),
        "check shouldShowInfoBar initially returns true");
 
     // Open the "options" drop down.
     yield openPopup(notif._getAnonElt("options"));
@@ -122,28 +134,29 @@ let gTests = [
        "the options menu is open");
 
     // Check that the item is not disabled.
     ok(!notif._getAnonElt("neverForLanguage").disabled,
        "The 'Never translate <language>' item isn't disabled");
 
     // Click the 'Never for French' item.
     notif._getAnonElt("neverForLanguage").click();
-    ok(!getInfoBar(), "infobar hidden");
+    notif = yield getInfoBar();
+    ok(!notif, "infobar hidden");
 
     // Check this has been saved to the exceptions list.
     let langs = getLanguageExceptions();
     is(langs.length, 1, "one language in the exception list");
     is(langs[0], "fr", "correct language in the exception list");
     ok(!ui.shouldShowInfoBar(uri, "fr"),
        "the infobar wouldn't be shown anymore");
 
     // Reopen the infobar.
     PopupNotifications.getNotification("translate").anchorElement.click();
-    notif = getInfoBar();
+    notif = yield getInfoBar();
     // Open the "options" drop down.
     yield openPopup(notif._getAnonElt("options"));
     ok(notif._getAnonElt("neverForLanguage").disabled,
        "The 'Never translate French' item is disabled");
 
     // Cleanup.
     Services.prefs.setCharPref(kLanguagesPref, "");
     notif.close();
@@ -153,17 +166,17 @@ let gTests = [
 {
   desc: "never for site",
   run: function* checkNeverForSite() {
     // Show the infobar for example.com and fr.
     Translation.documentStateReceived(gBrowser.selectedBrowser,
                                       {state: Translation.STATE_OFFER,
                                        originalShown: true,
                                        detectedLanguage: "fr"});
-    let notif = getInfoBar();
+    let notif = yield getInfoBar();
     ok(notif, "the infobar is visible");
     let ui = gBrowser.selectedBrowser.translationUI;
     let uri = gBrowser.selectedBrowser.currentURI;
     ok(ui.shouldShowInfoBar(uri, "fr"),
        "check shouldShowInfoBar initially returns true");
 
     // Open the "options" drop down.
     yield openPopup(notif._getAnonElt("options"));
@@ -171,28 +184,29 @@ let gTests = [
        "the options menu is open");
 
     // Check that the item is not disabled.
     ok(!notif._getAnonElt("neverForSite").disabled,
        "The 'Never translate site' item isn't disabled");
 
     // Click the 'Never for French' item.
     notif._getAnonElt("neverForSite").click();
-    ok(!getInfoBar(), "infobar hidden");
+    notif = yield getInfoBar();
+    ok(!notif, "infobar hidden");
 
     // Check this has been saved to the exceptions list.
     let sites = getDomainExceptions();
     is(sites.length, 1, "one site in the exception list");
     is(sites[0].origin, "http://example.com", "correct site in the exception list");
     ok(!ui.shouldShowInfoBar(uri, "fr"),
        "the infobar wouldn't be shown anymore");
 
     // Reopen the infobar.
     PopupNotifications.getNotification("translate").anchorElement.click();
-    notif = getInfoBar();
+    notif = yield getInfoBar();
     // Open the "options" drop down.
     yield openPopup(notif._getAnonElt("options"));
     ok(notif._getAnonElt("neverForSite").disabled,
        "The 'Never translate French' item is disabled");
 
     // Cleanup.
     Services.perms.remove(makeURI("http://example.com"), "translate");
     notif.close();