fx-compat: Fix waitForWindow()/waitForDialog() in tests
This commit is contained in:
parent
d2dbf959b6
commit
4a3ff46bd7
1 changed files with 10 additions and 13 deletions
|
@ -136,16 +136,14 @@ function waitForWindow(uri, callback) {
|
|||
Zotero.debug("Window opened: " + ev.target.location.href);
|
||||
|
||||
if (ev.target.location.href != uri) {
|
||||
Zotero.debug(`Ignoring window ${uri} in waitForWindow()`);
|
||||
Zotero.debug(`Ignoring window ${ev.target.location.href} in waitForWindow()`);
|
||||
return;
|
||||
}
|
||||
|
||||
Services.ww.unregisterNotification(winobserver);
|
||||
var win = ev.target.docShell
|
||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
var win = ev.target.ownerGlobal;
|
||||
// Give window code time to run on load
|
||||
win.setTimeout(function () {
|
||||
win.setTimeout(function () {
|
||||
if (callback) {
|
||||
try {
|
||||
// If callback returns a promise, wait for it
|
||||
|
@ -167,8 +165,7 @@ function waitForWindow(uri, callback) {
|
|||
};
|
||||
var winobserver = {"observe":function(subject, topic, data) {
|
||||
if(topic != "domwindowopened") return;
|
||||
var win = subject.QueryInterface(Components.interfaces.nsIDOMWindow);
|
||||
win.addEventListener("load", loadobserver, false);
|
||||
subject.addEventListener("load", loadobserver, false);
|
||||
}};
|
||||
Services.ww.registerNotification(winobserver);
|
||||
return deferred.promise;
|
||||
|
@ -184,11 +181,11 @@ function waitForWindow(uri, callback) {
|
|||
* @return {Promise}
|
||||
*/
|
||||
function waitForDialog(onOpen, button='accept', url) {
|
||||
return waitForWindow(url || "chrome://global/content/commonDialog.xul", Zotero.Promise.method(function (dialog) {
|
||||
return waitForWindow(url || "chrome://global/content/commonDialog.xhtml", Zotero.Promise.method(function (win) {
|
||||
var failure = false;
|
||||
if (onOpen) {
|
||||
try {
|
||||
onOpen(dialog);
|
||||
onOpen(win);
|
||||
}
|
||||
catch (e) {
|
||||
failure = e;
|
||||
|
@ -203,13 +200,13 @@ function waitForDialog(onOpen, button='accept', url) {
|
|||
let deferred = Zotero.Promise.defer();
|
||||
function acceptWhenEnabled() {
|
||||
// Handle delayed buttons
|
||||
if (dialog.document.documentElement.getButton(button).disabled) {
|
||||
dialog.setTimeout(function () {
|
||||
if (win.document.querySelector('dialog').getButton(button).disabled) {
|
||||
win.setTimeout(function () {
|
||||
acceptWhenEnabled();
|
||||
}, 250);
|
||||
}
|
||||
else {
|
||||
dialog.document.documentElement.getButton(button).click();
|
||||
win.document.querySelector('dialog').getButton(button).click();
|
||||
if (failure) {
|
||||
deferred.reject(failure);
|
||||
}
|
||||
|
@ -222,7 +219,7 @@ function waitForDialog(onOpen, button='accept', url) {
|
|||
return deferred.promise;
|
||||
}
|
||||
else {
|
||||
dialog.document.documentElement.getButton(button).click();
|
||||
win.document.querySelector('dialog').getButton(button).click();
|
||||
if (failure) {
|
||||
throw failure;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue