From 9b34f348c7ebadf7015a7a121c3ea8f01f1692b4 Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Wed, 23 Jun 2010 16:28:10 +0200 Subject: [PATCH] Bug 573740 - Register resource://services-sync before xpcshell tests get run [r=Mardak] Don't try to create the alias too early, add-on chrome registration might not have happened yet, so do it during testing. --- services/sync/Weave.js | 41 +++++++++++++----------- services/sync/tests/unit/head_appinfo.js | 4 +++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/services/sync/Weave.js b/services/sync/Weave.js index b5bbb03b31c..0e5e2bbaf40 100644 --- a/services/sync/Weave.js +++ b/services/sync/Weave.js @@ -40,7 +40,9 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -function WeaveService() {} +function WeaveService() { + this.wrappedJSObject = this; +} WeaveService.prototype = { classDescription: "Weave Service", contractID: "@mozilla.org/weave/service;1", @@ -56,6 +58,7 @@ WeaveService.prototype = { let os = Cc["@mozilla.org/observer-service;1"]. getService(Ci.nsIObserverService); os.addObserver(this, "final-ui-startup", true); + this.addResourceAlias(); break; case "final-ui-startup": @@ -68,6 +71,25 @@ WeaveService.prototype = { }, 10000, Ci.nsITimer.TYPE_ONE_SHOT); break; } + }, + + addResourceAlias: function() { + let ioService = Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); + let resProt = ioService.getProtocolHandler("resource") + .QueryInterface(Ci.nsIResProtocolHandler); + + // Only create alias if resource://services-sync doesn't already exist. + if (resProt.hasSubstitution("services-sync")) + return; + + let uri = ioService.newURI("resource://gre/modules/services-sync", + null, null); + let file = uri.QueryInterface(Ci.nsIFileURL) + .file.QueryInterface(Ci.nsILocalFile); + + let aliasURI = ioService.newFileURI(file); + resProt.setSubstitution("services-sync", aliasURI); } }; @@ -134,20 +156,3 @@ function NSGetModule(compMgr, fileSpec) { AboutWeaveLog1 ]); } - -(function addResourceAlias() { - let ioService = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - let resProt = ioService.getProtocolHandler("resource"). - QueryInterface(Ci.nsIResProtocolHandler); - - // Only create alias if resource://services-sync doesn't already exist. - if (resProt.hasSubstitution("services-sync")) - return; - - let uri = ioService.newURI("resource://gre/modules/services-sync", null, null); - let file = uri.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); - - let aliasURI = ioService.newFileURI(file); - resProt.setSubstitution("services-sync", aliasURI); -})(); diff --git a/services/sync/tests/unit/head_appinfo.js b/services/sync/tests/unit/head_appinfo.js index d6a2ef5f929..278ee6dc0a1 100644 --- a/services/sync/tests/unit/head_appinfo.js +++ b/services/sync/tests/unit/head_appinfo.js @@ -58,3 +58,7 @@ registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}" XULAppInfoFactory); } + +// Provide resource://services-sync if it isn't already available +let weaveService = Cc["@mozilla.org/weave/service;1"].getService(); +weaveService.wrappedJSObject.addResourceAlias();