Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/editor/composer/test/     Datei vom 27.6.2026 mit Größe 3 kB image not shown  

Quelle  test_bug519928.html  Sprache: HTML


 products/Sources/formale Sprachen/C/Firefox/editor/composer/test/test_bug519928.html


<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=519928
-->

<head>
  <title>Test for Bug 519928</title>
  <script 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) {
  SpecialPowers.wrap(frame.contentWindow).windowGlobalChild.windowContext.allowJavascript = allow;
}

async function expectJSAllowed(allowed, testCondition) {
  window.ICanRunMyJS = false;
  const self_ = window;
  testCondition();

  const doc = iframe.contentDocument;
  const innerFrame = doc.createElement("iframe");
  // eslint-disable-next-line no-useless-concat
  innerFrame.srcdoc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
  const loaded = new Promise(resolve => innerFrame.onload = resolve);
  doc.body.append(innerFrame);

  await loaded;
  is(self_.ICanRunMyJS, allowed, "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript");

  innerFrame.remove();
}

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

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

  const doc = iframe.contentDocument;
  const innerFrame = doc.createElement("iframe");
  // eslint-disable-next-line no-useless-concat
  innerFrame.srcdoc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
  const loaded = new Promise(resolve => innerFrame.onload = resolve);
  doc.body.append(innerFrame);

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

  await loaded;
  is(self_.ICanRunMyJS, false, "The inner iframe should not be able to run Javascript");

  innerFrame.remove();
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(async function() {
  var enterDesignMode = function() { document.designMode = "on"; };
  var leaveDesignMode = function() { document.designMode = "off"; };

  await expectJSAllowed(false, disableJS);
  await expectJSAllowed(true, enableJS);
  await expectJSAllowed(true, enterDesignMode);
  await expectJSAllowed(true, leaveDesignMode);
  await expectJSAllowed(false, disableJS);
  await expectJSAllowed(false, enterDesignMode);
  await expectJSAllowed(false, leaveDesignMode);
  await expectJSAllowed(true, enableJS);

  enterDesignMode = function() { iframe.contentDocument.designMode = "on"; };
  leaveDesignMode = function() { iframe.contentDocument.designMode = "off"; };

  await expectJSAllowed(false, disableJS);
  await expectJSAllowed(true, enableJS);
  await expectJSAllowed(true, enterDesignMode);
  await expectJSAllowed(true, leaveDesignMode);
  await expectJSAllowed(false, disableJS);
  await expectJSAllowed(false, enterDesignMode);
  await expectJSAllowed(false, leaveDesignMode);
  await expectJSAllowed(true, enableJS);

  await testDocumentDisabledJS();

  SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

Messung
CHZG
899910096

¤ Dauer der Verarbeitung: 0.23 Sekunden  ¤

*© Formatika GbR, Deutschland