OLD | NEW |
(Empty) | |
| 1 library animation_runner_spec; |
| 2 |
| 3 import 'dart:async'; |
| 4 import '../_specs.dart'; |
| 5 |
| 6 main() { |
| 7 describe('AnimationLoop', () { |
| 8 TestBed _; |
| 9 AnimationLoop runner; |
| 10 MockAnimationFrame frame; |
| 11 beforeEach(async(inject((TestBed tb, VmTurnZone zone) { |
| 12 _ = tb; |
| 13 frame = new MockAnimationFrame(); |
| 14 runner = new AnimationLoop(frame, new Profiler(), zone); |
| 15 }))); |
| 16 |
| 17 it('should play animations with window animation frames', async(() { |
| 18 var animation = new MockAnimation(); |
| 19 animation.when(callsTo('read', anything)).alwaysReturn(null); |
| 20 animation.when(callsTo('update', anything)) |
| 21 .thenReturn(true, 2) |
| 22 .thenReturn(false); |
| 23 |
| 24 runner.play(animation); |
| 25 |
| 26 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(0)); |
| 27 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(0)); |
| 28 animation.clearLogs(); |
| 29 |
| 30 frame.frame(0.0); |
| 31 microLeap(); |
| 32 |
| 33 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(1)); |
| 34 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(1)); |
| 35 animation.clearLogs(); |
| 36 |
| 37 frame.frame(0.0); |
| 38 microLeap(); |
| 39 |
| 40 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(1)); |
| 41 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(1)); |
| 42 animation.clearLogs(); |
| 43 |
| 44 frame.frame(0.0); |
| 45 microLeap(); |
| 46 |
| 47 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(1)); |
| 48 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(1)); |
| 49 animation.clearLogs(); |
| 50 |
| 51 frame.frame(0.0); |
| 52 microLeap(); |
| 53 |
| 54 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(0)); |
| 55 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(0)); |
| 56 })); |
| 57 |
| 58 it('should forget about animations when forget(animation) is called', async(
() { |
| 59 var animation = new MockAnimation(); |
| 60 animation.when(callsTo('read', anything)).alwaysReturn(null); |
| 61 animation.when(callsTo('update', anything)) |
| 62 .thenReturn(true, 2) |
| 63 .thenReturn(false); |
| 64 |
| 65 runner.play(animation); |
| 66 runner.forget(animation); |
| 67 |
| 68 frame.frame(0.0); |
| 69 microLeap(); |
| 70 |
| 71 animation.getLogs(callsTo('read', anything)).verify(happenedExactly(0)); |
| 72 animation.getLogs(callsTo('update', anything)).verify(happenedExactly(0)); |
| 73 })); |
| 74 }); |
| 75 } |
| 76 |
| 77 class MockAnimation extends Mock implements LoopedAnimation { |
| 78 final Completer<AnimationResult> onCompletedCompleter = new Completer<Animatio
nResult>(); |
| 79 Future<AnimationResult> get onCompleted => onCompletedCompleter.future; |
| 80 |
| 81 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 82 } |
| 83 |
| 84 class MockAnimationFrame implements AnimationFrame { |
| 85 Completer<num> frameCompleter; |
| 86 Future<num> get animationFrame { |
| 87 if (frameCompleter == null) |
| 88 frameCompleter = new Completer<num>(); |
| 89 return frameCompleter.future; |
| 90 } |
| 91 |
| 92 frame(num time) { |
| 93 var completer = frameCompleter; |
| 94 frameCompleter = null; |
| 95 if (completer != null) { |
| 96 completer.complete(time); |
| 97 } |
| 98 } |
| 99 } |
OLD | NEW |