|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=519928 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 519928</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=519928">Mozilla Bug 519928</a> |
|
13 <p id="display"></p> |
|
14 <div id="content"> |
|
15 <iframe id="load-frame"></iframe> |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script class="testbody" type="text/javascript"> |
|
19 |
|
20 var iframe = document.getElementById("load-frame"); |
|
21 |
|
22 function enableJS() allowJS(true, iframe); |
|
23 function disableJS() allowJS(false, iframe); |
|
24 function allowJS(allow, frame) { |
|
25 SpecialPowers.wrap(frame.contentWindow) |
|
26 .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) |
|
27 .getInterface(SpecialPowers.Ci.nsIWebNavigation) |
|
28 .QueryInterface(SpecialPowers.Ci.nsIDocShell) |
|
29 .allowJavascript = allow; |
|
30 } |
|
31 function expectJSAllowed(allowed, testCondition, callback) { |
|
32 window.ICanRunMyJS = false; |
|
33 var self_ = window; |
|
34 testCondition(); |
|
35 |
|
36 var doc = iframe.contentDocument; |
|
37 doc.body.innerHTML = "<iframe></iframe>"; |
|
38 var innerFrame = doc.querySelector("iframe"); |
|
39 innerFrame.addEventListener("load", function() { |
|
40 innerFrame.removeEventListener("load", arguments.callee, false); |
|
41 |
|
42 var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript"; |
|
43 is(self_.ICanRunMyJS, allowed, msg); |
|
44 callback(); |
|
45 }, false); |
|
46 var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>"; |
|
47 innerFrame.src = iframeSrc; |
|
48 } |
|
49 |
|
50 SimpleTest.waitForExplicitFinish(); |
|
51 addLoadEvent(function() { |
|
52 var enterDesignMode = function() document.designMode = "on"; |
|
53 var leaveDesignMode = function() document.designMode = "off"; |
|
54 expectJSAllowed(false, disableJS, function() { |
|
55 expectJSAllowed(true, enableJS, function() { |
|
56 expectJSAllowed(true, enterDesignMode, function() { |
|
57 expectJSAllowed(true, leaveDesignMode, function() { |
|
58 expectJSAllowed(false, disableJS, function() { |
|
59 expectJSAllowed(false, enterDesignMode, function() { |
|
60 expectJSAllowed(false, leaveDesignMode, function() { |
|
61 expectJSAllowed(true, enableJS, function() { |
|
62 enterDesignMode = function() iframe.contentDocument.designMode = "on"; |
|
63 leaveDesignMode = function() iframe.contentDocument.designMode = "off"; |
|
64 expectJSAllowed(false, disableJS, function() { |
|
65 expectJSAllowed(true, enableJS, function() { |
|
66 expectJSAllowed(true, enterDesignMode, function() { |
|
67 expectJSAllowed(true, leaveDesignMode, function() { |
|
68 expectJSAllowed(false, disableJS, function() { |
|
69 expectJSAllowed(false, enterDesignMode, function() { |
|
70 expectJSAllowed(false, leaveDesignMode, function() { |
|
71 expectJSAllowed(true, enableJS, function() { |
|
72 testDocumentDisabledJS(); |
|
73 }); |
|
74 }); |
|
75 }); |
|
76 }); |
|
77 }); |
|
78 }); |
|
79 }); |
|
80 }); |
|
81 }); |
|
82 }); |
|
83 }); |
|
84 }); |
|
85 }); |
|
86 }); |
|
87 }); |
|
88 }); |
|
89 }); |
|
90 |
|
91 function testDocumentDisabledJS() { |
|
92 window.ICanRunMyJS = false; |
|
93 var self_ = window; |
|
94 // Ensure design modes are disabled |
|
95 document.designMode = "off"; |
|
96 iframe.contentDocument.designMode = "off"; |
|
97 |
|
98 // Javascript enabled on the main iframe |
|
99 enableJS(); |
|
100 |
|
101 var doc = iframe.contentDocument; |
|
102 doc.body.innerHTML = "<iframe></iframe>"; |
|
103 var innerFrame = doc.querySelector("iframe"); |
|
104 |
|
105 // Javascript disabled on the innerFrame. |
|
106 allowJS(false, innerFrame); |
|
107 |
|
108 innerFrame.addEventListener("load", function() { |
|
109 innerFrame.removeEventListener("load", arguments.callee, false); |
|
110 |
|
111 var msg = "The inner iframe should not be able to run Javascript"; |
|
112 is(self_.ICanRunMyJS, false, msg); |
|
113 SimpleTest.finish(); |
|
114 }, false); |
|
115 var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>"; |
|
116 innerFrame.src = iframeSrc; |
|
117 } |
|
118 |
|
119 </script> |
|
120 </pre> |
|
121 </body> |
|
122 </html> |
|
123 |