docshell/test/test_bfcache_plus_hash.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bfcache_plus_hash.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=646641
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 646641</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.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=646641">Mozilla Bug 646641</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript;version=1.7">
    1.23 +
    1.24 +/** Test for Bug 646641 **/
    1.25 +
    1.26 +/* 
    1.27 + * In a popup (because navigating the main frame confuses Mochitest), do the
    1.28 + * following:
    1.29 + *
    1.30 + *  * Call history.pushState().
    1.31 + *  * Navigate to a new page.
    1.32 + *  * Go back two history entries.
    1.33 + *
    1.34 + * Check that we go back, we retrieve the document from bfcache.
    1.35 + */
    1.36 +
    1.37 +SimpleTest.waitForExplicitFinish();
    1.38 +
    1.39 +function debug(msg) {
    1.40 +  // Wrap dump so we can turn debug messages on and off easily.
    1.41 +  dump(msg + '\n');
    1.42 +}
    1.43 +
    1.44 +var expectedLoadNum = -1;
    1.45 +function childLoad(n) {
    1.46 +  if (n == expectedLoadNum) {
    1.47 +    debug('Got load ' + n);
    1.48 +    expectedLoadNum = -1;
    1.49 +
    1.50 +    // Spin the event loop before calling gGen.next() so the generator runs
    1.51 +    // outside the onload handler.  This prevents us from encountering all
    1.52 +    // sorts of docshell quirks.
    1.53 +    //
    1.54 +    // (I don't know why I need to wrap gGen.next() in a function, but it
    1.55 +    // throws an error otherwise.)
    1.56 +    setTimeout(function() { gGen.next() }, 0);
    1.57 +  }
    1.58 +  else {
    1.59 +    debug('Got unexpected load ' + n);
    1.60 +    ok(false, 'Got unexpected load ' + n);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +var expectedPageshowNum = -1;
    1.65 +function childPageshow(n) {
    1.66 +  if (n == expectedPageshowNum) {
    1.67 +    debug('Got expected pageshow ' + n);
    1.68 +    expectedPageshowNum = -1;
    1.69 +    ok(true, 'Got expected pageshow ' + n);
    1.70 +    setTimeout(function() { gGen.next() }, 0);
    1.71 +  }
    1.72 +  else {
    1.73 +    debug('Got pageshow ' + n);
    1.74 +  }
    1.75 +
    1.76 +  // Since a pageshow comes along with an onload, don't fail the test if we get
    1.77 +  // an unexpected pageshow.
    1.78 +}
    1.79 +
    1.80 +function waitForLoad(n) {
    1.81 +  debug('Waiting for load ' + n);
    1.82 +  expectedLoadNum = n;
    1.83 +}
    1.84 +
    1.85 +function waitForShow(n) {
    1.86 +  debug('Waiting for show ' + n);
    1.87 +  expectedPageshowNum = n;
    1.88 +}
    1.89 +
    1.90 +function test() {
    1.91 +  var popup = window.open('data:text/html,' +
    1.92 +                          '<html><body onload="opener.childLoad(1)" ' +
    1.93 +                                      'onpageshow="opener.childPageshow(1)">' +
    1.94 +                                'Popup 1' +
    1.95 +                                '</body></html>');
    1.96 +  waitForLoad(1);
    1.97 +  yield undefined;
    1.98 +
    1.99 +  popup.history.pushState('', '', '');
   1.100 +
   1.101 +  popup.location = 'data:text/html,<html><body onload="opener.childLoad(2)">Popup 2</body></html>';
   1.102 +  waitForLoad(2);
   1.103 +  yield undefined;
   1.104 +
   1.105 +  // Now go back 2.  The first page should be retrieved from bfcache.
   1.106 +  popup.history.go(-2);
   1.107 +  waitForShow(1);
   1.108 +  yield undefined;
   1.109 +
   1.110 +  popup.close();
   1.111 +  SimpleTest.finish();
   1.112 +  
   1.113 +  // Yield once more so we don't throw a StopIteration exception.
   1.114 +  yield undefined;
   1.115 +}
   1.116 +
   1.117 +var gGen = test();
   1.118 +gGen.next();
   1.119 +
   1.120 +</script>
   1.121 +</pre>
   1.122 +</body>
   1.123 +</html>

mercurial