OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 suiteSetup(function() { |
| 6 cr.define('bookmarks', function() { |
| 7 var TestTimerProxy = function(data) { |
| 8 bookmarks.TimerProxy.call(this); |
| 9 |
| 10 this.immediatelyResolveTimeouts = true; |
| 11 |
| 12 /** @private */ |
| 13 this.timeoutIds_ = 0; |
| 14 |
| 15 /** @private {!Map<number, !Function>} */ |
| 16 this.activeTimeouts_ = new Map(); |
| 17 }; |
| 18 |
| 19 TestTimerProxy.prototype = { |
| 20 __proto__: bookmarks.TimerProxy.prototype, |
| 21 |
| 22 /** |
| 23 * @param {Function|string} fn |
| 24 * @param {number=} delay |
| 25 * @return {number} |
| 26 * @override |
| 27 */ |
| 28 setTimeout: function(fn, delay) { |
| 29 if (this.immediatelyResolveTimeouts) |
| 30 fn(); |
| 31 else |
| 32 this.activeTimeouts_[this.timeoutIds_] = fn; |
| 33 |
| 34 return this.timeoutIds_++; |
| 35 }, |
| 36 |
| 37 /** |
| 38 * @param {number|undefined?} id |
| 39 * @override |
| 40 */ |
| 41 clearTimeout: function(id) { |
| 42 this.activeTimeouts_.delete(id); |
| 43 }, |
| 44 |
| 45 /** |
| 46 * Run the function associated with a timeout id and clear it from the |
| 47 * active timeouts. |
| 48 * @param {number} id |
| 49 */ |
| 50 runTimeoutFn: function(id) { |
| 51 this.activeTimeouts_[id](); |
| 52 this.clearTimeout(id); |
| 53 }, |
| 54 |
| 55 /** |
| 56 * Returns true if a given timeout id has not been run or cleared. |
| 57 * @param {number} id |
| 58 * @return {boolean} |
| 59 */ |
| 60 hasTimeout: function(id) { |
| 61 return this.activeTimeouts_.has(id); |
| 62 }, |
| 63 }; |
| 64 |
| 65 return { |
| 66 TestTimerProxy: TestTimerProxy, |
| 67 }; |
| 68 }); |
| 69 }); |
OLD | NEW |