Bug 1439713 - Update tests relying on nsIContentPolicy. r=bz

This commit is contained in:
Christoph Kerschbaumer 2018-03-29 11:14:58 +02:00
parent 3739c23b85
commit 4197b7d96d
6 changed files with 24 additions and 17 deletions

View File

@ -51,7 +51,9 @@ var policy = {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
let contentType = loadInfo.externalContentPolicyType;
let context = loadInfo.loadingContext;
if (SpecialPowers.wrap(contentLocation).spec !== document.getElementById("testlink").href) { if (SpecialPowers.wrap(contentLocation).spec !== document.getElementById("testlink").href) {
// not the URI we are looking for, allow the load // not the URI we are looking for, allow the load
@ -77,7 +79,7 @@ var policy = {
return Ci.nsIContentPolicy.REJECT_REQUEST; return Ci.nsIContentPolicy.REJECT_REQUEST;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }
} }

View File

@ -46,8 +46,8 @@ var policy = {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
let contentType = loadInfo.externalContentPolicyType;
// Remember last content type seen for the test url // Remember last content type seen for the test url
if (SpecialPowers.wrap(contentLocation).spec == testURL) { if (SpecialPowers.wrap(contentLocation).spec == testURL) {
lastContentType = contentType; lastContentType = contentType;
@ -57,7 +57,7 @@ var policy = {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }

View File

@ -44,9 +44,12 @@ var policy = {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
mimeTypeGuess, extra) {
var url = window.location.href.substr(0, window.location.href.indexOf('test_bug498897')); var url = window.location.href.substr(0, window.location.href.indexOf('test_bug498897'));
let loadingPrincipal = loadInfo.loadingPrincipal;
if (loadingPrincipal) {
requestOrigin = loadingPrincipal.URI;
}
if (contentLocation.spec == url + "file_bug498897.css" && if (contentLocation.spec == url + "file_bug498897.css" &&
requestOrigin.spec == url + "file_bug498897.html") { requestOrigin.spec == url + "file_bug498897.html") {
checkedLoad = true; checkedLoad = true;
@ -55,8 +58,7 @@ var policy = {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, context, shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
mimeTypeGuess, extra) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }
} }

View File

@ -51,8 +51,8 @@ var policy = {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
context, mimeTypeGuess, extra) { let contentType = loadInfo.externalContentPolicyType;
// make sure we get the right amount of content policy calls // make sure we get the right amount of content policy calls
// e.g. about:blank also gets chrcked by content policies // e.g. about:blank also gets chrcked by content policies
@ -60,14 +60,14 @@ var policy = {
is(contentType, EXPECTED_CONTENT_TYPE, is(contentType, EXPECTED_CONTENT_TYPE,
"content policy type should TYPESUBDOCUMENT"); "content policy type should TYPESUBDOCUMENT");
categoryManager.deleteCategoryEntry("content-policy", POLICYNAME, false); categoryManager.deleteCategoryEntry("content-policy", POLICYNAME, false);
componentManager.unregisterFactory(POLICYID, policy);
SimpleTest.finish(); SimpleTest.finish();
return Ci.nsIContentPolicy.REJECT_REQUEST; return Ci.nsIContentPolicy.REJECT_REQUEST;
} }
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
context, mimeTypeGuess, extra) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }
} }

View File

@ -49,8 +49,9 @@ function setupPolicy() {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
// Remember last content type seen for the test url // Remember last content type seen for the test url
let contentType = loadInfo.externalContentPolicyType;
if (SpecialPowers.wrap(contentLocation).spec == beaconUrl) { if (SpecialPowers.wrap(contentLocation).spec == beaconUrl) {
is(contentType, Ci.nsIContentPolicy.TYPE_BEACON, "Beacon content type should match expected. is: " + contentType + " should be: " + Ci.nsIContentPolicy.TYPE_BEACON); is(contentType, Ci.nsIContentPolicy.TYPE_BEACON, "Beacon content type should match expected. is: " + contentType + " should be: " + Ci.nsIContentPolicy.TYPE_BEACON);
@ -61,7 +62,7 @@ function setupPolicy() {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }
} }

View File

@ -36,11 +36,11 @@ var policy = {
}, },
// nsIContentPolicy implementation // nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
info(`shouldLoad is invoked for ${SpecialPowers.wrap(contentLocation).spec}`); info(`shouldLoad is invoked for ${SpecialPowers.wrap(contentLocation).spec}`);
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
}, },
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) { shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
return Ci.nsIContentPolicy.ACCEPT; return Ci.nsIContentPolicy.ACCEPT;
} }
} }
@ -65,6 +65,8 @@ async function runTests() {
}); });
ok(true, `${test} doesn't crash`); ok(true, `${test} doesn't crash`);
} }
categoryManager.deleteCategoryEntry("content-policy", policyName, false);
componentManager.unregisterFactory(policyID, policy);
SimpleTest.finish(); SimpleTest.finish();
} }
runTests(); runTests();