forked from mirrors/gecko-dev
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:
parent
68b0311309
commit
8354e335b0
7 changed files with 79 additions and 101 deletions
|
|
@ -68,7 +68,7 @@ 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/**
|
||||
|
|
|
|||
|
|
@ -5,57 +5,43 @@ 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");
|
||||
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 closes on click");
|
||||
|
||||
//
|
||||
// Page change from prev/next buttons
|
||||
//
|
||||
var prevPage = content.document.querySelector('button#previous'),
|
||||
nextPage = content.document.querySelector('button#next');
|
||||
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -143,13 +143,13 @@ const TESTS = [
|
|||
|
||||
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) {
|
||||
|
|
@ -166,7 +166,7 @@ add_task(function* test() {
|
|||
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");
|
||||
});
|
||||
});
|
||||
|
|
@ -230,24 +230,24 @@ function* contentSetUp() {
|
|||
* @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);
|
||||
}
|
||||
|
|
@ -262,14 +262,14 @@ function* runTests(browser) {
|
|||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,9 @@ 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() {
|
||||
|
|
@ -23,7 +21,7 @@ function test() {
|
|||
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
|
||||
|
|
@ -31,23 +29,21 @@ function changeMimeHandler(preferredAction, 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);
|
||||
|
||||
|
|
@ -59,7 +55,7 @@ function addWindowListener(aURL, aCallback) {
|
|||
aCallback();
|
||||
}, domwindow);
|
||||
},
|
||||
onCloseWindow: function(aXULWindow) { },
|
||||
onWindowTitleChange: function(aXULWindow, aNewTitle) { }
|
||||
onCloseWindow(aXULWindow) { },
|
||||
onWindowTitleChange(aXULWindow, aNewTitle) { }
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,14 @@ 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) {
|
||||
|
|
@ -24,24 +23,24 @@ add_task(function* test() {
|
|||
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",
|
||||
|
|
@ -49,8 +48,8 @@ add_task(function* test() {
|
|||
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"), "",
|
||||
|
|
|
|||
|
|
@ -59,30 +59,28 @@ const TESTS = [
|
|||
];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -98,29 +96,28 @@ add_task(function* test() {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
@ -128,21 +125,21 @@ add_task(function* test() {
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
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.
|
||||
|
|
@ -9,7 +9,7 @@ function waitForPdfJS(browser, url) {
|
|||
resolve();
|
||||
}, false, true);
|
||||
|
||||
content.location = url;
|
||||
content.location = contentUrl;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue