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

Unified Diff: samples/tests/samples/src/lib/observable/AbstractObservableTests.dart

Issue 9382027: Move client/{base, observable, layout, touch, util, view} to samples/ui_lib . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: samples/tests/samples/src/lib/observable/AbstractObservableTests.dart
===================================================================
--- samples/tests/samples/src/lib/observable/AbstractObservableTests.dart (revision 0)
+++ samples/tests/samples/src/lib/observable/AbstractObservableTests.dart (revision 0)
@@ -0,0 +1,73 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+testAbstractObservable() {
+ group('addChangeListener()', () {
+ test('adding the same listener twice returns false the second time', () {
+ final target = new AbstractObservable();
+ final listener = (e) { };
+
+ expect(target.addChangeListener(listener)).isTrue();
+ expect(target.addChangeListener(listener)).isFalse();
+ });
+
+ test('modifies listeners list', () {
+ // check that add/remove works, see contents of listeners too
+ final target = new AbstractObservable();
+ final l1 = (e) { };
+ final l2 = (e) { };
+ final l3 = (e) { };
+ final l4 = (e) { };
+
+ expect(target.listeners).equalsCollection([]);
+
+ target.addChangeListener(l1);
+ expect(target.listeners).equalsCollection([l1]);
+
+ target.addChangeListener(l2);
+ expect(target.listeners).equalsCollection([l1, l2]);
+
+ target.addChangeListener(l3);
+ target.addChangeListener(l4);
+ expect(target.listeners).equalsCollection([l1, l2, l3, l4]);
+
+ target.removeChangeListener(l4);
+ expect(target.listeners).equalsCollection([l1, l2, l3]);
+
+ target.removeChangeListener(l2);
+ expect(target.listeners).equalsCollection([l1, l3]);
+
+ target.removeChangeListener(l1);
+ expect(target.listeners).equalsCollection([l3]);
+
+ target.removeChangeListener(l3);
+ expect(target.listeners).equalsCollection([]);
+ });
+ });
+
+ test('fires immediately if no batch', () {
+ // If no batch is created, a summary should be automatically created and
+ // fired on each property change.
+ final target = new AbstractObservable();
+ EventSummary res = null;
+ target.addChangeListener((summary) {
+ expect(res).isNull();
+ res = summary;
+ expect(res).isNotNull();
+ });
+
+ target.recordPropertyUpdate('pM', 10, 11);
+
+ expect(res).isNotNull();
+ expect(res.events.length).equals(1);
+ validateUpdate(res.events[0], target, 'pM', null, 10, 11);
+ res = null;
+
+ target.recordPropertyUpdate('pL', '11', '13');
+
+ expect(res).isNotNull();
+ expect(res.events.length).equals(1);
+ validateUpdate(res.events[0], target, 'pL', null, '11', '13');
+ });
+}
« no previous file with comments | « samples/tests/samples/src/lib/layout/layout.scss ('k') | samples/tests/samples/src/lib/observable/ChangeEventTests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698