js/xpconnect/tests/chrome/test_discardSystemSource.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_discardSystemSource.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=990353
     1.9 +-->
    1.10 +<window title="Mozilla Bug 990353"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +
    1.14 +  <!-- test results are displayed in the html:body -->
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.16 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=990353"
    1.17 +     target="_blank">Mozilla Bug 990353</a>
    1.18 +  </body>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +  <script type="application/javascript">
    1.22 +  <![CDATA[
    1.23 +  /** Test for Bug 990353 **/
    1.24 +  SimpleTest.waitForExplicitFinish();
    1.25 +  const Cu = Components.utils;
    1.26 +
    1.27 +  function canary() {
    1.28 +    var someBitOfSource = 42;
    1.29 +  }
    1.30 +
    1.31 +  var gLoadCount = 0;
    1.32 +  function frameLoaded() {
    1.33 +    switch (++gLoadCount) {
    1.34 +      case 1:
    1.35 +        ok(/sourceless/.test(window[0].canary.toSource()), "System function should be sourceless: " + window[0].canary.toSource());
    1.36 +        ok(/sourceless/.test(window[0].onload.toSource()), "System event handler should be sourceless: " + window[0].onload.toSource());
    1.37 +        var sb = new Cu.Sandbox('http://www.example.com', { discardSource: true });
    1.38 +        Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb);
    1.39 +        ok(/sourceless/.test(sb.canary.toSource()), "Function from sandbox with explicit discarding should be sourceless");
    1.40 +        try {
    1.41 +          window[0].throwSomething();
    1.42 +          ok(false, "should have thrown");
    1.43 +        } catch (e) {
    1.44 +          ok(/some error/.test(e), "Threw exception as expected: " + e);
    1.45 +          ok(/throwSomething/.test(e.stack), "Exception stack trace works: " + e.stack);
    1.46 +        }
    1.47 +        window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
    1.48 +        break;
    1.49 +      case 2:
    1.50 +        ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toSource()), "Content function should have source");
    1.51 +        ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toSource()), "Content event handler should have source");
    1.52 +        testWorker();
    1.53 +        break;
    1.54 +    }
    1.55 +  }
    1.56 +
    1.57 +  function testWorker() {
    1.58 +    var worker = new window[0].wrappedJSObject.Worker('worker_discardSystemSource.js');
    1.59 +    worker.onmessage = function(evt) {
    1.60 +      ok(/someBitOfSource/.test(evt.data), "Non-chrome worker should have source: " + evt.data);
    1.61 +      var chromeWorker = new Worker('worker_discardSystemSource.js');
    1.62 +      chromeWorker.onmessage = function(evt) {
    1.63 +        ok(/sourceless/.test(evt.data), "Chrome worker should not have source: " + evt.data);
    1.64 +        SimpleTest.finish();
    1.65 +      }
    1.66 +    }
    1.67 +  }
    1.68 +
    1.69 +  function go() {
    1.70 +    // We should have our own source, because the pref wasn't enabled when we
    1.71 +    // were loaded.
    1.72 +    ok(/someBitOfSource/.test(canary.toSource()), "Should have own source");
    1.73 +
    1.74 +    window[0].frameElement.onload = frameLoaded;
    1.75 +    window[0].location = "file_discardSystemSource.html";
    1.76 +  }
    1.77 +  addLoadEvent(function() {
    1.78 +    SpecialPowers.pushPrefEnv({set: [['javascript.options.discardSystemSource', true]]}, go);
    1.79 +  });
    1.80 +
    1.81 +  ]]>
    1.82 +  </script>
    1.83 +  <iframe></iframe>
    1.84 +</window>

mercurial