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.

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

mercurial