Bug 1051224 - Test console's cd() against sandboxed iframes. r=msucan a=sylvestre
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 22 Sep 2014 19:37:07 +0200
changeset 216816 0ae1af037f6e
parent 216815 6cdc428e3e62
child 216817 9337f5dcf107
push id3923
push userbobbyholley@gmail.com
push date2014-09-22 17:37 +0000
treeherdermozilla-beta@0ae1af037f6e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsucan, sylvestre
bugs1051224
milestone33.0
Bug 1051224 - Test console's cd() against sandboxed iframes. r=msucan a=sylvestre
toolkit/devtools/webconsole/test/chrome.ini
toolkit/devtools/webconsole/test/common.js
toolkit/devtools/webconsole/test/sandboxed_iframe.html
toolkit/devtools/webconsole/test/test_jsterm_cd_iframe.html
--- a/toolkit/devtools/webconsole/test/chrome.ini
+++ b/toolkit/devtools/webconsole/test/chrome.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 support-files =
   common.js
   data.json
   data.json^headers^
   network_requests_iframe.html
+  sandboxed_iframe.html
 
 [test_basics.html]
 [test_bug819670_getter_throws.html]
 [test_cached_messages.html]
 [test_consoleapi.html]
 [test_consoleapi_innerID.html]
 [test_file_uri.html]
 [test_reflow.html]
--- a/toolkit/devtools/webconsole/test/common.js
+++ b/toolkit/devtools/webconsole/test/common.js
@@ -115,16 +115,19 @@ function checkObject(aObject, aExpected)
 function checkValue(aName, aValue, aExpected)
 {
   if (aExpected === null) {
     ok(!aValue, "'" + aName + "' is null");
   }
   else if (aValue === undefined) {
     ok(false, "'" + aName + "' is undefined");
   }
+  else if (aValue === null) {
+    ok(false, "'" + aName + "' is null");
+  }
   else if (typeof aExpected == "string" || typeof aExpected == "number" ||
            typeof aExpected == "boolean") {
     is(aValue, aExpected, "property '" + aName + "'");
   }
   else if (aExpected instanceof RegExp) {
     ok(aExpected.test(aValue), aName + ": " + aExpected + " matched " + aValue);
   }
   else if (Array.isArray(aExpected)) {
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/webconsole/test/sandboxed_iframe.html
@@ -0,0 +1,8 @@
+<html>
+<head><title>Sandboxed iframe</title></head>
+<body>
+  <iframe id="sandboxed-iframe"
+          sandbox="allow-scripts"
+          srcdoc="<script>var foobarObject = {bug1051224: 'sandboxed'};</script>"></iframe>
+</body>
+</html>
--- a/toolkit/devtools/webconsole/test/test_jsterm_cd_iframe.html
+++ b/toolkit/devtools/webconsole/test/test_jsterm_cd_iframe.html
@@ -6,16 +6,18 @@
   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript;version=1.8" src="common.js"></script>
   <!-- Any copyright is dedicated to the Public Domain.
      - http://creativecommons.org/publicdomain/zero/1.0/ -->
 </head>
 <body>
 <p>Test for the cd() function</p>
 
+<iframe id="content-iframe" src="http://example.com/chrome/toolkit/devtools/webconsole/test/sandboxed_iframe.html"></iframe>
+
 <script class="testbody" type="text/javascript;version=1.8">
 SimpleTest.waitForExplicitFinish();
 
 let gState;
 
 function startTest()
 {
   removeEventListener("load", startTest);
@@ -28,17 +30,21 @@ function onAttach(aState, aResponse)
   top.foobarObject = Object.create(null);
   top.foobarObject.bug609872 = "parent";
 
   window.foobarObject = Object.create(null);
   window.foobarObject.bug609872 = "child";
 
   gState = aState;
 
-  let tests = [doCheckParent, doCdIframe, doCheckIframe, doCdParent,
+  let tests = [doCheckParent, doCdIframe, doCheckIframe,
+      doCdContentIframe,
+      doCdSandboxedIframe, doCheckSandboxedIframe,
+      doCdParent,
+      doCdParent,
       doCheckParent2];
   runTests(tests, testEnd);
 }
 
 function doCheckParent()
 {
   info("check parent window");
   gState.client.evaluateJS("window.foobarObject.bug609872",
@@ -95,16 +101,79 @@ function onFooObjectFromIframe(aResponse
   });
 
   ok(!aResponse.exception, "no js eval exception");
   ok(!aResponse.helperResult, "no helper result");
 
   nextTest();
 }
 
+function doCdContentIframe()
+{
+  info("test cd('#content-iframe')");
+  gState.client.evaluateJS("cd('#content-iframe')", onCdContentIframe);
+}
+
+function onCdContentIframe(aResponse)
+{
+  checkObject(aResponse, {
+    from: gState.actor,
+    input: "cd('#content-iframe')",
+    result: { type: "undefined" },
+    helperResult: { type: "cd" },
+  });
+
+  ok(!aResponse.exception, "no eval exception");
+
+  nextTest();
+}
+function doCdSandboxedIframe()
+{
+  // Don't use string to ensure we don't get security exception
+  // when passing a content window reference.
+  let cmd = "cd(document.getElementById('sandboxed-iframe').contentWindow)";
+  info("test " + cmd);
+  gState.client.evaluateJS(cmd, onCdSandboxedIframe.bind(null, cmd));
+}
+
+function onCdSandboxedIframe(cmd, aResponse)
+{
+  checkObject(aResponse, {
+    from: gState.actor,
+    input: cmd,
+    result: { type: "undefined" },
+    helperResult: { type: "cd" },
+  });
+
+  ok(!aResponse.exception, "no eval exception");
+
+  nextTest();
+}
+
+function doCheckSandboxedIframe()
+{
+  info("check foobarObject from the sandboxed iframe");
+  gState.client.evaluateJS("window.foobarObject.bug1051224",
+                           onFooObjectFromSandboxedIframe);
+}
+
+function onFooObjectFromSandboxedIframe(aResponse)
+{
+  checkObject(aResponse, {
+    from: gState.actor,
+    input: "window.foobarObject.bug1051224",
+    result: "sandboxed",
+  });
+
+  ok(!aResponse.exception, "no js eval exception");
+  ok(!aResponse.helperResult, "no helper result");
+
+  nextTest();
+}
+
 function doCdParent()
 {
   info("test cd() back to parent");
   gState.client.evaluateJS("cd()", onCdParent);
 }
 
 function onCdParent(aResponse)
 {