editor/composer/test/test_bug519928.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/composer/test/test_bug519928.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=519928
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 519928</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=519928">Mozilla Bug 519928</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content">
    1.18 +<iframe id="load-frame"></iframe>  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +
    1.23 +var iframe = document.getElementById("load-frame");
    1.24 +
    1.25 +function enableJS() allowJS(true, iframe);
    1.26 +function disableJS() allowJS(false, iframe);
    1.27 +function allowJS(allow, frame) {
    1.28 +  SpecialPowers.wrap(frame.contentWindow)
    1.29 +               .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
    1.30 +               .getInterface(SpecialPowers.Ci.nsIWebNavigation)
    1.31 +               .QueryInterface(SpecialPowers.Ci.nsIDocShell)
    1.32 +               .allowJavascript = allow;
    1.33 +}
    1.34 +function expectJSAllowed(allowed, testCondition, callback) {
    1.35 +  window.ICanRunMyJS = false;
    1.36 +  var self_ = window;
    1.37 +  testCondition();
    1.38 +
    1.39 +  var doc = iframe.contentDocument;
    1.40 +  doc.body.innerHTML = "<iframe></iframe>";
    1.41 +  var innerFrame = doc.querySelector("iframe");
    1.42 +  innerFrame.addEventListener("load", function() {
    1.43 +    innerFrame.removeEventListener("load", arguments.callee, false);
    1.44 +
    1.45 +    var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript";
    1.46 +    is(self_.ICanRunMyJS, allowed, msg);
    1.47 +    callback();
    1.48 +  }, false);
    1.49 +  var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
    1.50 +  innerFrame.src = iframeSrc;
    1.51 +}
    1.52 +
    1.53 +SimpleTest.waitForExplicitFinish();
    1.54 +addLoadEvent(function() {
    1.55 +  var enterDesignMode = function() document.designMode = "on";
    1.56 +  var leaveDesignMode = function() document.designMode = "off";
    1.57 +  expectJSAllowed(false, disableJS, function() {
    1.58 +    expectJSAllowed(true, enableJS, function() {
    1.59 +      expectJSAllowed(true, enterDesignMode, function() {
    1.60 +        expectJSAllowed(true, leaveDesignMode, function() {
    1.61 +          expectJSAllowed(false, disableJS, function() {
    1.62 +            expectJSAllowed(false, enterDesignMode, function() {
    1.63 +              expectJSAllowed(false, leaveDesignMode, function() {
    1.64 +                expectJSAllowed(true, enableJS, function() {
    1.65 +                  enterDesignMode = function() iframe.contentDocument.designMode = "on";
    1.66 +                  leaveDesignMode = function() iframe.contentDocument.designMode = "off";
    1.67 +                  expectJSAllowed(false, disableJS, function() {
    1.68 +                    expectJSAllowed(true, enableJS, function() {
    1.69 +                      expectJSAllowed(true, enterDesignMode, function() {
    1.70 +                        expectJSAllowed(true, leaveDesignMode, function() {
    1.71 +                          expectJSAllowed(false, disableJS, function() {
    1.72 +                            expectJSAllowed(false, enterDesignMode, function() {
    1.73 +                              expectJSAllowed(false, leaveDesignMode, function() {
    1.74 +                                expectJSAllowed(true, enableJS, function() {
    1.75 +                                  testDocumentDisabledJS();
    1.76 +                                });
    1.77 +                              });
    1.78 +                            });
    1.79 +                          });
    1.80 +                        });
    1.81 +                      });
    1.82 +                    });
    1.83 +                  });
    1.84 +                });
    1.85 +              });
    1.86 +            });
    1.87 +          });
    1.88 +        });
    1.89 +      });
    1.90 +    });
    1.91 +  });
    1.92 +});
    1.93 +
    1.94 +function testDocumentDisabledJS() {
    1.95 +  window.ICanRunMyJS = false;
    1.96 +  var self_ = window;
    1.97 +  // Ensure design modes are disabled
    1.98 +  document.designMode = "off";
    1.99 +  iframe.contentDocument.designMode = "off";
   1.100 +
   1.101 +  // Javascript enabled on the main iframe
   1.102 +  enableJS();
   1.103 +
   1.104 +  var doc = iframe.contentDocument;
   1.105 +  doc.body.innerHTML = "<iframe></iframe>";
   1.106 +  var innerFrame = doc.querySelector("iframe");
   1.107 +
   1.108 +  // Javascript disabled on the innerFrame.
   1.109 +  allowJS(false, innerFrame);
   1.110 +
   1.111 +  innerFrame.addEventListener("load", function() {
   1.112 +    innerFrame.removeEventListener("load", arguments.callee, false);
   1.113 +
   1.114 +    var msg = "The inner iframe should not be able to run Javascript";
   1.115 +    is(self_.ICanRunMyJS, false, msg);
   1.116 +    SimpleTest.finish();
   1.117 +  }, false);
   1.118 +  var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
   1.119 +  innerFrame.src = iframeSrc;
   1.120 +}
   1.121 +
   1.122 +</script>
   1.123 +</pre>
   1.124 +</body>
   1.125 +</html>
   1.126 +

mercurial