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

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

Issue 2312183003: Removed Polymer from Observatory deps (Closed)
Patch Set: Created 4 years, 3 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
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 @CustomTag('foo-bar')
16 class FooBar extends PolymerElement {
17 // A little too much boilerplate?
18 static const EventStreamProvider<CustomEvent> fooEvent =
19 const EventStreamProvider<CustomEvent>('foo');
20 static const EventStreamProvider<CustomEvent> barBazEvent =
21 const EventStreamProvider<CustomEvent>('barbaz');
22
23 FooBar.created() : super.created();
24
25 Stream<CustomEvent> get onFooEvent => FooBar.fooEvent.forTarget(this);
26 Stream<CustomEvent> get onBarBazEvent => FooBar.barBazEvent.forTarget(this);
27
28 fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x));
29 fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x));
30 }
31
32 @CustomTag('test-custom-event')
33 class TestCustomEvent extends PolymerElement {
34 TestCustomEvent.created() : super.created();
35
36 get fooBar => shadowRoots['test-custom-event'].querySelector('foo-bar');
37
38 final events = [];
39 fooHandler(e) => events.add(['foo', e]);
40 barBazHandler(e) => events.add(['barbaz', e]);
41 }
42
43 main() {
44 enableBindingsReflection = true;
45
46 initPolymer().then((zone) => zone.run(() {
47 useHtmlConfiguration();
48
49 setUp(() => Polymer.onReady);
50
51 test('custom event', () {
52 final testComp = querySelector('test-custom-event');
53 final fooBar = testComp.fooBar;
54
55 final binding = nodeBind(fooBar).bindings['on-barbaz'];
56 expect(binding is Bindable, true,
57 reason: 'on-barbaz event should be bound');
58
59 expect(binding.value, '{{ barBazHandler }}',
60 reason: 'event bindings use the string as value');
61
62 fooBar.fireFoo(123);
63 fooBar.fireBarBaz(42);
64 fooBar.fireFoo(777);
65
66 final events = testComp.events;
67 expect(events.length, 3);
68 expect(events.map((e) => e[0]), ['foo', 'barbaz', 'foo']);
69 expect(events.map((e) => e[1].detail), [123, 42, 777]);
70 });
71 }));
72 }
OLDNEW
« no previous file with comments | « packages/polymer/test/computed_properties_test.html ('k') | packages/polymer/test/custom_event_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698