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