2007-06-17 06:50:50 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=375314
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 375314</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375314">Mozilla Bug 375314</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 375314 **/
|
|
|
|
|
|
|
|
var lastContentType = -1;
|
|
|
|
const testURL = window.location.href + "/this/is/the/test/url";
|
2012-01-18 19:10:14 -08:00
|
|
|
const Cc = SpecialPowers.wrap(Components).classes;
|
2007-06-17 06:50:50 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
// Content policy / factory implementation for the test
|
2012-01-18 19:10:14 -08:00
|
|
|
var policyID = SpecialPowers.wrap(Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
|
2007-06-17 06:50:50 -07:00
|
|
|
var policyName = "@mozilla.org/testpolicy;1";
|
|
|
|
var policy = {
|
|
|
|
// nsISupports implementation
|
|
|
|
QueryInterface: function(iid) {
|
|
|
|
|
2012-01-18 19:10:14 -08:00
|
|
|
iid = SpecialPowers.wrap(iid);
|
2007-06-17 06:50:50 -07:00
|
|
|
if (iid.equals(Ci.nsISupports) ||
|
|
|
|
iid.equals(Ci.nsIFactory) ||
|
|
|
|
iid.equals(Ci.nsIContentPolicy))
|
|
|
|
return this;
|
|
|
|
|
2012-01-18 19:10:14 -08:00
|
|
|
throw SpecialPowers.wrap(Components).results.NS_ERROR_NO_INTERFACE;
|
2007-06-17 06:50:50 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsIFactory implementation
|
|
|
|
createInstance: function(outer, iid) {
|
|
|
|
return this.QueryInterface(iid);
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIContentPolicy implementation
|
|
|
|
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
|
|
|
|
|
|
|
|
// Remember last content type seen for the test url
|
2012-01-18 19:10:14 -08:00
|
|
|
if (SpecialPowers.wrap(contentLocation).spec == testURL) {
|
2007-06-17 06:50:50 -07:00
|
|
|
lastContentType = contentType;
|
|
|
|
return Ci.nsIContentPolicy.REJECT_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ci.nsIContentPolicy.ACCEPT;
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
|
|
|
|
|
|
|
|
return Ci.nsIContentPolicy.ACCEPT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register content policy
|
2012-01-18 19:10:14 -08:00
|
|
|
var componentManager = SpecialPowers.wrap(Components).manager
|
|
|
|
.QueryInterface(Ci.nsIComponentRegistrar);
|
|
|
|
|
2007-06-17 06:50:50 -07:00
|
|
|
componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
|
|
|
|
|
|
|
|
var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
|
|
|
categoryManager.addCategoryEntry("content-policy", policyName, policyName, false, true);
|
|
|
|
|
|
|
|
// Try creating different request types
|
2008-02-01 15:41:39 -08:00
|
|
|
var tests = ["SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "DOCUMENT", "SUBDOCUMENT", "XBL", "XMLHTTPREQUEST"];
|
2007-06-17 06:50:50 -07:00
|
|
|
var curTest = -1;
|
|
|
|
|
2009-06-25 14:58:56 -07:00
|
|
|
var div;
|
|
|
|
|
2007-06-17 06:50:50 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
setTimeout(runNextTest, 0);
|
|
|
|
|
|
|
|
function runNextTest() {
|
|
|
|
|
|
|
|
if (curTest >= 0) {
|
|
|
|
var type = "TYPE_" + tests[curTest];
|
|
|
|
is(lastContentType, Ci.nsIContentPolicy[type], "Content policies triggered for " + type);
|
2009-06-25 14:58:56 -07:00
|
|
|
|
|
|
|
if (tests[curTest] == "XBL")
|
|
|
|
{
|
|
|
|
//XXX Removing binding to work-around a memory leak (bugs 478528, 499735).
|
|
|
|
document.removeBinding(div, testURL);
|
|
|
|
}
|
2007-06-17 06:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
curTest++;
|
|
|
|
if (curTest < tests.length) {
|
|
|
|
var method = "request_" + tests[curTest].toLowerCase();
|
|
|
|
try {
|
|
|
|
window[method]();
|
|
|
|
} catch(e) {}
|
|
|
|
setTimeout(runNextTest, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Unregister content policy
|
|
|
|
categoryManager.deleteCategoryEntry("content-policy", policyName, false);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
// Component must be unregistered delayed, otherwise other content
|
|
|
|
// policy will not be removed from the category correctly
|
|
|
|
componentManager.unregisterFactory(policyID, policy);
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request creating functions
|
|
|
|
|
|
|
|
function request_script() {
|
|
|
|
var content = $("content");
|
|
|
|
|
|
|
|
var script = document.createElement("script");
|
|
|
|
script.setAttribute("type", "text/javascript")
|
|
|
|
script.setAttribute("src", testURL)
|
|
|
|
content.appendChild(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_image() {
|
|
|
|
var content = $("content");
|
|
|
|
|
|
|
|
var image = new Image();
|
|
|
|
image.src = testURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_stylesheet() {
|
|
|
|
var content = $("content");
|
|
|
|
|
|
|
|
var stylesheet = document.createElement("link");
|
|
|
|
stylesheet.setAttribute("rel", "stylesheet");
|
|
|
|
stylesheet.setAttribute("type", "text/css");
|
|
|
|
stylesheet.setAttribute("href", testURL);
|
|
|
|
content.appendChild(stylesheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_object() {
|
|
|
|
var content = $("content");
|
|
|
|
|
|
|
|
var object = document.createElement("embed");
|
|
|
|
object.setAttribute("src", testURL);
|
|
|
|
content.appendChild(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_document() {
|
|
|
|
top.location.href = testURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_subdocument() {
|
|
|
|
var content = $("content");
|
|
|
|
|
|
|
|
var frame = document.createElement("iframe");
|
|
|
|
frame.setAttribute("src", testURL);
|
|
|
|
content.appendChild(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_xbl() {
|
|
|
|
var content = $("content");
|
|
|
|
|
2009-06-25 14:58:56 -07:00
|
|
|
div = document.createElement("div");
|
2007-06-17 06:50:50 -07:00
|
|
|
content.appendChild(div);
|
|
|
|
|
|
|
|
document.addBinding(div, testURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_xmlhttprequest() {
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("GET", testURL, false);
|
|
|
|
request.send(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|