| OLD | NEW |
| (Empty) | |
| 1 var items = [ |
| 2 { |
| 3 title: "first", |
| 4 index: 0 |
| 5 }, |
| 6 { |
| 7 title: "second", |
| 8 index: 1 |
| 9 }, |
| 10 { |
| 11 title: "third", |
| 12 index: 2 |
| 13 }, |
| 14 { |
| 15 title: "fourth", |
| 16 index: 3 |
| 17 }, |
| 18 { |
| 19 title: "disabled 4.5", |
| 20 disabled: true, |
| 21 index: 4 |
| 22 }, |
| 23 { |
| 24 title: "fifth", |
| 25 index: 5 |
| 26 }, |
| 27 { |
| 28 title: "sixth", |
| 29 index: 6 |
| 30 }, |
| 31 { |
| 32 title: "seventh", |
| 33 index: 7 |
| 34 }, |
| 35 { |
| 36 title: "eighth", |
| 37 index: 8 |
| 38 } |
| 39 ]; |
| 40 |
| 41 class Delegate { |
| 42 titleFor(item) { |
| 43 return item.title; |
| 44 } |
| 45 |
| 46 createElementForItem(item) { |
| 47 var element = createElement("div"); |
| 48 element.textContent = this.titleFor(item); |
| 49 return element; |
| 50 } |
| 51 |
| 52 isItemSelectable(item) { |
| 53 return !item.disabled; |
| 54 } |
| 55 |
| 56 itemSelected(item) { |
| 57 if (item !== null) |
| 58 TestRunner.addResult("Item selected: " + this.titleFor(item)); |
| 59 } |
| 60 |
| 61 highlightedItemChanged(from, to, fromElement, toElement) { |
| 62 if (to !== null) |
| 63 TestRunner.addResult("Item highlighted: " + this.titleFor(to)); |
| 64 } |
| 65 }; |
| 66 |
| 67 function pressKey(key) { |
| 68 var element = document.deepActiveElement(); |
| 69 if (!element) |
| 70 return; |
| 71 TestRunner.addResult(key); |
| 72 element.dispatchEvent(TestRunner.createKeyEvent(key)); |
| 73 } |
| 74 var model = new UI.ListModel(); |
| 75 var dropDown = new UI.SoftDropDown(model, new Delegate()); |
| 76 for (var i = items.length - 1; i >= 0; i--) |
| 77 model.insertWithComparator(items[i], (a, b) => a.index - b.index); |
| 78 |
| 79 UI.inspectorView.element.appendChild(dropDown.element); |
| 80 dropDown.selectItem(items[5]); |
| 81 TestRunner.addResult("Showing drop down"); |
| 82 dropDown.element.dispatchEvent(new Event("mousedown")); |
| 83 pressKey('ArrowDown'); |
| 84 pressKey('ArrowDown'); |
| 85 pressKey('ArrowDown'); |
| 86 pressKey('ArrowUp'); |
| 87 pressKey('ArrowUp'); |
| 88 pressKey('ArrowUp'); |
| 89 pressKey('ArrowDown'); |
| 90 pressKey('ArrowDown'); |
| 91 pressKey('f'); |
| 92 pressKey('f'); |
| 93 pressKey('t'); |
| 94 TestRunner.completeTest(); |
| OLD | NEW |