caps/tests/mochitest/test_bug292789.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:807d247e9f0a
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=292789
5 -->
6 <head>
7 <title>Test for Bug 292789</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=292789">Mozilla Bug 292789</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
15 <script src="chrome://global/content/treeUtils.js"></script>
16 <script type="application/javascript;version=1.8" src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js"></script>
17 <script id="resjs" type="application/javascript;version=1.8"></script>
18 </div>
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
21
22 /** Test for Bug 292789
23 **
24 ** Selectively allow access to whitelisted chrome packages
25 ** even for ALLOW_CHROME mechanisms (<script>, <img> etc)
26 **/
27
28 SimpleTest.waitForExplicitFinish();
29
30 /** <script src=""> test **/
31 function testScriptSrc(aCallback) {
32 is(typeof gTreeUtils.sort, "function",
33 "content can still load <script> from chrome://global");
34 is(typeof XPInstallConfirm, "undefined",
35 "content should not be able to load <script> from chrome://mozapps");
36
37 /** make sure the last one didn't pass because someone
38 ** moved the resource
39 **/
40 var resjs = document.getElementById("resjs");
41 resjs.onload = scriptOnload;
42 resjs.src = "resource://gre/chrome/toolkit/content/mozapps/xpinstall/xpinstallConfirm.js";
43 document.getElementById("content").appendChild(resjs);
44
45 function scriptOnload() {
46 is(typeof XPInstallConfirm, "object",
47 "xpinstallConfirm.js has not moved unexpectedly");
48
49 // trigger the callback
50 if (aCallback)
51 aCallback();
52 }
53 }
54
55 /** <img src=""> tests **/
56 var img_global = "chrome://global/skin/icons/Error.png";
57 var img_mozapps = "chrome://mozapps/skin/passwordmgr/key.png";
58 var res_mozapps = "resource://gre/chrome/toolkit/skin/classic/mozapps/passwordmgr/key.png";
59
60 var imgTests = [[img_global, "success"],
61 [img_mozapps, "fail"],
62 [res_mozapps, "success"]];
63
64 var curImgTest = 0;
65
66 function runImgTest() {
67 var test = imgTests[curImgTest++];
68 var callback = curImgTest == imgTests.length ? finishTest : runImgTest;
69 loadImage(test[0], test[1], callback);
70 }
71
72 function finishTest() {
73 SimpleTest.finish();
74 }
75
76 function fail(event) {
77 is(event.target.expected, "fail",
78 "content should not be allowed to load "+event.target.src);
79 if (event.target.callback)
80 event.target.callback();
81 }
82
83 function success(event) {
84 is(event.target.expected, "success",
85 "content should be able to load "+event.target.src);
86 if (event.target.callback)
87 event.target.callback();
88 }
89
90 function loadImage(uri, expect, callback) {
91 var img = document.createElement("img");
92 img.onerror = fail;
93 img.onload = success;
94 img.expected = expect;
95 img.callback = callback;
96 img.src = uri;
97 //document.getElementById("content").appendChild(img);
98 }
99
100 // Start off the script src test, and have it start the img tests when complete.
101 testScriptSrc(runImgTest);
102 </script>
103 </pre>
104 </body>
105 </html>

mercurial