From 4f9366749c7cb2b8229afe84f9110987d58206bd Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 14 Apr 2015 16:09:55 -0400 Subject: [PATCH 1/2] Add Zotero.alert() method This is just a wrapper around nsIPromptService.alert() that takes Zotero.noUserInput into consideration, which avoids long timeouts during testing (e.g., for lookup failures). --- chrome/content/zotero/lookup.js | 18 ++++++++++-------- chrome/content/zotero/xpcom/zotero.js | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index dd97426bb..3ee559dc1 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -87,10 +87,11 @@ const Zotero_Lookup = new function () { } if(!items.length) { - var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - prompts.alert(window, Zotero.getString("lookup.failure.title"), - Zotero.getString("lookup.failureToID.description")); + Zotero.alert( + window, + Zotero.getString("lookup.failure.title"), + Zotero.getString("lookup.failureToID.description") + ); return false; } @@ -127,10 +128,11 @@ const Zotero_Lookup = new function () { if(successful) { document.getElementById("zotero-lookup-panel").hidePopup(); } else { - var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - prompts.alert(window, Zotero.getString("lookup.failure.title"), - Zotero.getString("lookup.failure.description")); + Zotero.alert( + window, + Zotero.getString("lookup.failure.title"), + Zotero.getString("lookup.failure.description") + ); } } }); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 221765c0a..46014c27a 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1308,6 +1308,29 @@ Components.utils.import("resource://gre/modules/Services.jsm"); err.lineNumber ? err.lineNumber : null, null); } + + /** + * Display an alert in a given window + * + * This is just a wrapper around nsIPromptService.alert() that takes the Zotero.noUserInput + * flag into consideration + * + * @param {Window} + * @param {String} title + * @param {String} msg + */ + this.alert = function (window, title, msg) { + if (this.noUserInput) { + Zotero.debug("Not displaying alert: " + title + ": " + msg); + return; + } + + var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + ps.alert(window, title, msg); + } + + function getErrors(asStrings) { var errors = []; From 96f3cc18613b7abb9fadc7878f3c3fb67b10a671 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 15 Apr 2015 00:48:03 -0400 Subject: [PATCH 2/2] Enable debug.time pref in tests --- test/runtests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.sh b/test/runtests.sh index ee9ee850a..d62b31800 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -76,6 +76,7 @@ mkdir "$PROFILE/zotero" cat < "$PROFILE/prefs.js" user_pref("extensions.autoDisableScopes", 0); user_pref("extensions.zotero.debug.log", $DEBUG); +user_pref("extensions.zotero.debug.time", $DEBUG); user_pref("extensions.zotero.firstRunGuidance", false); user_pref("extensions.zotero.firstRun2", false); EOF