Chromium Code Reviews| Index: chrome/test/data/webui/fake_chrome_event.js |
| diff --git a/chrome/test/data/webui/fake_chrome_event.js b/chrome/test/data/webui/fake_chrome_event.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c7c19f9a11e877ff8bb45e71a15936939259ef05 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/fake_chrome_event.js |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Fake implementations of ChromeEvent. |
| + */ |
| + |
| +/** |
| + * @constructor |
| + * @extends {ChromeEvent} |
| + */ |
| +function FakeChromeEvent() { |
| + /** @type {!Set<!Function>} */ |
| + this.listeners_ = new Set; |
|
dpapad
2015/12/17 00:04:18
Nit: Can we use the following syntax?
this.listen
stevenjb
2015/12/17 00:18:11
Sure. That's just my C background (and newness to
|
| +} |
| + |
| +FakeChromeEvent.prototype = { |
| + /** @param {Function} listener */ |
| + addListener: function(listener) { |
|
dschuyler
2015/12/16 22:27:03
Maybe: since this is now a Set and therefore shoul
stevenjb
2015/12/17 00:18:11
Done.
|
| + this.listeners_.add(listener); |
| + }, |
| + |
| + /** @param {Function} listener */ |
| + removeListener: function(listener) { |
| + if (!this.listeners_.has(listener)) { |
| + console.error('removeListener: not found'); |
| + return; |
| + } |
| + this.listeners_.delete(listener); |
| + }, |
| + |
| + /** @param {...} args */ |
| + callListeners: function(...args) { |
| + this.listeners_.forEach(function(l) { |
| + l.apply(null, args); |
| + }); |
| + } |
| +}; |