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 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 2 | |
michael@0 | 3 | let HandlerService = { |
michael@0 | 4 | classID: Components.ID("{b4ed9fab-fd39-435a-8e3e-edc3e689e72e}"), |
michael@0 | 5 | |
michael@0 | 6 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, |
michael@0 | 7 | Ci.nsIExternalProtocolService]), |
michael@0 | 8 | |
michael@0 | 9 | createInstance: function(aOuter, aIID) { |
michael@0 | 10 | if (aOuter) { |
michael@0 | 11 | throw Cr.NS_ERROR_NO_AGGREGATION; |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | return this.QueryInterface(aIID); |
michael@0 | 15 | }, |
michael@0 | 16 | |
michael@0 | 17 | init: function() { |
michael@0 | 18 | Components.manager.nsIComponentRegistrar.registerFactory(this.classID, |
michael@0 | 19 | "Test Protocol Handler Service", |
michael@0 | 20 | "@mozilla.org/uriloader/external-protocol-service;1", |
michael@0 | 21 | this); |
michael@0 | 22 | }, |
michael@0 | 23 | |
michael@0 | 24 | getProtocolHandlerInfo: function(aProtocolScheme) { |
michael@0 | 25 | let handlerInfoObj = { |
michael@0 | 26 | launchWithURI: function(aURI) { |
michael@0 | 27 | is(aURI.spec, |
michael@0 | 28 | "http://test/webapprtChrome/webapprt/test/chrome/sample.html", |
michael@0 | 29 | "The app tried to open the link in the default browser"); |
michael@0 | 30 | |
michael@0 | 31 | finish(); |
michael@0 | 32 | } |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | return handlerInfoObj; |
michael@0 | 36 | } |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | HandlerService.init(); |
michael@0 | 40 | |
michael@0 | 41 | function test() { |
michael@0 | 42 | waitForExplicitFinish(); |
michael@0 | 43 | |
michael@0 | 44 | let progressListener = { |
michael@0 | 45 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, |
michael@0 | 46 | Ci.nsISupportsWeakReference]), |
michael@0 | 47 | onLocationChange: function(progress, request, location, flags) { |
michael@0 | 48 | ok(false, "Location changed"); |
michael@0 | 49 | finish(); |
michael@0 | 50 | } |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | let winObserver = function(win, topic) { |
michael@0 | 54 | if (topic == "domwindowopened") { |
michael@0 | 55 | win.addEventListener("load", function onLoadWindow() { |
michael@0 | 56 | win.removeEventListener("load", onLoadWindow, false); |
michael@0 | 57 | |
michael@0 | 58 | if (win.location == "chrome://webapprt/content/webapp.xul") { |
michael@0 | 59 | ok(false, "New app window opened"); |
michael@0 | 60 | finish(); |
michael@0 | 61 | } |
michael@0 | 62 | }, false); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | loadWebapp("window-open-blank.webapp", undefined, function() { |
michael@0 | 67 | gAppBrowser.addProgressListener(progressListener, |
michael@0 | 68 | Ci.nsIWebProgress.NOTIFY_LOCATION); |
michael@0 | 69 | }); |
michael@0 | 70 | |
michael@0 | 71 | registerCleanupFunction(function() { |
michael@0 | 72 | Services.ww.unregisterNotification(winObserver); |
michael@0 | 73 | gAppBrowser.removeProgressListener(progressListener); |
michael@0 | 74 | }); |
michael@0 | 75 | } |