|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=498897 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 498897</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498897">Mozilla Bug 498897</a> |
|
13 <p id="display"><iframe id="testframe"></iframe></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript"> |
|
19 |
|
20 /** Test for Bug 498897 **/ |
|
21 |
|
22 var checkedLoad = false; |
|
23 |
|
24 const Cc = SpecialPowers.Cc; |
|
25 const Ci = SpecialPowers.Ci; |
|
26 |
|
27 // Content policy / factory implementation for the test |
|
28 var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{65944d64-2390-422e-bea3-80d0af7f69ef}"); |
|
29 var policyName = "@mozilla.org/498897_testpolicy;1"; |
|
30 var policy = { |
|
31 // nsISupports implementation |
|
32 QueryInterface: function(iid) { |
|
33 if (iid.equals(Ci.nsISupports) || |
|
34 iid.equals(Ci.nsIFactory) || |
|
35 iid.equals(Ci.nsIContentPolicy)) |
|
36 return this; |
|
37 |
|
38 throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; |
|
39 }, |
|
40 |
|
41 // nsIFactory implementation |
|
42 createInstance: function(outer, iid) { |
|
43 return this.QueryInterface(iid); |
|
44 }, |
|
45 |
|
46 // nsIContentPolicy implementation |
|
47 shouldLoad: function(contentType, contentLocation, requestOrigin, context, |
|
48 mimeTypeGuess, extra) { |
|
49 var url = window.location.href.substr(0, window.location.href.indexOf('test_bug498897')); |
|
50 if (contentLocation.spec == url + "file_bug498897.css" && |
|
51 requestOrigin.spec == url + "file_bug498897.html") { |
|
52 checkedLoad = true; |
|
53 } |
|
54 |
|
55 return Ci.nsIContentPolicy.ACCEPT; |
|
56 }, |
|
57 |
|
58 shouldProcess: function(contentType, contentLocation, requestOrigin, context, |
|
59 mimeTypeGuess, extra) { |
|
60 return Ci.nsIContentPolicy.ACCEPT; |
|
61 } |
|
62 } |
|
63 policy = SpecialPowers.wrapCallbackObject(policy); |
|
64 |
|
65 var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager |
|
66 .QueryInterface(Ci.nsIComponentRegistrar); |
|
67 componentManager.registerFactory(policyID, "Test content policy for bug 498897", |
|
68 policyName, policy); |
|
69 |
|
70 var categoryManager = |
|
71 Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); |
|
72 categoryManager.addCategoryEntry("content-policy", policyName, policyName, |
|
73 false, true); |
|
74 |
|
75 function testFinished() |
|
76 { |
|
77 ok(checkedLoad, "Content policy didn't get called!"); |
|
78 |
|
79 categoryManager.deleteCategoryEntry("content-policy", policyName, false); |
|
80 |
|
81 setTimeout(function() { |
|
82 componentManager.unregisterFactory(policyID, policy); |
|
83 |
|
84 SimpleTest.finish(); |
|
85 }, 0); |
|
86 } |
|
87 |
|
88 SimpleTest.waitForExplicitFinish(); |
|
89 |
|
90 document.getElementById("testframe").src = "file_bug498897.html"; |
|
91 |
|
92 </script> |
|
93 </pre> |
|
94 </body> |
|
95 </html> |