From 1266c9f1e61b66035caa6188014c6ab7059fc233 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 31 Aug 2016 02:50:02 -0400 Subject: [PATCH] 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...?) --- .../tools/testTranslators/translatorTester.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/chrome/content/zotero/tools/testTranslators/translatorTester.js b/chrome/content/zotero/tools/testTranslators/translatorTester.js index 3de43ca5a4..ef1c30ed11 100644 --- a/chrome/content/zotero/tools/testTranslators/translatorTester.js +++ b/chrome/content/zotero/tools/testTranslators/translatorTester.js @@ -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); + } } /**