Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | |
michael@0 | 5 | <window title="Toolbar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 6 | onload="startTest();"> |
michael@0 | 7 | |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | |
michael@0 | 10 | <toolbox id="toolbox"> |
michael@0 | 11 | <toolbarpalette> |
michael@0 | 12 | <toolbarbutton id="p1" label="p1"/> |
michael@0 | 13 | <toolbarbutton id="p2" label="p2"/> |
michael@0 | 14 | <toolbarbutton id="p3" label="p3"/> |
michael@0 | 15 | <toolbarbutton id="p4" label="p4"/> |
michael@0 | 16 | <toolbarbutton id="p5" label="p5"/> |
michael@0 | 17 | <toolbarbutton id="p6" label="p6"/> |
michael@0 | 18 | <toolbarbutton id="p7" label="p7"/> |
michael@0 | 19 | <toolbarbutton id="p8" label="p8"/> |
michael@0 | 20 | <toolbarbutton id="p9" label="p9"/> |
michael@0 | 21 | <toolbarbutton id="p10" label="p10"/> |
michael@0 | 22 | <toolbarbutton id="p11" label="p11"/> |
michael@0 | 23 | <toolbarbutton id="p12" label="p12"/> |
michael@0 | 24 | </toolbarpalette> |
michael@0 | 25 | |
michael@0 | 26 | <toolbar id="tb1" defaultset="p1,p2"/> |
michael@0 | 27 | <toolbar id="tb2" defaultset="p4,p3"/> |
michael@0 | 28 | <toolbar id="tb3" defaultset="p5,p6,t31"> |
michael@0 | 29 | <toolbarbutton id="t31" label="t31" removable="true"/> |
michael@0 | 30 | </toolbar> |
michael@0 | 31 | <toolbar id="tb4" defaultset="t41,p7,p8"> |
michael@0 | 32 | <toolbarbutton id="t41" label="t41" removable="true"/> |
michael@0 | 33 | </toolbar> |
michael@0 | 34 | <toolbar id="tb5" defaultset="p9,t51,p10"> |
michael@0 | 35 | <toolbarbutton id="t51" label="t51" removable="true"/> |
michael@0 | 36 | </toolbar> |
michael@0 | 37 | |
michael@0 | 38 | <toolbar id="tb-test" defaultset="p11,p12"/> |
michael@0 | 39 | <toolbar id="tb-test2" defaultset=""/> |
michael@0 | 40 | <!-- fixed toolbarbuttons always have 'fixed' in their id --> |
michael@0 | 41 | <toolbar id="tb-test3" defaultset=""> |
michael@0 | 42 | <toolbarbutton id="tb-fixed-1" label="tb-test3-1"/> |
michael@0 | 43 | <toolbarbutton id="tb-fixed-2" label="tb-test3-2" removable="false"/> |
michael@0 | 44 | <toolbarbutton id="tb-fixed-3" label="tb-test3-3"/> |
michael@0 | 45 | </toolbar> |
michael@0 | 46 | </toolbox> |
michael@0 | 47 | |
michael@0 | 48 | <toolbar id="notoolbox"/> |
michael@0 | 49 | |
michael@0 | 50 | <!-- test resuls are displayed in the html:body --> |
michael@0 | 51 | <body xmlns="http://www.w3.org/1999/xhtml" |
michael@0 | 52 | style="height: 300px; overflow: auto;"/> |
michael@0 | 53 | |
michael@0 | 54 | <!-- test code goes here --> |
michael@0 | 55 | <script type="text/javascript"><![CDATA[ |
michael@0 | 56 | const SPACER = /^spacer\d+/; |
michael@0 | 57 | const SEPARATOR = /^separator\d+/; |
michael@0 | 58 | const SPRING = /^spring\d+/; |
michael@0 | 59 | |
michael@0 | 60 | function testSet(aTb, aIDs, aResultIDs, aUseFixed) { |
michael@0 | 61 | // build a list of the fixed items in the order they appear on the toolbar |
michael@0 | 62 | var fixedSet = []; |
michael@0 | 63 | if (aUseFixed) { |
michael@0 | 64 | for (let i = 0; i < aTb.childNodes.length; i++) { |
michael@0 | 65 | var id = aTb.childNodes[i].id; |
michael@0 | 66 | if (id.indexOf("fixed") >= 0) |
michael@0 | 67 | fixedSet.push(id); |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | var currentSet = aIDs.join(","); |
michael@0 | 72 | ok(currentSet, "setting currentSet: " + currentSet); |
michael@0 | 73 | aTb.currentSet = currentSet; |
michael@0 | 74 | var resultIDs = aResultIDs || aIDs; |
michael@0 | 75 | checkSet(aTb, resultIDs, fixedSet); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | var checkSetCount = 0; |
michael@0 | 79 | function checkSet(aTb, aResultIDs, aFixedSet) { |
michael@0 | 80 | checkSetCount++; |
michael@0 | 81 | var testID = "checkSet(" + checkSetCount + ") "; |
michael@0 | 82 | |
michael@0 | 83 | for (let i = 0; i < aTb.childNodes.length; i++) { |
michael@0 | 84 | let id = aTb.childNodes[i].id; |
michael@0 | 85 | if (aResultIDs[i] instanceof RegExp) { |
michael@0 | 86 | ok(aResultIDs[i].test(id), |
michael@0 | 87 | testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + "; got: " + id); |
michael@0 | 88 | } |
michael@0 | 89 | else if (aResultIDs[i] == "*") { |
michael@0 | 90 | is(id, aFixedSet.shift(), testID + "is fixed with ID " + id + " for toolbar " + aTb.id); |
michael@0 | 91 | } |
michael@0 | 92 | else { |
michael@0 | 93 | is(id, aResultIDs[i], |
michael@0 | 94 | testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + |
michael@0 | 95 | "****" + aResultIDs + "," + i + ","); |
michael@0 | 96 | // remove the item from the fixed set once found |
michael@0 | 97 | if (aFixedSet && id.indexOf("fixed") >= 0) |
michael@0 | 98 | aFixedSet.splice(aFixedSet.indexOf(id), 1); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | if (aFixedSet) |
michael@0 | 103 | is(aFixedSet.length, 0, testID + "extra fixed items for " + aTb.id); |
michael@0 | 104 | is(aTb.childNodes.length, aResultIDs.length, |
michael@0 | 105 | testID + "correct number of children for " + aTb.id); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | function test_defaultSet() { |
michael@0 | 109 | checkSet($("tb1"), ["p1", "p2"]); |
michael@0 | 110 | checkSet($("tb2"), ["p4", "p3"]); |
michael@0 | 111 | checkSet($("tb3"), ["p5", "p6", "t31"]); |
michael@0 | 112 | checkSet($("tb4"), ["t41", "p7", "p8"]); |
michael@0 | 113 | checkSet($("tb5"), ["p9", "t51", "p10"]); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function test_currentSet(aTb) { |
michael@0 | 117 | ok(aTb, "have toolbar"); |
michael@0 | 118 | var defaultSet = aTb.getAttribute("defaultset"); |
michael@0 | 119 | var setLength = (defaultSet && defaultSet.split(",").length) || 0; |
michael@0 | 120 | is(setLength, aTb.childNodes.length, "correct # of children initially"); |
michael@0 | 121 | |
michael@0 | 122 | var emptySet = [["__empty"], []]; |
michael@0 | 123 | var testSets = [ |
michael@0 | 124 | emptySet, |
michael@0 | 125 | [["p11"]], |
michael@0 | 126 | [["p11","p12"]], |
michael@0 | 127 | [["p11","p12","bogus"], ["p11","p12"]], |
michael@0 | 128 | [["p11"]], |
michael@0 | 129 | emptySet, |
michael@0 | 130 | [["spacer"], [SPACER]], |
michael@0 | 131 | [["spring"], [SPRING]], |
michael@0 | 132 | [["separator"], [SEPARATOR]], |
michael@0 | 133 | [["p11", "p11", "p12", "spacer", "p11"], ["p11", "p12", SPACER]], |
michael@0 | 134 | [["separator", "separator", "p11", "spring", "spacer"], |
michael@0 | 135 | [SEPARATOR, SEPARATOR, "p11", SPRING, SPACER]], |
michael@0 | 136 | [["separator", "spacer", "separator", "p11", "spring", "spacer", "p12", "spring"], |
michael@0 | 137 | [SEPARATOR, SPACER, SEPARATOR, "p11", SPRING, SPACER, "p12", SPRING]], |
michael@0 | 138 | emptySet |
michael@0 | 139 | ]; |
michael@0 | 140 | |
michael@0 | 141 | cycleSets(aTb, testSets, emptySet, false); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function test_currentSet_nonremovable() { |
michael@0 | 145 | var tb = $("tb-test3"); |
michael@0 | 146 | ok(tb, "have tb-test-3"); |
michael@0 | 147 | |
michael@0 | 148 | // the * used in the tests below means that any fixed item can appear in that position |
michael@0 | 149 | var emptySet = [["__empty"], ["*", "*", "*"]]; |
michael@0 | 150 | var testSets = [ |
michael@0 | 151 | [["p1", "tb-fixed-1", "p2"], |
michael@0 | 152 | ["p1", "tb-fixed-1", "p2", "*", "*"]], |
michael@0 | 153 | [["p1", "tb-fixed-2", "p2"], |
michael@0 | 154 | ["p1", "tb-fixed-2", "p2", "*", "*"]], |
michael@0 | 155 | [["p1", "tb-fixed-3", "p2"], |
michael@0 | 156 | ["p1", "tb-fixed-3", "p2", "*", "*"]], |
michael@0 | 157 | emptySet, |
michael@0 | 158 | |
michael@0 | 159 | [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"], |
michael@0 | 160 | ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"]], |
michael@0 | 161 | [["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"], |
michael@0 | 162 | ["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"]], |
michael@0 | 163 | |
michael@0 | 164 | [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"], |
michael@0 | 165 | ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"]], |
michael@0 | 166 | |
michael@0 | 167 | [["tb-fixed-1", "p2", "p1"], |
michael@0 | 168 | ["tb-fixed-1", "p2", "p1", "*", "*"]], |
michael@0 | 169 | |
michael@0 | 170 | [["tb-fixed-1", "p2"], |
michael@0 | 171 | ["tb-fixed-1", "p2", "*", "*"]], |
michael@0 | 172 | |
michael@0 | 173 | [["p1", "p2"], ["p1", "p2", "*", "*", "*"]], |
michael@0 | 174 | [["p2", "p1"], ["p2", "p1", "*", "*", "*"]], |
michael@0 | 175 | |
michael@0 | 176 | [["tb-fixed-3", "spacer", "p1"], |
michael@0 | 177 | ["tb-fixed-3", SPACER, "p1", "*", "*"]] |
michael@0 | 178 | ]; |
michael@0 | 179 | |
michael@0 | 180 | cycleSets(tb, testSets, emptySet, true); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | function cycleSets(aTb, aSets, aEmptySet, aUseFixed) { |
michael@0 | 184 | // Since a lot of the tricky cases handled in the currentSet setter |
michael@0 | 185 | // depend on going from one state to another, run through the test set |
michael@0 | 186 | // multiple times in different orders. |
michael@0 | 187 | var length = aSets.length; |
michael@0 | 188 | |
michael@0 | 189 | for (var i = 0; i < length; i++) { |
michael@0 | 190 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 191 | } |
michael@0 | 192 | for (var i = length - 1; i >= 0; i--) { |
michael@0 | 193 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 194 | } |
michael@0 | 195 | for (var i = 0; i < length; i++) { |
michael@0 | 196 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 197 | testSet(aTb, aSets[length - i - 1][0], aSets[length - i - 1][1], aUseFixed); |
michael@0 | 198 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 199 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 200 | } |
michael@0 | 201 | for (var i = 0; i < length; i++) { |
michael@0 | 202 | testSet(aTb, aEmptySet[0], aEmptySet[1], aUseFixed); |
michael@0 | 203 | testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed); |
michael@0 | 204 | } |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 208 | function startTest() { |
michael@0 | 209 | test_defaultSet(); |
michael@0 | 210 | test_currentSet($("tb-test")); |
michael@0 | 211 | test_currentSet($("tb-test2")); |
michael@0 | 212 | test_currentSet_nonremovable(); |
michael@0 | 213 | |
michael@0 | 214 | var toolbox = $("toolbox"); |
michael@0 | 215 | var toolbars = document.getElementsByTagName("toolbar"); |
michael@0 | 216 | for (var t = 0; t < toolbars.length; t++) { |
michael@0 | 217 | var toolbar = toolbars[t]; |
michael@0 | 218 | is(toolbar.toolbox, toolbar.id == "notoolbox" ? null : toolbox, |
michael@0 | 219 | "toolbar " + toolbar.id + " has correct toolbox"); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | $("tb1").toolbox = document.documentElement; |
michael@0 | 223 | is($("tb1").toolbox, toolbox, "toolbox still correct after set"); |
michael@0 | 224 | SimpleTest.finish(); |
michael@0 | 225 | } |
michael@0 | 226 | ]]></script> |
michael@0 | 227 | </window> |