1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_menuitem_commands.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 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="Menuitem Commands Test" 1.9 + onload="runOrOpen()" 1.10 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.14 + 1.15 +<script> 1.16 +<![CDATA[ 1.17 +SimpleTest.waitForExplicitFinish(); 1.18 + 1.19 +function checkAttributes(elem, label, accesskey, disabled, hidden, isAfter) 1.20 +{ 1.21 + var is = window.opener.wrappedJSObject.SimpleTest.is; 1.22 + 1.23 + is(elem.getAttribute("label"), label, elem.id + " label " + (isAfter ? "after" : "before") + " open"); 1.24 + is(elem.getAttribute("accesskey"), accesskey, elem.id + " accesskey " + (isAfter ? "after" : "before") + " open"); 1.25 + is(elem.getAttribute("disabled"), disabled, elem.id + " disabled " + (isAfter ? "after" : "before") + " open"); 1.26 + is(elem.getAttribute("hidden"), hidden, elem.id + " hidden " + (isAfter ? "after" : "before") + " open"); 1.27 +} 1.28 + 1.29 +function runOrOpen() 1.30 +{ 1.31 + if (window.opener) { 1.32 + SimpleTest.waitForFocus(runTest); 1.33 + } 1.34 + else { 1.35 + window.open("test_menuitem_commands.xul", "", "chrome"); 1.36 + } 1.37 +} 1.38 + 1.39 +function runTest() 1.40 +{ 1.41 + runTestSet(""); 1.42 + runTestSet("bar"); 1.43 + window.close(); 1.44 + window.opener.wrappedJSObject.SimpleTest.finish(); 1.45 +} 1.46 + 1.47 +function runTestSet(suffix) 1.48 +{ 1.49 + var isMac = (navigator.platform.indexOf("Mac") >= 0); 1.50 + 1.51 + var one = $("one" + suffix); 1.52 + var two = $("two" + suffix); 1.53 + var three = $("three" + suffix); 1.54 + var four = $("four" + suffix); 1.55 + 1.56 + checkAttributes(one, "One", "", "", "true", false); 1.57 + checkAttributes(two, "", "", "false", "", false); 1.58 + checkAttributes(three, "Three", "T", "true", "", false); 1.59 + checkAttributes(four, "Four", "F", "", "", false); 1.60 + 1.61 + if (isMac && suffix) { 1.62 + var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). 1.63 + getInterface(Components.interfaces.nsIDOMWindowUtils); 1.64 + utils.forceUpdateNativeMenuAt("0"); 1.65 + } 1.66 + else { 1.67 + $("menu" + suffix).open = true; 1.68 + } 1.69 + 1.70 + checkAttributes(one, "One", "", "", "false", true); 1.71 + checkAttributes(two, "Cat", "C", "", "", true); 1.72 + checkAttributes(three, "Dog", "D", "false", "true", true); 1.73 + checkAttributes(four, "Four", "F", "true", "", true); 1.74 + 1.75 + $("menu" + suffix).open = false; 1.76 +} 1.77 +]]> 1.78 +</script> 1.79 + 1.80 +<command id="cmd_one" hidden="false"/> 1.81 +<command id="cmd_two" label="Cat" accesskey="C"/> 1.82 +<command id="cmd_three" label="Dog" accesskey="D" disabled="false" hidden="true"/> 1.83 +<command id="cmd_four" disabled="true"/> 1.84 + 1.85 +<button id="menu" type="menu"> 1.86 + <menupopup> 1.87 + <menuitem id="one" label="One" hidden="true" command="cmd_one"/> 1.88 + <menuitem id="two" disabled="false" command="cmd_two"/> 1.89 + <menuitem id="three" label="Three" accesskey="T" disabled="true" command="cmd_three"/> 1.90 + <menuitem id="four" label="Four" accesskey="F" command="cmd_four"/> 1.91 + </menupopup> 1.92 +</button> 1.93 + 1.94 +<menubar> 1.95 + <menu id="menubar" label="Sample"> 1.96 + <menupopup> 1.97 + <menuitem id="onebar" label="One" hidden="true" command="cmd_one"/> 1.98 + <menuitem id="twobar" disabled="false" command="cmd_two"/> 1.99 + <menuitem id="threebar" label="Three" accesskey="T" disabled="true" command="cmd_three"/> 1.100 + <menuitem id="fourbar" label="Four" accesskey="F" command="cmd_four"/> 1.101 + </menupopup> 1.102 + </menu> 1.103 +</menubar> 1.104 + 1.105 +<body xmlns="http://www.w3.org/1999/xhtml"><p id="display"/></body> 1.106 + 1.107 +</window>