OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 polymer.test.web.event_path_test; |
| 6 |
| 7 import 'dart:html'; |
| 8 import 'package:polymer/polymer.dart'; |
| 9 import 'package:unittest/html_config.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 |
| 12 @CustomTag('x-selector') |
| 13 class XSelector extends PolymerElement { |
| 14 XSelector.created() : super.created(); |
| 15 } |
| 16 |
| 17 @CustomTag('x-overlay') |
| 18 class XOverlay extends PolymerElement { |
| 19 XOverlay.created() : super.created(); |
| 20 } |
| 21 |
| 22 @CustomTag('x-menu') |
| 23 class XMenu extends XSelector { |
| 24 XMenu.created() : super.created(); |
| 25 } |
| 26 |
| 27 @CustomTag('x-menu-button') |
| 28 class XMenuButton extends PolymerElement { |
| 29 XMenuButton.created() : super.created(); |
| 30 } |
| 31 |
| 32 main() => initPolymer().then((zone) => zone.run(() { |
| 33 useHtmlConfiguration(); |
| 34 |
| 35 setUp(() => Polymer.onReady); |
| 36 |
| 37 test('bubbling in the right order', () { |
| 38 var item1 = querySelector('#item1'); |
| 39 var menuButton = querySelector('#menuButton'); |
| 40 // Note: polymer uses automatic node finding (menuButton.$.menu) |
| 41 // also note that their node finding code also reachs into the ids |
| 42 // from the parent shadow (menu.$.selectorContent instead of |
| 43 // menu.$.menuShadow.$.selectorContent) |
| 44 var menu = menuButton.shadowRoot.querySelector('#menu'); |
| 45 var overlay = menuButton.shadowRoot.querySelector('#overlay'); |
| 46 var expectedPath = <Node>[ |
| 47 item1, |
| 48 menuButton.shadowRoot.querySelector('#menuButtonContent'), |
| 49 menu.shadowRoot.olderShadowRoot.querySelector('#selectorContent'), |
| 50 menu.shadowRoot.olderShadowRoot.querySelector('#selectorDiv'), |
| 51 menu.shadowRoot.olderShadowRoot, |
| 52 menu.shadowRoot.querySelector('#menuShadow'), |
| 53 menu.shadowRoot.querySelector('#menuDiv'), |
| 54 menu.shadowRoot, |
| 55 menu, |
| 56 menuButton.shadowRoot.querySelector('#menuButtonDiv'), |
| 57 // TODO(sigmund): this test is currently broken because currently |
| 58 // registerElement is sensitive to the order in which each custom |
| 59 // element is registered. When fixed, we should be able to add the |
| 60 // following three targets: |
| 61 // overlay.shadowRoot.query('#overlayContent'), |
| 62 // overlay.shadowRoot, |
| 63 // overlay, |
| 64 menuButton.shadowRoot, |
| 65 menuButton |
| 66 ]; |
| 67 var x = 0; |
| 68 for (int i = 0; i < expectedPath.length; i++) { |
| 69 var node = expectedPath[i]; |
| 70 expect(node, isNotNull, reason: "Should not be null at $i"); |
| 71 node.on['x'].listen(expectAsync((e) { |
| 72 expect(e.currentTarget, node); |
| 73 expect(x++, i); |
| 74 })); |
| 75 } |
| 76 |
| 77 item1.dispatchEvent(new Event('x', canBubble: true)); |
| 78 }); |
| 79 })); |
OLD | NEW |