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.
6 * Fakes a Chrome event that supports one listener.
8 * @extends {ChromeEvent}
10 function FakeChromeEvent() {
15 this.listener_ = null;
18 FakeChromeEvent.prototype = {
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.
24 addListener: function(listener) {
25 this.assertNoListener();
26 this.listener_ = listener;
30 * Gets the listener of the event, failing the test if there's none.
31 * @return {Function} The event's listener.
33 getListener: function() {
34 assertNotEquals(null, this.listener_);
35 return this.listener_;
39 * Asserts that this object doesn't have any listener added.
41 assertNoListener: function() {
42 assertEquals(null, this.listener_);