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