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);
|
Zotero.debug("Window opened: " + ev.target.location.href);
|
||||||
|
|
||||||
if (ev.target.location.href != uri) {
|
if (ev.target.location.href != uri) {
|
||||||
Zotero.debug(`Ignoring window ${uri} in waitForWindow()`);
|
Zotero.debug(`Ignoring window ${ev.target.location.href} in waitForWindow()`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.ww.unregisterNotification(winobserver);
|
Services.ww.unregisterNotification(winobserver);
|
||||||
var win = ev.target.docShell
|
var win = ev.target.ownerGlobal;
|
||||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
||||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
|
||||||
// Give window code time to run on load
|
// Give window code time to run on load
|
||||||
win.setTimeout(function () {
|
win.setTimeout(function () {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
try {
|
try {
|
||||||
// If callback returns a promise, wait for it
|
// If callback returns a promise, wait for it
|
||||||
|
@ -167,8 +165,7 @@ function waitForWindow(uri, callback) {
|
||||||
};
|
};
|
||||||
var winobserver = {"observe":function(subject, topic, data) {
|
var winobserver = {"observe":function(subject, topic, data) {
|
||||||
if(topic != "domwindowopened") return;
|
if(topic != "domwindowopened") return;
|
||||||
var win = subject.QueryInterface(Components.interfaces.nsIDOMWindow);
|
subject.addEventListener("load", loadobserver, false);
|
||||||
win.addEventListener("load", loadobserver, false);
|
|
||||||
}};
|
}};
|
||||||
Services.ww.registerNotification(winobserver);
|
Services.ww.registerNotification(winobserver);
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
@ -184,11 +181,11 @@ function waitForWindow(uri, callback) {
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
function waitForDialog(onOpen, button='accept', url) {
|
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;
|
var failure = false;
|
||||||
if (onOpen) {
|
if (onOpen) {
|
||||||
try {
|
try {
|
||||||
onOpen(dialog);
|
onOpen(win);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
failure = e;
|
failure = e;
|
||||||
|
@ -203,13 +200,13 @@ function waitForDialog(onOpen, button='accept', url) {
|
||||||
let deferred = Zotero.Promise.defer();
|
let deferred = Zotero.Promise.defer();
|
||||||
function acceptWhenEnabled() {
|
function acceptWhenEnabled() {
|
||||||
// Handle delayed buttons
|
// Handle delayed buttons
|
||||||
if (dialog.document.documentElement.getButton(button).disabled) {
|
if (win.document.querySelector('dialog').getButton(button).disabled) {
|
||||||
dialog.setTimeout(function () {
|
win.setTimeout(function () {
|
||||||
acceptWhenEnabled();
|
acceptWhenEnabled();
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dialog.document.documentElement.getButton(button).click();
|
win.document.querySelector('dialog').getButton(button).click();
|
||||||
if (failure) {
|
if (failure) {
|
||||||
deferred.reject(failure);
|
deferred.reject(failure);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +219,7 @@ function waitForDialog(onOpen, button='accept', url) {
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dialog.document.documentElement.getButton(button).click();
|
win.document.querySelector('dialog').getButton(button).click();
|
||||||
if (failure) {
|
if (failure) {
|
||||||
throw failure;
|
throw failure;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue