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

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

Issue 794473002: Delete polymer from the Dart repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/test/computed_properties_test.html ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.web.custom_event_test;
6
7 import 'dart:async';
8 import 'dart:html';
9 import 'package:polymer/polymer.dart';
10 import 'package:template_binding/template_binding.dart'
11 show nodeBind, enableBindingsReflection;
12 import 'package:unittest/unittest.dart';
13 import 'package:unittest/html_config.dart';
14
15
16 @CustomTag('foo-bar')
17 class FooBar extends PolymerElement {
18 // A little too much boilerplate?
19 static const EventStreamProvider<CustomEvent> fooEvent =
20 const EventStreamProvider<CustomEvent>('foo');
21 static const EventStreamProvider<CustomEvent> barBazEvent =
22 const EventStreamProvider<CustomEvent>('barbaz');
23
24 FooBar.created() : super.created();
25
26 Stream<CustomEvent> get onFooEvent =>
27 FooBar.fooEvent.forTarget(this);
28 Stream<CustomEvent> get onBarBazEvent =>
29 FooBar.barBazEvent.forTarget(this);
30
31 fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x));
32 fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x));
33 }
34
35 @CustomTag('test-custom-event')
36 class TestCustomEvent extends PolymerElement {
37 TestCustomEvent.created() : super.created();
38
39 get fooBar => shadowRoots['test-custom-event'].querySelector('foo-bar');
40
41 final events = [];
42 fooHandler(e) => events.add(['foo', e]);
43 barBazHandler(e) => events.add(['barbaz', e]);
44 }
45
46 main() {
47 enableBindingsReflection = true;
48
49 initPolymer().run(() {
50 useHtmlConfiguration();
51
52 setUp(() => Polymer.onReady);
53
54 test('custom event', () {
55 final testComp = querySelector('test-custom-event');
56 final fooBar = testComp.fooBar;
57
58 final binding = nodeBind(fooBar).bindings['on-barbaz'];
59 expect(binding is Bindable, true,
60 reason: 'on-barbaz event should be bound');
61
62 expect(binding.value, '{{ barBazHandler }}',
63 reason: 'event bindings use the string as value');
64
65 fooBar.fireFoo(123);
66 fooBar.fireBarBaz(42);
67 fooBar.fireFoo(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 });
74 });
75 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/computed_properties_test.html ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698