docshell/test/test_bug509055.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bug509055.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=509055
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 509055</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=509055">Mozilla Bug 509055</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="status"></div>
    1.19 +<div id="content">
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript;version=1.7">
    1.23 +
    1.24 +/** Test for Bug 509055 **/
    1.25 +
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +
    1.28 +var gGen;
    1.29 +
    1.30 +function shortWait() {
    1.31 +  setTimeout(function() { gGen.next(); }, 0, false);
    1.32 +}
    1.33 +
    1.34 +function onChildHashchange(e) {
    1.35 +  // gGen might be undefined when we refresh the page, so we have to check here
    1.36 +  dump("onChildHashchange() called.\n");
    1.37 +  if(gGen)
    1.38 +    gGen.next();
    1.39 +}
    1.40 +
    1.41 +function onChildLoad(e) {
    1.42 +  if(gGen)
    1.43 +    gGen.next();
    1.44 +}
    1.45 +
    1.46 +function runTest() {
    1.47 +  var popup = window.open("file_bug509055.html", "popup 0",
    1.48 +                           "height=200,width=200,location=yes," +
    1.49 +                           "menubar=yes,status=yes,toolbar=yes,dependent=yes");
    1.50 +  popup.hashchangeCallback = onChildHashchange;
    1.51 +  popup.onload = onChildLoad;
    1.52 +  dump('Waiting for initial load.\n');
    1.53 +  yield undefined;
    1.54 +
    1.55 +  // Without this wait, the change to location.hash below doesn't create a
    1.56 +  // SHEntry or enable the back button.
    1.57 +  shortWait();
    1.58 +  dump('Got initial load.  Spinning event loop.\n');
    1.59 +  yield undefined;
    1.60 +
    1.61 +  popup.location.hash = "#1";
    1.62 +  dump('Waiting for hashchange.\n');
    1.63 +  yield undefined;
    1.64 +
    1.65 +  popup.history.back();
    1.66 +  dump('Waiting for second hashchange.\n');
    1.67 +  yield undefined; // wait for hashchange
    1.68 +
    1.69 +  popup.document.title = "Changed";
    1.70 +
    1.71 +  // Wait for listeners to be notified of the title change.
    1.72 +  shortWait();
    1.73 +  dump('Got second hashchange.  Spinning event loop.\n');
    1.74 +  yield undefined;
    1.75 +
    1.76 +  var sh = SpecialPowers.wrap(popup)
    1.77 +                        .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
    1.78 +                        .getInterface(SpecialPowers.Ci.nsIWebNavigation)
    1.79 +                        .sessionHistory;
    1.80 +
    1.81 +  // Get the title of the inner popup's current SHEntry 
    1.82 +  var sheTitle = sh.getEntryAtIndex(sh.index, false).title;
    1.83 +  is(sheTitle, "Changed", "SHEntry's title should change when we change.");
    1.84 +
    1.85 +  popup.close();
    1.86 +
    1.87 +  SimpleTest.executeSoon(SimpleTest.finish);
    1.88 +  dump('Final yield.\n');
    1.89 +  yield undefined;
    1.90 +}
    1.91 +
    1.92 +window.addEventListener('load', function() {
    1.93 +  gGen = runTest();
    1.94 +  gGen.next();
    1.95 +}, false);
    1.96 +
    1.97 +</script>
    1.98 +
    1.99 +</body>
   1.100 +</html>
   1.101 +

mercurial