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..27a18712a2e297280fab575663ad09dbf489f3db |
--- /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 {!Array<!Function>} */ |
+ this.listeners_ = []; |
+} |
+ |
+FakeChromeEvent.prototype = { |
+ /** @param {Function} listener */ |
+ addListener: function(listener) { |
+ this.listeners_.push(listener); |
+ }, |
+ |
+ /** @param {Function} listener */ |
+ removeListener: function(listener) { |
+ var index = this.listeners_.indexOf(listener); |
dpapad
2015/12/16 21:18:07
Can you use a native Javascript Set instead of an
stevenjb
2015/12/16 22:20:57
Done.
|
+ if (index < 0) { |
+ console.error('removeListener: not found'); |
+ return; |
+ } |
+ this.listeners_.slice(index, 1); |
+ }, |
+ |
+ /** @param {...} args */ |
+ callListeners: function(...args) { |
+ for (var l of this.listeners_) |
+ l.apply(null, args); |
+ } |
+}; |