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
☠☠ backed out by 8fc6195511e5 ☠ ☠
authorJonas Jenwald <jonas.jenwald@gmail.com>
Sat, 28 Mar 2015 23:55:21 +0100
changeset 260262 b29a45098630
parent 260261 0efa961d5162
child 260263 e46c9612492a
push id731
push userryanvm@gmail.com
push date2015-04-24 19:52 +0000
treeherdermozilla-release@38ff61772a2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, test-only
bugs1112947
milestone38.0
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;
 }