Automatically close rogue dialog boxes

A few sites (e.g., Gallica) were causing alerts to pop up in Standalone during
testing, which breaks testing, so accept them automatically. (Hopefully these
don't happen during manual translation...?)
This commit is contained in:
Dan Stillman 2016-08-31 02:50:02 -04:00
parent 6ad195521b
commit 1266c9f1e6

View file

@ -40,6 +40,8 @@ Zotero_TranslatorTesters = new function() {
* Runs all tests
*/
this.runAllTests = function (numConcurrentTests, skipTranslators, resultsCallback) {
waitForDialog();
if(!Zotero) {
Zotero = Components.classes["@zotero.org/Zotero;1"]
.getService(Components.interfaces.nsISupports).wrappedJSObject;
@ -109,6 +111,27 @@ Zotero_TranslatorTesters = new function() {
runNextTester();
};
}
function waitForDialog() {
Components.utils.import("resource://gre/modules/Services.jsm");
var loadobserver = function (ev) {
ev.originalTarget.removeEventListener("load", loadobserver, false);
if (ev.target.location == "chrome://global/content/commonDialog.xul") {
let win = ev.target.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
Zotero.debug("Closing rogue dialog box!\n\n" + win.document.documentElement.textContent, 2);
win.document.documentElement.getButton('accept').click();
}
};
var winobserver = {
observe: function (subject, topic, data) {
if (topic != "domwindowopened") return;
var win = subject.QueryInterface(Components.interfaces.nsIDOMWindow);
win.addEventListener("load", loadobserver, false);
}
};
Services.ww.registerNotification(winobserver);
}
}
/**