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

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

Issue 50203004: port TemplateBinding to ed3266266e751b5ab1f75f8e0509d0d5f0ef35d8 (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
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 polymer.test.event_handlers_test; 5 library polymer.test.event_handlers_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 9
10 import 'package:logging/logging.dart';
11 import 'package:polymer/polymer.dart';
12 import 'package:template_binding/template_binding.dart';
10 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
11 import 'package:unittest/html_config.dart'; 14 import 'package:unittest/html_config.dart';
12 import 'package:polymer/polymer.dart';
13 import 'package:template_binding/template_binding.dart';
14 15
15 @CustomTag('x-test') 16 @CustomTag('x-test')
16 class XTest extends PolymerElement { 17 class XTest extends PolymerElement {
17 int _testCount = 0; 18 int _testCount = 0;
18 String _lastEvent; 19 String _lastEvent;
19 String _lastMessage; 20 String _lastMessage;
20 List list1 = []; 21 List list1 = [];
21 List list2 = []; 22 List list2 = [];
22 final _ready = new Completer();
23 Future _onTestDone; 23 Future _onTestDone;
24 24
25 XTest.created() : super.created() { 25 XTest.created() : super.created();
26 _onTestDone = _ready.future.then(_runTest);
27 }
28 26
29 ready() { 27 ready() {
30 super.ready(); 28 super.ready();
31 for (var i = 0; i < 10; i++) { 29 for (var i = 0; i < 10; i++) {
32 var model = new MiniModel(this, i); 30 var model = new MiniModel(this, i);
33 list1.add(model); 31 list1.add(model);
34 list2.add(model); 32 list2.add(model);
35 } 33 }
36 _ready.complete(); 34
35 _onTestDone = new Future.sync(_runTests);
37 } 36 }
38 37
39 hostTapAction(event, detail, node) => _logEvent(event); 38 hostTapAction(event, detail, node) => _logEvent(event);
40 39
41 divTapAction(event, detail, node) => _logEvent(event); 40 divTapAction(event, detail, node) => _logEvent(event);
42 41
43 focusAction(event, detail, node) => _logEvent(event); 42 focusAction(event, detail, node) => _logEvent(event);
44 43
45 blurAction(event, detail, node) => _logEvent(event); 44 blurAction(event, detail, node) => _logEvent(event);
46 45
47 scrollAction(event, detail, node) => _logEvent(event); 46 scrollAction(event, detail, node) => _logEvent(event);
48 47
49 itemTapAction(event, detail, node) { 48 itemTapAction(event, detail, node) {
50 var model = nodeBind(event.target).templateInstance.model; 49 var model = nodeBind(event.target).templateInstance.model;
51 _logEvent(event, "x-test callback ${model['this']}"); 50 _logEvent(event, "x-test callback ${model['this']}");
52 } 51 }
53 52
54 _logEvent(event, [message]) { 53 _logEvent(event, [message]) {
55 _testCount++; 54 _testCount++;
56 _lastEvent = event.type; 55 _lastEvent = event.type;
57 _lastMessage = message; 56 _lastMessage = message;
58 } 57 }
59 58
60 _runTest(_) { 59 Future _runTests() {
61 fire('tap', toNode: $['div']); 60 fire('tap', toNode: $['div']);
62 expect(_testCount, 2, reason: 'event heard at div and host'); 61 expect(_testCount, 2, reason: 'event heard at div and host');
63 expect(_lastEvent, 'tap', reason: 'tap handled'); 62 expect(_lastEvent, 'tap', reason: 'tap handled');
64 fire('focus', toNode: $['input'], canBubble: false); 63 fire('focus', toNode: $['input'], canBubble: false);
65 expect(_testCount, 3, reason: 'event heard by input'); 64 expect(_testCount, 3, reason: 'event heard by input');
66 expect(_lastEvent, 'focus', reason: 'focus handled'); 65 expect(_lastEvent, 'focus', reason: 'focus handled');
67 fire('blur', toNode: $['input'], canBubble: false); 66 fire('blur', toNode: $['input'], canBubble: false);
68 expect(_testCount, 4, reason: 'event heard by input'); 67 expect(_testCount, 4, reason: 'event heard by input');
69 expect(_lastEvent, 'blur', reason: 'blur handled'); 68 expect(_lastEvent, 'blur', reason: 'blur handled');
70 fire('scroll', toNode: $['list'], canBubble: false); 69 fire('scroll', toNode: $['list'], canBubble: false);
71 expect(_testCount, 5, reason: 'event heard by list'); 70 expect(_testCount, 5, reason: 'event heard by list');
72 expect(_lastEvent, 'scroll', reason: 'scroll handled'); 71 expect(_lastEvent, 'scroll', reason: 'scroll handled');
72
73 return onMutation($['list']).then((_) { 73 return onMutation($['list']).then((_) {
74 var l1 = $['list'].querySelectorAll('.list1')[4]; 74 var l1 = $['list'].querySelectorAll('.list1')[4];
75 fire('tap', toNode: l1, canBubble: false); 75 fire('tap', toNode: l1, canBubble: false);
76 expect(_testCount, 6, reason: 'event heard by list1 item'); 76 expect(_testCount, 6, reason: 'event heard by list1 item');
77 expect(_lastEvent, 'tap', reason: 'tap handled'); 77 expect(_lastEvent, 'tap', reason: 'tap handled');
78 expect(_lastMessage, 'x-test callback <mini-model 4>'); 78 expect(_lastMessage, 'x-test callback <mini-model 4>');
79 79
80 var l2 = $['list'].querySelectorAll('.list2')[3]; 80 var l2 = $['list'].querySelectorAll('.list2')[3];
81 fire('tap', toNode: l2, canBubble: false); 81 fire('tap', toNode: l2, canBubble: false);
82 expect(_testCount, 7, reason: 'event heard by list2 item'); 82 expect(_testCount, 7, reason: 'event heard by list2 item');
(...skipping 13 matching lines...) Expand all
96 } 96 }
97 MiniModel(this._element, this.index) { 97 MiniModel(this._element, this.index) {
98 // TODO(sigmund): remove this and reflect directly on the method. This is 98 // TODO(sigmund): remove this and reflect directly on the method. This is
99 // needed to work around bug 13002 99 // needed to work around bug 13002
100 itemTapAction = _itemTapAction; 100 itemTapAction = _itemTapAction;
101 } 101 }
102 String toString() => "<mini-model $index>"; 102 String toString() => "<mini-model $index>";
103 } 103 }
104 104
105 main() { 105 main() {
106 Logger.root..level = Level.FINE
107 ..onRecord.listen((m) => print('${m.loggerName} ${m.message}'));
108
106 initPolymer(); 109 initPolymer();
107 } 110 }
108 111
109 @initMethod _init() { 112 @initMethod _init() {
110 useHtmlConfiguration(); 113 useHtmlConfiguration();
111 114
112 setUp(() => Polymer.onReady); 115 setUp(() => Polymer.onReady);
113 test('events handled', () => (query('x-test') as XTest)._onTestDone); 116 test('events handled', () {
117 XTest test = query('x-test');
118 expect(test._onTestDone, isNotNull, reason: 'ready was called');
119 });
114 } 120 }
115
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698