Bug 1101287 - fix browser_934951_zoom_in_toolbar.js to use a mutation observer to wait for a label change, r=adw
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 10 Dec 2014 18:18:14 +0000
changeset 220369 f9cafb3df61a434a3f32138527c330d802575ed7
parent 220368 84b5923001d69e67c27069cb8f9969d332f4d0fc
child 220370 353443a10c4b3259e14f874e590cc59027afa68d
push id27985
push userryanvm@gmail.com
push dateThu, 18 Dec 2014 22:32:46 +0000
treeherdermozilla-central@9acb15a52030 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1101287
milestone37.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 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,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");
 }