Merge m-c to b-i
authorNigel Babu <nigelbabu@gmail.com>
Mon, 16 Nov 2015 18:48:46 +0530
changeset 272677 85e02d7df478916a9a0cc167457842950a6ee7ed
parent 272676 3dc13ad8efbefd53b2560b760c442799fa6a737e (current diff)
parent 272606 4294bf91174b71ed7440dc491dac5d15394ec227 (diff)
child 272678 01db672f735bb2675ee2e98a86cc43220c1ffff8
push id29681
push userkwierso@gmail.com
push dateMon, 16 Nov 2015 23:39:08 +0000
treeherdermozilla-central@ffe020f91452 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone45.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
Merge m-c to b-i
browser/extensions/pdfjs/test/head.js
--- a/browser/extensions/pdfjs/test/browser.ini
+++ b/browser/extensions/pdfjs/test/browser.ini
@@ -1,10 +1,12 @@
 [DEFAULT]
-support-files =
-  file_pdfjs_test.pdf
-  head.js
+support-files = file_pdfjs_test.pdf
 
 [browser_pdfjs_main.js]
+skip-if = e10s # Bug 1159385
 [browser_pdfjs_navigation.js]
+skip-if = e10s # Bug 1159385
 [browser_pdfjs_savedialog.js]
 [browser_pdfjs_views.js]
+skip-if = e10s # Bug 1159385
 [browser_pdfjs_zoom.js]
+skip-if = e10s # Bug 1159385
--- a/browser/extensions/pdfjs/test/browser_pdfjs_main.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_main.js
@@ -1,67 +1,98 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
 
-add_task(function* test() {
+function test() {
+  var tab;
+
   let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
   let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
 
   // Make sure pdf.js is the default handler.
   is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
   is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
 
   info('Pref action: ' + handlerInfo.preferredAction);
 
-  yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
-    function* (newTabBrowser) {
-      ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(tab);
+  });
 
-      yield waitForPdfJS(newTabBrowser);
+  tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
+  var newTabBrowser = gBrowser.getBrowserForTab(tab);
+  newTabBrowser.addEventListener("load", function eventHandler() {
+    newTabBrowser.removeEventListener("load", eventHandler, true);
+
+    var document = newTabBrowser.contentDocument,
+        window = newTabBrowser.contentWindow;
 
-      yield ContentTask.spawn(newTabBrowser, null, function* () {
-        //
-        // Overall sanity tests
-        //
-        ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
-        ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
+    // Runs tests after all 'load' event handlers have fired off
+    window.addEventListener("documentload", function() {
+      runTests(document, window, tab, function () {
+        closePDFViewer(window, finish);
+      });
+    }, false, true);
+  }, true);
+}
+
+
+function runTests(document, window, tab, callback) {
 
-        //
-        // Sidebar: open
-        //
-        var sidebar = content.document.querySelector('button#sidebarToggle'),
-            outerContainer = content.document.querySelector('div#outerContainer');
+  //
+  // Overall sanity tests
+  //
+  ok(document.querySelector('div#viewer'), "document content has viewer UI");
+  ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
+  ok('PDFViewerApplication' in window.wrappedJSObject,
+     "window content has viewer object");
 
-        sidebar.click();
-        ok(outerContainer.classList.contains('sidebarOpen'), "sidebar opens on click");
+  //
+  // Browser Find
+  //
+  ok(gBrowser.isFindBarInitialized(tab), "Browser FindBar initialized!");
 
-        //
-        // Sidebar: close
-        //
-        sidebar.click();
-        ok(!outerContainer.classList.contains('sidebarOpen'), "sidebar closes on click");
+  //
+  // Sidebar: open
+  //
+  var sidebar = document.querySelector('button#sidebarToggle'),
+      outerContainer = document.querySelector('div#outerContainer');
+
+  sidebar.click();
+  ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
 
-        //
-        // Page change from prev/next buttons
-        //
-        var prevPage = content.document.querySelector('button#previous'),
-            nextPage = content.document.querySelector('button#next');
+  //
+  // Sidebar: close
+  //
+  sidebar.click();
+  ok(!outerContainer.classList.contains('sidebarOpen'), 'sidebar closes on click');
+
+  //
+  // Page change from prev/next buttons
+  //
+  var prevPage = document.querySelector('button#previous'),
+      nextPage = document.querySelector('button#next');
 
-        var pgNumber = content.document.querySelector('input#pageNumber').value;
-        is(parseInt(pgNumber, 10), 1, 'initial page is 1');
+  var pageNumber = document.querySelector('input#pageNumber');
+  is(parseInt(pageNumber.value), 1, 'initial page is 1');
+
+  //
+  // Bookmark button
+  //
+  var viewBookmark = document.querySelector('a#viewBookmark');
+  viewBookmark.click();
+  ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
 
-        //
-        // Bookmark button
-        //
-        var viewBookmark = content.document.querySelector('a#viewBookmark');
-        viewBookmark.click();
+  callback();
+}
 
-        ok(viewBookmark.href.length > 0, "viewBookmark button has href");
-
-        var viewer = content.wrappedJSObject.PDFViewerApplication;
-        yield viewer.close();
-      });
-    });
-});
+/**
+ * Destroys PDF.js viewer opened document.
+ */
+function closePDFViewer(window, callback) {
+  var viewer = window.wrappedJSObject.PDFViewerApplication;
+  viewer.close().then(callback);
+}
--- a/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
@@ -134,148 +134,172 @@ const TESTS = [
       value: 5,
       event: "change"
     },
     expectedPage: 5,
     message: "navigated to 5th page using pagenumber"
   }
 ];
 
-add_task(function* test() {
+function test() {
+  var tab;
+
   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
   let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
 
   // Make sure pdf.js is the default handler.
   is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
   is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
 
   info('Pref action: ' + handlerInfo.preferredAction);
 
-  yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
-    function* (newTabBrowser) {
-      yield waitForPdfJS(newTabBrowser);
-
-      yield ContentTask.spawn(newTabBrowser, null, function* () {
-        // Check if PDF is opened with internal viewer
-        ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
-        ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
-      });
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(tab);
+  });
 
-      yield ContentTask.spawn(newTabBrowser, null, contentSetUp);
-
-      yield Task.spawn(runTests(newTabBrowser));
+  tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
+  gBrowser.selectedTab = tab;
 
-      yield ContentTask.spawn(newTabBrowser, null, function*() {
-        let pageNumber = content.document.querySelector('input#pageNumber');
-        is(pageNumber.value, pageNumber.max, "Document is left on the last page");
-      });
-    });
-});
+  var newTabBrowser = gBrowser.getBrowserForTab(tab);
+  newTabBrowser.addEventListener("load", function eventHandler() {
+    newTabBrowser.removeEventListener("load", eventHandler, true);
+
+    var document = newTabBrowser.contentDocument,
+        window = newTabBrowser.contentWindow;
 
-function* contentSetUp() {
-  /**
-   * Outline Items gets appended to the document later on we have to
-   * wait for them before we start to navigate though document
-   *
-   * @param document
-   * @returns {deferred.promise|*}
-   */
-  function waitForOutlineItems(document) {
-    return new Promise((resolve, reject) => {
-      document.addEventListener("outlineloaded", function outlineLoaded(evt) {
-        document.removeEventListener("outlineloaded", outlineLoaded);
-        var outlineCount = evt.detail.outlineCount;
-
-        if (document.querySelectorAll(".outlineItem").length === outlineCount) {
-          resolve();
-        } else {
-          reject();
-        }
+    // Runs tests after all 'load' event handlers have fired off
+    window.addEventListener("documentload", function() {
+      runTests(document, window, function () {
+        var pageNumber = document.querySelector('input#pageNumber');
+        is(pageNumber.value, pageNumber.max, "Document is left on the last page");
+        finish();
       });
-    });
-  }
+    }, false, true);
+  }, true);
+}
 
-  /**
-   * The key navigation has to happen in page-fit, otherwise it won't scroll
-   * through a complete page
-   *
-   * @param document
-   * @returns {deferred.promise|*}
-   */
-  function setZoomToPageFit(document) {
-    return new Promise((resolve) => {
-      document.addEventListener("pagerendered", function onZoom(e) {
-        document.removeEventListener("pagerendered", onZoom);
-        document.querySelector("#viewer").click();
-        resolve();
-      });
+function runTests(document, window, finish) {
+  // Check if PDF is opened with internal viewer
+  ok(document.querySelector('div#viewer'), "document content has viewer UI");
+  ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
 
-      var select = document.querySelector("select#scaleSelect");
-      select.selectedIndex = 2;
-      select.dispatchEvent(new Event("change"));
+  // 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 set to 'page-fit'");
+      finish();
     });
-  }
-
-  yield waitForOutlineItems(content.document);
-  yield setZoomToPageFit(content.document);
+  }, function () {
+    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
  *
  * @param document
  * @param window
  * @param test
  * @param callback
  */
-function* runTests(browser) {
-  yield ContentTask.spawn(browser, TESTS, function* (TESTS) {
-    let window = content;
-    let document = window.document;
-
-    for (let test of TESTS) {
-      let deferred = {};
-      deferred.promise = new Promise((resolve, reject) => {
-        deferred.resolve = resolve;
-        deferred.reject = reject;
-      });
+function runNextTest(document, window, endCallback) {
+  var test = TESTS.shift(),
+      deferred = Promise.defer(),
+      pageNumber = document.querySelector('input#pageNumber');
 
-      let pageNumber = document.querySelector('input#pageNumber');
+  // Add an event-listener to wait for page to change, afterwards resolve the promise
+  var timeout = window.setTimeout(() => deferred.reject(), 5000);
+  window.addEventListener('pagechange', function pageChange() {
+    if (pageNumber.value == test.expectedPage) {
+      window.removeEventListener('pagechange', pageChange);
+      window.clearTimeout(timeout);
+      deferred.resolve(pageNumber.value);
+    }
+  });
 
-      // Add an event-listener to wait for page to change, afterwards resolve the promise
-      let timeout = window.setTimeout(() => deferred.reject(), 5000);
-      window.addEventListener('pagechange', function pageChange() {
-        if (pageNumber.value == test.expectedPage) {
-          window.removeEventListener('pagechange', pageChange);
-          window.clearTimeout(timeout);
-          deferred.resolve(+pageNumber.value);
-        }
-      });
+  // Get the element and trigger the action for changing the page
+  var el = document.querySelector(test.action.selector);
+  ok(el, "Element '" + test.action.selector + "' has been found");
+
+  // The value option is for input case
+  if (test.action.value)
+    el.value = test.action.value;
 
-      // Get the element and trigger the action for changing the page
-      var el = document.querySelector(test.action.selector);
-      ok(el, "Element '" + test.action.selector + "' has been found");
+  // Dispatch the event for changing the page
+  if (test.action.event == "keydown") {
+    var ev = document.createEvent("KeyboardEvent");
+        ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
+                        test.action.keyCode, 0);
+    el.dispatchEvent(ev);
+  }
+  else {
+    var ev = new Event(test.action.event);
+  }
+  el.dispatchEvent(ev);
 
-      // The value option is for input case
-      if (test.action.value)
-        el.value = test.action.value;
 
-      // Dispatch the event for changing the page
-      if (test.action.event == "keydown") {
-        var ev = document.createEvent("KeyboardEvent");
-            ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
-                            test.action.keyCode, 0);
-        el.dispatchEvent(ev);
-      }
-      else {
-        var ev = new Event(test.action.event);
-      }
-      el.dispatchEvent(ev);
+  // When the promise gets resolved we call the next test if there are any left
+  // or else we call the final callback which will end the test
+  deferred.promise.then(function (pgNumber) {
+    is(pgNumber, test.expectedPage, test.message);
 
-      let pgNumber = yield deferred.promise;
-      is(pgNumber, test.expectedPage, test.message);
-    }
-
-    var viewer = content.wrappedJSObject.PDFViewerApplication;
-    yield viewer.close();
+    if (TESTS.length)
+      runNextTest(document, window, endCallback);
+    else
+      endCallback();
+  }, function () {
+    ok(false, "Test '" + test.message + "' failed with timeout.");
+    endCallback();
   });
 }
+
+/**
+ * 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();
+  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();
+    }
+  });
+
+  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);
+    document.querySelector("#viewer").click();
+    deferred.resolve();
+  });
+
+  var select = document.querySelector("select#scaleSelect");
+  select.selectedIndex = 2;
+  select.dispatchEvent(new Event("change"));
+
+  return deferred.promise;
+}
+
--- a/browser/extensions/pdfjs/test/browser_pdfjs_views.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_views.js
@@ -1,61 +1,86 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
 
-add_task(function* test() {
+function test() {
+  var tab;
+
   let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
   let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
 
   // Make sure pdf.js is the default handler.
   is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
   is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
 
   info('Pref action: ' + handlerInfo.preferredAction);
 
-  yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
-    function* (browser) {
-      // check that PDF is opened with internal viewer
-      yield waitForPdfJS(browser);
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(tab);
+  });
 
-      yield ContentTask.spawn(browser, null, function* () {
-        ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
-        ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
+  tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
+  var newTabBrowser = gBrowser.getBrowserForTab(tab);
+  newTabBrowser.addEventListener("load", function eventHandler() {
+    newTabBrowser.removeEventListener("load", eventHandler, true);
+
+    var document = newTabBrowser.contentDocument,
+        window = newTabBrowser.contentWindow;
 
-        //open sidebar
-        var sidebar = content.document.querySelector('button#sidebarToggle');
-        var outerContainer = content.document.querySelector('div#outerContainer');
+    // Runs tests after all 'load' event handlers have fired off
+    window.addEventListener("documentload", function() {
+      runTests(document, window, function () {
+        closePDFViewer(window, finish);
+      });
+    }, false, true);
+  }, true);
+}
 
-        sidebar.click();
-        ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
+function runTests(document, window, callback) {
+  // check that PDF is opened with internal viewer
+  ok(document.querySelector('div#viewer'), "document content has viewer UI");
+  ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
 
-        // check that thumbnail view is open
-        var thumbnailView = content.document.querySelector('div#thumbnailView');
-        var outlineView = content.document.querySelector('div#outlineView');
+  //open sidebar
+  var sidebar = document.querySelector('button#sidebarToggle');
+  var outerContainer = document.querySelector('div#outerContainer');
+
+  sidebar.click();
+  ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
 
-        is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
-        is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
+  // check that thumbnail view is open
+  var thumbnailView = document.querySelector('div#thumbnailView');
+  var outlineView = document.querySelector('div#outlineView');
+
+  is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
+  is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
 
-        //switch to outline view
-        var viewOutlineButton = content.document.querySelector('button#viewOutline');
-        viewOutlineButton.click();
+  //switch to outline view
+  var viewOutlineButton = document.querySelector('button#viewOutline');
+  viewOutlineButton.click();
 
-        is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected');
-        is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected');
+  is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected');
+  is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected');
 
-        //switch back to thumbnail view
-        var viewThumbnailButton = content.document.querySelector('button#viewThumbnail');
-        viewThumbnailButton.click();
+  //switch back to thumbnail view
+  var viewThumbnailButton = document.querySelector('button#viewThumbnail');
+  viewThumbnailButton.click();
 
-        is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
-        is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
+  is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
+  is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
+
+  sidebar.click();
 
-        sidebar.click();
+  callback();
+}
 
-        var viewer = content.wrappedJSObject.PDFViewerApplication;
-        yield viewer.close();
-      });
-    });
-});
+/**
+ * Destroys PDF.js viewer opened document.
+ */
+function closePDFViewer(window, callback) {
+  var viewer = window.wrappedJSObject.PDFViewerApplication;
+  viewer.close().then(callback);
+}
--- a/browser/extensions/pdfjs/test/browser_pdfjs_zoom.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_zoom.js
@@ -23,27 +23,25 @@ const TESTS = [
     },
     expectedZoom: -1, // -1 - zoom out
     message: "Zoomed out using the '-' (zoom out) button"
   },
 
   {
     action: {
       keyboard: true,
-      keyCode: 61,
       event: "+"
     },
     expectedZoom: 1, // 1 - zoom in
     message: "Zoomed in using the CTRL++ keys"
   },
 
   {
     action: {
       keyboard: true,
-      keyCode: 109,
       event: "-"
     },
     expectedZoom: -1, // -1 - zoom out
     message: "Zoomed out using the CTRL+- keys"
   },
 
   {
     action: {
@@ -51,102 +49,137 @@ const TESTS = [
       index: 5,
       event: "change"
     },
     expectedZoom: -1, // -1 - zoom out
     message: "Zoomed using the zoom picker"
   }
 ];
 
-add_task(function* test() {
+var initialWidth; // the initial width of the PDF document
+var previousWidth; // the width of the PDF document at previous step/test
+
+function test() {
+  var tab;
   let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"]
                        .getService(Ci.nsIHandlerService);
   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
   let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
 
   // Make sure pdf.js is the default handler.
   is(handlerInfo.alwaysAskBeforeHandling, false,
      'pdf handler defaults to always-ask is false');
   is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally,
     'pdf handler defaults to internal');
 
   info('Pref action: ' + handlerInfo.preferredAction);
 
-  yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" + "#zoom=100" },
-    function* (newTabBrowser) {
-      yield waitForPdfJS(newTabBrowser);
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(tab);
+  });
 
-      yield ContentTask.spawn(newTabBrowser, TESTS, function* (TESTS) {
-        let document = content.document;
+  tab = gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
+  var newTabBrowser = gBrowser.getBrowserForTab(tab);
+
+  newTabBrowser.addEventListener("load", function eventHandler() {
+    newTabBrowser.removeEventListener("load", eventHandler, true);
 
-        function waitForRender() {
-          return new Promise((resolve) => {
-            document.addEventListener("pagerendered", function onPageRendered(e) {
-              if(e.detail.pageNumber !== 1) {
-                return;
-              }
+    var document = newTabBrowser.contentDocument,
+        window = newTabBrowser.contentWindow;
 
-              document.removeEventListener("pagerendered", onPageRendered, true);
-              resolve();
-            }, true);
-          });
-        }
+    // Runs tests after all 'load' event handlers have fired off
+    window.addEventListener("documentload", function() {
+      initialWidth = parseInt(document.querySelector("div#pageContainer1").style.width);
+      previousWidth = initialWidth;
+      runTests(document, window, function () {
+        closePDFViewer(window, finish);
+      });
+    }, false, true);
+  }, true);
+}
 
-        // check that PDF is opened with internal viewer
-        ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
-        ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
+function runTests(document, window, callback) {
+  // check that PDF is opened with internal viewer
+  ok(document.querySelector('div#viewer'), "document content has viewer UI");
+  ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
 
-        let initialWidth, previousWidth;
-        initialWidth = previousWidth =
-          parseInt(content.document.querySelector("div#pageContainer1").style.width);
+  // Start the zooming tests after the document is loaded
+  waitForDocumentLoad(document).then(function () {
+    zoomPDF(document, window, TESTS.shift(), callback);
+  });
+}
 
-        for (let test of TESTS) {
-          // We zoom using an UI element
-          var ev;
-          if (test.action.selector) {
-            // Get the element and trigger the action for changing the zoom
-            var el = document.querySelector(test.action.selector);
-            ok(el, "Element '" + test.action.selector + "' has been found");
+function waitForDocumentLoad(document) {
+  var deferred = Promise.defer();
+  var interval = setInterval(function () {
+    if (document.querySelector("div#pageContainer1") != null){
+      clearInterval(interval);
+      deferred.resolve();
+    }
+  }, 500);
 
-            if (test.action.index){
-              el.selectedIndex = test.action.index;
-            }
+  return deferred.promise;
+}
+
+function zoomPDF(document, window, test, endCallback) {
+  var renderedPage;
+
+  document.addEventListener("pagerendered", function onPageRendered(e) {
+    if(e.detail.pageNumber !== 1) {
+      return;
+    }
 
-            // Dispatch the event for changing the zoom
-            ev = new Event(test.action.event);
-          }
-          // We zoom using keyboard
-          else {
-            // Simulate key press
-            ev = new content.KeyboardEvent("keydown",
-                                           { key: test.action.event,
-                                             keyCode: test.action.keyCode,
-                                             ctrlKey: true });
-            el = content;
-          }
+    document.removeEventListener("pagerendered", onPageRendered, true);
+
+    var pageZoomScale = document.querySelector('select#scaleSelect');
+
+    // The zoom value displayed in the zoom select
+    var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
+
+    let pageContainer = document.querySelector('div#pageContainer1');
+    let actualWidth  = parseInt(pageContainer.style.width);
+
+    // the actual zoom of the PDF document
+    let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
+    is(computedZoomValue, zoomValue, "Content has correct zoom");
 
-          el.dispatchEvent(ev);
-          yield waitForRender();
+    // Check that document zooms in the expected way (in/out)
+    let zoom = (actualWidth - previousWidth) * test.expectedZoom;
+    ok(zoom > 0, test.message);
 
-          var pageZoomScale = content.document.querySelector('select#scaleSelect');
+    // Go to next test (if there is any) or finish
+    var nextTest = TESTS.shift();
+    if (nextTest) {
+      previousWidth = actualWidth;
+      zoomPDF(document, window, nextTest, endCallback);
+    }
+    else
+      endCallback();
+  }, true);
 
-          // The zoom value displayed in the zoom select
-          var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
+  // We zoom using an UI element
+  if (test.action.selector) {
+    // Get the element and trigger the action for changing the zoom
+    var el = document.querySelector(test.action.selector);
+    ok(el, "Element '" + test.action.selector + "' has been found");
 
-          let pageContainer = content.document.querySelector('div#pageContainer1');
-          let actualWidth = parseInt(pageContainer.style.width);
-
-          // the actual zoom of the PDF document
-          let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
-          is(computedZoomValue, zoomValue, "Content has correct zoom");
+    if (test.action.index){
+      el.selectedIndex = test.action.index;
+    }
 
-          // Check that document zooms in the expected way (in/out)
-          let zoom = (actualWidth - previousWidth) * test.expectedZoom;
-          ok(zoom > 0, test.message);
+    // Dispatch the event for changing the zoom
+    el.dispatchEvent(new Event(test.action.event));
+  }
+  // We zoom using keyboard
+  else {
+    // Simulate key press
+    EventUtils.synthesizeKey(test.action.event, { ctrlKey: true });
+  }
+}
 
-          previousWidth = actualWidth;
-        }
-
-        var viewer = content.wrappedJSObject.PDFViewerApplication;
-        yield viewer.close();
-      });
-    });
-});
+/**
+ * Destroys PDF.js viewer opened document.
+ */
+function closePDFViewer(window, callback) {
+  var viewer = window.wrappedJSObject.PDFViewerApplication;
+  viewer.close().then(callback);
+}
deleted file mode 100644
--- a/browser/extensions/pdfjs/test/head.js
+++ /dev/null
@@ -1,11 +0,0 @@
-function waitForPdfJS(browser) {
-  // Runs tests after all 'load' event handlers have fired off
-  return ContentTask.spawn(browser, null, function* () {
-    yield new Promise((resolve) => {
-      content.addEventListener("documentload", function listener() {
-        content.removeEventListener("documentload", listener, false);
-        resolve();
-      }, false, true);
-    });
-  });
-}
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -332,17 +332,17 @@ this.BrowserTestUtils = {
       win.close();
     });
   },
 
   /**
    * Waits for an event to be fired on a specified element.
    *
    * Usage:
-   *    let promiseEvent = BrowserTestUtils.waitForEvent(element, "eventName");
+   *    let promiseEvent = BrowserTestUtil.waitForEvent(element, "eventName");
    *    // Do some processing here that will cause the event to be fired
    *    // ...
    *    // Now yield until the Promise is fulfilled
    *    let receivedEvent = yield promiseEvent;
    *
    * @param {Element} subject
    *        The element that should receive the event.
    * @param {string} eventName