Bug 1332170 - Make the pdf.js mochitests pass ESLint and remove them from the whitelist. r=yury
authorRyan VanderMeulen <ryanvm@gmail.com>
Thu, 19 Jan 2017 10:11:57 -0500
changeset 375145 fe7445d0ec0a017bb016fad6a21ae8f1d5bf0984
parent 375144 efeda43ab7b20d9216bf72b5f97a3dd715312e2a
child 375146 111109712e7700e8544d0da27589016662d48399
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyury
bugs1332170
milestone53.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
Bug 1332170 - Make the pdf.js mochitests pass ESLint and remove them from the whitelist. r=yury
.eslintignore
browser/extensions/pdfjs/test/browser_pdfjs_main.js
browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js
browser/extensions/pdfjs/test/browser_pdfjs_views.js
browser/extensions/pdfjs/test/browser_pdfjs_zoom.js
browser/extensions/pdfjs/test/head.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -63,17 +63,17 @@ browser/base/content/test/general/file_c
 browser/base/content/test/urlbar/file_blank_but_not_blank.html
 browser/base/content/newtab/**
 browser/components/downloads/**
 browser/components/privatebrowsing/**
 browser/components/sessionstore/**
 browser/components/tabview/**
 # generated files in cld2
 browser/components/translation/cld2/cld-worker.js
-browser/extensions/pdfjs/**
+browser/extensions/pdfjs/content/**
 # generated or library files in pocket
 browser/extensions/pocket/content/panels/js/tmpl.js
 browser/extensions/pocket/content/panels/js/vendor/**
 browser/locales/**
 # imported from chromium
 browser/extensions/mortar/**
 
 # devtools/ exclusions
--- a/browser/extensions/pdfjs/test/browser_pdfjs_main.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_main.js
@@ -1,66 +1,52 @@
 /* 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() {
-  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');
+  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');
+  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);
+  info("Pref action: " + handlerInfo.preferredAction);
 
-  yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: "about:blank" },
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
     function* (newTabBrowser) {
       yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf");
 
       ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
 
       yield ContentTask.spawn(newTabBrowser, null, function* () {
-        //
         // Overall sanity tests
-        //
-        Assert.ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
-        Assert.ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
+        Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
+        Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
 
-        //
         // Sidebar: open
-        //
-        var sidebar = content.document.querySelector('button#sidebarToggle'),
-            outerContainer = content.document.querySelector('div#outerContainer');
+        var sidebar = content.document.querySelector("button#sidebarToggle"),
+            outerContainer = content.document.querySelector("div#outerContainer");
 
         sidebar.click();
-        Assert.ok(outerContainer.classList.contains('sidebarOpen'), "sidebar opens on click");
-
-        //
-        // Sidebar: close
-        //
-        sidebar.click();
-        Assert.ok(!outerContainer.classList.contains('sidebarOpen'), "sidebar closes on click");
+        Assert.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();
+        Assert.ok(!outerContainer.classList.contains("sidebarOpen"), "sidebar closes on click");
 
-        var pgNumber = content.document.querySelector('input#pageNumber').value;
+        // Verify that initial page is 1
+        var pgNumber = content.document.querySelector("input#pageNumber").value;
         Assert.equal(parseInt(pgNumber, 10), 1, "initial page is 1");
 
-        //
         // Bookmark button
-        //
-        var viewBookmark = content.document.querySelector('a#viewBookmark');
+        var viewBookmark = content.document.querySelector("a#viewBookmark");
         viewBookmark.click();
 
         Assert.ok(viewBookmark.href.length > 0, "viewBookmark button has href");
 
         var viewer = content.wrappedJSObject.PDFViewerApplication;
         yield viewer.close();
       });
     });
--- a/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js
@@ -138,40 +138,40 @@ const TESTS = [
     },
     expectedPage: 5,
     message: "navigated to 5th page using pagenumber"
   }
 ];
 
 add_task(function* test() {
   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
-  let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
+  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');
+  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);
+  info("Pref action: " + handlerInfo.preferredAction);
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
     function* (newTabBrowser) {
       yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf");
 
       yield ContentTask.spawn(newTabBrowser, null, function* () {
         // Check if PDF is opened with internal viewer
         Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
         Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
       });
 
       yield ContentTask.spawn(newTabBrowser, null, contentSetUp);
 
       yield Task.spawn(runTests(newTabBrowser));
 
       yield ContentTask.spawn(newTabBrowser, null, function*() {
-        let pageNumber = content.document.querySelector('input#pageNumber');
+        let pageNumber = content.document.querySelector("input#pageNumber");
         Assert.equal(pageNumber.value, pageNumber.max, "Document is left on the last page");
       });
     });
 });
 
 function* contentSetUp() {
   /**
    * Outline Items gets appended to the document later on we have to
@@ -225,56 +225,56 @@ function* contentSetUp() {
  * 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) {
+  yield ContentTask.spawn(browser, TESTS, function* (contentTESTS) {
     let window = content;
     let document = window.document;
 
-    for (let test of TESTS) {
+    for (let test of contentTESTS) {
       let deferred = {};
       deferred.promise = new Promise((resolve, reject) => {
         deferred.resolve = resolve;
         deferred.reject = reject;
       });
 
-      let 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
       let timeout = window.setTimeout(() => deferred.reject(), 5000);
-      window.addEventListener('pagechange', function pageChange() {
+      window.addEventListener("pagechange", function pageChange() {
         if (pageNumber.value == test.expectedPage) {
-          window.removeEventListener('pagechange', pageChange);
+          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);
       Assert.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;
 
       // Dispatch the event for changing the page
+      var ev;
       if (test.action.event == "keydown") {
-        var ev = document.createEvent("KeyboardEvent");
-            ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
-                            test.action.keyCode, 0);
+        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);
+      } else {
+        ev = new Event(test.action.event);
       }
       el.dispatchEvent(ev);
 
       let pgNumber = yield deferred.promise;
       Assert.equal(pgNumber, test.expectedPage, test.message);
     }
 
     var viewer = content.wrappedJSObject.PDFViewerApplication;
--- a/browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js
@@ -2,64 +2,60 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
 
 function test() {
   var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
   var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
-  //
   // Test: "Open with" dialog comes up when pdf.js is not selected as the default
   // handler.
-  //
-  addWindowListener('chrome://mozapps/content/downloads/unknownContentType.xul', finish);
+  addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", finish);
 
   waitForExplicitFinish();
   registerCleanupFunction(function() {
     changeMimeHandler(oldAction[0], oldAction[1]);
     gBrowser.removeTab(tab);
   });
 }
 
 function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
   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');
+  let handlerInfo = mimeService.getFromTypeAndExtension("application/pdf", "pdf");
   var oldAction = [handlerInfo.preferredAction, handlerInfo.alwaysAskBeforeHandling];
 
   // Change and save mime handler settings
   handlerInfo.alwaysAskBeforeHandling = alwaysAskBeforeHandling;
   handlerInfo.preferredAction = preferredAction;
   handlerService.store(handlerInfo);
 
-  Services.obs.notifyObservers(null, 'pdfjs:handlerChanged', null);
+  Services.obs.notifyObservers(null, "pdfjs:handlerChanged", null);
 
   // Refresh data
-  handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
+  handlerInfo = mimeService.getFromTypeAndExtension("application/pdf", "pdf");
 
-  //
   // Test: Mime handler was updated
-  //
-  is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, 'always-ask prompt change successful');
-  is(handlerInfo.preferredAction, preferredAction, 'mime handler change successful');
+  is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, "always-ask prompt change successful");
+  is(handlerInfo.preferredAction, preferredAction, "mime handler change successful");
 
   return oldAction;
 }
 
 function addWindowListener(aURL, aCallback) {
   Services.wm.addListener({
-    onOpenWindow: function(aXULWindow) {
+    onOpenWindow(aXULWindow) {
       info("window opened, waiting for focus");
       Services.wm.removeListener(this);
 
       var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                                 .getInterface(Ci.nsIDOMWindow);
       waitForFocus(function() {
         is(domwindow.document.location.href, aURL, "should have seen the right window open");
         domwindow.close();
         aCallback();
       }, domwindow);
     },
-    onCloseWindow: function(aXULWindow) { },
-    onWindowTitleChange: function(aXULWindow, aNewTitle) { }
+    onCloseWindow(aXULWindow) { },
+    onWindowTitleChange(aXULWindow, aNewTitle) { }
   });
 }
--- a/browser/extensions/pdfjs/test/browser_pdfjs_views.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_views.js
@@ -1,61 +1,60 @@
 /* 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() {
-  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');
+  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');
+  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);
+  info("Pref action: " + handlerInfo.preferredAction);
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
     function* (browser) {
       // check that PDF is opened with internal viewer
       yield waitForPdfJS(browser, TESTROOT + "file_pdfjs_test.pdf");
 
       yield ContentTask.spawn(browser, null, function* () {
         Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
         Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
 
-        //open sidebar
-        var sidebar = content.document.querySelector('button#sidebarToggle');
-        var outerContainer = content.document.querySelector('div#outerContainer');
+        // open sidebar
+        var sidebar = content.document.querySelector("button#sidebarToggle");
+        var outerContainer = content.document.querySelector("div#outerContainer");
 
         sidebar.click();
         Assert.ok(outerContainer.classList.contains("sidebarOpen"), "sidebar opens on click");
 
         // check that thumbnail view is open
-        var thumbnailView = content.document.querySelector('div#thumbnailView');
-        var outlineView = content.document.querySelector('div#outlineView');
+        var thumbnailView = content.document.querySelector("div#thumbnailView");
+        var outlineView = content.document.querySelector("div#outlineView");
 
         Assert.equal(thumbnailView.getAttribute("class"), null,
           "Initial view is thumbnail view");
         Assert.equal(outlineView.getAttribute("class"), "hidden",
           "Outline view is hidden initially");
 
-        //switch to outline view
-        var viewOutlineButton = content.document.querySelector('button#viewOutline');
+        // switch to outline view
+        var viewOutlineButton = content.document.querySelector("button#viewOutline");
         viewOutlineButton.click();
 
         Assert.equal(thumbnailView.getAttribute("class"), "hidden",
           "Thumbnail view is hidden when outline is selected");
         Assert.equal(outlineView.getAttribute("class"), "",
           "Outline view is visible when selected");
 
-        //switch back to thumbnail view
-        var viewThumbnailButton = content.document.querySelector('button#viewThumbnail');
+        // switch back to thumbnail view
+        var viewThumbnailButton = content.document.querySelector("button#viewThumbnail");
         viewThumbnailButton.click();
 
         Assert.equal(thumbnailView.getAttribute("class"), "",
           "Thumbnail view is visible when selected");
         Assert.equal(outlineView.getAttribute("class"), "hidden",
           "Outline view is hidden when thumbnail is selected");
 
         sidebar.click();
--- a/browser/extensions/pdfjs/test/browser_pdfjs_zoom.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_zoom.js
@@ -54,100 +54,97 @@ const TESTS = [
       event: "change"
     },
     expectedZoom: -1, // -1 - zoom out
     message: "Zoomed using the zoom picker"
   }
 ];
 
 add_task(function* test() {
-  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');
+  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');
+     "pdf handler defaults to always-ask is false");
   is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally,
-    'pdf handler defaults to internal');
+    "pdf handler defaults to internal");
 
-  info('Pref action: ' + handlerInfo.preferredAction);
+  info("Pref action: " + handlerInfo.preferredAction);
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
     function* (newTabBrowser) {
       yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf" + "#zoom=100");
 
-      yield ContentTask.spawn(newTabBrowser, TESTS, function* (TESTS) {
+      yield ContentTask.spawn(newTabBrowser, TESTS, function* (contentTESTS) {
         let document = content.document;
 
         function waitForRender() {
           return new Promise((resolve) => {
             document.addEventListener("pagerendered", function onPageRendered(e) {
-              if(e.detail.pageNumber !== 1) {
+              if (e.detail.pageNumber !== 1) {
                 return;
               }
 
               document.removeEventListener("pagerendered", onPageRendered, true);
               resolve();
             }, true);
           });
         }
 
         // check that PDF is opened with internal viewer
         Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
         Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
 
         let initialWidth, previousWidth;
         initialWidth = previousWidth =
-          parseInt(content.document.querySelector('div.page[data-page-number="1"]').style.width);
+          parseInt(content.document.querySelector("div.page[data-page-number='1']").style.width);
 
-        for (let test of TESTS) {
+        for (let subTest of contentTESTS) {
           // We zoom using an UI element
           var ev;
-          if (test.action.selector) {
+          if (subTest.action.selector) {
             // Get the element and trigger the action for changing the zoom
-            var el = document.querySelector(test.action.selector);
-            Assert.ok(el, "Element '" + test.action.selector + "' has been found");
+            var el = document.querySelector(subTest.action.selector);
+            Assert.ok(el, "Element '" + subTest.action.selector + "' has been found");
 
-            if (test.action.index){
-              el.selectedIndex = test.action.index;
+            if (subTest.action.index) {
+              el.selectedIndex = subTest.action.index;
             }
 
             // Dispatch the event for changing the zoom
-            ev = new Event(test.action.event);
-          }
-          // We zoom using keyboard
-          else {
+            ev = new Event(subTest.action.event);
+          } else {
+            // We zoom using keyboard
             // Simulate key press
             ev = new content.KeyboardEvent("keydown",
-                                           { key: test.action.event,
-                                             keyCode: test.action.keyCode,
+                                           { key: subTest.action.event,
+                                             keyCode: subTest.action.keyCode,
                                              ctrlKey: true });
             el = content;
           }
 
           el.dispatchEvent(ev);
           yield waitForRender();
 
-          var pageZoomScale = content.document.querySelector('select#scaleSelect');
+          var pageZoomScale = content.document.querySelector("select#scaleSelect");
 
           // The zoom value displayed in the zoom select
           var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
 
-          let pageContainer = content.document.querySelector('div.page[data-page-number="1"]');
+          let pageContainer = content.document.querySelector("div.page[data-page-number='1']");
           let actualWidth = parseInt(pageContainer.style.width);
 
           // the actual zoom of the PDF document
-          let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
+          let computedZoomValue = parseInt(((actualWidth / initialWidth).toFixed(2)) * 100) + "%";
           Assert.equal(computedZoomValue, zoomValue, "Content has correct zoom");
 
           // Check that document zooms in the expected way (in/out)
-          let zoom = (actualWidth - previousWidth) * test.expectedZoom;
-          Assert.ok(zoom > 0, test.message);
+          let zoom = (actualWidth - previousWidth) * subTest.expectedZoom;
+          Assert.ok(zoom > 0, subTest.message);
 
           previousWidth = actualWidth;
         }
 
         var viewer = content.wrappedJSObject.PDFViewerApplication;
         yield viewer.close();
       });
     });
--- a/browser/extensions/pdfjs/test/head.js
+++ b/browser/extensions/pdfjs/test/head.js
@@ -1,15 +1,15 @@
 function waitForPdfJS(browser, url) {
-  // Runs tests after all 'load' event handlers have fired off
-  return ContentTask.spawn(browser, url, function* (url) {
+  // Runs tests after all "load" event handlers have fired off
+  return ContentTask.spawn(browser, url, function* (contentUrl) {
     yield new Promise((resolve) => {
       // NB: Add the listener to the global object so that we receive the
       // event fired from the new window.
       addEventListener("documentload", function listener() {
         removeEventListener("documentload", listener, false);
         resolve();
       }, false, true);
 
-      content.location = url;
+      content.location = contentUrl;
     });
   });
 }