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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/list-control-grow.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 and selection for grow mode.');
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 = (10 + item % 5) + 'px';
11 element.textContent = item;
12 return element;
13 }
14
15 heightForItem(item) {
16 TestRunner.addResult('heightForItem should not be called');
17 return 10 + item % 5;
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.Grow);
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('');
51 }
52
53 TestRunner.addResult('Adding 0, 1, 2');
54 list.replaceAllItems([0, 1, 2]);
55 dumpList();
56
57 TestRunner.addResult('Scrolling to 0');
58 list.scrollItemAtIndexIntoView(0);
59 dumpList();
60
61 TestRunner.addResult('Scrolling to 2');
62 list.scrollItemAtIndexIntoView(2);
63 dumpList();
64
65 TestRunner.addResult('Adding 3-20');
66 list.replaceItemsInRange(3, 3, [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
67 dumpList();
68
69 TestRunner.addResult('Scrolling to 19');
70 list.scrollItemAtIndexIntoView(19);
71 dumpList();
72
73 TestRunner.addResult('Replacing 0, 1 with 25-36');
74 list.replaceItemsInRange(0, 2, [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]) ;
75 dumpList();
76
77 TestRunner.addResult('Scrolling to 18');
78 list.scrollItemAtIndexIntoView(28);
79 dumpList();
80
81 TestRunner.addResult('Replacing 25-36 with 0-1');
82 list.replaceItemsInRange(0, 12, [0, 1]);
83 dumpList();
84
85 TestRunner.addResult('Replacing 16-18 with 45');
86 list.replaceItemsInRange(16, 19, [45]);
87 dumpList();
88
89 TestRunner.addResult('Scrolling to 4');
90 list.scrollItemAtIndexIntoView(4);
91 dumpList();
92
93 TestRunner.addResult('Replacing 45 with 16-18');
94 list.replaceItemsInRange(16, 17, [16, 17, 18]);
95 dumpList();
96
97 TestRunner.completeTest();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698