1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_richlist_direction.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 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 + XUL Widget Test for listbox direction 1.9 + --> 1.10 +<window title="Listbox direction test" 1.11 + onload="test_richlistbox()" 1.12 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.13 + <script type="application/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="application/javascript" 1.16 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.17 + 1.18 + <richlistbox seltype="multiple" id="richlistbox" flex="1" minheight="80" maxheight="80" height="80" /> 1.19 + 1.20 + <!-- test results are displayed in the html:body --> 1.21 + <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> 1.22 + 1.23 +<script type="application/javascript"> 1.24 +<![CDATA[ 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 +var richListBox = document.getElementById("richlistbox"); 1.29 + 1.30 +function getScrollIndexAmount(aDirection) { 1.31 + return (4 * aDirection + richListBox.currentIndex); 1.32 +} 1.33 + 1.34 +function test_richlistbox() 1.35 +{ 1.36 + richListBox.minHeight = richListBox.maxHeight = richListBox.height = 1.37 + 80 + (80 - richListBox.scrollBoxObject.height); 1.38 + var height = richListBox.scrollBoxObject.height; 1.39 + var item; 1.40 + do { 1.41 + item = richListBox.appendItem("Test", ""); 1.42 + item.height = item.minHeight = item.maxHeight = Math.floor(height / 4); 1.43 + } while (item.getBoundingClientRect().bottom < (height * 2)) 1.44 + richListBox.appendItem("Test", ""); 1.45 + richListBox.firstChild.nextSibling.id = "list-box-first"; 1.46 + richListBox.lastChild.previousSibling.id = "list-box-last"; 1.47 + 1.48 + // direction = "reverse", the values here are backwards due to the fact that 1.49 + // richlistboxes respond differently when a user initiates a selection 1.50 + richListBox.dir = "reverse"; 1.51 + var count = richListBox.itemCount; 1.52 + richListBox.focus(); 1.53 + richListBox.selectedIndex = count - 1; 1.54 + sendKey("DOWN"); 1.55 + is(richListBox.currentIndex, count - 2, "Selection should move to the next item"); 1.56 + sendKey("UP"); 1.57 + is(richListBox.currentIndex, count - 1, "Selection should move to the previous item"); 1.58 + sendKey("END"); 1.59 + is(richListBox.currentIndex, 0, "Selection should move to the last item"); 1.60 + sendKey("HOME"); 1.61 + is(richListBox.currentIndex, count - 1, "Selection should move to the first item"); 1.62 + var currentIndex = richListBox.currentIndex; 1.63 + var index = getScrollIndexAmount(-1); 1.64 + sendKey("PAGE_DOWN"); 1.65 + is(richListBox.currentIndex, index, "Selection should move to one page down"); 1.66 + ok(richListBox.currentIndex < currentIndex, "Selection should move downwards"); 1.67 + sendKey("END"); 1.68 + currentIndex = richListBox.currentIndex; 1.69 + index = getScrollIndexAmount(1); 1.70 + sendKey("PAGE_UP"); 1.71 + is(richListBox.currentIndex, index, "Selection should move to one page up"); 1.72 + ok(richListBox.currentIndex > currentIndex, "Selection should move upwards"); 1.73 + richListBox.selectedItem = richListBox.lastChild; 1.74 + richListBox.focus(); 1.75 + synthesizeKey("VK_DOWN", {shiftKey: true, type: "keypress"}, window); 1.76 + let items = [richListBox.selectedItems[0], 1.77 + richListBox.selectedItems[1]]; 1.78 + is(items[0], richListBox.lastChild, "The last element should still be selected"); 1.79 + is(items[1], richListBox.lastChild.previousSibling, "Both elements should now be selected"); 1.80 + richListBox.clearSelection(); 1.81 + richListBox.selectedItem = richListBox.lastChild; 1.82 + sendMouseEvent({type: "click", shiftKey: true, clickCount: 1}, 1.83 + "list-box-last", 1.84 + window); 1.85 + items = [richListBox.selectedItems[0], 1.86 + richListBox.selectedItems[1]]; 1.87 + is(items[0], richListBox.lastChild, "The last element should still be selected"); 1.88 + is(items[1], richListBox.lastChild.previousSibling, "Both elements should now be selected"); 1.89 + richListBox.addEventListener("keypress", function(aEvent) { 1.90 + richListBox.removeEventListener("keypress", arguments.callee, true); 1.91 + aEvent.preventDefault(); 1.92 + }, true); 1.93 + richListBox.selectedIndex = 1; 1.94 + sendKey("HOME"); 1.95 + is(richListBox.selectedIndex, 1, "A stopped event should return indexing to normal"); 1.96 + 1.97 + // direction = "normal" 1.98 + richListBox.dir = "normal"; 1.99 + richListBox.selectedIndex = 0; 1.100 + sendKey("DOWN"); 1.101 + is(richListBox.currentIndex, 1, "Selection should move to the next item"); 1.102 + sendKey("UP"); 1.103 + is(richListBox.currentIndex, 0, "Selection should move to the previous item"); 1.104 + sendKey("END"); 1.105 + is(richListBox.currentIndex, count - 1, "Selection should move to the last item"); 1.106 + sendKey("HOME"); 1.107 + is(richListBox.currentIndex, 0, "Selection should move to the first item"); 1.108 + var currentIndex = richListBox.currentIndex; 1.109 + var index = richListBox.scrollOnePage(1); 1.110 + sendKey("PAGE_DOWN"); 1.111 + is(richListBox.currentIndex, index, "Selection should move to one page down"); 1.112 + ok(richListBox.currentIndex > currentIndex, "Selection should move downwards"); 1.113 + sendKey("END"); 1.114 + currentIndex = richListBox.currentIndex; 1.115 + index = richListBox.scrollOnePage(-1) + richListBox.currentIndex; 1.116 + sendKey("PAGE_UP"); 1.117 + is(richListBox.currentIndex, index, "Selection should move to one page up"); 1.118 + ok(richListBox.currentIndex < currentIndex, "Selection should move upwards"); 1.119 + richListBox.selectedItem = richListBox.firstChild; 1.120 + richListBox.focus(); 1.121 + synthesizeKey("VK_DOWN", {shiftKey: true, type: "keypress"}, window); 1.122 + items = [richListBox.selectedItems[0], 1.123 + richListBox.selectedItems[1]]; 1.124 + is(items[0], richListBox.firstChild, "The last element should still be selected"); 1.125 + is(items[1], richListBox.firstChild.nextSibling, "Both elements should now be selected"); 1.126 + richListBox.clearSelection(); 1.127 + richListBox.selectedItem = richListBox.firstChild; 1.128 + sendMouseEvent({type: "click", shiftKey: true, clickCount: 1}, 1.129 + "list-box-first", 1.130 + window); 1.131 + items = [richListBox.selectedItems[0], 1.132 + richListBox.selectedItems[1]]; 1.133 + is(items[0], richListBox.firstChild, "The last element should still be selected"); 1.134 + is(items[1], richListBox.firstChild.nextSibling, "Both elements should now be selected"); 1.135 + SimpleTest.finish(); 1.136 +} 1.137 + 1.138 +]]> 1.139 +</script> 1.140 + 1.141 +</window>