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

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

Issue 335943003: merge to trunk all changes from 36817 until 37378 under the packages: polymer, (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 6 months 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
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.web.custom_event_test; 5 library polymer.test.web.custom_event_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'package:polymer/polymer.dart'; 9 import 'package:polymer/polymer.dart';
10 import 'package:template_binding/template_binding.dart' show nodeBind; 10 import 'package:template_binding/template_binding.dart'
11 show nodeBind, enableBindingsReflection;
11 import 'package:unittest/unittest.dart'; 12 import 'package:unittest/unittest.dart';
12 import 'package:unittest/html_config.dart'; 13 import 'package:unittest/html_config.dart';
13 14
14 15
15 @CustomTag('foo-bar') 16 @CustomTag('foo-bar')
16 class FooBar extends PolymerElement { 17 class FooBar extends PolymerElement {
17 // A little too much boilerplate? 18 // A little too much boilerplate?
18 static const EventStreamProvider<CustomEvent> fooEvent = 19 static const EventStreamProvider<CustomEvent> fooEvent =
19 const EventStreamProvider<CustomEvent>('foo'); 20 const EventStreamProvider<CustomEvent>('foo');
20 static const EventStreamProvider<CustomEvent> barBazEvent = 21 static const EventStreamProvider<CustomEvent> barBazEvent =
21 const EventStreamProvider<CustomEvent>('barbaz'); 22 const EventStreamProvider<CustomEvent>('barbaz');
22 23
23 FooBar.created() : super.created(); 24 FooBar.created() : super.created();
24 25
25 Stream<CustomEvent> get onFooEvent => 26 Stream<CustomEvent> get onFooEvent =>
26 FooBar.fooEvent.forTarget(this); 27 FooBar.fooEvent.forTarget(this);
27 Stream<CustomEvent> get onBarBazEvent => 28 Stream<CustomEvent> get onBarBazEvent =>
28 FooBar.barBazEvent.forTarget(this); 29 FooBar.barBazEvent.forTarget(this);
29 30
30 fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x)); 31 fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x));
31 fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x)); 32 fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x));
32 } 33 }
33 34
34 @CustomTag('test-custom-event') 35 @CustomTag('test-custom-event')
35 class TestCustomEvent extends PolymerElement { 36 class TestCustomEvent extends PolymerElement {
36 TestCustomEvent.created() : super.created(); 37 TestCustomEvent.created() : super.created();
37 38
38 get fooBar => getShadowRoot('test-custom-event').querySelector('foo-bar'); 39 get fooBar => shadowRoots['test-custom-event'].querySelector('foo-bar');
39 40
40 final events = []; 41 final events = [];
41 fooHandler(e) => events.add(['foo', e]); 42 fooHandler(e) => events.add(['foo', e]);
42 barBazHandler(e) => events.add(['barbaz', e]); 43 barBazHandler(e) => events.add(['barbaz', e]);
43 } 44 }
44 45
45 main() => initPolymer().run(() { 46 main() {
46 useHtmlConfiguration(); 47 enableBindingsReflection = true;
47 48
48 setUp(() => Polymer.onReady); 49 initPolymer().run(() {
50 useHtmlConfiguration();
49 51
50 test('custom event', () { 52 setUp(() => Polymer.onReady);
51 final testComp = querySelector('test-custom-event');
52 final fooBar = testComp.fooBar;
53 53
54 final binding = nodeBind(fooBar).bindings['on-barbaz']; 54 test('custom event', () {
55 expect(binding is Bindable, true, 55 final testComp = querySelector('test-custom-event');
56 reason: 'on-barbaz event should be bound'); 56 final fooBar = testComp.fooBar;
57 57
58 expect(binding.value, null, reason: 'event bindings do not have value'); 58 final binding = nodeBind(fooBar).bindings['on-barbaz'];
59 expect(binding is Bindable, true,
60 reason: 'on-barbaz event should be bound');
59 61
60 fooBar.fireFoo(123); 62 expect(binding.value, '{{ barBazHandler }}',
61 fooBar.fireBarBaz(42); 63 reason: 'event bindings use the string as value');
62 fooBar.fireFoo(777);
63 64
64 final events = testComp.events; 65 fooBar.fireFoo(123);
65 expect(events.length, 3); 66 fooBar.fireBarBaz(42);
66 expect(events.map((e) => e[0]), ['foo', 'barbaz', 'foo']); 67 fooBar.fireFoo(777);
67 expect(events.map((e) => e[1].detail), [123, 42, 777]); 68
69 final events = testComp.events;
70 expect(events.length, 3);
71 expect(events.map((e) => e[0]), ['foo', 'barbaz', 'foo']);
72 expect(events.map((e) => e[1].detail), [123, 42, 777]);
73 });
68 }); 74 });
69 }); 75 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/build/script_compactor_test.dart ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698