Bug 1101287 - fix browser_934951_zoom_in_toolbar.js to use a mutation observer to wait for a label change, r=adw
☠☠ backed out by 0d35326dfbae ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 10 Dec 2014 18:18:14 +0000
changeset 219140 c677f867a18a1c2627078263157848fb3b198406
parent 219139 00b588dac8bc373f019a400baa894808721d7fc2
child 219141 0812ccbf1b659304d484e186771632c834ddc558
push id10365
push usergijskruitbosch@gmail.com
push dateThu, 11 Dec 2014 18:51:38 +0000
treeherderfx-team@c677f867a18a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1101287
milestone37.0a1
Bug 1101287 - fix browser_934951_zoom_in_toolbar.js to use a mutation observer to wait for a label change, r=adw
browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
browser/components/customizableui/test/head.js
--- a/browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
+++ b/browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
@@ -37,17 +37,24 @@ add_task(function() {
   FullZoom.reset();
   yield zoomResetPromise;
   is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
 
   // Test zoom label updates while navigating pages in the same tab.
   FullZoom.enlarge();
   yield zoomChangePromise;
   is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
-  yield promiseTabLoadEvent(tab1, "about:home");
+  let attributeChangePromise = promiseAttributeMutation(zoomResetButton, {
+    attributes: true,
+    attributeFilter: ["label"],
+  });
+  // don't need to wait for the tab load as waiting for the attribute is enough
+  // but do need to actually load this page:
+  promiseTabLoadEvent(tab1, "about:home");
+  yield attributeChangePromise;
   is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
   yield promiseTabHistoryNavigation(-1, function() {
     return parseInt(zoomResetButton.label, 10) == 110;
   });
   is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
 });
 
 function promiseObserverNotification(aObserver) {
--- a/browser/components/customizableui/test/head.js
+++ b/browser/components/customizableui/test/head.js
@@ -456,16 +456,37 @@ function promiseTabHistoryNavigation(aDi
   }
   gBrowser.addEventListener("pageshow", listener, true);
 
   content.history.go(aDirection);
 
   return deferred.promise;
 }
 
+/**
+ * Wait for an attribute on a node to change
+ *
+ * @param aNode      Node on which the mutation is expected
+ * @param aOptions   MutationObserver options to select the right mutation.
+ * @return {Promise} resolved when the requisite mutation shows up.
+ */
+function promiseAttributeMutation(aNode, aOptions) {
+  return new Promise((resolve, reject) => {
+    info("waiting for mutation: " + JSON.stringify(aOptions));
+    let obs = new MutationObserver((mutations) => {
+      if (mutations.length > 0) {
+        ok(true, "mutation occurred");
+        obs.disconnect();
+        resolve();
+      }
+    });
+    obs.observe(aNode, aOptions);
+  });
+}
+
 function popupShown(aPopup) {
   return promisePopupEvent(aPopup, "shown");
 }
 
 function popupHidden(aPopup) {
   return promisePopupEvent(aPopup, "hidden");
 }