Debian Codegraph @

dojox/mobile/tests/doh/longlistmixin/LongListMixin.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5 <meta name="viewport"
6 content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
7 <meta name="apple-mobile-web-app-capable" content="yes"/>
8 <title>LongListMixin Tests</title>
9
10 <!-- DOH test for dojox/mobile/LongListMixin (performance booster for long scrollable lists) -->
11
12 <script type="text/javascript" src="../../../deviceTheme.js"></script>
13 <script type="text/javascript" src="../../../../../dojo/dojo.js"
14 data-dojo-config="async: true, parseOnLoad: true, mblAlwaysHideAddressBar: true"></script>
15
16 <script type="text/javascript">
17 require([
18 "dojo/ready",
19 "dijit/registry",
20 "doh/runner",
21 "dojo/query",
22 "dojo/dom-geometry",
23 "dojox/mobile/ListItem",
24 "dojo/store/Memory",
25 "dojox/mobile/parser",
26 "dojox/mobile",
27 "dojox/mobile/compat",
28 "dojox/mobile/ScrollableView",
29 "dojox/mobile/RoundRectList",
30 "dojox/mobile/RoundRectStoreList",
31 "dojox/mobile/LongListMixin"
32 ], function(ready, registry, runner, query, domGeometry, ListItem, MemoryStore){
33
34 function fillList(list, variableHeight){
35 list = registry.byId(list);
36 var c = list.getChildren();
37 var i;
38 for(i = 0; i < c.length; i++){
39 list.removeChild(c[i]);
40 }
41 doh.assertEqual(0, list.getChildren().length, "list not empty after removing all children");
42 for(i = 0; i < 1000; i++){
43 list.addChild(new ListItem(
44 !variableHeight ?
45 {
46 label: "Item " + i
47 } :
48 {
49 variableHeight: true,
50 innerHTML: "Item " + i + "<br/>Some more content<br/>in the list item<br/>etc..."
51 }
52 ));
53 }
54 doh.assertEqual(1000, list.getChildren().length, "list should have 1000 children");
55 }
56
57 function fillStoreList(list){
58 list = registry.byId(list);
59 var data = [];
60 for(i = 0; i < 1000; i++){
61 data.push({ label: "Store item " + i });
62 }
63
64 var store = new MemoryStore({idProperty: "label", data: data});
65 list.setStore(store);
66
67 doh.assertEqual(1000, list.getChildren().length, "list should have 1000 children");
68 }
69
70 function verifyList(list){
71 list = registry.byId(list);
72 var itemHeight = list.getChildren()[0].domNode.offsetHeight;
73
74 if (itemHeight > 0){
75 var item = list.getChildren()[0].domNode,
76 itemMargin = Math.max(parseFloat(window.getComputedStyle(item).marginTop),
77 parseFloat(window.getComputedStyle(item).marginBottom));
78 if (!isNaN(itemMargin)){
79 itemHeight += itemMargin;
80 }
81 }
82
83 var viewHeight = list.getParent().domNode.offsetHeight;
84 var pageSize = list.pageSize;
85
86 // total list height (should be approx nitems *itemHeight, modulo margin collapsing)
87 var expectedListHeight = itemHeight * list.getChildren().length;
88 var actualListHeight = list.domNode.offsetHeight;
89 var delta = 3*list.getChildren().length;
90 if(list.getChildren()[0].variableHeight){
91 delta *= 2;
92 }
93 doh.assertTrue(Math.abs(expectedListHeight-actualListHeight) < delta, "wrong list height: " + actualListHeight + " != " + expectedListHeight);
94
95 // expected number of items in list DOM: multiple of pageSize, less than maxPages*pageSize
96 var count = query(".mblListItem", list.containerNode).length;
97 doh.assertTrue(count % pageSize == 0, "not a multiple of pageSize: " + count);
98 doh.assertTrue(count < pageSize * list.maxPages, "more than maxPages: " + count);
99
100 // check that the visible area is actually filled by items
101 var listBox = domGeometry.getContentBox(list.containerNode);
102 var viewBox = domGeometry.getContentBox(list.getParent().domNode);
103 doh.assertTrue(listBox.t <= viewBox.t, "empty space at top " + listBox.t + " > " + viewBox.t);
104 doh.assertTrue(listBox.t + listBox.h >= viewBox.t + viewBox.h, "empty space at bottom " + (listBox.t+listBox.h) + " < " + (viewBox.t+viewBox.h));
105 }
106
107 ready(function(){
108 doh.register("dojox.mobile.test.doh.LongListMixinTests", [
109 {
110 name: "LongListMixin - initial items",
111 timeout: 200,
112 setUp: function(){
113 fillList("list1");
114 },
115 runTest: function(){
116 var d = new doh.Deferred();
117 setTimeout(d.getTestCallback(function(){
118 verifyList("list1");
119 }), 200);
120 return d;
121 }
122 },
123 {
124 name: "LongListMixin - scroll",
125 timeout: 1000,
126 setUp: function(){
127 fillList("list1")
128 var view = registry.byId("view1");
129 view.scrollTo({y:-1000});
130 },
131 runTest: function(){
132 var d = new doh.Deferred();
133 setTimeout(d.getTestCallback(function(){
134 verifyList("list1");
135 }), 200);
136 return d;
137 }
138 },
139 {
140 name: "LongListMixin - slide",
141 timeout: 1000,
142 setUp: function(){
143 fillList("list1");
144 var view = registry.byId("view1");
145 view.scrollTo({y:-1000});
146 view.slideTo({y:-1200}, 0.3, "ease-out");
147 },
148 runTest: function(){
149 var d = new doh.Deferred();
150 setTimeout(d.getTestCallback(function(){
151 verifyList("list1");
152 }), 500);
153 return d;
154 }
155 },
156 {
157 name: "LongListMixin - variable height - initial items",
158 timeout: 200,
159 setUp: function(){
160 fillList("list1", true);
161 },
162 runTest: function(){
163 var d = new doh.Deferred();
164 setTimeout(d.getTestCallback(function(){
165 verifyList("list1");
166 }), 200);
167 return d;
168 }
169 },
170 {
171 name: "LongListMixin - variable height - scroll",
172 timeout: 1000,
173 setUp: function(){
174 fillList("list1", true)
175 var view = registry.byId("view1");
176 view.scrollTo({y:-5000});
177 },
178 runTest: function(){
179 var d = new doh.Deferred();
180 setTimeout(d.getTestCallback(function(){
181 verifyList("list1");
182 }), 200);
183 return d;
184 }
185 },
186 {
187 name: "LongListMixin - variable height - slide",
188 timeout: 1000,
189 setUp: function(){
190 fillList("list1", true);
191 var view = registry.byId("view1");
192 view.scrollTo({y:-5000});
193 view.slideTo({y:-5200}, 0.3, "ease-out");
194 },
195 runTest: function(){
196 var d = new doh.Deferred();
197 setTimeout(d.getTestCallback(function(){
198 verifyList("list1");
199 }), 500);
200 return d;
201 }
202 },
203 {
204 name: "LongListMixin + store - initial items",
205 timeout: 200,
206 setUp: function(){
207 registry.byId("view2").show();
208 fillStoreList("list2");
209 },
210 runTest: function(){
211 var d = new doh.Deferred();
212 setTimeout(d.getTestCallback(function(){
213 verifyList("list1");
214 }), 200);
215 return d;
216 }
217 },
218 {
219 name: "LongListMixin + store - scroll",
220 timeout: 1000,
221 setUp: function(){
222 fillStoreList("list2")
223 var view = registry.byId("view2");
224 view.scrollTo({y:-1000});
225 },
226 runTest: function(){
227 var d = new doh.Deferred();
228 setTimeout(d.getTestCallback(function(){
229 verifyList("list1");
230 }), 200);
231 return d;
232 }
233 },
234 {
235 name: "LongListMixin + store - slide",
236 timeout: 1000,
237 setUp: function(){
238 fillStoreList("list2");
239 var view = registry.byId("view2");
240 view.scrollTo({y:-1000});
241 view.slideTo({y:-1200}, 0.3, "ease-out");
242 },
243 runTest: function(){
244 var d = new doh.Deferred();
245 setTimeout(d.getTestCallback(function(){
246 verifyList("list1");
247 }), 500);
248 return d;
249 }
250 }
251 ]);
252 runner.run();
253 });
254 })
255 </script>
256
257 </head>
258 <body>
259 <div id="view1" data-dojo-type="dojox/mobile/ScrollableView" data-dojo-props="height:'400px'">
260 <h1 data-dojo-type="dojox/mobile/Heading" data-dojo-props="fixed: 'top'">LongListMixin - no store</h1>
261 <ul data-dojo-type="dojox/mobile/RoundRectList" id="list1"
262 data-dojo-mixins="dojox/mobile/LongListMixin"></ul>
263 </div>
264 <div id="view2" data-dojo-type="dojox/mobile/ScrollableView" data-dojo-props="height:'400px'">
265 <h1 data-dojo-type="dojox/mobile/Heading" data-dojo-props="fixed: 'top'">LongListMixin + store</h1>
266 <ul data-dojo-type="dojox/mobile/RoundRectStoreList" id="list2"
267 data-dojo-mixins="dojox/mobile/LongListMixin"></ul>
268 </div>
269 </body>
270 </html>