fune/browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js
Kris Maglione 577b96ad55 Bug 1479245: Don't eagerly load any PDF.js scripts in the content process. r=bdahl
MozReview-Commit-ID: GDSmAH9gpnX

--HG--
rename : browser/extensions/pdfjs/content/PdfJsRegistration.jsm => browser/extensions/pdfjs/pdfjs.js
extra : source : f0ccbdcaa8a1e82b43406540c76ebac4236581ee
extra : amend_source : 4efab8deca2fe945ba7cc3434efaf725ea5ee12a
2018-07-28 19:05:22 -07:00

60 lines
2.3 KiB
JavaScript

/* 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;
function test() {
var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
var tab = BrowserTestUtils.addTab(gBrowser, 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);
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");
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");
Services.ppmm.sharedData.flush();
// Refresh data
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");
return oldAction;
}
function addWindowListener(aURL, aCallback) {
Services.wm.addListener({
onOpenWindow(aXULWindow) {
info("window opened, waiting for focus");
Services.wm.removeListener(this);
var domwindow = aXULWindow.docShell.domWindow;
waitForFocus(function() {
is(domwindow.document.location.href, aURL, "should have seen the right window open");
domwindow.close();
aCallback();
}, domwindow);
},
onCloseWindow(aXULWindow) { },
});
}