Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=375314
5 -->
6 <head>
7 <title>Test for Bug 375314</title>
8 <script type="text/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=375314">Mozilla Bug 375314</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
16 </div>
17 <pre id="test">
18 <script class="testbody" type="text/javascript">
20 /** Test for Bug 375314 **/
22 var lastContentType = -1;
23 const testURL = window.location.href + "/this/is/the/test/url";
24 const Cc = SpecialPowers.Cc;
25 const Ci = SpecialPowers.Ci;
27 // Content policy / factory implementation for the test
28 var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
29 var policyName = "@mozilla.org/testpolicy;1";
30 var policy = {
31 // nsISupports implementation
32 QueryInterface: function(iid) {
34 iid = SpecialPowers.wrap(iid);
35 if (iid.equals(Ci.nsISupports) ||
36 iid.equals(Ci.nsIFactory) ||
37 iid.equals(Ci.nsIContentPolicy))
38 return this;
40 throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
41 },
43 // nsIFactory implementation
44 createInstance: function(outer, iid) {
45 return this.QueryInterface(iid);
46 },
48 // nsIContentPolicy implementation
49 shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
51 // Remember last content type seen for the test url
52 if (SpecialPowers.wrap(contentLocation).spec == testURL) {
53 lastContentType = contentType;
54 return Ci.nsIContentPolicy.REJECT_REQUEST;
55 }
57 return Ci.nsIContentPolicy.ACCEPT;
58 },
60 shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
62 return Ci.nsIContentPolicy.ACCEPT;
63 }
64 }
65 policy = SpecialPowers.wrapCallbackObject(policy);
67 // Register content policy
68 var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
69 .QueryInterface(Ci.nsIComponentRegistrar);
71 componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
73 var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
74 categoryManager.addCategoryEntry("content-policy", policyName, policyName, false, true);
76 // Try creating different request types
77 var tests = ["SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "DOCUMENT", "SUBDOCUMENT", "XBL", "XMLHTTPREQUEST"];
78 var curTest = -1;
80 var div;
82 SimpleTest.waitForExplicitFinish();
83 setTimeout(runNextTest, 0);
85 function runNextTest() {
87 if (curTest >= 0) {
88 var type = "TYPE_" + tests[curTest];
89 is(lastContentType, Ci.nsIContentPolicy[type], "Content policies triggered for " + type);
91 if (tests[curTest] == "XBL")
92 {
93 //XXX Removing binding to work-around a memory leak (bugs 478528, 499735).
94 div.style.MozBinding = "";
95 }
96 }
98 curTest++;
99 if (curTest < tests.length) {
100 var method = "request_" + tests[curTest].toLowerCase();
101 try {
102 window[method]();
103 } catch(e) {}
104 setTimeout(runNextTest, 0);
105 }
106 else {
107 // Unregister content policy
108 categoryManager.deleteCategoryEntry("content-policy", policyName, false);
110 setTimeout(function() {
111 // Component must be unregistered delayed, otherwise other content
112 // policy will not be removed from the category correctly
113 componentManager.unregisterFactory(policyID, policy);
114 }, 0);
116 SimpleTest.finish();
117 }
118 }
120 // Request creating functions
122 function request_script() {
123 var content = $("content");
125 var script = document.createElement("script");
126 script.setAttribute("type", "text/javascript")
127 script.setAttribute("src", testURL)
128 content.appendChild(script);
129 }
131 function request_image() {
132 var content = $("content");
134 var image = new Image();
135 image.src = testURL;
136 }
138 function request_stylesheet() {
139 var content = $("content");
141 var stylesheet = document.createElement("link");
142 stylesheet.setAttribute("rel", "stylesheet");
143 stylesheet.setAttribute("type", "text/css");
144 stylesheet.setAttribute("href", testURL);
145 content.appendChild(stylesheet);
146 }
148 function request_object() {
149 var content = $("content");
151 var object = document.createElement("embed");
152 object.setAttribute("src", testURL);
153 content.appendChild(object);
154 }
156 function request_document() {
157 top.location.href = testURL;
158 }
160 function request_subdocument() {
161 var content = $("content");
163 var frame = document.createElement("iframe");
164 frame.setAttribute("src", testURL);
165 content.appendChild(frame);
166 }
168 function request_xbl() {
169 var content = $("content");
171 div = document.createElement("div");
172 div.style.MozBinding = "url(" + testURL + ")";
173 $('test').appendChild(div);
174 div.offsetLeft; // Flush styles.
175 }
177 function request_xmlhttprequest() {
178 var request = new XMLHttpRequest();
179 request.open("GET", testURL, false);
180 request.send(null);
181 }
183 </script>
184 </pre>
185 </body>
186 </html>