1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_popup_preventdefault.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 + 1.8 +<window title="Popup Prevent Default Tests" 1.9 + onload="setTimeout(runTest, 0);" 1.10 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.11 + 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + 1.14 +<!-- 1.15 + This tests checks that preventDefault can be called on a popupshowing 1.16 + event and that preventDefault has no effect for the popuphiding event. 1.17 + --> 1.18 + 1.19 +<script> 1.20 +SimpleTest.waitForExplicitFinish(); 1.21 + 1.22 +var gBlockShowing = true; 1.23 +var gShownNotAllowed = true; 1.24 + 1.25 +function runTest() 1.26 +{ 1.27 + document.getElementById("menu").open = true; 1.28 +} 1.29 + 1.30 +function popupShowing(event) 1.31 +{ 1.32 + if (gBlockShowing) { 1.33 + event.preventDefault(); 1.34 + gBlockShowing = false; 1.35 + setTimeout(function() { 1.36 + gShownNotAllowed = false; 1.37 + document.getElementById("menu").open = true; 1.38 + }, 3000, true); 1.39 + } 1.40 +} 1.41 + 1.42 +function popupShown() 1.43 +{ 1.44 + ok(!gShownNotAllowed, "popupshowing preventDefault"); 1.45 + document.getElementById("menu").open = false; 1.46 +} 1.47 + 1.48 +function popupHiding(event) 1.49 +{ 1.50 + // since this is a content test, preventDefault should have no effect 1.51 + event.preventDefault(); 1.52 +} 1.53 + 1.54 +function popupHidden() 1.55 +{ 1.56 + ok(true, "popuphiding preventDefault not allowed"); 1.57 + SimpleTest.finish(); 1.58 +} 1.59 +</script> 1.60 + 1.61 +<button id="menu" type="menu" label="Menu"> 1.62 + <menupopup onpopupshowing="popupShowing(event);" 1.63 + onpopupshown="popupShown();" 1.64 + onpopuphiding="popupHiding(event);" 1.65 + onpopuphidden="popupHidden();"> 1.66 + <menuitem label="Item"/> 1.67 + </menupopup> 1.68 +</button> 1.69 + 1.70 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.71 +<p id="display"> 1.72 +</p> 1.73 +<div id="content" style="display: none"> 1.74 +</div> 1.75 +<pre id="test"> 1.76 +</pre> 1.77 +</body> 1.78 + 1.79 +</window>