browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
michael@0 5 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
michael@0 6
michael@0 7 function test() {
michael@0 8 var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
michael@0 9 var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
michael@0 10 //
michael@0 11 // Test: "Open with" dialog comes up when pdf.js is not selected as the default
michael@0 12 // handler.
michael@0 13 //
michael@0 14 addWindowListener('chrome://mozapps/content/downloads/unknownContentType.xul', finish);
michael@0 15
michael@0 16 waitForExplicitFinish();
michael@0 17 registerCleanupFunction(function() {
michael@0 18 changeMimeHandler(oldAction[0], oldAction[1]);
michael@0 19 gBrowser.removeTab(tab);
michael@0 20 });
michael@0 21 }
michael@0 22
michael@0 23 function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
michael@0 24 let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
michael@0 25 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
michael@0 26 let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
michael@0 27 var oldAction = [handlerInfo.preferredAction, handlerInfo.alwaysAskBeforeHandling];
michael@0 28
michael@0 29 // Change and save mime handler settings
michael@0 30 handlerInfo.alwaysAskBeforeHandling = alwaysAskBeforeHandling;
michael@0 31 handlerInfo.preferredAction = preferredAction;
michael@0 32 handlerService.store(handlerInfo);
michael@0 33
michael@0 34 Services.obs.notifyObservers(null, 'pdfjs:handlerChanged', null);
michael@0 35
michael@0 36 // Refresh data
michael@0 37 handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
michael@0 38
michael@0 39 //
michael@0 40 // Test: Mime handler was updated
michael@0 41 //
michael@0 42 is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, 'always-ask prompt change successful');
michael@0 43 is(handlerInfo.preferredAction, preferredAction, 'mime handler change successful');
michael@0 44
michael@0 45 return oldAction;
michael@0 46 }
michael@0 47
michael@0 48 function addWindowListener(aURL, aCallback) {
michael@0 49 Services.wm.addListener({
michael@0 50 onOpenWindow: function(aXULWindow) {
michael@0 51 info("window opened, waiting for focus");
michael@0 52 Services.wm.removeListener(this);
michael@0 53
michael@0 54 var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 55 .getInterface(Ci.nsIDOMWindow);
michael@0 56 waitForFocus(function() {
michael@0 57 is(domwindow.document.location.href, aURL, "should have seen the right window open");
michael@0 58 domwindow.close();
michael@0 59 aCallback();
michael@0 60 }, domwindow);
michael@0 61 },
michael@0 62 onCloseWindow: function(aXULWindow) { },
michael@0 63 onWindowTitleChange: function(aXULWindow, aNewTitle) { }
michael@0 64 });
michael@0 65 }

mercurial