1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_toolbar.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,227 @@ 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="Toolbar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.9 + onload="startTest();"> 1.10 + 1.11 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.12 + 1.13 + <toolbox id="toolbox"> 1.14 + <toolbarpalette> 1.15 + <toolbarbutton id="p1" label="p1"/> 1.16 + <toolbarbutton id="p2" label="p2"/> 1.17 + <toolbarbutton id="p3" label="p3"/> 1.18 + <toolbarbutton id="p4" label="p4"/> 1.19 + <toolbarbutton id="p5" label="p5"/> 1.20 + <toolbarbutton id="p6" label="p6"/> 1.21 + <toolbarbutton id="p7" label="p7"/> 1.22 + <toolbarbutton id="p8" label="p8"/> 1.23 + <toolbarbutton id="p9" label="p9"/> 1.24 + <toolbarbutton id="p10" label="p10"/> 1.25 + <toolbarbutton id="p11" label="p11"/> 1.26 + <toolbarbutton id="p12" label="p12"/> 1.27 + </toolbarpalette> 1.28 + 1.29 + <toolbar id="tb1" defaultset="p1,p2"/> 1.30 + <toolbar id="tb2" defaultset="p4,p3"/> 1.31 + <toolbar id="tb3" defaultset="p5,p6,t31"> 1.32 + <toolbarbutton id="t31" label="t31" removable="true"/> 1.33 + </toolbar> 1.34 + <toolbar id="tb4" defaultset="t41,p7,p8"> 1.35 + <toolbarbutton id="t41" label="t41" removable="true"/> 1.36 + </toolbar> 1.37 + <toolbar id="tb5" defaultset="p9,t51,p10"> 1.38 + <toolbarbutton id="t51" label="t51" removable="true"/> 1.39 + </toolbar> 1.40 + 1.41 + <toolbar id="tb-test" defaultset="p11,p12"/> 1.42 + <toolbar id="tb-test2" defaultset=""/> 1.43 + <!-- fixed toolbarbuttons always have 'fixed' in their id --> 1.44 + <toolbar id="tb-test3" defaultset=""> 1.45 + <toolbarbutton id="tb-fixed-1" label="tb-test3-1"/> 1.46 + <toolbarbutton id="tb-fixed-2" label="tb-test3-2" removable="false"/> 1.47 + <toolbarbutton id="tb-fixed-3" label="tb-test3-3"/> 1.48 + </toolbar> 1.49 + </toolbox> 1.50 + 1.51 + <toolbar id="notoolbox"/> 1.52 + 1.53 + <!-- test resuls are displayed in the html:body --> 1.54 + <body xmlns="http://www.w3.org/1999/xhtml" 1.55 + style="height: 300px; overflow: auto;"/> 1.56 + 1.57 + <!-- test code goes here --> 1.58 + <script type="text/javascript"><![CDATA[ 1.59 + const SPACER = /^spacer\d+/; 1.60 + const SEPARATOR = /^separator\d+/; 1.61 + const SPRING = /^spring\d+/; 1.62 + 1.63 + function testSet(aTb, aIDs, aResultIDs, aUseFixed) { 1.64 + // build a list of the fixed items in the order they appear on the toolbar 1.65 + var fixedSet = []; 1.66 + if (aUseFixed) { 1.67 + for (let i = 0; i < aTb.childNodes.length; i++) { 1.68 + var id = aTb.childNodes[i].id; 1.69 + if (id.indexOf("fixed") >= 0) 1.70 + fixedSet.push(id); 1.71 + } 1.72 + } 1.73 + 1.74 + var currentSet = aIDs.join(","); 1.75 + ok(currentSet, "setting currentSet: " + currentSet); 1.76 + aTb.currentSet = currentSet; 1.77 + var resultIDs = aResultIDs || aIDs; 1.78 + checkSet(aTb, resultIDs, fixedSet); 1.79 + } 1.80 + 1.81 + var checkSetCount = 0; 1.82 + function checkSet(aTb, aResultIDs, aFixedSet) { 1.83 + checkSetCount++; 1.84 + var testID = "checkSet(" + checkSetCount + ") "; 1.85 + 1.86 + for (let i = 0; i < aTb.childNodes.length; i++) { 1.87 + let id = aTb.childNodes[i].id; 1.88 + if (aResultIDs[i] instanceof RegExp) { 1.89 + ok(aResultIDs[i].test(id), 1.90 + testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + "; got: " + id); 1.91 + } 1.92 + else if (aResultIDs[i] == "*") { 1.93 + is(id, aFixedSet.shift(), testID + "is fixed with ID " + id + " for toolbar " + aTb.id); 1.94 + } 1.95 + else { 1.96 + is(id, aResultIDs[i], 1.97 + testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + 1.98 + "****" + aResultIDs + "," + i + ","); 1.99 + // remove the item from the fixed set once found 1.100 + if (aFixedSet && id.indexOf("fixed") >= 0) 1.101 + aFixedSet.splice(aFixedSet.indexOf(id), 1); 1.102 + } 1.103 + } 1.104 + 1.105 + if (aFixedSet) 1.106 + is(aFixedSet.length, 0, testID + "extra fixed items for " + aTb.id); 1.107 + is(aTb.childNodes.length, aResultIDs.length, 1.108 + testID + "correct number of children for " + aTb.id); 1.109 + } 1.110 + 1.111 + function test_defaultSet() { 1.112 + checkSet($("tb1"), ["p1", "p2"]); 1.113 + checkSet($("tb2"), ["p4", "p3"]); 1.114 + checkSet($("tb3"), ["p5", "p6", "t31"]); 1.115 + checkSet($("tb4"), ["t41", "p7", "p8"]); 1.116 + checkSet($("tb5"), ["p9", "t51", "p10"]); 1.117 + } 1.118 + 1.119 + function test_currentSet(aTb) { 1.120 + ok(aTb, "have toolbar"); 1.121 + var defaultSet = aTb.getAttribute("defaultset"); 1.122 + var setLength = (defaultSet && defaultSet.split(",").length) || 0; 1.123 + is(setLength, aTb.childNodes.length, "correct # of children initially"); 1.124 + 1.125 + var emptySet = [["__empty"], []]; 1.126 + var testSets = [ 1.127 + emptySet, 1.128 + [["p11"]], 1.129 + [["p11","p12"]], 1.130 + [["p11","p12","bogus"], ["p11","p12"]], 1.131 + [["p11"]], 1.132 + emptySet, 1.133 + [["spacer"], [SPACER]], 1.134 + [["spring"], [SPRING]], 1.135 + [["separator"], [SEPARATOR]], 1.136 + [["p11", "p11", "p12", "spacer", "p11"], ["p11", "p12", SPACER]], 1.137 + [["separator", "separator", "p11", "spring", "spacer"], 1.138 + [SEPARATOR, SEPARATOR, "p11", SPRING, SPACER]], 1.139 + [["separator", "spacer", "separator", "p11", "spring", "spacer", "p12", "spring"], 1.140 + [SEPARATOR, SPACER, SEPARATOR, "p11", SPRING, SPACER, "p12", SPRING]], 1.141 + emptySet 1.142 + ]; 1.143 + 1.144 + cycleSets(aTb, testSets, emptySet, false); 1.145 + } 1.146 + 1.147 + function test_currentSet_nonremovable() { 1.148 + var tb = $("tb-test3"); 1.149 + ok(tb, "have tb-test-3"); 1.150 + 1.151 + // the * used in the tests below means that any fixed item can appear in that position 1.152 + var emptySet = [["__empty"], ["*", "*", "*"]]; 1.153 + var testSets = [ 1.154 + [["p1", "tb-fixed-1", "p2"], 1.155 + ["p1", "tb-fixed-1", "p2", "*", "*"]], 1.156 + [["p1", "tb-fixed-2", "p2"], 1.157 + ["p1", "tb-fixed-2", "p2", "*", "*"]], 1.158 + [["p1", "tb-fixed-3", "p2"], 1.159 + ["p1", "tb-fixed-3", "p2", "*", "*"]], 1.160 + emptySet, 1.161 + 1.162 + [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"], 1.163 + ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"]], 1.164 + [["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"], 1.165 + ["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"]], 1.166 + 1.167 + [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"], 1.168 + ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"]], 1.169 + 1.170 + [["tb-fixed-1", "p2", "p1"], 1.171 + ["tb-fixed-1", "p2", "p1", "*", "*"]], 1.172 + 1.173 + [["tb-fixed-1", "p2"], 1.174 + ["tb-fixed-1", "p2", "*", "*"]], 1.175 + 1.176 + [["p1", "p2"], ["p1", "p2", "*", "*", "*"]], 1.177 + [["p2", "p1"], ["p2", "p1", "*", "*", "*"]], 1.178 + 1.179 + [["tb-fixed-3", "spacer", "p1"], 1.180 + ["tb-fixed-3", SPACER, "p1", "*", "*"]] 1.181 + ]; 1.182 + 1.183 + cycleSets(tb, testSets, emptySet, true); 1.184 + } 1.185 + 1.186 + function cycleSets(aTb, aSets, aEmptySet, aUseFixed) { 1.187 + // Since a lot of the tricky cases handled in the currentSet setter 1.188 + // depend on going from one state to another, run through the test set 1.189 + // multiple times in different orders. 1.190 + var length = aSets.length; 1.191 + 1.192 + for (var i = 0; i < length; i++) { 1.193 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.194 + } 1.195 + for (var i = length - 1; i >= 0; i--) { 1.196 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.197 + } 1.198 + for (var i = 0; i < length; i++) { 1.199 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.200 + testSet(aTb, aSets[length - i - 1][0], aSets[length - i - 1][1], aUseFixed); 1.201 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.202 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.203 + } 1.204 + for (var i = 0; i < length; i++) { 1.205 + testSet(aTb, aEmptySet[0], aEmptySet[1], aUseFixed); 1.206 + testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); 1.207 + } 1.208 + } 1.209 + 1.210 + SimpleTest.waitForExplicitFinish(); 1.211 + function startTest() { 1.212 + test_defaultSet(); 1.213 + test_currentSet($("tb-test")); 1.214 + test_currentSet($("tb-test2")); 1.215 + test_currentSet_nonremovable(); 1.216 + 1.217 + var toolbox = $("toolbox"); 1.218 + var toolbars = document.getElementsByTagName("toolbar"); 1.219 + for (var t = 0; t < toolbars.length; t++) { 1.220 + var toolbar = toolbars[t]; 1.221 + is(toolbar.toolbox, toolbar.id == "notoolbox" ? null : toolbox, 1.222 + "toolbar " + toolbar.id + " has correct toolbox"); 1.223 + } 1.224 + 1.225 + $("tb1").toolbox = document.documentElement; 1.226 + is($("tb1").toolbox, toolbox, "toolbox still correct after set"); 1.227 + SimpleTest.finish(); 1.228 + } 1.229 + ]]></script> 1.230 +</window>