editor/composer/test/test_bug519928.html
author Bas Schouten <bschouten@mozilla.com>
Wed, 08 Sep 2010 05:27:29 +0200
changeset 52172 87d1bedd44d9876492744c82929923dc26821c73
parent 48119 05a194f6de30fb8694bc5e4c98b56eeb9092c885
child 69764 1d5ffdf05dab05ee9ad3edc92878b8bd45d4c378
permissions -rw-r--r--
Bug 593268 - Part 1: Expose LayerManager::CreateOptimalSurface. r=vlad sr=roc

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=519928
-->
<head>
  <title>Test for Bug 519928</title>
  <script type="text/javascript" src="/MochiKit/packed.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=519928">Mozilla Bug 519928</a>
<p id="display"></p>
<div id="content">
<iframe id="load-frame"></iframe>  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

var iframe = document.getElementById("load-frame");

function enableJS() allowJS(true, iframe);
function disableJS() allowJS(false, iframe);
function allowJS(allow, frame) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  frame.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIWebNavigation)
                     .QueryInterface(Components.interfaces.nsIDocShell)
                     .allowJavascript = allow;
}
function expectJSAllowed(allowed, testCondition, callback) {
  window.ICanRunMyJS = false;
  var self_ = window;
  testCondition();

  var doc = iframe.contentDocument;
  doc.body.innerHTML = "<iframe></iframe>";
  var innerFrame = doc.querySelector("iframe");
  innerFrame.addEventListener("load", function() {
    innerFrame.removeEventListener("load", arguments.callee, false);

    var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript";
    is(self_.ICanRunMyJS, allowed, msg);
    callback();
  }, false);
  var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
  innerFrame.src = iframeSrc;
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
  var enterDesignMode = function() document.designMode = "on";
  var leaveDesignMode = function() document.designMode = "off";
  expectJSAllowed(false, disableJS, function() {
    expectJSAllowed(true, enableJS, function() {
      expectJSAllowed(true, enterDesignMode, function() {
        expectJSAllowed(true, leaveDesignMode, function() {
          expectJSAllowed(false, disableJS, function() {
            expectJSAllowed(false, enterDesignMode, function() {
              expectJSAllowed(false, leaveDesignMode, function() {
                expectJSAllowed(true, enableJS, function() {
                  enterDesignMode = function() iframe.contentDocument.designMode = "on";
                  leaveDesignMode = function() iframe.contentDocument.designMode = "off";
                  expectJSAllowed(false, disableJS, function() {
                    expectJSAllowed(true, enableJS, function() {
                      expectJSAllowed(true, enterDesignMode, function() {
                        expectJSAllowed(true, leaveDesignMode, function() {
                          expectJSAllowed(false, disableJS, function() {
                            expectJSAllowed(true, enterDesignMode, function() {
                              expectJSAllowed(false, leaveDesignMode, function() {
                                expectJSAllowed(true, enableJS, function() {
                                  testDocumentDisabledJS();
                                });
                              });
                            });
                          });
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
  });
});

function testDocumentDisabledJS() {
  window.ICanRunMyJS = false;
  var self_ = window;
  // Ensure design modes are disabled
  document.designMode = "off";
  iframe.contentDocument.designMode = "off";

  // Javascriont enabled on the main iframe
  enableJS();

  var doc = iframe.contentDocument;
  doc.body.innerHTML = "<iframe></iframe>";
  var innerFrame = doc.querySelector("iframe");

  // Javascript disabled on the innerFrame.
  allowJS(false, innerFrame);

  innerFrame.addEventListener("load", function() {
    innerFrame.removeEventListener("load", arguments.callee, false);

    var msg = "The inner iframe should not be able to run Javascript";
    is(self_.ICanRunMyJS, false, msg);
    SimpleTest.finish();
    endTest();
  }, false);
  var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
  innerFrame.src = iframeSrc;
}

</script>
</pre>
</body>
</html>