Bug 1272800: Wait for zoom event after switching tab if current value is not as expected. r=me
authorKris Maglione <maglione.k@gmail.com>
Tue, 31 May 2016 13:43:28 -0700
changeset 324141 3f1686cbca54bb830163dd7fbb0fb9048916ea8f
parent 324140 aee75e50fbc15694bbe48724eb28dea184ef985e
child 324142 d39456c7ccf19d98bb20c3de1dd88cb3c9513c55
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1272800
milestone49.0a1
Bug 1272800: Wait for zoom event after switching tab if current value is not as expected. r=me MozReview-Commit-ID: 4GtQMLOLZNP
browser/components/extensions/test/browser/browser_ext_tabs_zoom.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_zoom.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_zoom.js
@@ -45,16 +45,37 @@ add_task(function* () {
     let eventPromises = [];
     browser.tabs.onZoomChange.addListener(info => {
       zoomEvents.push(info);
       if (eventPromises.length) {
         eventPromises.shift().resolve();
       }
     });
 
+    let awaitZoom = (tabId, newValue) => {
+      let listener;
+
+      return new Promise(resolve => {
+        listener = info => {
+          if (info.tabId == tabId && info.newZoomFactor == newValue) {
+            resolve();
+          }
+        };
+        browser.tabs.onZoomChange.addListener(listener);
+
+        browser.tabs.getZoom(tabId).then(zoomFactor => {
+          if (zoomFactor == newValue) {
+            resolve();
+          }
+        });
+      }).then(() => {
+        browser.tabs.onZoomChange.removeListener(listener);
+      });
+    };
+
     let checkZoom = (tabId, newValue, oldValue = null) => {
       let awaitEvent;
       if (oldValue != null && !zoomEvents.length) {
         awaitEvent = new Promise(resolve => {
           eventPromises.push({resolve});
         });
       }
 
@@ -113,19 +134,20 @@ add_task(function* () {
       return checkZoom(tabIds[1], 2, 1);
     }).then(() => {
       browser.test.log(`Update zoom in tab 2, expect changes in both tabs`);
       return browser.tabs.setZoom(tabIds[1], 1.5);
     }).then(() => {
       return checkZoom(tabIds[1], 1.5, 2);
     }).then(() => {
       browser.test.log(`Switch to tab 1, expect asynchronous zoom change just after the switch`);
-      return browser.tabs.update(tabIds[0], {active: true});
-    }).then(() => {
-      return new Promise(resolve => setTimeout(resolve, 0));
+      return Promise.all([
+        awaitZoom(tabIds[0], 1.5),
+        browser.tabs.update(tabIds[0], {active: true}),
+      ]);
     }).then(() => {
       return checkZoom(tabIds[0], 1.5, 2);
     }).then(() => {
       browser.test.log("Set zoom to 0, expect it set to 1");
       return browser.tabs.setZoom(tabIds[0], 0);
     }).then(() => {
       return checkZoom(tabIds[0], 1, 1.5);
     }).then(() => {