js/xpconnect/tests/chrome/test_discardSystemSource.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial