зеркало из https://github.com/mozilla/gecko-dev.git
Bug 693417: Add a SpecialPowers API for nested event loops. r=jmaher
This commit is contained in:
Родитель
9c61adf314
Коммит
cf14b34b6f
|
@ -41,6 +41,9 @@
|
|||
|
||||
var Ci = Components.interfaces;
|
||||
var Cc = Components.classes;
|
||||
var Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function SpecialPowersAPI() {
|
||||
this._consoleListeners = [];
|
||||
|
@ -53,6 +56,7 @@ function SpecialPowersAPI() {
|
|||
this._applyingPrefs = false;
|
||||
this._fm = null;
|
||||
this._cb = null;
|
||||
this._nestedEventLoopLevel = 0;
|
||||
}
|
||||
|
||||
function bindDOMWindowUtils(aWindow) {
|
||||
|
@ -654,6 +658,18 @@ SpecialPowersAPI.prototype = {
|
|||
focus: function(window) {
|
||||
window.focus();
|
||||
},
|
||||
|
||||
enterNestedEventLoop: function() {
|
||||
let eventLoopLevel = ++this._nestedEventLoopLevel;
|
||||
let currentThread = Services.tm.currentThread;
|
||||
|
||||
while (eventLoopLevel <= this._nestedEventLoopLevel)
|
||||
currentThread.processNextEvent(true);
|
||||
},
|
||||
|
||||
exitNestedEventLoop: function () {
|
||||
--this._nestedEventLoopLevel;
|
||||
},
|
||||
|
||||
getClipboardData: function(flavor) {
|
||||
if (this._cb == null)
|
||||
|
|
|
@ -90,6 +90,23 @@ function starttest(){
|
|||
//try to run garbage collection
|
||||
SpecialPowers.gc();
|
||||
|
||||
// Enter a nested event loop
|
||||
// XXXkhuey if we ever fix nested event loops and events we might have to
|
||||
// change this test.
|
||||
var eventListenerFiredCount = 0;
|
||||
window.onmessage = function() {
|
||||
eventListenerFiredCount++;
|
||||
if (eventListenerFiredCount == 1) {
|
||||
window.postMessage("obai", "*");
|
||||
SpecialPowers.enterNestedEventLoop();
|
||||
}
|
||||
SpecialPowers.exitNestedEventLoop();
|
||||
}
|
||||
window.postMessage("ohai", "*");
|
||||
is(eventListenerFiredCount, 0, "eventListener shouldn't have fired yet.");
|
||||
SpecialPowers.enterNestedEventLoop();
|
||||
is(eventListenerFiredCount, 2, "eventListener should have fired twice now.");
|
||||
|
||||
SimpleTest.info("\nProfile::SpecialPowersRunTime: " + (new Date() - startTime) + "\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче