Clean up event handlers (untested)

Needs manual testing and then a unit test (that exercises multiple eventTypes as well).
Fix typo in DomRange event handler cleanup
Add a test for cleaning up event handlers when template is destroyed
Merge branch 'event-cleanup-cherrypick' into devel
Rename `closePopup` to `OAuth._endOfLoginResponse`.