1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/general/test_bug504220.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=504220 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 504220</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 onload="run_test();"> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=504220">Mozilla Bug 504220</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 + <iframe id="frame" style="height:100px; width:100px; border:0"></iframe> 1.20 + <div id="status" style="display: none"></div> 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script type="application/javascript;version=1.7"> 1.24 + 1.25 +/** Test for Bug 504220 **/ 1.26 + 1.27 +function run_test() { 1.28 + ok("onhashchange" in document.body, 1.29 + "document.body should contain 'onhashchange'."); 1.30 + 1.31 + ok("onhashchange" in window, "window should contain 'onhashchange'."); 1.32 + 1.33 + // window.onhashchange should mirror document.body.onhashchange. 1.34 + var func = function() { return 42; }; 1.35 + document.body.onhashchange = func; 1.36 + is(window.onhashchange, func); 1.37 + 1.38 + // Likewise, document.body.hashchange should mirror window.onhashchange 1.39 + numEvents = 0; 1.40 + var func2 = function() { numEvents++; gGen.next() }; 1.41 + window.onhashchange = func2; 1.42 + is(document.body.onhashchange, func2); 1.43 + 1.44 + SimpleTest.waitForExplicitFinish(); 1.45 + 1.46 + function waitForHashchange() { 1.47 + // Change the document's hash. If we've been running this test manually, 1.48 + // the hash might already be "#foo", so we need to check in order to be 1.49 + // sure we trigger a hashchange. 1.50 + if (location.hash != "#foo") 1.51 + location.hash = "#foo"; 1.52 + else 1.53 + location.hash = "#bar"; 1.54 + 1.55 + yield undefined; 1.56 + 1.57 + is(numEvents, 1, "Exactly one hashchange should have been fired."); 1.58 + SimpleTest.finish(); 1.59 + yield undefined; 1.60 + } 1.61 + 1.62 + var gGen = waitForHashchange(); 1.63 + gGen.next(); 1.64 +} 1.65 + 1.66 +</script> 1.67 +</pre> 1.68 +</body> 1.69 +</html>