gecko-dev/dom/base/test/file_simplecontentpolicy.js
Carsten "Tomcat" Book 08997000eb Backed out 2 changesets (bug 1202902) to recking bug 1202902 to be able to reopen inbound on a CLOSED TREE
Backed out changeset 647025383676 (bug 1202902)
Backed out changeset d70c7fe532c6 (bug 1202902)
2015-10-07 14:03:21 +02:00

74 lines
2.3 KiB
JavaScript

var Ci = Components.interfaces;
var Cc = Components.classes;
var Cr = Components.results;
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function executeSoon(f)
{
Services.tm.mainThread.dispatch(f, Ci.nsIThread.DISPATCH_NORMAL);
}
var urlSuffix = "/this/is/the/test/url";
// Content policy / factory implementation for the test
var policyID = Components.ID("{6aadacff-f1f2-46f4-a6db-6d429f884a30}");
var policyName = "@mozilla.org/simpletestpolicy;1";
var policy = {
// nsISupports implementation
QueryInterface:
XPCOMUtils.generateQI([
Ci.nsISupports,
Ci.nsIFactory,
Ci.nsISimpleContentPolicy]),
// nsIFactory implementation
createInstance: function(outer, iid) {
return this.QueryInterface(iid);
},
// nsIContentPolicy implementation
shouldLoad: function(contentType,
contentLocation,
requestOrigin,
frame,
isTopLevel,
mimeTypeGuess,
extra)
{
// Remember last content type seen for the test url
if (contentLocation.spec.endsWith(urlSuffix)) {
assert.ok(frame === browserElement, "correct <browser> element");
sendAsyncMessage("shouldLoad", {contentType: contentType, isTopLevel: isTopLevel});
return Ci.nsIContentPolicy.REJECT_REQUEST;
}
return Ci.nsIContentPolicy.ACCEPT;
},
shouldProcess: function() {
return Ci.nsIContentPolicy.ACCEPT;
}
}
// Register content policy
var componentManager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
componentManager.registerFactory(policyID, "Test simple content policy", policyName, policy);
var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
categoryManager.addCategoryEntry("simple-content-policy", policyName, policyName, false, true);
addMessageListener("finished", () => {
// Unregister content policy
categoryManager.deleteCategoryEntry("simple-content-policy", policyName, false);
executeSoon(function() {
// Component must be unregistered delayed, otherwise other content
// policy will not be removed from the category correctly
componentManager.unregisterFactory(policyID, policy);
});
});
sendAsyncMessage("ready");