1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_menuchecks.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,147 @@ 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="Menu Checkbox and Radio Tests" 1.9 + onload="runTest()" 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 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.14 + 1.15 + <hbox> 1.16 + <button id="menu" type="menu" label="View"> 1.17 + <menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()"> 1.18 + <menuitem id="toolbar" label="Show Toolbar" type="checkbox"/> 1.19 + <menuitem id="statusbar" label="Show Status Bar" type="checkbox" checked="true"/> 1.20 + <menuitem id="bookmarks" label="Show Bookmarks" type="checkbox" autocheck="false"/> 1.21 + <menuitem id="history" label="Show History" type="checkbox" autocheck="false" checked="true"/> 1.22 + <menuseparator/> 1.23 + <menuitem id="byname" label="By Name" type="radio" name="sort"/> 1.24 + <menuitem id="bydate" label="By Date" type="radio" name="sort" checked="true"/> 1.25 + <menuseparator/> 1.26 + <menuitem id="ascending" label="Ascending" type="radio" name="order" checked="true"/> 1.27 + <menuitem id="descending" label="Descending" type="radio" name="order" autocheck="false"/> 1.28 + <menuitem id="bysubject" label="By Subject" type="radio" name="sort"/> 1.29 + </menupopup> 1.30 + </button> 1.31 + 1.32 + </hbox> 1.33 + 1.34 + <!-- 1.35 + This test checks that checkbox and radio menu items work properly 1.36 + --> 1.37 + <script class="testbody" type="application/javascript"> 1.38 + <![CDATA[ 1.39 + 1.40 + SimpleTest.waitForExplicitFinish(); 1.41 + var gTestIndex = 0; 1.42 + 1.43 + // tests to perform 1.44 + var tests = [ 1.45 + { 1.46 + testname: "select unchecked checkbox", 1.47 + item: "toolbar", 1.48 + checked: ["toolbar", "statusbar", "history", "bydate", "ascending"] 1.49 + }, 1.50 + { 1.51 + testname: "select checked checkbox", 1.52 + item: "statusbar", 1.53 + checked: ["toolbar", "history", "bydate", "ascending"] 1.54 + }, 1.55 + { 1.56 + testname: "select unchecked autocheck checkbox", 1.57 + item: "bookmarks", 1.58 + checked: ["toolbar", "history", "bydate", "ascending"] 1.59 + }, 1.60 + { 1.61 + testname: "select checked autocheck checkbox", 1.62 + item: "history", 1.63 + checked: ["toolbar", "history", "bydate", "ascending"] 1.64 + }, 1.65 + { 1.66 + testname: "select unchecked radio", 1.67 + item: "byname", 1.68 + checked: ["toolbar", "history", "byname", "ascending"] 1.69 + }, 1.70 + { 1.71 + testname: "select checked radio", 1.72 + item: "byname", 1.73 + checked: ["toolbar", "history", "byname", "ascending"] 1.74 + }, 1.75 + { 1.76 + testname: "select out of order checked radio", 1.77 + item: "bysubject", 1.78 + checked: ["toolbar", "history", "bysubject", "ascending"] 1.79 + }, 1.80 + { 1.81 + testname: "select first radio again", 1.82 + item: "byname", 1.83 + checked: ["toolbar", "history", "byname", "ascending"] 1.84 + }, 1.85 + { 1.86 + testname: "select autocheck radio", 1.87 + item: "descending", 1.88 + checked: ["toolbar", "history", "byname", "ascending"] 1.89 + } 1.90 + ]; 1.91 + 1.92 + function runTest() 1.93 + { 1.94 + checkMenus(["statusbar", "history", "bydate", "ascending"], "initial"); 1.95 + document.getElementById("menu").open = true; 1.96 + } 1.97 + 1.98 + function checkMenus(checkedItems, testname) 1.99 + { 1.100 + var isok = true; 1.101 + var children = document.getElementById("popup").childNodes; 1.102 + for (var c = 0; c < children.length; c++) { 1.103 + var child = children[c]; 1.104 + if ((checkedItems.indexOf(child.id) != -1 && child.getAttribute("checked") != "true") || 1.105 + (checkedItems.indexOf(child.id) == -1 && child.hasAttribute("checked"))) { 1.106 + isok = false; 1.107 + break; 1.108 + } 1.109 + } 1.110 + 1.111 + ok(isok, testname); 1.112 + } 1.113 + 1.114 + function popupShown() 1.115 + { 1.116 + var test = tests[gTestIndex]; 1.117 + synthesizeMouse(document.getElementById(test.item), 4, 4, { }); 1.118 + } 1.119 + 1.120 + function popupHidden() 1.121 + { 1.122 + if (gTestIndex < tests.length) { 1.123 + var test = tests[gTestIndex]; 1.124 + checkMenus(test.checked, test.testname); 1.125 + gTestIndex++; 1.126 + if (gTestIndex < tests.length) { 1.127 + document.getElementById("menu").open = true; 1.128 + } 1.129 + else { 1.130 + // manually setting the checkbox should also update the radio state 1.131 + document.getElementById("bydate").setAttribute("checked", "true"); 1.132 + checkMenus(["toolbar", "history", "bydate", "ascending"], "set checked attribute on radio"); 1.133 + SimpleTest.finish(); 1.134 + } 1.135 + } 1.136 + } 1.137 + 1.138 + ]]> 1.139 + </script> 1.140 + 1.141 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.142 +<p id="display"> 1.143 +</p> 1.144 +<div id="content" style="display: none"> 1.145 +</div> 1.146 +<pre id="test"> 1.147 +</pre> 1.148 +</body> 1.149 + 1.150 +</window>