summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-event-dom.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /addon-sdk/source/test/test-event-dom.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/source/test/test-event-dom.js')
-rw-r--r--addon-sdk/source/test/test-event-dom.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/addon-sdk/source/test/test-event-dom.js b/addon-sdk/source/test/test-event-dom.js
new file mode 100644
index 000000000..fbbc6825b
--- /dev/null
+++ b/addon-sdk/source/test/test-event-dom.js
@@ -0,0 +1,92 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { openWindow, closeWindow } = require('./util');
+const { Loader } = require('sdk/test/loader');
+const { getMostRecentBrowserWindow } = require('sdk/window/utils');
+const { Cc, Ci } = require('chrome');
+const els = Cc["@mozilla.org/eventlistenerservice;1"].
+ getService(Ci.nsIEventListenerService);
+
+function countListeners(target, type) {
+ let listeners = els.getListenerInfoFor(target, {});
+ return listeners.filter(listener => listener.type == type).length;
+}
+
+exports['test window close clears listeners'] = function(assert) {
+ let window = yield openWindow();
+ let loader = Loader(module);
+
+ // Any element will do here
+ let gBrowser = window.gBrowser;
+
+ // Other parts of the app may be listening for this
+ let windowListeners = countListeners(window, "DOMWindowClose");
+
+ // We can assume we're the only ones using the test events
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 0, "Should be no listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+
+ let { open } = loader.require('sdk/event/dom');
+
+ open(gBrowser, "TestEvent1");
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners + 1,
+ "Should have added a DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 1, "Should be a listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+
+ open(gBrowser, "TestEvent2");
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners + 1,
+ "Should not have added another DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 1, "Should be a listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 1, "Should be a listener for test event 2");
+
+ window = yield closeWindow(window);
+
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners,
+ "Should have removed a DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 0, "Should be no listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+
+ loader.unload();
+};
+
+exports['test unload clears listeners'] = function(assert) {
+ let window = getMostRecentBrowserWindow();
+ let loader = Loader(module);
+
+ // Any element will do here
+ let gBrowser = window.gBrowser;
+
+ // Other parts of the app may be listening for this
+ let windowListeners = countListeners(window, "DOMWindowClose");
+
+ // We can assume we're the only ones using the test events
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 0, "Should be no listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+
+ let { open } = loader.require('sdk/event/dom');
+
+ open(gBrowser, "TestEvent1");
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners + 1,
+ "Should have added a DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 1, "Should be a listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+
+ open(gBrowser, "TestEvent2");
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners + 1,
+ "Should not have added another DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 1, "Should be a listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 1, "Should be a listener for test event 2");
+
+ loader.unload();
+
+ assert.equal(countListeners(window, "DOMWindowClose"), windowListeners,
+ "Should have removed a DOMWindowClose listener");
+ assert.equal(countListeners(gBrowser, "TestEvent1"), 0, "Should be no listener for test event 1");
+ assert.equal(countListeners(gBrowser, "TestEvent2"), 0, "Should be no listener for test event 2");
+};
+
+require('sdk/test').run(exports);