Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
| 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 | } |