Bug 990353 - Tests. r=bent
☠☠ backed out by 7e51adede3b6 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Fri, 18 Apr 2014 23:46:27 -0700
changeset 179742 74b75c1552050dd846ed1508fc0498cb1e35e952
parent 179741 394e09fe2da2ecc2d8a57fedacaa8563ad6f90b7
child 179743 2926ad6c594fd1ef27907b8d79823dfbbd46fe3f
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbent
bugs990353
milestone31.0a1
Bug 990353 - Tests. r=bent
js/xpconnect/tests/chrome/chrome.ini
js/xpconnect/tests/chrome/file_discardSystemSource.html
js/xpconnect/tests/chrome/mochitest.ini
js/xpconnect/tests/chrome/test_discardSystemSource.xul
js/xpconnect/tests/chrome/worker_discardSystemSource.js
--- a/js/xpconnect/tests/chrome/chrome.ini
+++ b/js/xpconnect/tests/chrome/chrome.ini
@@ -1,13 +1,15 @@
 [DEFAULT]
 support-files =
   bug503926.xul
   file_bug618176.xul
   file_bug996069.html
+  file_discardSystemSource.html
+  worker_discardSystemSource.js
   file_evalInSandbox.html
   file_expandosharing.jsm
   outoflinexulscript.js
   subscript.js
   utf8_subscript.js
 
 [test_APIExposer.xul]
 [test_bug361111.xul]
@@ -52,16 +54,17 @@ support-files =
 [test_bug866823.xul]
 [test_bug895340.xul]
 [test_bug932906.xul]
 [test_bug996069.xul]
 [test_xrayToJS.xul]
 [test_chrometoSource.xul]
 [test_cloneInto.xul]
 [test_cows.xul]
+[test_discardSystemSource.xul]
 [test_documentdomain.xul]
 [test_doublewrappedcompartments.xul]
 [test_evalInSandbox.xul]
 [test_evalInWindow.xul]
 [test_exnstack.xul]
 [test_expandosharing.xul]
 [test_exposeInDerived.xul]
 [test_getweakmapkeys.xul]
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/chrome/file_discardSystemSource.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+  function canary() {
+    var someBitOfSource = 42;
+  }
+  function inner() {
+    throw new Error("some error");
+  }
+  function throwSomething() {
+    inner();
+  }
+</script>
+</head>
+<body onload="someBitOfSource = 42">
+</body>
+</html>
--- a/js/xpconnect/tests/chrome/mochitest.ini
+++ b/js/xpconnect/tests/chrome/mochitest.ini
@@ -1,1 +1,4 @@
 [DEFAULT]
+support-files =
+  file_discardSystemSource.html
+  worker_discardSystemSource.js
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/chrome/test_discardSystemSource.xul
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=990353
+-->
+<window title="Mozilla Bug 990353"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=990353"
+     target="_blank">Mozilla Bug 990353</a>
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+  /** Test for Bug 990353 **/
+  SimpleTest.waitForExplicitFinish();
+  const Cu = Components.utils;
+
+  function canary() {
+    var someBitOfSource = 42;
+  }
+
+  var gLoadCount = 0;
+  function frameLoaded() {
+    switch (++gLoadCount) {
+      case 1:
+        ok(/sourceless/.test(window[0].canary.toSource()), "System function should be sourceless: " + window[0].canary.toSource());
+        ok(/sourceless/.test(window[0].onload.toSource()), "System event handler should be sourceless: " + window[0].onload.toSource());
+        try {
+          window[0].throwSomething();
+          ok(false, "should have thrown");
+        } catch (e) {
+          ok(/some error/.test(e), "Threw exception as expected: " + e);
+          ok(/throwSomething/.test(e.stack), "Exception stack trace works: " + e.stack);
+        }
+        window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
+        break;
+      case 2:
+        ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toSource()), "Content function should have source");
+        ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toSource()), "Content event handler should have source");
+        testWorker();
+        break;
+    }
+  }
+
+  function testWorker() {
+    var worker = new window[0].wrappedJSObject.Worker('worker_discardSystemSource.js');
+    worker.onmessage = function(evt) {
+      ok(/someBitOfSource/.test(evt.data), "Non-chrome worker should have source: " + evt.data);
+      var chromeWorker = new Worker('worker_discardSystemSource.js');
+      chromeWorker.onmessage = function(evt) {
+        ok(/sourceless/.test(evt.data), "Chrome worker should not have source: " + evt.data);
+        SimpleTest.finish();
+      }
+    }
+  }
+
+  function go() {
+    // We should have our own source, because the pref wasn't enabled when we
+    // were loaded.
+    ok(/someBitOfSource/.test(canary.toSource()), "Should have own source");
+
+    window[0].frameElement.onload = frameLoaded;
+    window[0].location = "file_discardSystemSource.html";
+  }
+  addLoadEvent(function() {
+    SpecialPowers.pushPrefEnv({set: [['javascript.options.discardSystemSource', true]]}, go);
+  });
+
+  ]]>
+  </script>
+  <iframe></iframe>
+</window>
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/chrome/worker_discardSystemSource.js
@@ -0,0 +1,5 @@
+function canary() {
+  var someBitOfSource = 42;
+}
+
+postMessage(canary.toSource());