Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/list-control-variable-height.js

Issue 2609363002: [DevTools] Tweak ListControl API. (Closed)
Patch Set: fixed review comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 TestRunner.addResult('Test ListControl rendering for variable height case.');
2
3 class Delegate {
4 constructor() {
5 }
6
7 createElementForItem(item) {
8 TestRunner.addResult('Creating element for ' + item);
9 var element = document.createElement('div');
10 element.style.height = this.heightForItem(item) + 'px';
11 element.textContent = item;
12 return element;
13 }
14
15 heightForItem(item) {
16 return 7 + item % 10;
17 }
18
19 isItemSelectable(item) {
20 return (item % 5 === 0) || (item % 5 === 2);
21 }
22
23 selectedItemChanged(from, to, fromElement, toElement) {
24 TestRunner.addResult('Selection changed from ' + from + ' to ' + to);
25 if (fromElement)
26 fromElement.classList.remove('selected');
27 if (toElement)
28 toElement.classList.add('selected');
29 }
30 }
31
32 var delegate = new Delegate();
33 var list = new UI.ListControl(delegate, UI.ListMode.ViewportVariableItems);
34 list.element.style.height = '73px';
35 UI.inspectorView.element.appendChild(list.element);
36
37 function dumpList()
38 {
39 var height = list.element.offsetHeight;
40 TestRunner.addResult(`----list[length=${list.length()}][height=${height}]----` );
41 for (var child of list.element.children) {
42 var offsetTop = child.getBoundingClientRect().top - list.element.getBounding ClientRect().top;
43 var offsetBottom = child.getBoundingClientRect().bottom - list.element.getBo undingClientRect().top;
44 var visible = (offsetBottom <= 0 || offsetTop >= height) ? ' ' :
45 (offsetTop >= 0 && offsetBottom <= height ? '*' : '+');
46 var selected = child.classList.contains('selected') ? ' (selected)' : '';
47 var text = child === list._topElement ? 'top' : (child === list._bottomEleme nt ? 'bottom' : child.textContent);
48 TestRunner.addResult(`${visible}[${offsetTop}] ${text}${selected}`);
49 }
50 TestRunner.addResult('offsets: ' + list._variableOffsets.join(' '));
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('Adding 3-20');
67 list.replaceItemsInRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
68 dumpList();
69
70 TestRunner.addResult('Scrolling to 11');
71 list.scrollItemAtIndexIntoView(11);
72 dumpList();
73
74 TestRunner.addResult('Scrolling to 19');
75 list.scrollItemAtIndexIntoView(19);
76 dumpList();
77
78 TestRunner.addResult('Scrolling to 16');
79 list.scrollItemAtIndexIntoView(16);
80 dumpList();
81
82 TestRunner.addResult('Scrolling to 3');
83 list.scrollItemAtIndexIntoView(3);
84 dumpList();
85
86 TestRunner.addResult('Replacing 0, 1 with 25-36');
87 list.replaceItemsInRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]) ;
88 dumpList();
89
90 TestRunner.addResult('Scrolling to 18');
91 list.scrollItemAtIndexIntoView(28);
92 dumpList();
93
94 TestRunner.addResult('Replacing 25-36 with 0-1');
95 list.replaceItemsInRange(0, 12, [0, 1]);
96 dumpList();
97
98 TestRunner.addResult('Replacing 16-18 with 45');
99 list.replaceItemsInRange(16, 19, [45]);
100 dumpList();
101
102 TestRunner.addResult('Scrolling to 4');
103 list.scrollItemAtIndexIntoView(4);
104 dumpList();
105
106 TestRunner.addResult('Replacing 45 with 16-18');
107 list.replaceItemsInRange(16, 17, [16, 17, 18]);
108 dumpList();
109
110 TestRunner.addResult('Resizing');
111 list.element.style.height = '190px';
112 list.viewportResized();
113 dumpList();
114
115 TestRunner.completeTest();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698