Testing frame work should handle event listener in itself

NEW
Unassigned

Status

8 years ago
11 months ago

People

(Reporter: hiro, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

8 years ago
For example, many tests have codes like this:

window.addEventListener("needThisEvent", function(event) {
  window.removeEventListener("needThisEvent", arguments.callee, false);
  ...
}, false);

But this listener is not removed when the test is timed out.

So we currently have to do something like this:

var listener = function(event) {
 ..
}
registerCleanupFunction(function() {
  window.removeEventListener("needThisEvent", listener, false);
});
window.addEventListener("needThisEvent", listener, false);

But this code is a little bit inconvenient to write, many test codes does actually not use registerCleanupFunction for removal of event listener.

So I'd propose more convenient way and testing frame work does remove event listener even if the test is timed out.
(Reporter)

Comment 1

8 years ago
Created attachment 536470 [details] [diff] [review]
Proposed patch

Add registerEventListener and unregisterEventListener.
Group: core-security
Bug 454717 is related.

IIRC removeEventListener can't throw, so I don't think you need the try/catch.

A unregisterListener(listeningObject) method would allow sharing some code.
(Assignee)

Updated

11 months ago
Component: BrowserTest → Mochitest
Product: Testing → Testing
You need to log in before you can comment on or make changes to this bug.