1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/extensions/pdfjs/test/browser_pdfjs_savedialog.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const RELATIVE_DIR = "browser/extensions/pdfjs/test/"; 1.8 +const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; 1.9 + 1.10 +function test() { 1.11 + var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true); 1.12 + var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf"); 1.13 + // 1.14 + // Test: "Open with" dialog comes up when pdf.js is not selected as the default 1.15 + // handler. 1.16 + // 1.17 + addWindowListener('chrome://mozapps/content/downloads/unknownContentType.xul', finish); 1.18 + 1.19 + waitForExplicitFinish(); 1.20 + registerCleanupFunction(function() { 1.21 + changeMimeHandler(oldAction[0], oldAction[1]); 1.22 + gBrowser.removeTab(tab); 1.23 + }); 1.24 +} 1.25 + 1.26 +function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) { 1.27 + let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService); 1.28 + let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); 1.29 + let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf'); 1.30 + var oldAction = [handlerInfo.preferredAction, handlerInfo.alwaysAskBeforeHandling]; 1.31 + 1.32 + // Change and save mime handler settings 1.33 + handlerInfo.alwaysAskBeforeHandling = alwaysAskBeforeHandling; 1.34 + handlerInfo.preferredAction = preferredAction; 1.35 + handlerService.store(handlerInfo); 1.36 + 1.37 + Services.obs.notifyObservers(null, 'pdfjs:handlerChanged', null); 1.38 + 1.39 + // Refresh data 1.40 + handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf'); 1.41 + 1.42 + // 1.43 + // Test: Mime handler was updated 1.44 + // 1.45 + is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, 'always-ask prompt change successful'); 1.46 + is(handlerInfo.preferredAction, preferredAction, 'mime handler change successful'); 1.47 + 1.48 + return oldAction; 1.49 +} 1.50 + 1.51 +function addWindowListener(aURL, aCallback) { 1.52 + Services.wm.addListener({ 1.53 + onOpenWindow: function(aXULWindow) { 1.54 + info("window opened, waiting for focus"); 1.55 + Services.wm.removeListener(this); 1.56 + 1.57 + var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) 1.58 + .getInterface(Ci.nsIDOMWindow); 1.59 + waitForFocus(function() { 1.60 + is(domwindow.document.location.href, aURL, "should have seen the right window open"); 1.61 + domwindow.close(); 1.62 + aCallback(); 1.63 + }, domwindow); 1.64 + }, 1.65 + onCloseWindow: function(aXULWindow) { }, 1.66 + onWindowTitleChange: function(aXULWindow, aNewTitle) { } 1.67 + }); 1.68 +}