OLD | NEW |
(Empty) | |
| 1 TestRunner.addResult('Test ListControl rendering and selection for fixed height
case.'); |
| 2 |
| 3 class Delegate { |
| 4 constructor() { |
| 5 this.height = 10; |
| 6 } |
| 7 |
| 8 createElementForItem(item) { |
| 9 TestRunner.addResult('Creating element for ' + item); |
| 10 var element = document.createElement('div'); |
| 11 element.style.height = this.height + 'px'; |
| 12 element.textContent = item; |
| 13 return element; |
| 14 } |
| 15 |
| 16 heightForItem(item) { |
| 17 return this.height; |
| 18 } |
| 19 |
| 20 isItemSelectable(item) { |
| 21 return (item % 5 === 0) || (item % 5 === 2); |
| 22 } |
| 23 |
| 24 selectedItemChanged(from, to, fromElement, toElement) { |
| 25 TestRunner.addResult('Selection changed from ' + from + ' to ' + to); |
| 26 if (fromElement) |
| 27 fromElement.classList.remove('selected'); |
| 28 if (toElement) |
| 29 toElement.classList.add('selected'); |
| 30 } |
| 31 } |
| 32 |
| 33 var delegate = new Delegate(); |
| 34 var list = new UI.ListControl(delegate); |
| 35 list.setHeightMode(UI.ListHeightMode.Fixed); |
| 36 list.element.style.height = '73px'; |
| 37 UI.inspectorView.element.appendChild(list.element); |
| 38 |
| 39 function dumpList() |
| 40 { |
| 41 var height = list.element.offsetHeight; |
| 42 TestRunner.addResult(`----list[length=${list.length()}][height=${height}]----`
); |
| 43 for (var child of list.element.children) { |
| 44 var offsetTop = child.getBoundingClientRect().top - list.element.getBounding
ClientRect().top; |
| 45 var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBo
undingClientRect().top; |
| 46 var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' : |
| 47 (offsetTop >= 0 && offsetBottom <= height ? '*' : '+'); |
| 48 var selected = child.classList.contains('selected') ? ' (selected)' : ''; |
| 49 var text = child === list._topElement ? 'top' : (child === list._bottomEleme
nt ? 'bottom' : child.textContent); |
| 50 TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`); |
| 51 } |
| 52 TestRunner.addResult(''); |
| 53 } |
| 54 |
| 55 TestRunner.addResult('Adding 0, 1, 2'); |
| 56 list.replaceAllItems([0, 1, 2]); |
| 57 dumpList(); |
| 58 |
| 59 TestRunner.addResult('Scrolling to 0'); |
| 60 list.scrollItemAtIndexIntoView(0); |
| 61 dumpList(); |
| 62 |
| 63 TestRunner.addResult('Scrolling to 2'); |
| 64 list.scrollItemAtIndexIntoView(2); |
| 65 dumpList(); |
| 66 |
| 67 TestRunner.addResult('ArrowDown'); |
| 68 list.onKeyDown(TestRunner.createKeyEvent('ArrowDown')); |
| 69 dumpList(); |
| 70 |
| 71 TestRunner.addResult('Selecting 2'); |
| 72 list.selectItemAtIndex(2); |
| 73 dumpList(); |
| 74 |
| 75 TestRunner.addResult('PageUp'); |
| 76 list.onKeyDown(TestRunner.createKeyEvent('PageUp')); |
| 77 dumpList(); |
| 78 |
| 79 TestRunner.addResult('PageDown'); |
| 80 list.onKeyDown(TestRunner.createKeyEvent('PageDown')); |
| 81 dumpList(); |
| 82 |
| 83 TestRunner.addResult('ArrowDown'); |
| 84 list.onKeyDown(TestRunner.createKeyEvent('ArrowDown')); |
| 85 dumpList(); |
| 86 |
| 87 TestRunner.addResult('Replacing 0 with 5, 6, 7'); |
| 88 list.replaceItemsInRange(0, 1, [5, 6, 7]); |
| 89 dumpList(); |
| 90 |
| 91 TestRunner.addResult('ArrowUp'); |
| 92 list.onKeyDown(TestRunner.createKeyEvent('ArrowUp')); |
| 93 dumpList(); |
| 94 |
| 95 TestRunner.addResult('Pushing 10'); |
| 96 list.pushItem(10); |
| 97 dumpList(); |
| 98 |
| 99 TestRunner.addResult('Selecting 10'); |
| 100 list.selectItemAtIndex(5); |
| 101 dumpList(); |
| 102 |
| 103 TestRunner.addResult('Popping 10'); |
| 104 list.popItem(); |
| 105 dumpList(); |
| 106 |
| 107 TestRunner.addResult('Removing 2'); |
| 108 list.removeItemAtIndex(4); |
| 109 dumpList(); |
| 110 |
| 111 TestRunner.addResult('Inserting 8'); |
| 112 list.insertItemAtIndex(1, 8); |
| 113 dumpList(); |
| 114 |
| 115 TestRunner.addResult('Replacing with 0...20'); |
| 116 list.replaceAllItems([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19]); |
| 117 dumpList(); |
| 118 |
| 119 TestRunner.addResult('Resizing'); |
| 120 list.element.style.height = '84px'; |
| 121 list.viewportResized(); |
| 122 dumpList(); |
| 123 |
| 124 TestRunner.addResult('Scrolling to 19'); |
| 125 list.scrollItemAtIndexIntoView(19); |
| 126 dumpList(); |
| 127 |
| 128 TestRunner.addResult('Scrolling to 5'); |
| 129 list.scrollItemAtIndexIntoView(5); |
| 130 dumpList(); |
| 131 |
| 132 TestRunner.addResult('Scrolling to 12'); |
| 133 list.scrollItemAtIndexIntoView(12); |
| 134 dumpList(); |
| 135 |
| 136 TestRunner.addResult('Scrolling to 13'); |
| 137 list.scrollItemAtIndexIntoView(13); |
| 138 dumpList(); |
| 139 |
| 140 TestRunner.addResult('Changing the item height, switching to measure'); |
| 141 delegate.height = 15; |
| 142 list.setHeightMode(UI.ListHeightMode.Measured); |
| 143 dumpList(); |
| 144 |
| 145 TestRunner.addResult('Selecting 7'); |
| 146 list.selectItemAtIndex(7); |
| 147 dumpList(); |
| 148 |
| 149 TestRunner.addResult('Replacing 7 with 27'); |
| 150 list.replaceItemsInRange(7, 8, [27]); |
| 151 dumpList(); |
| 152 |
| 153 TestRunner.addResult('Replacing 18, 19 with 28, 29'); |
| 154 list.replaceItemsInRange(18, 20, [28, 29]); |
| 155 dumpList(); |
| 156 |
| 157 TestRunner.addResult('PageDown'); |
| 158 list.onKeyDown(TestRunner.createKeyEvent('PageDown')); |
| 159 dumpList(); |
| 160 |
| 161 TestRunner.addResult('Replacing 1, 2, 3 with [31-43]'); |
| 162 list.replaceItemsInRange(1, 4, [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43]); |
| 163 dumpList(); |
| 164 |
| 165 TestRunner.addResult('ArrowUp'); |
| 166 list.onKeyDown(TestRunner.createKeyEvent('ArrowUp')); |
| 167 dumpList(); |
| 168 |
| 169 TestRunner.addResult('Selecting -1'); |
| 170 list.selectItemAtIndex(-1); |
| 171 dumpList(); |
| 172 |
| 173 TestRunner.addResult('ArrowUp'); |
| 174 list.onKeyDown(TestRunner.createKeyEvent('ArrowUp')); |
| 175 dumpList(); |
| 176 |
| 177 TestRunner.addResult('Selecting -1'); |
| 178 list.selectItemAtIndex(-1); |
| 179 dumpList(); |
| 180 |
| 181 TestRunner.addResult('ArrowDown'); |
| 182 list.onKeyDown(TestRunner.createKeyEvent('ArrowDown')); |
| 183 dumpList(); |
| 184 |
| 185 TestRunner.addResult('Selecting -1'); |
| 186 list.selectItemAtIndex(-1); |
| 187 dumpList(); |
| 188 |
| 189 TestRunner.addResult('PageUp'); |
| 190 list.onKeyDown(TestRunner.createKeyEvent('PageUp')); |
| 191 dumpList(); |
| 192 |
| 193 TestRunner.addResult('Replacing all but 29 with []'); |
| 194 list.replaceItemsInRange(0, 29, []); |
| 195 dumpList(); |
| 196 |
| 197 TestRunner.addResult('ArrowDown'); |
| 198 list.onKeyDown(TestRunner.createKeyEvent('ArrowDown')); |
| 199 dumpList(); |
| 200 |
| 201 TestRunner.completeTest(); |
OLD | NEW |