OLD | NEW |
1 #library("dom_traverse_html"); | 1 #library("dom_traverse"); |
2 #import("dart:html"); | 2 #import("dart:html"); |
3 #import('../common/common.dart'); | 3 #import('../common/common.dart'); |
4 #source("Common.dart"); | 4 #import('runner.dart'); |
5 #source("RunnerSuite.dart"); | 5 |
6 | 6 |
7 void main() { | 7 void main() { |
8 final int num = 40; | 8 final int num = 40; |
9 | 9 |
10 // Try to force real results. | 10 // Try to force real results. |
11 var ret; | 11 var ret; |
12 | 12 |
13 String html = document.body.innerHTML; | 13 String html = document.body.innerHTML; |
14 | 14 |
15 new Suite(window, 'dom-traverse') | 15 new Suite(window, 'dom-traverse') |
16 .prep(() { | 16 .prep(() { |
17 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { | 17 html = BenchUtil.replaceAll(html, 'id="test(\\w).*?"', (Match match) { |
18 final group = match.group(1); | 18 final group = match.group(1); |
19 return 'id="test${group}${num}"'; | 19 return 'id="test${group}${num}"'; |
20 }); | 20 }); |
21 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { | 21 html = BenchUtil.replaceAll(html, 'name="test.*?"', (Match match) { |
22 return 'name="test${num}"'; | 22 return 'name="test${num}"'; |
23 }); | 23 }); |
24 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { | 24 html = BenchUtil.replaceAll(html, 'class="foo.*?"', (Match match) { |
25 return 'class="foo test${num} bar"'; | 25 return 'class="foo test${num} bar"'; |
26 }); | 26 }); |
27 | 27 |
28 final div = new Element.tag('div'); | 28 final div = new Element.tag('div'); |
29 div.innerHTML = html; | 29 div.innerHTML = html; |
30 document.body.nodes.add(div); | 30 document.body.appendChild(div); |
31 }) | 31 }) |
32 .test('firstChild', () { | 32 .test('firstChild', () { |
33 final nodes = document.body.nodes; | 33 final nodes = document.body.nodes; |
34 final nl = nodes.length; | 34 final nl = nodes.length; |
35 | 35 |
36 for (int i = 0; i < num; i++) { | 36 for (int i = 0; i < num; i++) { |
37 for (int j = 0; j < nl; j++) { | 37 for (int j = 0; j < nl; j++) { |
38 Node cur = nodes[j]; | 38 Node cur = nodes[j]; |
39 while (cur !== null) { | 39 while (cur !== null) { |
40 cur = cur.nodes.first; | 40 cur = cur.$dom_firstChild; |
41 } | 41 } |
42 ret = cur; | 42 ret = cur; |
43 } | 43 } |
44 } | 44 } |
45 }) | 45 }) |
46 .test('lastChild', () { | 46 .test('lastChild', () { |
47 final nodes = document.body.nodes; | 47 final nodes = document.body.nodes; |
48 final nl = nodes.length; | 48 final nl = nodes.length; |
49 | 49 |
50 for (int i = 0; i < num; i++) { | 50 for (int i = 0; i < num; i++) { |
51 for (int j = 0; j < nl; j++) { | 51 for (int j = 0; j < nl; j++) { |
52 Node cur = nodes[j]; | 52 Node cur = nodes[j]; |
53 while (cur !== null) { | 53 while (cur !== null) { |
54 cur = cur.nodes.last(); | 54 cur = cur.$dom_lastChild; |
55 } | 55 } |
56 ret = cur; | 56 ret = cur; |
57 } | 57 } |
58 } | 58 } |
59 }) | 59 }) |
60 .test('nextSibling', () { | 60 .test('nextSibling', () { |
61 for (int i = 0; i < num * 2; i++) { | 61 for (int i = 0; i < num * 2; i++) { |
62 Node cur = document.body.nodes.first; | 62 Node cur = document.body.$dom_firstChild; |
63 while (cur !== null) { | 63 while (cur !== null) { |
64 cur = cur.nextNode; | 64 cur = cur.nextNode; |
65 } | 65 } |
66 ret = cur; | 66 ret = cur; |
67 } | 67 } |
68 }) | 68 }) |
69 .test('previousSibling', () { | 69 .test('previousSibling', () { |
70 for (int i = 0; i < num * 2; i++) { | 70 for (int i = 0; i < num * 2; i++) { |
71 Node cur = document.body.nodes.last(); | 71 Node cur = document.body.$dom_lastChild; |
72 while (cur !== null) { | 72 while (cur !== null) { |
73 cur = cur.previousNode; | 73 cur = cur.previousNode; |
74 } | 74 } |
75 ret = cur; | 75 ret = cur; |
76 } | 76 } |
77 }) | 77 }) |
78 .test('childNodes', () { | 78 .test('childNodes', () { |
79 for (int i = 0; i < num; i++) { | 79 for (int i = 0; i < num; i++) { |
80 final nodes = document.body.nodes; | 80 final nodes = document.body.nodes; |
81 for (int j = 0; j < nodes.length; j++) { | 81 for (int j = 0; j < nodes.length; j++) { |
82 ret = nodes[j]; | 82 ret = nodes[j]; |
83 } | 83 } |
84 } | 84 } |
85 }) | 85 }) |
86 .end(); | 86 .end(); |
87 } | 87 } |
OLD | NEW |