[Pkg-mozext-commits] [requestpolicy] 06/257: xpcshell: fix `head_loadrp.js`
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:19:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit d67ec7b964befeff6edb3e0ce6b57ca453769af6
Author: Martin Kimmerle <dev at 256k.de>
Date: Sat Aug 1 01:48:50 2015 +0200
xpcshell: fix `head_loadrp.js`
Formerly, the "RequestPolicy component" has been registered, as
well as "resource://requestpolicy/". Both aren't used anymore.
Instead, the `chrome://rpcontinued/` URIs will be registered via
registering the Chrome Manifest. The Chrome Manifest from the
`build` directory will be used, because there all files are
completely prepared. A makefile target has been added to create
the corresponding files.
---
Makefile | 3 ++
tests/run-xpcshell-tests.sh | 2 +
tests/xpcshell/head_loadrp.js | 96 ++++++++++++-------------------------------
3 files changed, 32 insertions(+), 69 deletions(-)
diff --git a/Makefile b/Makefile
index 1c2c667..0daecbc 100644
--- a/Makefile
+++ b/Makefile
@@ -421,6 +421,9 @@ $(unit_testing__other_files): $$(patsubst $$(unit_testing__build_path)%,$$(sourc
$(unit_testing__root_files): $$(patsubst $$(unit_testing__build_path)%,%,$$@)
cp $(patsubst $(unit_testing__build_path)%,%,$@) $@
+.PHONY: unit-testing-files
+unit-testing-files: $(unit_testing__all_files)
+
# __________________
# "cleaning" targets
diff --git a/tests/run-xpcshell-tests.sh b/tests/run-xpcshell-tests.sh
index ca48317..f8473ca 100755
--- a/tests/run-xpcshell-tests.sh
+++ b/tests/run-xpcshell-tests.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+(cd `dirname $0`/.. ; make unit-testing-files)
+
TEST_DIR=`dirname $0`/xpcshell
MOZ_SRC_DIR=/moz/mozilla-central
diff --git a/tests/xpcshell/head_loadrp.js b/tests/xpcshell/head_loadrp.js
index a51b47d..b078aa1 100644
--- a/tests/xpcshell/head_loadrp.js
+++ b/tests/xpcshell/head_loadrp.js
@@ -5,82 +5,40 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
+const Cu = Components.utils;
-// Simulate ProfD in xpcshell tests.
-// Modified from http://ehsanakhgari.org/blog/2008-10-17/testing-cache-service
-function setup_profile_dir() {
- var dirSvc = Cc["@mozilla.org/file/directory_service;1"]
- .getService(Ci.nsIProperties);
- var provider = {
- getFile: function(prop, persistent) {
- persistent.value = true;
- if (prop == "ProfLD" ||
- prop == "ProfD" ||
- prop == "cachePDir")
- return do_get_profile();
- throw Cr.NS_ERROR_FAILURE;
- },
- QueryInterface: function(iid) {
- if (iid.equals(Ci.nsIDirectoryProvider) ||
- iid.equals(Ci.nsISupports)) {
- return this;
- }
- throw Cr.NS_ERROR_NO_INTERFACE;
- }
- };
- dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
+Cu.import("resource://gre/modules/Services.jsm");
+
+// Initialize profile.
+// This will create a Directory Service Provider for the
+// profile directory. See `head.js` in mozilla-central.
+{
+ let gProfD = do_get_profile();
}
-setup_profile_dir();
+// Register RequestPolicy's Chrome Manifest.
+{
+ let cwd = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
-// Register components in the "components" subdirectory. The current directory
-// is the tests/xpcshell/ directory.
-let cwd = Cc["@mozilla.org/file/directory_service;1"]
- .getService(Ci.nsIProperties)
- .get("CurWorkD", Ci.nsILocalFile);
-let compDir = cwd.parent.parent.clone();
-compDir.append("src");
-//compDir.append("components");
-Components.manager instanceof Ci.nsIComponentRegistrar;
-Components.manager.autoRegister(compDir);
+ let manifestFile = cwd.parent.parent.clone();
+ manifestFile.appendRelativePath("build/unit-testing/chrome.manifest");
-// TODO: Since resource://requestpolicy/ is not used anymore, we might have to
-// change code here.
-// Setup resource://requestpolicy/
-let ioService = Cc["@mozilla.org/network/io-service;1"]
- .getService(Ci.nsIIOService);
-let resProt = ioService.getProtocolHandler("resource")
- .QueryInterface(Ci.nsIResProtocolHandler);
-let aliasFile = Cc["@mozilla.org/file/local;1"]
- .createInstance(Ci.nsILocalFile);
-let modulesDir = cwd.parent.parent.clone();
-modulesDir.append("src");
-modulesDir.append("content");
-modulesDir.append("modules");
-aliasFile.initWithPath(modulesDir.path);
-let aliasURI = ioService.newFileURI(aliasFile);
-resProt.setSubstitution("requestpolicy", aliasURI);
+ Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
+ .autoRegister(manifestFile);
+}
-// register chrome://* URIs
-let cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
- .getService(Components.interfaces.nsIChromeRegistry);
-cr.checkForNewChrome();
+// Load default preferences
+Services.scriptloader.loadSubScript("chrome://rpcontinued/content/" +
+ "main/default-pref-handler.js", {});
+// Setup the Logger module
+{
+ let tmpScope = {};
+ Cu.import("chrome://rpcontinued/content/lib/logger.jsm", tmpScope);
-// Setup the Logger module to use |print| instead of |dump| because that's
-// what's available for xpcshell tests.
-if (!requestpolicy) {
- var requestpolicy = {
- mod : {}
+ // Use |do_print| instead of |dump| because that's what's
+ // available for xpcshell tests.
+ tmpScope.Logger.printFunc = function (msg) {
+ do_print(msg.trimRight());
};
}
-
-//// maybe this needs to be changed to:
-//var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
-// .getService(Ci.mozIJSSubScriptLoader);
-//loader.loadSubScript("chrome://rpcontinued/content/lib/logger.jsm");
-//// ? -- see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_bindings/XPConnect/xpcshell/HOWTO
-Components.utils.import("chrome://rpcontinued/content/lib/logger.jsm");
-Logger.printFunc = function (msg) {
- print(msg.trimRight());
-}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list