OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Overrides timeout and interval callbacks to mock timing behavior. | 6 * Overrides timeout and interval callbacks to mock timing behavior. |
7 * @constructor | 7 * @constructor |
8 */ | 8 */ |
9 function MockTimer() { | 9 function MockTimer() { |
10 /** | 10 /** |
11 * Default versions of the timing functions. | 11 * Default versions of the timing functions. |
12 * @type {Object.<string, !Function>} | 12 * @type {Object.<string, !Function>} |
13 * @private | 13 * @private |
14 */ | 14 */ |
15 this.originals_ = []; | 15 this.originals_ = []; |
16 | 16 |
17 /** | 17 /** |
18 * Key to assign on the next creation of a scheduled timer. Each call to | 18 * Key to assign on the next creation of a scheduled timer. Each call to |
19 * setTimeout or setInterval returns a unique key that can be used for | 19 * setTimeout or setInterval returns a unique key that can be used for |
20 * clearing the timer. | 20 * clearing the timer. |
21 * @type {number} | 21 * @type {number} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.nextTimerKey_ = 0; | 24 this.nextTimerKey_ = 1; |
25 | 25 |
26 /** | 26 /** |
27 * Details for active timers. | 27 * Details for active timers. |
28 * @type {Array.<{callback: Function, | 28 * @type {Array.<{callback: Function, |
29 * delay: number, | 29 * delay: number, |
30 * key: number, | 30 * key: number, |
31 * repeats: boolean}>} | 31 * repeats: boolean}>} |
32 * @private | 32 * @private |
33 */ | 33 */ |
34 this.timers_ = []; | 34 this.timers_ = []; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 details.callback.apply(window); | 200 details.callback.apply(window); |
201 if (details.repeats) | 201 if (details.repeats) |
202 this.scheduleTask_(details); | 202 this.scheduleTask_(details); |
203 else | 203 else |
204 this.clearTimeout_(details.key); | 204 this.clearTimeout_(details.key); |
205 } | 205 } |
206 this.now_ = this.until_; | 206 this.now_ = this.until_; |
207 }, | 207 }, |
208 | 208 |
209 }; | 209 }; |
OLD | NEW |