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 ShadowDOMTest; | 5 library ShadowDOMTest; |
| 6 |
6 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_individual_config.dart'; | 8 import 'package:unittest/html_individual_config.dart'; |
8 import 'dart:html'; | 9 import 'dart:html'; |
9 | 10 |
10 main() { | 11 main() { |
11 useHtmlIndividualConfiguration(); | 12 useHtmlIndividualConfiguration(); |
12 | 13 |
13 group('supported', () { | 14 group('supported', () { |
14 test('supported', () { | 15 test('supported', () { |
15 expect(ShadowRoot.supported, true); | 16 expect(ShadowRoot.supported, true); |
16 }); | 17 }); |
17 }); | 18 }); |
18 | 19 |
19 group('ShadowDOM_tests', () { | 20 group('ShadowDOM_tests', () { |
20 | |
21 var div1, div2, shadowRoot, paragraph1, paragraph2; | 21 var div1, div2, shadowRoot, paragraph1, paragraph2; |
22 | 22 |
23 init() { | 23 init() { |
24 paragraph1 = new ParagraphElement(); | 24 paragraph1 = new ParagraphElement(); |
25 paragraph2 = new ParagraphElement(); | 25 paragraph2 = new ParagraphElement(); |
26 [paragraph1, paragraph2].forEach((p) { p.classes.add('foo');}); | 26 [paragraph1, paragraph2].forEach((p) { |
| 27 p.classes.add('foo'); |
| 28 }); |
27 div1 = new DivElement(); | 29 div1 = new DivElement(); |
28 div2 = new DivElement(); | 30 div2 = new DivElement(); |
29 div1.classes.add('foo'); | 31 div1.classes.add('foo'); |
30 shadowRoot = div2.createShadowRoot(); | 32 shadowRoot = div2.createShadowRoot(); |
31 shadowRoot.append(paragraph1); | 33 shadowRoot.append(paragraph1); |
32 shadowRoot.append(new ContentElement()); | 34 shadowRoot.append(new ContentElement()); |
33 div2.append(paragraph2); | 35 div2.append(paragraph2); |
34 document.body.append(div1); | 36 document.body.append(div1); |
35 document.body.append(div2); | 37 document.body.append(div2); |
36 } | 38 } |
37 | 39 |
38 var expectation = ShadowRoot.supported ? returnsNormally : throws; | 40 var expectation = ShadowRoot.supported ? returnsNormally : throws; |
39 | 41 |
40 test("Shadowed nodes aren't visible to queries from outside ShadowDOM", () { | 42 test("Shadowed nodes aren't visible to queries from outside ShadowDOM", () { |
41 expect(() { | 43 expect(() { |
42 init(); | 44 init(); |
43 | 45 |
44 expect(queryAll('.foo'), equals([div1, paragraph2])); | 46 expect(queryAll('.foo'), equals([div1, paragraph2])); |
45 }, expectation); | 47 }, expectation); |
46 }); | 48 }); |
47 | 49 |
48 test('Parent node of a shadow root must be null.', () { | 50 test('Parent node of a shadow root must be null.', () { |
49 expect(() { | 51 expect(() { |
50 init(); | 52 init(); |
51 | 53 |
52 expect(shadowRoot.parent, isNull); | 54 expect(shadowRoot.parent, isNull); |
53 }, expectation); | 55 }, expectation); |
54 }); | 56 }); |
55 | 57 |
56 | |
57 // TODO(samhop): test that <content> and <content select="foo"> and | 58 // TODO(samhop): test that <content> and <content select="foo"> and |
58 // <shadow> | 59 // <shadow> |
59 // work properly. This is blocked on having a good way to do browser | 60 // work properly. This is blocked on having a good way to do browser |
60 // rendering tests. | 61 // rendering tests. |
61 | 62 |
62 test('Querying in shadowed fragment respects the shadow boundary.', () { | 63 test('Querying in shadowed fragment respects the shadow boundary.', () { |
63 expect(() { | 64 expect(() { |
64 init(); | 65 init(); |
65 | 66 |
66 expect(shadowRoot.queryAll('.foo'), equals([paragraph1])); | 67 expect(shadowRoot.queryAll('.foo'), equals([paragraph1])); |
67 }, expectation); | 68 }, expectation); |
68 }); | 69 }); |
69 | 70 |
70 if (ShadowRoot.supported) { | 71 if (ShadowRoot.supported) { |
71 test('Shadowroot contents are distributed', () { | 72 test('Shadowroot contents are distributed', () { |
72 | |
73 var div = new DivElement(); | 73 var div = new DivElement(); |
74 | 74 |
75 var box1 = new DivElement() | 75 var box1 = new DivElement()..classes.add('foo'); |
76 ..classes.add('foo'); | |
77 div.append(box1); | 76 div.append(box1); |
78 | 77 |
79 var box2 = new DivElement(); | 78 var box2 = new DivElement(); |
80 div.append(box2); | 79 div.append(box2); |
81 | 80 |
82 var sRoot = div.createShadowRoot(); | 81 var sRoot = div.createShadowRoot(); |
83 var content1 = new ContentElement() | 82 var content1 = new ContentElement()..select = ".foo"; |
84 ..select = ".foo"; | |
85 sRoot.append(content1); | 83 sRoot.append(content1); |
86 | 84 |
87 var content2 = new ContentElement(); | 85 var content2 = new ContentElement(); |
88 sRoot.append(content2); | 86 sRoot.append(content2); |
89 | 87 |
90 expect(content1.getDistributedNodes(), [box1]); | 88 expect(content1.getDistributedNodes(), [box1]); |
91 expect(content2.getDistributedNodes(), [box2]); | 89 expect(content2.getDistributedNodes(), [box2]); |
92 }); | 90 }); |
93 } | 91 } |
94 }); | 92 }); |
95 } | 93 } |
OLD | NEW |