OLD | NEW |
| (Empty) |
1 library dromaeo; | |
2 import 'dart:html'; | |
3 import '../common/common.dart'; | |
4 import 'dart:math' as Math; | |
5 part 'Common.dart'; | |
6 part 'RunnerSuite.dart'; | |
7 | |
8 void main() { | |
9 final int num = 40; | |
10 | |
11 // Try to force real results. | |
12 var ret; | |
13 | |
14 String html = document.body.innerHtml; | |
15 | |
16 new Suite(window, 'dom-query') | |
17 .prep(() { | |
18 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { | |
19 final group = match.group(1); | |
20 return 'id="test${group}${num}"'; | |
21 }); | |
22 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { | |
23 return 'name="test${num}"'; | |
24 }); | |
25 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { | |
26 return 'class="foo test${num} bar"'; | |
27 }); | |
28 final div = new Element.tag('div'); | |
29 div.innerHtml = html; | |
30 document.body.nodes.add(div); | |
31 }) | |
32 .test('getElementById', () { | |
33 for (int i = 0; i < num * 30; i++) { | |
34 ret = document.query('#testA$num').nodeType; | |
35 ret = document.query('#testB$num').nodeType; | |
36 ret = document.query('#testC$num').nodeType; | |
37 ret = document.query('#testD$num').nodeType; | |
38 ret = document.query('#testE$num').nodeType; | |
39 ret = document.query('#testF$num').nodeType; | |
40 } | |
41 }) | |
42 .test('getElementById (not in document)', () { | |
43 for (int i = 0; i < num * 30; i++) { | |
44 ret = document.query('#testA'); | |
45 ret = document.query('#testB'); | |
46 ret = document.query('#testC'); | |
47 ret = document.query('#testD'); | |
48 ret = document.query('#testE'); | |
49 ret = document.query('#testF'); | |
50 } | |
51 }) | |
52 .test('getElementsByTagName(div)', () { | |
53 for (int i = 0; i < num; i++) { | |
54 List<Element> elems = document.queryAll('div'); | |
55 ret = elems.last.nodeType; | |
56 } | |
57 }) | |
58 .test('getElementsByTagName(p)', () { | |
59 for (int i = 0; i < num; i++) { | |
60 List<Element> elems = document.queryAll('p'); | |
61 ret = elems.last.nodeType; | |
62 } | |
63 }) | |
64 .test('getElementsByTagName(a)', () { | |
65 for (int i = 0; i < num; i++) { | |
66 List<Element> elems = document.queryAll('a'); | |
67 ret = elems.last.nodeType; | |
68 } | |
69 }) | |
70 .test('getElementsByTagName(*)', () { | |
71 for (int i = 0; i < num; i++) { | |
72 List<Element> elems = document.queryAll('*'); | |
73 ret = elems.last.nodeType; | |
74 } | |
75 }) | |
76 .test('getElementsByTagName (not in document)', () { | |
77 for (int i = 0; i < num; i++) { | |
78 List<Element> elems = document.queryAll('strong'); | |
79 ret = elems.isEmpty; | |
80 } | |
81 }) | |
82 .test('getElementsByName', () { | |
83 for (int i = 0; i < num * 20; i++) { | |
84 List<Element> elems = document.queryAll('[name="test$num"]'); | |
85 ret = elems.last.nodeType; | |
86 elems = document.queryAll('[name="test$num"]'); | |
87 ret = elems.last.nodeType; | |
88 elems = document.queryAll('[name="test$num"]'); | |
89 ret = elems.last.nodeType; | |
90 elems = document.queryAll('[name="test$num"]'); | |
91 ret = elems.last.nodeType; | |
92 } | |
93 }) | |
94 .test('getElementsByName (not in document)', () { | |
95 for (int i = 0; i < num * 20; i++) { | |
96 ret = document.queryAll('[name="test"]').length == 0; | |
97 ret = document.queryAll('[name="test"]').length == 0; | |
98 ret = document.queryAll('[name="test"]').length == 0; | |
99 ret = document.queryAll('[name="test"]').length == 0; | |
100 ret = document.queryAll('[name="test"]').length == 0; | |
101 } | |
102 }) | |
103 .end(); | |
104 } | |
OLD | NEW |