Bug 1332170 - Make the pdf.js mochitests pass ESLint and remove them from the whitelist. r=yury

--HG--
extra : rebase_source : aea237747a5869bcab945bdfd3e6b6ecada7be17
This commit is contained in:
Ryan VanderMeulen 2017-01-19 10:11:57 -05:00
parent 68b0311309
commit 8354e335b0
7 changed files with 79 additions and 101 deletions

View file

@ -68,7 +68,7 @@ browser/components/sessionstore/**
browser/components/tabview/** browser/components/tabview/**
# generated files in cld2 # generated files in cld2
browser/components/translation/cld2/cld-worker.js browser/components/translation/cld2/cld-worker.js
browser/extensions/pdfjs/** browser/extensions/pdfjs/content/**
# generated or library files in pocket # generated or library files in pocket
browser/extensions/pocket/content/panels/js/tmpl.js browser/extensions/pocket/content/panels/js/tmpl.js
browser/extensions/pocket/content/panels/js/vendor/** browser/extensions/pocket/content/panels/js/vendor/**

View file

@ -5,57 +5,43 @@ const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() { 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 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. // Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false'); 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.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) { function* (newTabBrowser) {
yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf"); yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf");
ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!"); ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
yield ContentTask.spawn(newTabBrowser, null, function* () { yield ContentTask.spawn(newTabBrowser, null, function* () {
//
// Overall sanity tests // Overall sanity tests
// Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
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('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
//
// Sidebar: open // Sidebar: open
// var sidebar = content.document.querySelector("button#sidebarToggle"),
var sidebar = content.document.querySelector('button#sidebarToggle'), outerContainer = content.document.querySelector("div#outerContainer");
outerContainer = content.document.querySelector('div#outerContainer');
sidebar.click(); sidebar.click();
Assert.ok(outerContainer.classList.contains('sidebarOpen'), "sidebar opens on click"); Assert.ok(outerContainer.classList.contains("sidebarOpen"), "sidebar opens on click");
//
// Sidebar: close // Sidebar: close
//
sidebar.click(); sidebar.click();
Assert.ok(!outerContainer.classList.contains('sidebarOpen'), "sidebar closes on click"); Assert.ok(!outerContainer.classList.contains("sidebarOpen"), "sidebar closes on click");
// // Verify that initial page is 1
// Page change from prev/next buttons var pgNumber = content.document.querySelector("input#pageNumber").value;
//
var prevPage = content.document.querySelector('button#previous'),
nextPage = content.document.querySelector('button#next');
var pgNumber = content.document.querySelector('input#pageNumber').value;
Assert.equal(parseInt(pgNumber, 10), 1, "initial page is 1"); Assert.equal(parseInt(pgNumber, 10), 1, "initial page is 1");
//
// Bookmark button // Bookmark button
// var viewBookmark = content.document.querySelector("a#viewBookmark");
var viewBookmark = content.document.querySelector('a#viewBookmark');
viewBookmark.click(); viewBookmark.click();
Assert.ok(viewBookmark.href.length > 0, "viewBookmark button has href"); Assert.ok(viewBookmark.href.length > 0, "viewBookmark button has href");

View file

@ -143,13 +143,13 @@ const TESTS = [
add_task(function* test() { add_task(function* test() {
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); 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. // Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false'); 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.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" }, yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (newTabBrowser) { function* (newTabBrowser) {
@ -166,7 +166,7 @@ add_task(function* test() {
yield Task.spawn(runTests(newTabBrowser)); yield Task.spawn(runTests(newTabBrowser));
yield ContentTask.spawn(newTabBrowser, null, function*() { 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"); Assert.equal(pageNumber.value, pageNumber.max, "Document is left on the last page");
}); });
}); });
@ -230,24 +230,24 @@ function* contentSetUp() {
* @param callback * @param callback
*/ */
function* runTests(browser) { function* runTests(browser) {
yield ContentTask.spawn(browser, TESTS, function* (TESTS) { yield ContentTask.spawn(browser, TESTS, function* (contentTESTS) {
let window = content; let window = content;
let document = window.document; let document = window.document;
for (let test of TESTS) { for (let test of contentTESTS) {
let deferred = {}; let deferred = {};
deferred.promise = new Promise((resolve, reject) => { deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve; deferred.resolve = resolve;
deferred.reject = reject; 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 // Add an event-listener to wait for page to change, afterwards resolve the promise
let timeout = window.setTimeout(() => deferred.reject(), 5000); let timeout = window.setTimeout(() => deferred.reject(), 5000);
window.addEventListener('pagechange', function pageChange() { window.addEventListener("pagechange", function pageChange() {
if (pageNumber.value == test.expectedPage) { if (pageNumber.value == test.expectedPage) {
window.removeEventListener('pagechange', pageChange); window.removeEventListener("pagechange", pageChange);
window.clearTimeout(timeout); window.clearTimeout(timeout);
deferred.resolve(+pageNumber.value); deferred.resolve(+pageNumber.value);
} }
@ -262,14 +262,14 @@ function* runTests(browser) {
el.value = test.action.value; el.value = test.action.value;
// Dispatch the event for changing the page // Dispatch the event for changing the page
var ev;
if (test.action.event == "keydown") { if (test.action.event == "keydown") {
var ev = document.createEvent("KeyboardEvent"); ev = document.createEvent("KeyboardEvent");
ev.initKeyEvent("keydown", true, true, null, false, false, false, false, ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
test.action.keyCode, 0); test.action.keyCode, 0);
el.dispatchEvent(ev); el.dispatchEvent(ev);
} } else {
else { ev = new Event(test.action.event);
var ev = new Event(test.action.event);
} }
el.dispatchEvent(ev); el.dispatchEvent(ev);

View file

@ -7,11 +7,9 @@ const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
function test() { function test() {
var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true); var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf"); var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
//
// Test: "Open with" dialog comes up when pdf.js is not selected as the default // Test: "Open with" dialog comes up when pdf.js is not selected as the default
// handler. // handler.
// addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", finish);
addWindowListener('chrome://mozapps/content/downloads/unknownContentType.xul', finish);
waitForExplicitFinish(); waitForExplicitFinish();
registerCleanupFunction(function() { registerCleanupFunction(function() {
@ -23,7 +21,7 @@ function test() {
function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) { function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService); let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); 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]; var oldAction = [handlerInfo.preferredAction, handlerInfo.alwaysAskBeforeHandling];
// Change and save mime handler settings // Change and save mime handler settings
@ -31,23 +29,21 @@ function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
handlerInfo.preferredAction = preferredAction; handlerInfo.preferredAction = preferredAction;
handlerService.store(handlerInfo); handlerService.store(handlerInfo);
Services.obs.notifyObservers(null, 'pdfjs:handlerChanged', null); Services.obs.notifyObservers(null, "pdfjs:handlerChanged", null);
// Refresh data // Refresh data
handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf'); handlerInfo = mimeService.getFromTypeAndExtension("application/pdf", "pdf");
//
// Test: Mime handler was updated // Test: Mime handler was updated
// is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, "always-ask prompt change successful");
is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, 'always-ask prompt change successful'); is(handlerInfo.preferredAction, preferredAction, "mime handler change successful");
is(handlerInfo.preferredAction, preferredAction, 'mime handler change successful');
return oldAction; return oldAction;
} }
function addWindowListener(aURL, aCallback) { function addWindowListener(aURL, aCallback) {
Services.wm.addListener({ Services.wm.addListener({
onOpenWindow: function(aXULWindow) { onOpenWindow(aXULWindow) {
info("window opened, waiting for focus"); info("window opened, waiting for focus");
Services.wm.removeListener(this); Services.wm.removeListener(this);
@ -59,7 +55,7 @@ function addWindowListener(aURL, aCallback) {
aCallback(); aCallback();
}, domwindow); }, domwindow);
}, },
onCloseWindow: function(aXULWindow) { }, onCloseWindow(aXULWindow) { },
onWindowTitleChange: function(aXULWindow, aNewTitle) { } onWindowTitleChange(aXULWindow, aNewTitle) { }
}); });
} }

View file

@ -5,15 +5,14 @@ const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() { 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 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. // Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false'); 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.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" }, yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (browser) { function* (browser) {
@ -24,24 +23,24 @@ add_task(function* test() {
Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI"); 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("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
//open sidebar // open sidebar
var sidebar = content.document.querySelector('button#sidebarToggle'); var sidebar = content.document.querySelector("button#sidebarToggle");
var outerContainer = content.document.querySelector('div#outerContainer'); var outerContainer = content.document.querySelector("div#outerContainer");
sidebar.click(); sidebar.click();
Assert.ok(outerContainer.classList.contains("sidebarOpen"), "sidebar opens on click"); Assert.ok(outerContainer.classList.contains("sidebarOpen"), "sidebar opens on click");
// check that thumbnail view is open // check that thumbnail view is open
var thumbnailView = content.document.querySelector('div#thumbnailView'); var thumbnailView = content.document.querySelector("div#thumbnailView");
var outlineView = content.document.querySelector('div#outlineView'); var outlineView = content.document.querySelector("div#outlineView");
Assert.equal(thumbnailView.getAttribute("class"), null, Assert.equal(thumbnailView.getAttribute("class"), null,
"Initial view is thumbnail view"); "Initial view is thumbnail view");
Assert.equal(outlineView.getAttribute("class"), "hidden", Assert.equal(outlineView.getAttribute("class"), "hidden",
"Outline view is hidden initially"); "Outline view is hidden initially");
//switch to outline view // switch to outline view
var viewOutlineButton = content.document.querySelector('button#viewOutline'); var viewOutlineButton = content.document.querySelector("button#viewOutline");
viewOutlineButton.click(); viewOutlineButton.click();
Assert.equal(thumbnailView.getAttribute("class"), "hidden", Assert.equal(thumbnailView.getAttribute("class"), "hidden",
@ -49,8 +48,8 @@ add_task(function* test() {
Assert.equal(outlineView.getAttribute("class"), "", Assert.equal(outlineView.getAttribute("class"), "",
"Outline view is visible when selected"); "Outline view is visible when selected");
//switch back to thumbnail view // switch back to thumbnail view
var viewThumbnailButton = content.document.querySelector('button#viewThumbnail'); var viewThumbnailButton = content.document.querySelector("button#viewThumbnail");
viewThumbnailButton.click(); viewThumbnailButton.click();
Assert.equal(thumbnailView.getAttribute("class"), "", Assert.equal(thumbnailView.getAttribute("class"), "",

View file

@ -59,30 +59,28 @@ const TESTS = [
]; ];
add_task(function* test() { 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 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. // Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 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, 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" }, yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (newTabBrowser) { function* (newTabBrowser) {
yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf" + "#zoom=100"); 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; let document = content.document;
function waitForRender() { function waitForRender() {
return new Promise((resolve) => { return new Promise((resolve) => {
document.addEventListener("pagerendered", function onPageRendered(e) { document.addEventListener("pagerendered", function onPageRendered(e) {
if(e.detail.pageNumber !== 1) { if (e.detail.pageNumber !== 1) {
return; return;
} }
@ -98,29 +96,28 @@ add_task(function* test() {
let initialWidth, previousWidth; let initialWidth, previousWidth;
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 // We zoom using an UI element
var ev; var ev;
if (test.action.selector) { if (subTest.action.selector) {
// Get the element and trigger the action for changing the zoom // Get the element and trigger the action for changing the zoom
var el = document.querySelector(test.action.selector); var el = document.querySelector(subTest.action.selector);
Assert.ok(el, "Element '" + test.action.selector + "' has been found"); Assert.ok(el, "Element '" + subTest.action.selector + "' has been found");
if (test.action.index){ if (subTest.action.index) {
el.selectedIndex = test.action.index; el.selectedIndex = subTest.action.index;
} }
// Dispatch the event for changing the zoom // Dispatch the event for changing the zoom
ev = new Event(test.action.event); ev = new Event(subTest.action.event);
} } else {
// We zoom using keyboard // We zoom using keyboard
else {
// Simulate key press // Simulate key press
ev = new content.KeyboardEvent("keydown", ev = new content.KeyboardEvent("keydown",
{ key: test.action.event, { key: subTest.action.event,
keyCode: test.action.keyCode, keyCode: subTest.action.keyCode,
ctrlKey: true }); ctrlKey: true });
el = content; el = content;
} }
@ -128,21 +125,21 @@ add_task(function* test() {
el.dispatchEvent(ev); el.dispatchEvent(ev);
yield waitForRender(); yield waitForRender();
var pageZoomScale = content.document.querySelector('select#scaleSelect'); var pageZoomScale = content.document.querySelector("select#scaleSelect");
// The zoom value displayed in the zoom select // The zoom value displayed in the zoom select
var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML; 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); let actualWidth = parseInt(pageContainer.style.width);
// the actual zoom of the PDF document // 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"); Assert.equal(computedZoomValue, zoomValue, "Content has correct zoom");
// Check that document zooms in the expected way (in/out) // Check that document zooms in the expected way (in/out)
let zoom = (actualWidth - previousWidth) * test.expectedZoom; let zoom = (actualWidth - previousWidth) * subTest.expectedZoom;
Assert.ok(zoom > 0, test.message); Assert.ok(zoom > 0, subTest.message);
previousWidth = actualWidth; previousWidth = actualWidth;
} }

View file

@ -1,6 +1,6 @@
function waitForPdfJS(browser, url) { function waitForPdfJS(browser, url) {
// Runs tests after all 'load' event handlers have fired off // Runs tests after all "load" event handlers have fired off
return ContentTask.spawn(browser, url, function* (url) { return ContentTask.spawn(browser, url, function* (contentUrl) {
yield new Promise((resolve) => { yield new Promise((resolve) => {
// NB: Add the listener to the global object so that we receive the // NB: Add the listener to the global object so that we receive the
// event fired from the new window. // event fired from the new window.
@ -9,7 +9,7 @@ function waitForPdfJS(browser, url) {
resolve(); resolve();
}, false, true); }, false, true);
content.location = url; content.location = contentUrl;
}); });
}); });
} }