Bug 1283902 - Skip repeated onDownloadProgress events so the test may pass. r=aswan a=testonly
authorThomas Wisniewski <wisniewskit@gmail.com>
Sun, 31 Jul 2016 13:44:50 -0400
changeset 348067 7d3d4f307002cc8475800df191196b94999ffd0a
parent 348066 8c26f35e08a3ab42d442895a87ff6dd7614d0b70
child 348068 312abfcd4ee361c952d93558650e144b5f50ddca
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, testonly
bugs1283902
milestone50.0a2
Bug 1283902 - Skip repeated onDownloadProgress events so the test may pass. r=aswan a=testonly
toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
@@ -60,16 +60,17 @@ function* testInstall(browser, url, step
       "onDownloadFailed",
       "onInstallStarted",
       "onInstallEnded",
       "onInstallCancelled",
       "onInstallFailed",
     ];
     let eventWaiter = null;
     let receivedEvents = [];
+    let prevEvent = null;
     events.forEach(event => {
       install.addEventListener(event, e => {
         receivedEvents.push({
           event,
           state: install.state,
           error: install.error,
           progress: install.progress,
           maxProgress: install.maxProgress,
@@ -82,37 +83,45 @@ function* testInstall(browser, url, step
 
     // Returns a promise that is resolved when the given event occurs
     // or rejects if a different event comes first or if props is supplied
     // and properties on the AddonInstall don't match those in props.
     function expectEvent(event, props) {
       return new Promise((resolve, reject) => {
         function check() {
           let received = receivedEvents.shift();
+          // Skip any repeated onDownloadProgress events.
+          while (received &&
+                 received.event == prevEvent &&
+                 prevEvent == "onDownloadProgress") {
+            received = receivedEvents.shift();
+          }
+          // Wait for more events if we skipped all there were.
+          if (!received) {
+            eventWaiter = () => {
+              eventWaiter = null;
+              check();
+            }
+            return;
+          }
+          prevEvent = received.event;
           if (received.event != event) {
             let err = new Error(`expected ${event} but got ${received.event}`);
             reject(err);
           }
           if (props) {
             for (let key of Object.keys(props)) {
               if (received[key] != props[key]) {
                 throw new Error(`AddonInstall property ${key} was ${received[key]} but expected ${props[key]}`);
               }
             }
           }
           resolve();
         }
-        if (receivedEvents.length > 0) {
-          check();
-        } else {
-          eventWaiter = () => {
-            eventWaiter = null;
-            check();
-          }
-        }
+        check();
       });
     }
 
     while (steps.length > 0) {
       let nextStep = steps.shift();
       if (nextStep.action) {
         if (nextStep.action == "install") {
           yield install.install();