Bug 644565 - SpecialPowers should be able add event listeners to TabChildGlobal, r=ted

This commit is contained in:
Olli Pettay 2011-03-25 15:39:23 +02:00
Родитель caa6577fa5
Коммит a9f3d34d08
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -125,6 +125,13 @@ var SpecialPowers = {
return !this._getTopChromeWindow(window).document
.getElementById("Browser:Back")
.hasAttribute("disabled");
},
addChromeEventListener: function(type, listener, capture, allowUntrusted) {
addEventListener(type, listener, capture, allowUntrusted);
},
removeChromeEventListener: function(type, listener, capture) {
removeEventListener(type, listener, capture);
}
};

Просмотреть файл

@ -14,6 +14,22 @@
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var eventCount = 0;
function testEventListener(e) {
++eventCount;
}
function testEventListener2(e) {
++eventCount;
}
function dispatchTestEvent() {
var e = document.createEvent("Event");
e.initEvent("TestEvent", true, true);
window.dispatchEvent(e);
}
dump("\nSPECIALPTEST:::Test script loaded " + (new Date).getTime() + "\n");
SimpleTest.waitForExplicitFinish();
function starttest(){
@ -33,6 +49,16 @@ function starttest(){
SpecialPowers.setCharPref("extensions.foobaz", "hi there");
is(SpecialPowers.getCharPref("extensions.foobaz"), "hi there", "Check string pref");
SpecialPowers.addChromeEventListener("TestEvent", testEventListener, true, true);
SpecialPowers.addChromeEventListener("TestEvent", testEventListener2, true, false);
dispatchTestEvent();
is(eventCount, 1, "Should have got an event!");
SpecialPowers.removeChromeEventListener("TestEvent", testEventListener, true);
SpecialPowers.removeChromeEventListener("TestEvent", testEventListener2, true);
dispatchTestEvent();
is(eventCount, 1, "Shouldn't have got an event!");
// Test Complex Pref - TODO: Without chrome access, I don't know how you'd actually
// set this preference since you have to create an XPCOM object.
// Leaving untested for now.