Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/tests/mochitest/bugs/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 6 kB image not shown  

Quelle  test_bug346659.html

  Sprache: HTML
 

 products/Sources/formale Sprachen/C/Firefox/dom/tests/mochitest/bugs/test_bug346659.html


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

<head>
  <title>Test for Bug 346659</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=346659">Mozilla Bug 346659</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 346659 **/
var numTests = 10;
SimpleTest.requestLongerTimeout(2); // test takes a long time on android and b2g emulators
SimpleTest.waitForExplicitFinish();

var wins = [];

function r(base, tail) {
  return base.replace(/\/[^\/]*$/, "/" + tail);
}

/**
 * This function sets up the test according to the data it receives. If the data
 * is a JSON string, it will use the object parsed from that to determine how to
 * set up the test.
 */
async function handleCmd(evt) {
  var cmd;
  try {
    cmd = JSON.parse(evt.data);
  } catch (e) {
    // Not json, so it should be a test result. We don't need to set up test.
    return false;
  }  

  if ("load" in cmd) {
    var testNum = cmd.load;

    // Set up the testing window property and get necessary information from it.
    // We use SpecialPowers.spawn() here since the testing window could be cross
    // origin.
    var { isOpenerTest, location } =
      await SpecialPowers.spawn(wins[testNum], [testNum], testNum => {
        var win = content.wrappedJSObject;
        win.childWin.x = testNum;

        return {
          isOpenerTest: win.childWin.opener == win,
          location: content.location.href,
        };
      });

    // Get the test location according to the test.
    if (isOpenerTest) {
      if ("xsite" in cmd) {
        var loc = r(window.location.href, "bug346659-opener-echoer.html?" + testNum);
      } else {
        var loc = r(location, "bug346659-opener-echoer.html?" + testNum);
      }
    } else {
      if ("xsite" in cmd) {
        var loc = r(window.location.href, "bug346659-parent-echoer.html?" + testNum);
      } else {
        var loc = r(location, "bug346659-parent-echoer.html?" + testNum);
      }
    }

    // Trigger the loading on the child window of the testing window.
    await SpecialPowers.spawn(wins[testNum], [loc], loc => {
      content.wrappedJSObject.childWin.location.href = loc;
    });
    wins[testNum] = null;
  } else if ("write" in cmd) {
    var testNum = cmd.write;

    try {
      // Set up the test on the testing window.
      await SpecialPowers.spawn(wins[testNum], [testNum], testNum => {
        var win = content.wrappedJSObject;
        win.childWin.x = testNum;

        // Test document.write().
        if (win.childWin.opener == win) {
          win.childWin.document.write(`
            <script>
              window.opener.opener.postMessage("${testNum} - " + window.x, "http://mochi.test:8888/");
              window.opener.close();
              window.close();
            <` + '/script>');
        } else {
          win.childWin.document.write(`
            <script>
              window.parent.opener.postMessage("${testNum} - " + window.x, "http://mochi.test:8888/");
              window.parent.close();
            <` + '/script>');
        }
      });
    } catch (e) {
      if (e.name != "SecurityError" || e.code != 18) {
        throw e;
      }
      // Security error on cross-site write() is fine
      await SpecialPowers.spawn(wins[testNum], [], () => {
        var win = content.wrappedJSObject;
        if (win.childWin.opener == win) {
          win.childWin.close();
        }
      });

      handleTestEnd();
    }
    wins[testNum] = null;
  }
  return true;
}

async function messageReceiver(evt) {
  // First try to detect a load/write command
  if (await handleCmd(evt)) {
    return;
  }

  var testNumber = parseInt(evt.data);
  var testResult = evt.data.substring(3 + Math.floor(Math.log(testNumber) * Math.LOG10E + 1));

  switch (testNumber) {
    case 1:
      is(testResult, "1""Props on new window should be preserved when loading");
      break;
    case 2:
      is(testResult, "2""Props on new window should be preserved when writing");
      break;
    case 3:
      is(testResult, "3""Props on window opened from new window should be preserved when loading");
      break;
    case 4:
      is(testResult, "4""Props on window opened from new window should be preserved when writing");
      break;
    case 5:
      is(testResult, "undefined""Props on new window's child should go away when loading");
      break;
    case 6:
      is(testResult, "6""Props on new window's child should not go away when writing");
      break;
    case 7:
      is(testResult, "7""Props on different-domain window opened from different-domain new window can stay");
      break;
    case 9:
      is(testResult, "undefined""Props on different-domain new window's child should go away when loading");
      break;
    case 11:
      is(testResult, "undefined""Props on same-domain window opened from different-domain new window should go away when loading");
      break;
    case 12:
      is(testResult, "undefined""Props on different-domain new window's same-domain child should go away when loading");
      break;
    default:
      ok(0, "unexpected test number (" + testNumber + ") when data is " + evt.data);
  }

  handleTestEnd();
}

function handleTestEnd() {
  if (!--numTests) {
    SimpleTest.finish();
  }
}
window.addEventListener("message", messageReceiver);

var win = window.open("");
win.x = 1;
win.location.href = "bug346659-echoer.html";

win = window.open("");
win.x = 2;
win.document.write('<script> window.opener.postMessage("2 - " + window.x, window.location.href); window.close(); </' + 'script>');

wins[3] = window.open('bug346659-opener.html?{"load":3}');
wins[4] = window.open('bug346659-opener.html?{"write":4}');
wins[5] = window.open('bug346659-parent.html?{"load":5}');
wins[6] = window.open('bug346659-parent.html?{"write":6}');

is(location.host, "mochi.test:8888""Unexpected host");

SpecialPowers.pushPrefEnv({"set": [["dom.security.https_first", false]]}, function() {
  var baseurl = window.location.href.replace(/mochi\.test:8888/, "example.com");
  wins[7] = window.open(r(baseurl, 'bug346659-opener.html?{"load":7}'));
  wins[9] = window.open(r(baseurl, 'bug346659-parent.html?{"load":9}'));

  wins[11] = window.open(r(baseurl, 'bug346659-opener.html?{"load":11,"xsite":true}'));
  wins[12] = window.open(r(baseurl, 'bug346659-parent.html?{"load":12,"xsite":true}'));
});

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

Messung V0.5 in Prozent
C=100 H=100 G=100

¤ Dauer der Verarbeitung: 0.25 Sekunden  (vorverarbeitet am  2026-04-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.