OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 /** |
| 6 * Fakes a Chrome event that supports one listener. |
| 7 * @constructor |
| 8 * @extends {ChromeEvent} |
| 9 */ |
| 10 function FakeChromeEvent() { |
| 11 /** |
| 12 * @private |
| 13 * @type {Function} |
| 14 */ |
| 15 this.listener_ = null; |
| 16 } |
| 17 |
| 18 FakeChromeEvent.prototype = { |
| 19 /** |
| 20 * Fakes the corresponding call on a Chrome event. Sets the listener and |
| 21 * fails the test if it is already set. |
| 22 * @param {Function} listener The new listener. |
| 23 */ |
| 24 addListener: function(listener) { |
| 25 this.assertNoListener(); |
| 26 this.listener_ = listener; |
| 27 }, |
| 28 |
| 29 /** |
| 30 * Gets the listener of the event, failing the test if there's none. |
| 31 * @return {Function} The event's listener. |
| 32 */ |
| 33 getListener: function() { |
| 34 assertNotEquals(null, this.listener_); |
| 35 return this.listener_; |
| 36 }, |
| 37 |
| 38 /** |
| 39 * Asserts that this object doesn't have any listener added. |
| 40 */ |
| 41 assertNoListener: function() { |
| 42 assertEquals(null, this.listener_); |
| 43 } |
| 44 }; |
OLD | NEW |