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

Unified Diff: packages/observe/test/list_path_observer_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/observe/test/list_change_test.dart ('k') | packages/observe/test/observable_list_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/observe/test/list_path_observer_test.dart
diff --git a/packages/observe/test/list_path_observer_test.dart b/packages/observe/test/list_path_observer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..eddaf8cbea6fae0aee51735e08afbf141823a757
--- /dev/null
+++ b/packages/observe/test/list_path_observer_test.dart
@@ -0,0 +1,83 @@
+// Copyright (c) 2013, 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.
+
+import 'dart:async';
+import 'package:observe/observe.dart';
+import 'package:unittest/unittest.dart';
+import 'observe_test_utils.dart';
+
+import 'package:observe/mirrors_used.dart'; // make test smaller.
+import 'package:smoke/mirrors.dart';
+
+main() {
+ useMirrors();
+ dirtyCheckZone().run(_runTests);
+}
+
+_runTests() {
+ var list;
+ var obs;
+ var o1, o2, o3;
+ var sub;
+ int changes;
+
+ setUp(() {
+ list = toObservable([
+ o1 = new TestModel()..a = (new TestModel()..b = 1),
+ o2 = new TestModel()..a = (new TestModel()..b = 2),
+ o3 = new TestModel()..a = (new TestModel()..b = 3)]);
+ obs = new ListPathObserver(list, 'a.b');
+ changes = 0;
+ sub = obs.changes.listen((e) { changes++; });
+ });
+
+ tearDown(() {
+ sub.cancel();
+ list = obs = o1 = o2 = o3 = null;
+ });
+
+ test('list path observer noticed length changes', () {
+ expect(o2.a.b, 2);
+ expect(list[1].a.b, 2);
+ return _nextMicrotask(null).then((_) {
+ expect(changes, 0);
+ list.removeAt(1);
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 1);
+ expect(list[1].a.b, 3);
+ });
+ });
+
+ test('list path observer delivers deep change', () {
+ expect(o2.a.b, 2);
+ expect(list[1].a.b, 2);
+ int changes = 0;
+ obs.changes.listen((e) { changes++; });
+ return _nextMicrotask(null).then((_) {
+ expect(changes, 0);
+ o2.a.b = 4;
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 1);
+ expect(list[1].a.b, 4);
+ o1.a = new TestModel()..b = 5;
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 2);
+ expect(list[0].a.b, 5);
+ });
+ });
+}
+
+_nextMicrotask(_) => new Future(() {});
+
+@reflectable
+class TestModel extends ChangeNotifier {
+ var _a, _b;
+ TestModel();
+
+ get a => _a;
+ void set a(newValue) { _a = notifyPropertyChange(#a, _a, newValue); }
+
+ get b => _b;
+ void set b(newValue) { _b = notifyPropertyChange(#b, _b, newValue); }
+}
« no previous file with comments | « packages/observe/test/list_change_test.dart ('k') | packages/observe/test/observable_list_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698