Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Side by Side Diff: pkg/polymer/test/event_handlers_test.dart

Issue 44573005: Update polymer to commit b7200854b2441a22ce89f6563963f36c50f5150d (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.event_handlers_test;
6
7 import 'dart:async';
8 import 'dart:html';
9
10 import 'package:unittest/unittest.dart';
11 import 'package:unittest/html_config.dart';
12 import 'package:polymer/polymer.dart';
13 import 'package:template_binding/template_binding.dart';
14 import 'package:polymer/platform.dart' as Platform;
15
16 @CustomTag('x-test')
17 class XTest extends PolymerElement {
18 int _testCount = 0;
19 String _lastEvent;
20 String _lastMessage;
21 List list1 = [];
22 List list2 = [];
23 final _ready = new Completer();
24 Future _onTestDone;
25
26 XTest.created() : super.created() {
27 _onTestDone = _ready.future.then(_runTest);
28 }
29
30 ready() {
31 super.ready();
32 for (var i = 0; i < 10; i++) {
33 var model = new MiniModel(this, i);
34 list1.add(model);
35 list2.add(model);
36 }
37 _ready.complete();
38 }
39
40 hostTapAction(event, detail, node) => _logEvent(event);
41
42 divTapAction(event, detail, node) => _logEvent(event);
43
44 focusAction(event, detail, node) => _logEvent(event);
45
46 blurAction(event, detail, node) => _logEvent(event);
47
48 scrollAction(event, detail, node) => _logEvent(event);
49
50 itemTapAction(event, detail, node) {
51 var model = nodeBind(event.target).templateInstance.model;
52 _logEvent(event, "x-test callback ${model['this']}");
53 }
54
55 _logEvent(event, [message]) {
56 _testCount++;
57 _lastEvent = event.type;
58 _lastMessage = message;
59 }
60
61 _runTest(_) {
62 fire('tap', toNode: $['div']);
63 expect(_testCount, 2, reason: 'event heard at div and host');
64 expect(_lastEvent, 'tap', reason: 'tap handled');
65 fire('focus', toNode: $['input'], canBubble: false);
66 expect(_testCount, 3, reason: 'event heard by input');
67 expect(_lastEvent, 'focus', reason: 'focus handled');
68 fire('blur', toNode: $['input'], canBubble: false);
69 expect(_testCount, 4, reason: 'event heard by input');
70 expect(_lastEvent, 'blur', reason: 'blur handled');
71 fire('scroll', toNode: $['list'], canBubble: false);
72 expect(_testCount, 5, reason: 'event heard by list');
73 expect(_lastEvent, 'scroll', reason: 'scroll handled');
74 return onMutation($['list']).then((_) {
75 var l1 = $['list'].querySelectorAll('.list1')[4];
76 fire('tap', toNode: l1, canBubble: false);
77 expect(_testCount, 6, reason: 'event heard by list1 item');
78 expect(_lastEvent, 'tap', reason: 'tap handled');
79 expect(_lastMessage, 'x-test callback <mini-model 4>');
80
81 var l2 = $['list'].querySelectorAll('.list2')[3];
82 fire('tap', toNode: l2, canBubble: false);
83 expect(_testCount, 7, reason: 'event heard by list2 item');
84 expect(_lastEvent, 'tap', reason: 'tap handled by model');
85 expect(_lastMessage, 'mini-model callback <mini-model 3>');
86 });
87 }
88 }
89
90 class MiniModel extends Observable {
91 XTest _element;
92 @observable final int index;
93 @reflectable Function itemTapAction;
Siggi Cherem (dart-lang) 2013/10/25 21:05:26 I'm not proud of this hack, but it works.
Jennifer Messerly 2013/10/25 22:00:41 hmmm. interesting I thought PolymerExpressions "Me
Siggi Cherem (dart-lang) 2013/10/26 00:02:35 me neither. I'll be submitting this shortly and lo
94 _itemTapAction(e, d, n) {
95 _element._logEvent(e, 'mini-model callback $this');
96 e.stopPropagation();
97 }
98 MiniModel(this._element, this.index) {
99 // TODO(sigmund): remove this and reflect directly on the method. This is
100 // needed to work around bug 13002
101 itemTapAction = _itemTapAction;
102 }
103 String toString() => "<mini-model $index>";
104 }
105
106 main() {
107 initPolymer();
108 }
109
110 @initMethod _init() {
111 useHtmlConfiguration();
112
113 setUp(() => Polymer.onReady);
114 test('events handled', () => (query('x-test') as XTest)._onTestDone);
115 }
116
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698