pdf.js/test/mozcentral/browser_pdfjs_savedialog.js
Brendan Dahl 121040a5dc Make pdf.js the default pdf viewer for moz central.
Update the tests to reflect this.
2012-06-01 13:21:45 -07:00

79 lines
2.7 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() {
const Cc = Components.classes;
const Ci = Components.interfaces;
var tab;
var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
//
// 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);
});
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
var newTabBrowser = gBrowser.getBrowserForTab(tab);
}
function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
const Cc = Components.classes;
const Ci = Components.interfaces;
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', null);
// Refresh data
mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
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) {
const Cc = Components.classes;
const Ci = Components.interfaces;
Services.wm.addListener({
onOpenWindow: function(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) { }
});
}