| OLD | NEW |
| (Empty) | |
| 1 var items = [ |
| 2 { |
| 3 title: "first", |
| 4 depth: 0, |
| 5 index: 0 |
| 6 }, |
| 7 { |
| 8 title: "second", |
| 9 depth: 0, |
| 10 index: 1 |
| 11 }, |
| 12 { |
| 13 title: "third", |
| 14 depth: 0, |
| 15 index: 2 |
| 16 }, |
| 17 { |
| 18 title: "fourth", |
| 19 depth: 0, |
| 20 index: 3 |
| 21 }, |
| 22 { |
| 23 title: "disabled 4.5", |
| 24 disabled: true, |
| 25 depth: 0, |
| 26 index: 4 |
| 27 }, |
| 28 { |
| 29 title: "fifth", |
| 30 depth: 0, |
| 31 index: 5 |
| 32 }, |
| 33 { |
| 34 title: "sixth", |
| 35 depth: 0, |
| 36 index: 6 |
| 37 }, |
| 38 { |
| 39 title: "seventh", |
| 40 depth: 0, |
| 41 index: 7 |
| 42 }, |
| 43 { |
| 44 title: "seventh-sub-item", |
| 45 depth: 1, |
| 46 index: 8 |
| 47 }, |
| 48 { |
| 49 title: "seventh-sub-sub-item", |
| 50 depth: 2, |
| 51 index: 9 |
| 52 }, |
| 53 { |
| 54 title: "eighth", |
| 55 depth: 0, |
| 56 index: 10 |
| 57 } |
| 58 ]; |
| 59 |
| 60 class Delegate { |
| 61 titleFor(item) { |
| 62 return item.title; |
| 63 } |
| 64 |
| 65 depthFor(item) { |
| 66 return item.depth; |
| 67 } |
| 68 |
| 69 elementForItem(item) { |
| 70 var div = createElement("div"); |
| 71 div.textContent = this.titleFor(item); |
| 72 return div; |
| 73 } |
| 74 |
| 75 /** |
| 76 * @param {T} item |
| 77 * @return {boolean} |
| 78 */ |
| 79 isItemSelectable(item) { |
| 80 return !item.disabled; |
| 81 } |
| 82 |
| 83 /** |
| 84 * @param {?T} item |
| 85 */ |
| 86 itemSelected(item) { |
| 87 if (item !== null) |
| 88 TestRunner.addResult("Item selected: " + this.titleFor(item)); |
| 89 } |
| 90 |
| 91 /** |
| 92 * @param {?T} item |
| 93 */ |
| 94 itemHighlighted(item) { |
| 95 if (item !== null) |
| 96 TestRunner.addResult("Item highlighted: " + this.titleFor(item)); |
| 97 } |
| 98 }; |
| 99 |
| 100 function pressKey(key) { |
| 101 var element = document.deepActiveElement(); |
| 102 if (!element) |
| 103 return; |
| 104 TestRunner.addResult(key); |
| 105 element.dispatchEvent(TestRunner.createKeyEvent(key)); |
| 106 } |
| 107 |
| 108 var dropDown = new UI.SoftDropDown(new Delegate()); |
| 109 for (var i = items.length - 1; i >= 0; i--) { |
| 110 dropDown.insertItemWithComparator(items[i], (a, b) => a.index - b.index); |
| 111 } |
| 112 UI.inspectorView.element.appendChild(dropDown.element); |
| 113 dropDown.selectItem(items[5]); |
| 114 TestRunner.addResult("Showing drop down"); |
| 115 dropDown.element.dispatchEvent(new Event("mousedown")); |
| 116 pressKey('ArrowDown'); |
| 117 pressKey('ArrowDown'); |
| 118 pressKey('ArrowDown'); |
| 119 pressKey('ArrowUp'); |
| 120 pressKey('ArrowUp'); |
| 121 pressKey('ArrowUp'); |
| 122 pressKey('ArrowDown'); |
| 123 pressKey('ArrowDown'); |
| 124 pressKey('ArrowRight'); |
| 125 pressKey('ArrowRight'); |
| 126 pressKey('ArrowRight'); |
| 127 pressKey('ArrowLeft'); |
| 128 pressKey('ArrowLeft'); |
| 129 pressKey('ArrowLeft'); |
| 130 pressKey('ArrowLeft'); |
| 131 pressKey('f'); |
| 132 pressKey('f'); |
| 133 pressKey('t'); |
| 134 TestRunner.completeTest(); |
| OLD | NEW |