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