| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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('DocumentFragmentTest'); | 5 #library('DocumentFragmentTest'); |
| 6 #import('../../pkg/unittest/unittest.dart'); | 6 #import('../../pkg/unittest/unittest.dart'); |
| 7 #import('../../pkg/unittest/html_config.dart'); | 7 #import('../../pkg/unittest/html_config.dart'); |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 #source('util.dart'); | 9 #source('util.dart'); |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 elements = fragment.elements; | 110 elements = fragment.elements; |
| 111 fragment.nodes.addAll( | 111 fragment.nodes.addAll( |
| 112 [new Text("1"), new Element.tag("A"), new Element.tag("B"), | 112 [new Text("1"), new Element.tag("A"), new Element.tag("B"), |
| 113 new Text("2"), new Element.tag("I"), new Text("3"), | 113 new Text("2"), new Element.tag("I"), new Text("3"), |
| 114 new Element.tag("U")]); | 114 new Element.tag("U")]); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 test('is initially empty', () { | 117 test('is initially empty', () { |
| 118 elements = new DocumentFragment().elements; | 118 elements = new DocumentFragment().elements; |
| 119 Expect.listEquals([], elements); | 119 Expect.listEquals([], elements); |
| 120 Expect.isTrue(elements.isEmpty()); | 120 Expect.isTrue(elements.isEmpty); |
| 121 }); | 121 }); |
| 122 | 122 |
| 123 test('filters out non-element nodes', () { | 123 test('filters out non-element nodes', () { |
| 124 init(); | 124 init(); |
| 125 Expect.listEquals(["1", "A", "B", "2", "I", "3", "U"], | 125 Expect.listEquals(["1", "A", "B", "2", "I", "3", "U"], |
| 126 _nodeStrings(fragment.nodes)); | 126 _nodeStrings(fragment.nodes)); |
| 127 Expect.listEquals(["A", "B", "I", "U"], _nodeStrings(elements)); | 127 Expect.listEquals(["A", "B", "I", "U"], _nodeStrings(elements)); |
| 128 }); | 128 }); |
| 129 | 129 |
| 130 test('only indexes elements, not other nodes', () { | 130 test('only indexes elements, not other nodes', () { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 156 Expect.listEquals(["A", "B"], _nodeStrings(elements)); | 156 Expect.listEquals(["A", "B"], _nodeStrings(elements)); |
| 157 }); | 157 }); |
| 158 | 158 |
| 159 test('accessors are wrapped', () { | 159 test('accessors are wrapped', () { |
| 160 init(); | 160 init(); |
| 161 Expect.equals("A", elements[0].tagName); | 161 Expect.equals("A", elements[0].tagName); |
| 162 Expect.listEquals( | 162 Expect.listEquals( |
| 163 ["I"], _nodeStrings(elements.filter((e) => e.tagName == "I"))); | 163 ["I"], _nodeStrings(elements.filter((e) => e.tagName == "I"))); |
| 164 Expect.isTrue(elements.every((e) => e is Element)); | 164 Expect.isTrue(elements.every((e) => e is Element)); |
| 165 Expect.isTrue(elements.some((e) => e.tagName == "U")); | 165 Expect.isTrue(elements.some((e) => e.tagName == "U")); |
| 166 Expect.isFalse(elements.isEmpty()); | 166 Expect.isFalse(elements.isEmpty); |
| 167 Expect.equals(4, elements.length); | 167 Expect.equals(4, elements.length); |
| 168 Expect.equals("I", elements[2].tagName); | 168 Expect.equals("I", elements[2].tagName); |
| 169 Expect.equals("U", elements.last().tagName); | 169 Expect.equals("U", elements.last().tagName); |
| 170 }); | 170 }); |
| 171 | 171 |
| 172 test('setting elements overwrites nodes as well', () { | 172 test('setting elements overwrites nodes as well', () { |
| 173 init(); | 173 init(); |
| 174 fragment.elements = [new Element.tag("DIV"), new Element.tag("HEAD")]; | 174 fragment.elements = [new Element.tag("DIV"), new Element.tag("HEAD")]; |
| 175 Expect.listEquals(["DIV", "HEAD"], _nodeStrings(fragment.nodes)); | 175 Expect.listEquals(["DIV", "HEAD"], _nodeStrings(fragment.nodes)); |
| 176 }); | 176 }); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 fragment.webkitRequestFullScreen(2); | 291 fragment.webkitRequestFullScreen(2); |
| 292 }); | 292 }); |
| 293 | 293 |
| 294 test('default values', () { | 294 test('default values', () { |
| 295 var fragment = new DocumentFragment(); | 295 var fragment = new DocumentFragment(); |
| 296 fragment.rect.then(expectAsync1((ElementRect rect) { | 296 fragment.rect.then(expectAsync1((ElementRect rect) { |
| 297 expectEmptyRect(rect.client); | 297 expectEmptyRect(rect.client); |
| 298 expectEmptyRect(rect.offset); | 298 expectEmptyRect(rect.offset); |
| 299 expectEmptyRect(rect.scroll); | 299 expectEmptyRect(rect.scroll); |
| 300 expectEmptyRect(rect.bounding); | 300 expectEmptyRect(rect.bounding); |
| 301 Expect.isTrue(rect.clientRects.isEmpty()); | 301 Expect.isTrue(rect.clientRects.isEmpty); |
| 302 })); | 302 })); |
| 303 Expect.equals("false", fragment.contentEditable); | 303 Expect.equals("false", fragment.contentEditable); |
| 304 Expect.equals(-1, fragment.tabIndex); | 304 Expect.equals(-1, fragment.tabIndex); |
| 305 Expect.equals("", fragment.id); | 305 Expect.equals("", fragment.id); |
| 306 Expect.equals("", fragment.title); | 306 Expect.equals("", fragment.title); |
| 307 Expect.equals("", fragment.tagName); | 307 Expect.equals("", fragment.tagName); |
| 308 Expect.equals("", fragment.webkitdropzone); | 308 Expect.equals("", fragment.webkitdropzone); |
| 309 Expect.equals("", fragment.webkitRegionOverflow); | 309 Expect.equals("", fragment.webkitRegionOverflow); |
| 310 Expect.isFalse(fragment.isContentEditable); | 310 Expect.isFalse(fragment.isContentEditable); |
| 311 Expect.isFalse(fragment.draggable); | 311 Expect.isFalse(fragment.draggable); |
| 312 Expect.isFalse(fragment.hidden); | 312 Expect.isFalse(fragment.hidden); |
| 313 Expect.isFalse(fragment.spellcheck); | 313 Expect.isFalse(fragment.spellcheck); |
| 314 Expect.isFalse(fragment.translate); | 314 Expect.isFalse(fragment.translate); |
| 315 Expect.isNull(fragment.nextElementSibling); | 315 Expect.isNull(fragment.nextElementSibling); |
| 316 Expect.isNull(fragment.previousElementSibling); | 316 Expect.isNull(fragment.previousElementSibling); |
| 317 Expect.isNull(fragment.offsetParent); | 317 Expect.isNull(fragment.offsetParent); |
| 318 Expect.isNull(fragment.parent); | 318 Expect.isNull(fragment.parent); |
| 319 Expect.isTrue(fragment.attributes.isEmpty()); | 319 Expect.isTrue(fragment.attributes.isEmpty); |
| 320 Expect.isTrue(fragment.classes.isEmpty()); | 320 Expect.isTrue(fragment.classes.isEmpty); |
| 321 Expect.isTrue(fragment.dataAttributes.isEmpty()); | 321 Expect.isTrue(fragment.dataAttributes.isEmpty); |
| 322 Expect.isFalse(fragment.matchesSelector("foo")); | 322 Expect.isFalse(fragment.matchesSelector("foo")); |
| 323 Expect.isFalse(fragment.matchesSelector("*")); | 323 Expect.isFalse(fragment.matchesSelector("*")); |
| 324 }); | 324 }); |
| 325 | 325 |
| 326 test('style', () { | 326 test('style', () { |
| 327 var fragment = new DocumentFragment(); | 327 var fragment = new DocumentFragment(); |
| 328 var style = fragment.style; | 328 var style = fragment.style; |
| 329 expectEmptyStyleDeclaration(style); | 329 expectEmptyStyleDeclaration(style); |
| 330 fragment.computedStyle.then(expectAsync1((computedStyle) { | 330 fragment.computedStyle.then(expectAsync1((computedStyle) { |
| 331 expectEmptyStyleDeclaration(computedStyle); | 331 expectEmptyStyleDeclaration(computedStyle); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 345 // // assertConstError(() => fragment.classes.add('foo')); | 345 // // assertConstError(() => fragment.classes.add('foo')); |
| 346 // }); | 346 // }); |
| 347 | 347 |
| 348 test('query searches the fragment', () { | 348 test('query searches the fragment', () { |
| 349 var fragment = new DocumentFragment.html( | 349 var fragment = new DocumentFragment.html( |
| 350 "<div class='foo'><a>foo</a><b>bar</b></div>"); | 350 "<div class='foo'><a>foo</a><b>bar</b></div>"); |
| 351 Expect.equals("A", fragment.query(".foo a").tagName); | 351 Expect.equals("A", fragment.query(".foo a").tagName); |
| 352 Expect.listEquals(["A", "B"], _nodeStrings(fragment.queryAll(".foo *"))); | 352 Expect.listEquals(["A", "B"], _nodeStrings(fragment.queryAll(".foo *"))); |
| 353 }); | 353 }); |
| 354 } | 354 } |
| OLD | NEW |