Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / chrome / test_discardSystemSource.xhtml
blob86a353e5807c7e1f5262935763ae85e63657e353
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=990353
6 -->
7 <window title="Mozilla Bug 990353"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
11 <!-- test results are displayed in the html:body -->
12 <body xmlns="http://www.w3.org/1999/xhtml">
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=990353"
14 target="_blank">Mozilla Bug 990353</a>
15 </body>
17 <!-- test code goes here -->
18 <script type="application/javascript">
19 <![CDATA[
20 /** Test for Bug 990353 **/
21 SimpleTest.waitForExplicitFinish();
23 function canary() {
24 // eslint-disable-next-line no-unused-vars
25 var someBitOfSource = 42;
28 var gLoadCount = 0;
29 function frameLoaded() {
30 switch (++gLoadCount) {
31 case 1:
32 ok(/native code/.test(window[0].canary.toString()), "System function should be sourceless: " + window[0].canary.toString());
33 ok(/native code/.test(window[0].onload.toString()), "System event handler should be sourceless: " + window[0].onload.toString());
34 var sb = new Cu.Sandbox("https://www.example.com", { discardSource: true });
35 Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb);
36 ok(/native code/.test(sb.canary.toString()), "Function from sandbox with explicit discarding should be sourceless");
37 try {
38 window[0].throwSomething();
39 ok(false, "should have thrown");
40 } catch (e) {
41 ok(/some error/.test(e), "Threw exception as expected: " + e);
42 ok(/throwSomething/.test(e.stack), "Exception stack trace works: " + e.stack);
44 window[0].location = "https://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
45 break;
46 case 2:
47 ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toString()), "Content function should have source");
48 ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toString()), "Content event handler should have source");
49 testWorker();
50 break;
54 function testWorker() {
55 var worker = new window[0].wrappedJSObject.Worker('worker_discardSystemSource.js');
56 worker.onmessage = function(evt) {
57 ok(/someBitOfSource/.test(evt.data), "Non-chrome worker should have source: " + evt.data);
58 var chromeWorker = new Worker('worker_discardSystemSource.js');
59 chromeWorker.onmessage = function(evt) {
60 ok(/native code/.test(evt.data), "Chrome worker should not have source: " + evt.data);
61 SimpleTest.finish();
66 function go() {
67 // We should have our own source, because the pref wasn't enabled when we
68 // were loaded.
69 ok(/someBitOfSource/.test(canary.toString()), "Should have own source");
71 window[0].frameElement.onload = frameLoaded;
72 window[0].location = "file_discardSystemSource.html";
74 addLoadEvent(function() {
75 SpecialPowers.pushPrefEnv({set: [['javascript.options.discardSystemSource', true]]}, go);
76 });
78 ]]>
79 </script>
80 <iframe></iframe>
81 </window>