dom/tests/mochitest/bugs/test_bug458091.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug458091.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=458091
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 458091</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=458091">Mozilla Bug 458091</a>
    1.17 +
    1.18 +<div id="content" style="display: none">
    1.19 +
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<a id="testlink1" target="_blank" href="javascript:window.opener.finish(sessionStorage['testItem']);window.close();">Javascript Link</a>
    1.23 +<a id="testlink2" target="_blank" href="bug458091_child.html">HTTP Link</a>
    1.24 +<a id="testlink3" target="alreadyOpened" href="bug458091_child.html">Target Link</a>
    1.25 +<script type="application/javascript">
    1.26 +
    1.27 +/** Test for Bug 458091 **/
    1.28 +
    1.29 +var gTestWin;
    1.30 +var gRunningTests = 0;
    1.31 +
    1.32 +function runNextTest()
    1.33 +{
    1.34 +  if (gTests.length > 0) {
    1.35 +    var test = gTests.shift();
    1.36 +    test();
    1.37 +  } else {
    1.38 +    SimpleTest.finish();
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +function finish(val)
    1.43 +{
    1.44 +  is(val, "correct value",
    1.45 +     "New window should access the correct session storage");
    1.46 +  if (--gRunningTests == 0) {
    1.47 +    runNextTest();
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +SimpleTest.waitForExplicitFinish();
    1.52 +
    1.53 +function test1() {
    1.54 +  sessionStorage["testItem"] = "correct value";
    1.55 +
    1.56 +  gRunningTests++;
    1.57 +  window.open('javascript:window.opener.finish(sessionStorage["testItem"]);window.close();');
    1.58 +
    1.59 +  gRunningTests++;
    1.60 +  window.open("bug458091_child.html");
    1.61 +
    1.62 +  gRunningTests++;
    1.63 +  sendMouseEvent({type: "click"}, "testlink1");
    1.64 +
    1.65 +  gRunningTests++;
    1.66 +  sendMouseEvent({type: "click"}, "testlink2");
    1.67 +
    1.68 +  // targetted load into an existing window
    1.69 +  var testWin = window.open("about:blank", "alreadyOpened");
    1.70 +  gRunningTests++;
    1.71 +  sendMouseEvent({type: "click"}, "testlink3");
    1.72 +
    1.73 +  // window.location into an existing window.  Leave the window open
    1.74 +  // for further tests...
    1.75 +  gRunningTests++;
    1.76 +  gTestWin = window.open("about:blank", "testWindow");
    1.77 +  gTestWin.location = 'javascript:window.opener.finish(sessionStorage["testItem"]);';
    1.78 +}
    1.79 +
    1.80 +function test2() {
    1.81 +  // Now change session storage and load a new item in gTestWin, to
    1.82 +  // verify that they properly diverged after window.open().
    1.83 +  gRunningTests++;
    1.84 +  sessionStorage["testItem"] = "incorrect value";
    1.85 +  gTestWin.location = 'javascript:window.opener.finish(sessionStorage["testItem"]);';
    1.86 +}
    1.87 +
    1.88 +function test3()
    1.89 +{
    1.90 +  // Now, with session storage still changed, try the window.open()
    1.91 +  // path, make sure it doesn't overwrite the session storage.
    1.92 +  gRunningTests++;
    1.93 +  window.open('javascript:window.opener.finish(sessionStorage["testItem"]);window.close();',
    1.94 +              "testWindow");
    1.95 +}
    1.96 +
    1.97 +var gTests = [test1, test2, test3];
    1.98 +runNextTest();
    1.99 +
   1.100 +</script>
   1.101 +</pre>
   1.102 +</body>
   1.103 +</html>

mercurial