[Pkg-mozext-commits] [firebug] 05/82: FBTest: make sure that context menu listeners are removed at the end of the test
David Prévot
taffit at moszumanska.debian.org
Mon Mar 31 22:45:35 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag fbtest-1.11.2
in repository firebug.
commit 6a7d39d1eaa074efc3334621b09cfd9b28548b0b
Author: Jan Odvarko <odvarko at gmail.com>
Date: Mon Dec 17 13:18:27 2012 +0100
FBTest: make sure that context menu listeners are removed at the end of the test
---
tests/FBTest/content/FBTestContextMenu.js | 69 +++++++++++++++++++++++++++++++
tests/FBTest/content/FBTestFirebug.js | 17 ++++----
tests/FBTest/content/wrapAJSFile.html | 1 +
3 files changed, 80 insertions(+), 7 deletions(-)
diff --git a/tests/FBTest/content/FBTestContextMenu.js b/tests/FBTest/content/FBTestContextMenu.js
new file mode 100644
index 0000000..328fc2a
--- /dev/null
+++ b/tests/FBTest/content/FBTestContextMenu.js
@@ -0,0 +1,69 @@
+/* See license.txt for terms of usage */
+
+// ********************************************************************************************* //
+// Tooltip Controller
+
+/**
+ * The object is responsible for registering 'popupshowing' listeners and safe clean up.
+ * The clean up is important since it must happen even if the test doesn't fisnish.
+ */
+var ContextMenuController =
+{
+ listeners: [],
+
+ getContextMenu: function(target)
+ {
+ return FW.FBL.hasPrefix(target.ownerDocument.documentURI, "chrome://firebug/") ?
+ FW.FBL.$("fbContextMenu") : FW.Firebug.chrome.window.top.window.document.
+ getElementById("contentAreaContextMenu");
+ },
+
+ addListener: function(target, eventName, listener)
+ {
+ var contextMenu = this.getContextMenu(target);
+ contextMenu.addEventListener(eventName, listener, false);
+
+ this.listeners.push({
+ eventName: eventName,
+ contextMenu: contextMenu,
+ listener: listener,
+ });
+ },
+
+ removeListener: function(target, eventName, listener)
+ {
+ var contextMenu = this.getContextMenu(target);
+ contextMenu.removeEventListener(eventName, listener, false);
+
+ for (var i=0; i<this.listeners.length; i++)
+ {
+ var l = this.listeners[i];
+ if (l.listener == listener)
+ {
+ this.listeners.splice(i, 1);
+ break;
+ }
+ }
+ },
+
+ cleanUp: function()
+ {
+ for (var i=0; i<this.listeners.length; i++)
+ {
+ var l = this.listeners[i];
+ l.contextMenu.removeEventListener(l.eventName, l.listener, false);
+ }
+
+ this.listeners = [];
+ }
+};
+
+// ********************************************************************************************* //
+// Clean up
+
+window.addEventListener("unload", function testWindowUnload()
+{
+ ContextMenuController.cleanUp();
+}, true);
+
+// ********************************************************************************************* //
diff --git a/tests/FBTest/content/FBTestFirebug.js b/tests/FBTest/content/FBTestFirebug.js
index af42227..d6101c8 100644
--- a/tests/FBTest/content/FBTestFirebug.js
+++ b/tests/FBTest/content/FBTestFirebug.js
@@ -2295,22 +2295,25 @@ this.getSelectedNodeBox = function()
// Context menu
/**
- * Opens context menu for target element and executes specified command
+ * Opens context menu for target element and executes specified command.
+ * Context menu listener is registered through ContextMenuController object, which ensures
+ * that the listener is removed at the end of the test even in cases where the context menu
+ * is never opened and so, the listener not removed by the test itself.
+ *
* @param {Element} target Element, which's context menu should be opened
- * @param {String or Object} menuItemIdentifier ID or object holding the label of the menu item, that should be executed
+ * @param {String or Object} menuItemIdentifier ID or object holding the label of the
+ * menu item, that should be executed
* @param {Function} callback Function called as soon as the element is selected.
*/
this.executeContextMenuCommand = function(target, menuItemIdentifier, callback)
{
- var contextMenu = FW.FBL.hasPrefix(target.ownerDocument.documentURI, "chrome://firebug/") ?
- FW.FBL.$("fbContextMenu") : FW.Firebug.chrome.window.top.window.document.
- getElementById("contentAreaContextMenu");
+ var contextMenu = ContextMenuController.getContextMenu(target);
var self = this;
function onPopupShown(event)
{
- contextMenu.removeEventListener("popupshown", onPopupShown, false);
+ ContextMenuController.removeListener(target, "popupshown", onPopupShown);
// Fire the event handler asynchronously so items have a chance to be appended.
setTimeout(function()
@@ -2376,7 +2379,7 @@ this.executeContextMenuCommand = function(target, menuItemIdentifier, callback)
}
// Wait till the menu is displayed.
- contextMenu.addEventListener("popupshown", onPopupShown, false);
+ ContextMenuController.addListener(target, "popupshown", onPopupShown);
// Right click on the target element.
var eventDetails = {type: "contextmenu", button: 2};
diff --git a/tests/FBTest/content/wrapAJSFile.html b/tests/FBTest/content/wrapAJSFile.html
index 128deda..82fd7c2 100644
--- a/tests/FBTest/content/wrapAJSFile.html
+++ b/tests/FBTest/content/wrapAJSFile.html
@@ -5,6 +5,7 @@
<script type="application/x-javascript" src="chrome://fbtest/content/FBTestMutation.js"></script>
<script type="application/x-javascript" src="chrome://fbtest/content/FBTestSelection.js"></script>
<script type="application/x-javascript" src="chrome://fbtest/content/FBTestTooltip.js"></script>
+<script type="application/x-javascript" src="chrome://fbtest/content/FBTestContextMenu.js"></script>
<script type="application/x-javascript" src="chrome://fbtest/content/FBTestCookies.js"></script>
<script type="application/x-javascript" src="chrome://fbtest/content/jsdiff.js"></script>
<script type="application/x-javascript">
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git
More information about the Pkg-mozext-commits
mailing list