OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file | 3 // BSD-style license that can be found in the LICENSE file |
4 | 4 |
5 library ElementAddTest; | 5 library ElementAddTest; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 7 import 'package:unittest/html_config.dart'; |
8 import 'util.dart'; | 8 import 'util.dart'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 expect(el.children[0], equals(span)); | 55 expect(el.children[0], equals(span)); |
56 expect(el.children[1], isDivElement); | 56 expect(el.children[1], isDivElement); |
57 }); | 57 }); |
58 | 58 |
59 test('documentFragment', () { | 59 test('documentFragment', () { |
60 var fragment = new DocumentFragment(); | 60 var fragment = new DocumentFragment(); |
61 fragment.appendHtml('<span>something</span>'); | 61 fragment.appendHtml('<span>something</span>'); |
62 expect(fragment.children.length, equals(1)); | 62 expect(fragment.children.length, equals(1)); |
63 expect(fragment.children[0], isSpanElement); | 63 expect(fragment.children[0], isSpanElement); |
64 }); | 64 }); |
65 | |
66 test('html interpreted in correct context', () { | |
67 // appendHtml, in order to sanitize, needs to create a document fragment, | |
68 // but it needs to be created in the right context. If we try to append | |
69 // table components then the document fragment needs the table context | |
70 // or it will fail to create them. | |
71 var el = new TableElement(); | |
72 el.appendHtml('<tr><td>foo</td></tr>'); | |
73 expect(el.children.length, 1); | |
74 var section = el.children.first; | |
75 expect(section is TableSectionElement, isTrue); | |
76 var row = section.children.first; | |
77 expect(row is TableRowElement, isTrue); | |
78 var item = row.children.first; | |
79 expect(item is TableCellElement, isTrue); | |
80 expect(item.innerHtml, 'foo'); | |
81 }); | |
82 | |
83 test("use body context for elements that are don't support it", () { | |
84 // Some elements can't be used as context for createContextualFragment, | |
85 // often because it doesn't make any sense. So adding children to a | |
86 // <br> has no real effect on the page, but we can do it. But the | |
87 // document fragment will have to be created in the body context. Verify | |
88 // that this doesn't throw and that the children show up. | |
89 var el = new BRElement(); | |
90 el.appendHtml("<p>Stuff</p>"); | |
91 expect(el.children.length, 1); | |
92 expect(el.children[0].outerHtml, "<p>Stuff</p>"); | |
93 }); | |
94 }); | 65 }); |
95 | 66 |
96 group('appendText', () { | 67 group('appendText', () { |
97 test('htmlelement', () { | 68 test('htmlelement', () { |
98 var el = new DivElement(); | 69 var el = new DivElement(); |
99 el.appendText('foo'); | 70 el.appendText('foo'); |
100 // No children were created. | 71 // No children were created. |
101 expect(el.children.length, equals(0)); | 72 expect(el.children.length, equals(0)); |
102 // One text node was added. | 73 // One text node was added. |
103 expect(el.nodes.length, equals(1)); | 74 expect(el.nodes.length, equals(1)); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 var child = new DivElement(); | 232 var child = new DivElement(); |
262 parent.children.add(child); | 233 parent.children.add(child); |
263 | 234 |
264 parent.insertAdjacentText('beforeend', 'test'); | 235 parent.insertAdjacentText('beforeend', 'test'); |
265 | 236 |
266 expect(parent.nodes.length, 2); | 237 expect(parent.nodes.length, 2); |
267 expect(parent.nodes[1], isText); | 238 expect(parent.nodes[1], isText); |
268 }); | 239 }); |
269 }); | 240 }); |
270 } | 241 } |
OLD | NEW |