diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/base/test/file_simplecontentpolicy.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/file_simplecontentpolicy.js')
-rw-r--r-- | dom/base/test/file_simplecontentpolicy.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/dom/base/test/file_simplecontentpolicy.js b/dom/base/test/file_simplecontentpolicy.js new file mode 100644 index 000000000..1f9606c49 --- /dev/null +++ b/dom/base/test/file_simplecontentpolicy.js @@ -0,0 +1,73 @@ +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"); |