docshell/test/test_bug413310.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bug413310.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=413310
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 413310</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=413310">Mozilla Bug 413310</a>
    1.16 +<p id="display">
    1.17 +<script class="testbody" type="text/javascript">
    1.18 +
    1.19 +if (navigator.platform.startsWith("Mac")) {
    1.20 +  SimpleTest.expectAssertions(0, 2);
    1.21 +} else {
    1.22 +  SimpleTest.expectAssertions(0, 1);
    1.23 +}
    1.24 +
    1.25 +/** Test for Bug 413310 **/
    1.26 +
    1.27 +// NOTE: If we ever make subframes do bfcache stuff, this test will need to be
    1.28 +// modified accordingly!  It assumes that subframes do NOT get bfcached.
    1.29 +var onloadCount = 0;
    1.30 +
    1.31 +var step = -1;  // One increment will come from the initial subframe onload.
    1.32 +                // Note that this script should come before the subframe,
    1.33 +                // so that doNextStep is defined when its onload handler fires.
    1.34 +
    1.35 +var textContent;
    1.36 +
    1.37 +SimpleTest.waitForExplicitFinish();
    1.38 +
    1.39 +addLoadEvent(doNextStep);
    1.40 +
    1.41 +function doNextStep() {
    1.42 +  ++step;
    1.43 +  switch (step) {
    1.44 +    case 1:
    1.45 +      is(onloadCount, 1, "Loaded initial page");
    1.46 +      is($("i").contentWindow.location.href,
    1.47 +         location.href.replace(/test_bug413310.html/,
    1.48 +                               "bug413310-subframe.html"),
    1.49 +         "Unexpected subframe location after initial load");
    1.50 +      $("i").contentDocument.forms[0].submit();
    1.51 +      break;
    1.52 +    case 2:
    1.53 +      is(onloadCount, 2, "Loaded POST result");
    1.54 +
    1.55 +      is($("i").contentWindow.location.href,
    1.56 +         location.href.replace(/test_bug413310.html/,
    1.57 +                               "bug413310-post.sjs"),
    1.58 +         "Unexpected subframe location after POST load");
    1.59 +
    1.60 +      textContent = $("i").contentDocument.body.textContent;
    1.61 +      isDeeply(textContent.match(/^POST /), ["POST "], "Not a POST?");
    1.62 +
    1.63 +      $("i").contentWindow.location.hash = "foo";
    1.64 +      setTimeout(doNextStep, 0);
    1.65 +      break;
    1.66 +    case 3: 
    1.67 +      is(onloadCount, 2, "Anchor scroll should not fire onload");
    1.68 +      is($("i").contentWindow.location.href,
    1.69 +         location.href.replace(/test_bug413310.html/,
    1.70 +                               "bug413310-post.sjs#foo"),
    1.71 +         "Unexpected subframe location after anchor scroll");
    1.72 +      is(textContent, $("i").contentDocument.body.textContent,
    1.73 +         "Did a load when scrolling?");
    1.74 +      $("i").contentWindow.location.href = "bug413310-subframe.html";;
    1.75 +      break;
    1.76 +    case 4:
    1.77 +      is(onloadCount, 3, "Done new load");
    1.78 +      is($("i").contentWindow.location.href,
    1.79 +         location.href.replace(/test_bug413310.html/,
    1.80 +                               "bug413310-subframe.html"),
    1.81 +         "Unexpected subframe location after new load");
    1.82 +      history.back();
    1.83 +      break;
    1.84 +    case 5:
    1.85 +      is(onloadCount, 4,
    1.86 +         "History traversal didn't fire onload: bfcache issues!");
    1.87 +      is($("i").contentWindow.location.href,
    1.88 +         location.href.replace(/test_bug413310.html/,
    1.89 +                               "bug413310-post.sjs#foo"),
    1.90 +         "Unexpected subframe location");
    1.91 +      is(textContent, $("i").contentDocument.body.textContent,
    1.92 +         "Did a load when going back?");
    1.93 +      SimpleTest.finish();
    1.94 +      break;
    1.95 +  }
    1.96 +}
    1.97 +</script>
    1.98 +<!-- Use a timeout in onload so that we don't do a load immediately inside onload -->
    1.99 +<iframe id="i" src="bug413310-subframe.html" onload="setTimeout(doNextStep, 20)">
   1.100 +</iframe>
   1.101 +</p>
   1.102 +<div id="content" style="display: none">
   1.103 +  
   1.104 +</div>
   1.105 +<pre id="test">
   1.106 +</pre>
   1.107 +</body>
   1.108 +</html>
   1.109 +

mercurial