Bug 1101287 - Fix browser_934951_zoom_in_toolbar.js to use a mutation observer to wait for a label change. r=adw, a=test-only
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 10 Dec 2014 18:18:14 +0000
changeset 242514 e2c858e80cb1475fbc81e81f26573f539bc141d3
parent 242513 5590fdb108c5143cb03edbf400a3a782be0e9c4c
child 242515 40962163ae7e0d26d2763c812a4a4db3ec68d76f
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, test-only
bugs1101287
milestone36.0a2
Bug 1101287 - Fix browser_934951_zoom_in_toolbar.js to use a mutation observer to wait for a label change. r=adw, a=test-only
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,21 @@ 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");
+  let attributeChangePromise = promiseAttributeMutation(zoomResetButton, "label", (v) => {
+    return parseInt(v, 10) == 100;
+  });
   yield 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,44 @@ 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 aAttribute The attribute we're interested in
+ * @param aFilterFn  A function to check if the new value is what we want.
+ * @return {Promise} resolved when the requisite mutation shows up.
+ */
+function promiseAttributeMutation(aNode, aAttribute, aFilterFn) {
+  return new Promise((resolve, reject) => {
+    info("waiting for mutation of attribute '" + aAttribute + "'.");
+    let obs = new MutationObserver((mutations) => {
+      for (let mut of mutations) {
+        let attr = mut.attributeName;
+        let newValue = mut.target.getAttribute(attr);
+        if (aFilterFn(newValue)) {
+          ok(true, "mutation occurred: attribute '" + attr + "' changed to '" + newValue + "' from '" + mut.oldValue + "'.");
+          obs.disconnect();
+          resolve();
+        } else {
+          info("Ignoring mutation that produced value " + newValue + " because of filter.");
+        }
+      }
+    });
+    obs.observe(aNode, {attributeFilter: [aAttribute]});
+  });
+}
+
 function popupShown(aPopup) {
   return promisePopupEvent(aPopup, "shown");
 }
 
 function popupHidden(aPopup) {
   return promisePopupEvent(aPopup, "hidden");
 }