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 | // This script is used to test elements that implement |
michael@0 | 2 | // nsIDOMXULSelectControlElement. This currently is the following elements: |
michael@0 | 3 | // listbox, menulist, radiogroup, richlistbox, tabs |
michael@0 | 4 | // |
michael@0 | 5 | // flag behaviours that differ for certain elements |
michael@0 | 6 | // allow-other-value - alternate values for the value property may be used |
michael@0 | 7 | // besides those in the list |
michael@0 | 8 | // other-value-clears-selection - alternative values for the value property |
michael@0 | 9 | // clears the selected item |
michael@0 | 10 | // selection-required - an item must be selected in the list, unless there |
michael@0 | 11 | // aren't any to select |
michael@0 | 12 | // activate-disabled-menuitem - disabled menuitems can be highlighted |
michael@0 | 13 | // select-keynav-wraps - key navigation over a selectable list wraps |
michael@0 | 14 | // select-extended-keynav - home, end, page up and page down keys work to |
michael@0 | 15 | // navigate over a selectable list |
michael@0 | 16 | // keynav-leftright - key navigation is left/right rather than up/down |
michael@0 | 17 | // The win:, mac: and gtk: or other prefixes may be used for platform specific behaviour |
michael@0 | 18 | var behaviours = { |
michael@0 | 19 | menu: "win:activate-disabled-menuitem activate-disabled-menuitem-mousemove select-keynav-wraps select-extended-keynav", |
michael@0 | 20 | menulist: "allow-other-value other-value-clears-selection", |
michael@0 | 21 | listbox: "select-extended-keynav", |
michael@0 | 22 | richlistbox: "select-extended-keynav", |
michael@0 | 23 | radiogroup: "select-keynav-wraps dont-select-disabled allow-other-value", |
michael@0 | 24 | tabs: "select-extended-keynav mac:select-keynav-wraps allow-other-value selection-required keynav-leftright" |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | function behaviourContains(tag, behaviour) |
michael@0 | 28 | { |
michael@0 | 29 | var platform = "none:"; |
michael@0 | 30 | if (navigator.platform.indexOf("Mac") >= 0) |
michael@0 | 31 | platform = "mac:"; |
michael@0 | 32 | else if (navigator.platform.indexOf("Win") >= 0) |
michael@0 | 33 | platform = "win:"; |
michael@0 | 34 | else if (navigator.platform.indexOf("X") >= 0) |
michael@0 | 35 | platform = "gtk:"; |
michael@0 | 36 | |
michael@0 | 37 | var re = new RegExp("\\s" + platform + behaviour + "\\s|\\s" + behaviour + "\\s"); |
michael@0 | 38 | return re.test(" " + behaviours[tag] + " "); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function test_nsIDOMXULSelectControlElement(element, childtag, testprefix) |
michael@0 | 42 | { |
michael@0 | 43 | var testid = (testprefix) ? testprefix + " " : ""; |
michael@0 | 44 | testid += element.localName + " nsIDOMXULSelectControlElement "; |
michael@0 | 45 | |
michael@0 | 46 | // editable menulists use the label as the value instead |
michael@0 | 47 | var firstvalue = "first", secondvalue = "second", fourthvalue = "fourth"; |
michael@0 | 48 | if (element.localName == "menulist" && element.editable) { |
michael@0 | 49 | firstvalue = "First Item"; |
michael@0 | 50 | secondvalue = "Second Item" |
michael@0 | 51 | fourthvalue = "Fourth Item"; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | // 'initial' - check if the initial state of the element is correct |
michael@0 | 55 | test_nsIDOMXULSelectControlElement_States(element, testid + "initial", 0, null, -1, ""); |
michael@0 | 56 | |
michael@0 | 57 | test_nsIDOMXULSelectControlElement_init(element, testid); |
michael@0 | 58 | |
michael@0 | 59 | // 'appendItem' - check if appendItem works to add a new item |
michael@0 | 60 | var firstitem = element.appendItem("First Item", "first"); |
michael@0 | 61 | is(firstitem.localName, childtag, |
michael@0 | 62 | testid + "appendItem - first item is " + childtag); |
michael@0 | 63 | test_nsIDOMXULSelectControlElement_States(element, testid + "appendItem", 1, null, -1, ""); |
michael@0 | 64 | |
michael@0 | 65 | is(firstitem.control, element, testid + "control"); |
michael@0 | 66 | |
michael@0 | 67 | // 'selectedIndex' - check if an item may be selected |
michael@0 | 68 | element.selectedIndex = 0; |
michael@0 | 69 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex", 1, firstitem, 0, firstvalue); |
michael@0 | 70 | |
michael@0 | 71 | // 'appendItem 2' - check if a second item may be added |
michael@0 | 72 | var seconditem = element.appendItem("Second Item", "second"); |
michael@0 | 73 | test_nsIDOMXULSelectControlElement_States(element, testid + "appendItem 2", 2, firstitem, 0, firstvalue); |
michael@0 | 74 | |
michael@0 | 75 | // 'selectedItem' - check if the second item may be selected |
michael@0 | 76 | element.selectedItem = seconditem; |
michael@0 | 77 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedItem", 2, seconditem, 1, secondvalue); |
michael@0 | 78 | |
michael@0 | 79 | // 'selectedIndex 2' - check if selectedIndex may be set to -1 to deselect items |
michael@0 | 80 | var selectionRequired = behaviourContains(element.localName, "selection-required"); |
michael@0 | 81 | element.selectedIndex = -1; |
michael@0 | 82 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex 2", 2, |
michael@0 | 83 | selectionRequired ? seconditem : null, selectionRequired ? 1 : -1, |
michael@0 | 84 | selectionRequired ? secondvalue : ""); |
michael@0 | 85 | |
michael@0 | 86 | // 'selectedItem 2' - check if the selectedItem property may be set to null |
michael@0 | 87 | element.selectedIndex = 1; |
michael@0 | 88 | element.selectedItem = null; |
michael@0 | 89 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedItem 2", 2, |
michael@0 | 90 | selectionRequired ? seconditem : null, selectionRequired ? 1 : -1, |
michael@0 | 91 | selectionRequired ? secondvalue : ""); |
michael@0 | 92 | |
michael@0 | 93 | // 'getIndexOfItem' - check if getIndexOfItem returns the right index |
michael@0 | 94 | is(element.getIndexOfItem(firstitem), 0, testid + "getIndexOfItem - first item at index 0"); |
michael@0 | 95 | is(element.getIndexOfItem(seconditem), 1, testid + "getIndexOfItem - second item at index 1"); |
michael@0 | 96 | |
michael@0 | 97 | var otheritem = element.ownerDocument.createElement(childtag); |
michael@0 | 98 | is(element.getIndexOfItem(otheritem), -1, testid + "getIndexOfItem - other item not found"); |
michael@0 | 99 | |
michael@0 | 100 | // 'getItemAtIndex' - check if getItemAtIndex returns the right item |
michael@0 | 101 | is(element.getItemAtIndex(0), firstitem, testid + "getItemAtIndex - index 0 is first item"); |
michael@0 | 102 | is(element.getItemAtIndex(1), seconditem, testid + "getItemAtIndex - index 0 is second item"); |
michael@0 | 103 | is(element.getItemAtIndex(-1), null, testid + "getItemAtIndex - index -1 is null"); |
michael@0 | 104 | is(element.getItemAtIndex(2), null, testid + "getItemAtIndex - index 2 is null"); |
michael@0 | 105 | |
michael@0 | 106 | // check if setting the value changes the selection |
michael@0 | 107 | element.value = firstvalue; |
michael@0 | 108 | test_nsIDOMXULSelectControlElement_States(element, testid + "set value 1", 2, firstitem, 0, firstvalue); |
michael@0 | 109 | element.value = secondvalue; |
michael@0 | 110 | test_nsIDOMXULSelectControlElement_States(element, testid + "set value 2", 2, seconditem, 1, secondvalue); |
michael@0 | 111 | // setting the value attribute to one not in the list doesn't change the selection. |
michael@0 | 112 | // The value is only changed for elements which support having a value other than the |
michael@0 | 113 | // selection. |
michael@0 | 114 | element.value = "other"; |
michael@0 | 115 | var allowOtherValue = behaviourContains(element.localName, "allow-other-value"); |
michael@0 | 116 | var otherValueClearsSelection = behaviourContains(element.localName, "other-value-clears-selection"); |
michael@0 | 117 | test_nsIDOMXULSelectControlElement_States(element, testid + "set value other", 2, |
michael@0 | 118 | otherValueClearsSelection ? null : seconditem, |
michael@0 | 119 | otherValueClearsSelection ? -1 : 1, |
michael@0 | 120 | allowOtherValue ? "other" : secondvalue); |
michael@0 | 121 | if (allowOtherValue) |
michael@0 | 122 | element.value = ""; |
michael@0 | 123 | |
michael@0 | 124 | // 'removeItemAt' - check if removeItemAt removes the right item |
michael@0 | 125 | if (selectionRequired) |
michael@0 | 126 | element.value = secondvalue; |
michael@0 | 127 | else |
michael@0 | 128 | element.selectedIndex = -1; |
michael@0 | 129 | |
michael@0 | 130 | var removeditem = element.removeItemAt(0); |
michael@0 | 131 | is(removeditem, firstitem, testid + "removeItemAt return value"); |
michael@0 | 132 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt", 1, |
michael@0 | 133 | selectionRequired ? seconditem : null, selectionRequired ? 0 : -1, |
michael@0 | 134 | selectionRequired ? secondvalue : ""); |
michael@0 | 135 | |
michael@0 | 136 | is(removeditem.control, null, testid + "control not set"); |
michael@0 | 137 | |
michael@0 | 138 | var thirditem = element.appendItem("Third Item", "third"); |
michael@0 | 139 | var fourthitem = element.appendItem("Fourth Item", fourthvalue); |
michael@0 | 140 | var fifthitem = element.appendItem("Fifth Item", "fifth"); |
michael@0 | 141 | |
michael@0 | 142 | // 'removeItemAt 2' - check if removeItemAt removes the selected item and |
michael@0 | 143 | // adjusts the selection to the next item |
michael@0 | 144 | element.selectedItem = thirditem; |
michael@0 | 145 | is(element.removeItemAt(1), thirditem, testid + "removeItemAt 2 return value"); |
michael@0 | 146 | |
michael@0 | 147 | // radio buttons don't handle removing quite right due to XBL issues, |
michael@0 | 148 | // so disable testing some of these remove tests for now - bug 367400 |
michael@0 | 149 | var isnotradio = (element.localName != "radiogroup"); |
michael@0 | 150 | // XXXndeakin disable these tests for all widgets for now. They require bug 331513. |
michael@0 | 151 | isnotradio = false; |
michael@0 | 152 | if (isnotradio) |
michael@0 | 153 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 2", 3, fourthitem, 1, fourthvalue); |
michael@0 | 154 | |
michael@0 | 155 | // 'removeItemAt 3' - check if removeItemAt adjusts the selection |
michael@0 | 156 | // if an earlier item is removed |
michael@0 | 157 | element.selectedItem = fourthitem; |
michael@0 | 158 | element.removeItemAt(0); |
michael@0 | 159 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 3", 2, fourthitem, 0, fourthvalue); |
michael@0 | 160 | |
michael@0 | 161 | // 'removeItemAt 4' - check if removeItemAt adjusts the selection if the |
michael@0 | 162 | // last item is selected and removed |
michael@0 | 163 | element.selectedItem = fifthitem; |
michael@0 | 164 | element.removeItemAt(1); |
michael@0 | 165 | if (isnotradio) |
michael@0 | 166 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 4", 1, fourthitem, 0, fourthvalue); |
michael@0 | 167 | |
michael@0 | 168 | // 'removeItemAt 5' - check that removeItemAt doesn't fail when removing invalid items |
michael@0 | 169 | is(element.removeItemAt(-1), null, testid + "removeItemAt 5 return value"); |
michael@0 | 170 | if (isnotradio) |
michael@0 | 171 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 5", 1, fourthitem, 0, fourthvalue); |
michael@0 | 172 | |
michael@0 | 173 | // 'removeItemAt 6' - check that removeItemAt doesn't fail when removing invalid items |
michael@0 | 174 | is(element.removeItemAt(1), null, testid + "removeItemAt 6 return value"); |
michael@0 | 175 | is("item removed", "item removed", testid + "removeItemAt 6"); |
michael@0 | 176 | if (isnotradio) |
michael@0 | 177 | test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 6", 1, fourthitem, 0, fourthvalue); |
michael@0 | 178 | |
michael@0 | 179 | // 'insertItemAt' - check if insertItemAt inserts items at the right locations |
michael@0 | 180 | element.selectedIndex = 0; |
michael@0 | 181 | test_nsIDOMXULSelectControlElement_insertItemAt(element, 0, 0, testid, 5); |
michael@0 | 182 | test_nsIDOMXULSelectControlElement_insertItemAt(element, 2, 2, testid, 6); |
michael@0 | 183 | test_nsIDOMXULSelectControlElement_insertItemAt(element, -1, 3, testid, 7); |
michael@0 | 184 | test_nsIDOMXULSelectControlElement_insertItemAt(element, 6, 4, testid, 8); |
michael@0 | 185 | |
michael@0 | 186 | element.selectedIndex = 0; |
michael@0 | 187 | fourthitem.disabled = true; |
michael@0 | 188 | element.selectedIndex = 1; |
michael@0 | 189 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex disabled", 5, fourthitem, 1, fourthvalue); |
michael@0 | 190 | |
michael@0 | 191 | element.selectedIndex = 0; |
michael@0 | 192 | element.selectedItem = fourthitem; |
michael@0 | 193 | test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex disabled", 5, fourthitem, 1, fourthvalue); |
michael@0 | 194 | |
michael@0 | 195 | // 'removeall' - check if all items are removed |
michael@0 | 196 | while (element.itemCount) |
michael@0 | 197 | element.removeItemAt(0); |
michael@0 | 198 | if (isnotradio) |
michael@0 | 199 | test_nsIDOMXULSelectControlElement_States(element, testid + "remove all", 0, null, -1, |
michael@0 | 200 | allowOtherValue ? "number8" : ""); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | function test_nsIDOMXULSelectControlElement_init(element, testprefix) |
michael@0 | 204 | { |
michael@0 | 205 | // editable menulists use the label as the value |
michael@0 | 206 | var isEditable = (element.localName == "menulist" && element.editable); |
michael@0 | 207 | |
michael@0 | 208 | var id = element.id; |
michael@0 | 209 | element = document.getElementById(id + "-initwithvalue"); |
michael@0 | 210 | if (element) { |
michael@0 | 211 | var seconditem = element.getItemAtIndex(1); |
michael@0 | 212 | test_nsIDOMXULSelectControlElement_States(element, testprefix + " value initialization", |
michael@0 | 213 | 3, seconditem, 1, |
michael@0 | 214 | isEditable ? seconditem.label : seconditem.value); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | element = document.getElementById(id + "-initwithselected"); |
michael@0 | 218 | if (element) { |
michael@0 | 219 | var thirditem = element.getItemAtIndex(2); |
michael@0 | 220 | test_nsIDOMXULSelectControlElement_States(element, testprefix + " selected initialization", |
michael@0 | 221 | 3, thirditem, 2, |
michael@0 | 222 | isEditable ? thirditem.label : thirditem.value); |
michael@0 | 223 | } |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | function test_nsIDOMXULSelectControlElement_States(element, testid, |
michael@0 | 227 | expectedcount, expecteditem, |
michael@0 | 228 | expectedindex, expectedvalue) |
michael@0 | 229 | { |
michael@0 | 230 | // need an itemCount property here |
michael@0 | 231 | var count = element.itemCount; |
michael@0 | 232 | is(count, expectedcount, testid + " item count"); |
michael@0 | 233 | is(element.selectedItem, expecteditem, testid + " selectedItem"); |
michael@0 | 234 | is(element.selectedIndex, expectedindex, testid + " selectedIndex"); |
michael@0 | 235 | is(element.value, expectedvalue, testid + " value"); |
michael@0 | 236 | if (element.selectedItem) { |
michael@0 | 237 | is(element.selectedItem.selected, true, |
michael@0 | 238 | testid + " selectedItem marked as selected"); |
michael@0 | 239 | } |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | function test_nsIDOMXULSelectControlElement_insertItemAt(element, index, expectedindex, testid, number) |
michael@0 | 243 | { |
michael@0 | 244 | var expectedCount = element.itemCount; |
michael@0 | 245 | var expectedSelItem = element.selectedItem; |
michael@0 | 246 | var expectedSelIndex = element.selectedIndex; |
michael@0 | 247 | var expectedSelValue = element.value; |
michael@0 | 248 | |
michael@0 | 249 | var newitem = element.insertItemAt(index, "Item " + number, "number" + number); |
michael@0 | 250 | is(element.getIndexOfItem(newitem), expectedindex, |
michael@0 | 251 | testid + "insertItemAt " + expectedindex + " - get inserted item"); |
michael@0 | 252 | expectedCount++; |
michael@0 | 253 | if (expectedSelIndex >= expectedindex) |
michael@0 | 254 | expectedSelIndex++; |
michael@0 | 255 | |
michael@0 | 256 | test_nsIDOMXULSelectControlElement_States(element, testid + "insertItemAt " + index, |
michael@0 | 257 | expectedCount, expectedSelItem, |
michael@0 | 258 | expectedSelIndex, expectedSelValue); |
michael@0 | 259 | return newitem; |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | /** test_nsIDOMXULSelectControlElement_UI |
michael@0 | 263 | * |
michael@0 | 264 | * Test the UI aspects of an element which implements nsIDOMXULSelectControlElement |
michael@0 | 265 | * |
michael@0 | 266 | * Parameters: |
michael@0 | 267 | * element - element to test |
michael@0 | 268 | */ |
michael@0 | 269 | function test_nsIDOMXULSelectControlElement_UI(element, testprefix) |
michael@0 | 270 | { |
michael@0 | 271 | var testid = (testprefix) ? testprefix + " " : ""; |
michael@0 | 272 | testid += element.localName + " nsIDOMXULSelectControlElement UI "; |
michael@0 | 273 | |
michael@0 | 274 | while (element.itemCount) |
michael@0 | 275 | element.removeItemAt(0); |
michael@0 | 276 | |
michael@0 | 277 | var firstitem = element.appendItem("First Item", "first"); |
michael@0 | 278 | var seconditem = element.appendItem("Second Item", "second"); |
michael@0 | 279 | |
michael@0 | 280 | // 'mouse select' - check if clicking an item selects it |
michael@0 | 281 | synthesizeMouseExpectEvent(firstitem, 2, 2, {}, element, "select", testid + "mouse select"); |
michael@0 | 282 | test_nsIDOMXULSelectControlElement_States(element, testid + "mouse select", 2, firstitem, 0, "first"); |
michael@0 | 283 | |
michael@0 | 284 | synthesizeMouseExpectEvent(seconditem, 2, 2, {}, element, "select", testid + "mouse select 2"); |
michael@0 | 285 | test_nsIDOMXULSelectControlElement_States(element, testid + "mouse select 2", 2, seconditem, 1, "second"); |
michael@0 | 286 | |
michael@0 | 287 | // make sure the element is focused so keyboard navigation will apply |
michael@0 | 288 | element.selectedIndex = 1; |
michael@0 | 289 | element.focus(); |
michael@0 | 290 | |
michael@0 | 291 | var navLeftRight = behaviourContains(element.localName, "keynav-leftright"); |
michael@0 | 292 | var backKey = navLeftRight ? "VK_LEFT" : "VK_UP"; |
michael@0 | 293 | var forwardKey = navLeftRight ? "VK_RIGHT" : "VK_DOWN"; |
michael@0 | 294 | |
michael@0 | 295 | // 'key select' - check if keypresses move between items |
michael@0 | 296 | synthesizeKeyExpectEvent(backKey, {}, element, "select", testid + "key up"); |
michael@0 | 297 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up", 2, firstitem, 0, "first"); |
michael@0 | 298 | |
michael@0 | 299 | var keyWrap = behaviourContains(element.localName, "select-keynav-wraps"); |
michael@0 | 300 | |
michael@0 | 301 | var expectedItem = keyWrap ? seconditem : firstitem; |
michael@0 | 302 | var expectedIndex = keyWrap ? 1 : 0; |
michael@0 | 303 | var expectedValue = keyWrap ? "second" : "first"; |
michael@0 | 304 | synthesizeKeyExpectEvent(backKey, {}, keyWrap ? element : null, "select", testid + "key up 2"); |
michael@0 | 305 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up 2", 2, |
michael@0 | 306 | expectedItem, expectedIndex, expectedValue); |
michael@0 | 307 | |
michael@0 | 308 | element.selectedIndex = 0; |
michael@0 | 309 | synthesizeKeyExpectEvent(forwardKey, {}, element, "select", testid + "key down"); |
michael@0 | 310 | test_nsIDOMXULSelectControlElement_States(element, testid + "key down", 2, seconditem, 1, "second"); |
michael@0 | 311 | |
michael@0 | 312 | expectedItem = keyWrap ? firstitem : seconditem; |
michael@0 | 313 | expectedIndex = keyWrap ? 0 : 1; |
michael@0 | 314 | expectedValue = keyWrap ? "first" : "second"; |
michael@0 | 315 | synthesizeKeyExpectEvent(forwardKey, {}, keyWrap ? element : null, "select", testid + "key down 2"); |
michael@0 | 316 | test_nsIDOMXULSelectControlElement_States(element, testid + "key down 2", 2, |
michael@0 | 317 | expectedItem, expectedIndex, expectedValue); |
michael@0 | 318 | |
michael@0 | 319 | var thirditem = element.appendItem("Third Item", "third"); |
michael@0 | 320 | var fourthitem = element.appendItem("Fourth Item", "fourth"); |
michael@0 | 321 | if (behaviourContains(element.localName, "select-extended-keynav")) { |
michael@0 | 322 | var fifthitem = element.appendItem("Fifth Item", "fifth"); |
michael@0 | 323 | var sixthitem = element.appendItem("Sixth Item", "sixth"); |
michael@0 | 324 | |
michael@0 | 325 | synthesizeKeyExpectEvent("VK_END", {}, element, "select", testid + "key end"); |
michael@0 | 326 | test_nsIDOMXULSelectControlElement_States(element, testid + "key end", 6, sixthitem, 5, "sixth"); |
michael@0 | 327 | |
michael@0 | 328 | synthesizeKeyExpectEvent("VK_HOME", {}, element, "select", testid + "key home"); |
michael@0 | 329 | test_nsIDOMXULSelectControlElement_States(element, testid + "key home", 6, firstitem, 0, "first"); |
michael@0 | 330 | |
michael@0 | 331 | synthesizeKeyExpectEvent("VK_PAGE_DOWN", {}, element, "select", testid + "key page down"); |
michael@0 | 332 | test_nsIDOMXULSelectControlElement_States(element, testid + "key page down", 6, fourthitem, 3, "fourth"); |
michael@0 | 333 | synthesizeKeyExpectEvent("VK_PAGE_DOWN", {}, element, "select", testid + "key page down to end"); |
michael@0 | 334 | test_nsIDOMXULSelectControlElement_States(element, testid + "key page down to end", 6, sixthitem, 5, "sixth"); |
michael@0 | 335 | |
michael@0 | 336 | synthesizeKeyExpectEvent("VK_PAGE_UP", {}, element, "select", testid + "key page up"); |
michael@0 | 337 | test_nsIDOMXULSelectControlElement_States(element, testid + "key page up", 6, thirditem, 2, "third"); |
michael@0 | 338 | synthesizeKeyExpectEvent("VK_PAGE_UP", {}, element, "select", testid + "key page up to start"); |
michael@0 | 339 | test_nsIDOMXULSelectControlElement_States(element, testid + "key page up to start", 6, firstitem, 0, "first"); |
michael@0 | 340 | |
michael@0 | 341 | element.removeItemAt(5); |
michael@0 | 342 | element.removeItemAt(4); |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | // now test whether a disabled item works. |
michael@0 | 346 | element.selectedIndex = 0; |
michael@0 | 347 | seconditem.disabled = true; |
michael@0 | 348 | |
michael@0 | 349 | var dontSelectDisabled = (behaviourContains(element.localName, "dont-select-disabled")); |
michael@0 | 350 | |
michael@0 | 351 | // 'mouse select' - check if clicking an item selects it |
michael@0 | 352 | synthesizeMouseExpectEvent(seconditem, 2, 2, {}, element, |
michael@0 | 353 | dontSelectDisabled ? "!select" : "select", |
michael@0 | 354 | testid + "mouse select disabled"); |
michael@0 | 355 | test_nsIDOMXULSelectControlElement_States(element, testid + "mouse select disabled", 4, |
michael@0 | 356 | dontSelectDisabled ? firstitem: seconditem, dontSelectDisabled ? 0 : 1, |
michael@0 | 357 | dontSelectDisabled ? "first" : "second"); |
michael@0 | 358 | |
michael@0 | 359 | if (dontSelectDisabled) { |
michael@0 | 360 | // test whether disabling an item won't allow it to be selected |
michael@0 | 361 | synthesizeKeyExpectEvent(forwardKey, {}, element, "select", testid + "key down disabled"); |
michael@0 | 362 | test_nsIDOMXULSelectControlElement_States(element, testid + "key down disabled", 4, thirditem, 2, "third"); |
michael@0 | 363 | |
michael@0 | 364 | synthesizeKeyExpectEvent(backKey, {}, element, "select", testid + "key up disabled"); |
michael@0 | 365 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up disabled", 4, firstitem, 0, "first"); |
michael@0 | 366 | |
michael@0 | 367 | element.selectedIndex = 2; |
michael@0 | 368 | firstitem.disabled = true; |
michael@0 | 369 | |
michael@0 | 370 | synthesizeKeyExpectEvent(backKey, {}, keyWrap ? element : null, "select", testid + "key up disabled 2"); |
michael@0 | 371 | expectedItem = keyWrap ? fourthitem : thirditem; |
michael@0 | 372 | expectedIndex = keyWrap ? 3 : 2; |
michael@0 | 373 | expectedValue = keyWrap ? "fourth" : "third"; |
michael@0 | 374 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up disabled 2", 4, |
michael@0 | 375 | expectedItem, expectedIndex, expectedValue); |
michael@0 | 376 | } |
michael@0 | 377 | else { |
michael@0 | 378 | // in this case, disabled items should behave the same as non-disabled items. |
michael@0 | 379 | element.selectedIndex = 0; |
michael@0 | 380 | synthesizeKeyExpectEvent(forwardKey, {}, element, "select", testid + "key down disabled"); |
michael@0 | 381 | test_nsIDOMXULSelectControlElement_States(element, testid + "key down disabled", 4, seconditem, 1, "second"); |
michael@0 | 382 | synthesizeKeyExpectEvent(forwardKey, {}, element, "select", testid + "key down disabled again"); |
michael@0 | 383 | test_nsIDOMXULSelectControlElement_States(element, testid + "key down disabled again", 4, thirditem, 2, "third"); |
michael@0 | 384 | |
michael@0 | 385 | synthesizeKeyExpectEvent(backKey, {}, element, "select", testid + "key up disabled"); |
michael@0 | 386 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up disabled", 4, seconditem, 1, "second"); |
michael@0 | 387 | synthesizeKeyExpectEvent(backKey, {}, element, "select", testid + "key up disabled again"); |
michael@0 | 388 | test_nsIDOMXULSelectControlElement_States(element, testid + "key up disabled again", 4, firstitem, 0, "first"); |
michael@0 | 389 | } |
michael@0 | 390 | } |