1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/test_bug640387_1.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=640387 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 640387</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=640387">Mozilla Bug 640387</a> 1.17 + 1.18 +<script type='application/javascript;version=1.7'> 1.19 +SimpleTest.waitForExplicitFinish(); 1.20 + 1.21 +function test() { 1.22 + /* Spin the event loop so we get out of the onload handler. */ 1.23 + SimpleTest.executeSoon(function() { gGen.next() }); 1.24 + yield undefined; 1.25 + 1.26 + popup.history.pushState('', '', '#hash1'); 1.27 + popup.history.pushState('', '', '#hash2'); 1.28 + 1.29 + // Now the history looks like: 1.30 + // file_bug640387.html 1.31 + // file_bug640387.html#hash1 1.32 + // file_bug640387.html#hash2 <-- current 1.33 + 1.34 + // Going back should trigger a hashchange, which will wake us up from the 1.35 + // yield. 1.36 + popup.history.back(); 1.37 + yield undefined; 1.38 + ok(true, 'Got first hashchange.'); 1.39 + 1.40 + // Going back should wake us up again. 1.41 + popup.history.back(); 1.42 + yield undefined; 1.43 + ok(true, 'Got second hashchange.'); 1.44 + 1.45 + // Now the history looks like: 1.46 + // file_bug640387.html <-- current 1.47 + // file_bug640387.html#hash1 1.48 + // file_bug640387.html#hash2 1.49 + 1.50 + // Going forward should trigger a hashchange. 1.51 + popup.history.forward(); 1.52 + yield undefined; 1.53 + ok(true, 'Got third hashchange.'); 1.54 + 1.55 + // Now modify the history so it looks like: 1.56 + // file_bug640387.html 1.57 + // file_bug640387.html#hash1 1.58 + // file_bug640387.html#hash1 <-- current 1.59 + popup.history.pushState('', '', '#hash1'); 1.60 + 1.61 + // Now when we go back, we should not get a hashchange. Instead, wait for a 1.62 + // popstate. We need to asynchronously go back because popstate is fired 1.63 + // sync. 1.64 + gHashchangeExpected = false; 1.65 + gCallbackOnPopstate = true; 1.66 + SimpleTest.executeSoon(function() { popup.history.back() }); 1.67 + yield undefined; 1.68 + ok(true, 'Got popstate.'); 1.69 + gCallbackOnPopstate = false; 1.70 + 1.71 + // Spin the event loop so hashchange has a chance to fire, if it's going to. 1.72 + SimpleTest.executeSoon(function() { gGen.next() }); 1.73 + yield undefined; 1.74 + 1.75 + popup.close(); 1.76 + SimpleTest.finish(); 1.77 + yield undefined; 1.78 +} 1.79 + 1.80 +gGen = null; 1.81 +function childLoad() { 1.82 + gGen = test(); 1.83 + gGen.next(); 1.84 +} 1.85 + 1.86 +gHashchangeExpected = true; 1.87 +function childHashchange() { 1.88 + if (gHashchangeExpected) { 1.89 + gGen.next(); 1.90 + } 1.91 + else { 1.92 + ok(false, "Got hashchange when we weren't expecting one."); 1.93 + } 1.94 +} 1.95 + 1.96 +gCallbackOnPopstate = false; 1.97 +function childPopstate() { 1.98 + if (gCallbackOnPopstate) { 1.99 + gGen.next(); 1.100 + } 1.101 +} 1.102 + 1.103 +/* We need to run this test in a popup, because navigating an iframe 1.104 + * back/forwards tends to cause intermittent orange. */ 1.105 +popup = window.open('file_bug640387.html'); 1.106 + 1.107 +/* Control now flows up to childLoad(), called once the popup loads. */ 1.108 + 1.109 +</script> 1.110 + 1.111 +</body> 1.112 +</html>