1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<!DOCTYPE HTML>
<html>
<head>
<title>Crashtests for style system with content policy</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>
<iframe id="iframe"></iframe>
<script>
const TESTS = [
"file_bug1381233.html",
];
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
var policyName = "@mozilla.org/testpolicy;1";
var policy = {
// nsISupports implementation
QueryInterface: function(iid) {
iid = SpecialPowers.wrap(iid);
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsIContentPolicy))
return this;
throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation
createInstance: function(outer, iid) {
return this.QueryInterface(iid);
},
// nsIContentPolicy implementation
shouldLoad: function(contentLocation, loadInfo, mimeTypeGuess) {
info(`shouldLoad is invoked for ${SpecialPowers.wrap(contentLocation).spec}`);
return Ci.nsIContentPolicy.ACCEPT;
},
shouldProcess: function(contentLocation, loadInfo, mimeTypeGuess) {
return Ci.nsIContentPolicy.ACCEPT;
}
}
policy = SpecialPowers.wrapCallbackObject(policy);
// Register content policy
var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
.QueryInterface(Ci.nsIComponentRegistrar);
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);
SimpleTest.waitForExplicitFinish();
async function runTests() {
let iframe = document.getElementById("iframe");
for (let test of TESTS) {
iframe.src = test;
await new Promise(resolve => {
iframe.onload = resolve;
});
ok(true, `${test} doesn't crash`);
}
categoryManager.deleteCategoryEntry("content-policy", policyName, false);
componentManager.unregisterFactory(policyID, policy);
SimpleTest.finish();
}
runTests();
</script>
</body>
</html>
|