Bug 1112947 - Replace a setTimeout with an EventListener to fix an intermittent failure in browser/extensions/pdfjs/test/browser_pdfjs_navigation.js. r=mossop, a=test-only
authorJonas Jenwald <jonas.jenwald@gmail.com>
Sat, 28 Mar 2015 23:55:21 +0100
changeset 267198 58ab5d4e0e0a07f855a8bfbfcdbde5387a1ee0b4
parent 267197 472989ca7f7ffb38e8af882839a539ae0e2da87c
child 267199 e429aa5f271c6df540d38651f324b5a40eb1037b
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, test-only
bugs1112947
milestone39.0a2
Bug 1112947 - Replace a setTimeout with an EventListener to fix an intermittent failure in browser/extensions/pdfjs/test/browser_pdfjs_navigation.js. r=mossop, a=test-only This patch also fixes three small typos in the code. Two of them are trivial spelling errors, while the third one concerns the removal of an EventListener in the function |setZoomToPageFit|.
browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
--- a/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
@@ -184,21 +184,21 @@ function runTests(document, window, fini
 
   // Wait for outline items, the start the navigation actions
   waitForOutlineItems(document).then(function () {
     // The key navigation has to happen in page-fit, otherwise it won't scroll
     // trough a complete page
     setZoomToPageFit(document).then(function () {
       runNextTest(document, window, finish);
     }, function () {
-      ok(false, "Current scale has been ste to 'page-fit'");
+      ok(false, "Current scale has been set to 'page-fit'");
       finish();
     });
   }, function () {
-    ok(false, "Outline items have ben found");
+    ok(false, "Outline items have been found");
     finish();
   });
 }
 
 /**
  * As the page changes asynchronously, we have to wait for the event after
  * we trigger the action so we will be at the expected page number after each action
  *
@@ -262,43 +262,44 @@ function runNextTest(document, window, e
  * Outline Items gets appended to the document latter on we have to
  * wait for them before we start to navigate though document
  *
  * @param document
  * @returns {deferred.promise|*}
  */
 function waitForOutlineItems(document) {
   var deferred = Promise.defer();
-  var timeout = setTimeout(() => deferred.reject(), 10000);
-  var interval = setInterval(function () {
-    if (document.querySelectorAll(".outlineItem").length == PDF_OUTLINE_ITEMS) {
-      clearInterval(interval);
-      clearTimeout(timeout);
+  document.addEventListener("outlineloaded", function outlineLoaded(evt) {
+    document.removeEventListener("outlineloaded", outlineLoaded);
+    var outlineCount = evt.detail.outlineCount;
+
+    if (document.querySelectorAll(".outlineItem").length === outlineCount) {
       deferred.resolve();
+    } else {
+      deferred.reject();
     }
-  }, 500);
+  });
 
   return deferred.promise;
 }
 
 /**
  * The key navigation has to happen in page-fit, otherwise it won't scroll
  * trough a complete page
  *
  * @param document
  * @returns {deferred.promise|*}
  */
 function setZoomToPageFit(document) {
   var deferred = Promise.defer();
   document.addEventListener("pagerendered", function onZoom(e) {
-    document.removeEventListener("pagerendered", onZoom), false;
+    document.removeEventListener("pagerendered", onZoom);
     document.querySelector("#viewer").click();
     deferred.resolve();
-
-  }, false);
+  });
 
   var select = document.querySelector("select#scaleSelect");
   select.selectedIndex = 2;
   select.dispatchEvent(new Event("change"));
 
   return deferred.promise;
 }