From 4b119a94d89c0b642386a03f36b31e69fe081791 Mon Sep 17 00:00:00 2001 From: "alanknight@google.com" Date: Tue, 7 Apr 2015 20:52:54 +0000 Subject: [PATCH] Better way of fixing attribute_changed_callback_test, doesn't require a timer BUG= Review URL: https://codereview.chromium.org//1061403002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44946 260f80e4-7a28-3924-810f-c04153c831b5 --- .../attribute_changed_callback_test.dart | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/html/custom/attribute_changed_callback_test.dart b/tests/html/custom/attribute_changed_callback_test.dart index 07abbf3e0af..d0c0e322e2a 100644 --- a/tests/html/custom/attribute_changed_callback_test.dart +++ b/tests/html/custom/attribute_changed_callback_test.dart @@ -32,8 +32,14 @@ class B extends HtmlElement { static var invocations = []; + Completer completer; + void attributeChanged(name, oldValue, newValue) { invocations.add('$name: $oldValue => $newValue'); + if (completer != null) { + completer.complete('value changed to $newValue'); + completer = null; + } } } @@ -90,16 +96,19 @@ main() { B.invocations = []; var b = new B(); + var completer = new Completer(); + b.completer = completer; b.id = 'x'; - - return new Future.delayed(new Duration(milliseconds: 1)) + return completer.future .then((_) => expect(B.invocations, ['created', 'id: null => x'])) .then((_) { - B.invocations = []; - b.attributes.remove('id'); - }) - .then((_) => new Future.delayed(new Duration(milliseconds: 1))) - .then((_) => expect(B.invocations, ['id: x => null'])); + B.invocations = []; + var secondCompleter = new Completer(); + b.completer = secondCompleter; + b.attributes.remove('id'); + return secondCompleter.future; + }) + .then((_) => expect(B.invocations, ['id: x => null'])); }); });