fx-compat: Restore tests and test using actual Zotero executable

The test runner now uses the Zotero executable from
`zotero-standalone-build/staging` rather than the Firefox from
`zotero-standalone-build/xulrunner`. Along with testing the actual
program, this restores visible UI updates during tests, which should
make debugging various things easier. We can also now remove anything
related to Zotero being an extension.

Many tests are still broken, but this at least lets us start running
them.
This commit is contained in:
Dan Stillman 2022-06-09 03:00:54 -04:00
parent 5d08359dc9
commit 730e86d661
7 changed files with 51 additions and 44 deletions

View file

@ -73,7 +73,7 @@ Zotero.Debug = new function () {
if (Zotero.isStandalone) {
// Enable dump() from window (non-XPCOM) scopes when terminal or viewer logging is enabled.
// (These will always go to the terminal, even in viewer mode.)
Zotero.Prefs.set('browser.dom.window.dump.enabled', _console || _consoleViewer, true);
Zotero.Prefs.set('browser.dom.window.dump.enabled', _console || _consoleViewer || Zotero.test, true);
if (_consoleViewer) {
setTimeout(function () {

View file

@ -105,7 +105,9 @@ Zotero.Schema = new function(){
Zotero.debug('Database does not exist -- creating\n');
return _initializeSchema()
.then(function() {
(Zotero.isStandalone ? Zotero.uiReadyPromise : Zotero.initializationPromise)
// Don't load bundled files until after UI is ready, unless this is a test run,
// in which case tests can run without a window open
(!Zotero.test ? Zotero.uiReadyPromise : Zotero.initializationPromise)
.delay(1000)
.then(async function () {
await this.updateBundledFiles();
@ -294,9 +296,8 @@ Zotero.Schema = new function(){
// Reset sync queue tries if new version
await _checkClientVersion();
// In Standalone, don't load bundled files until after UI is ready. In Firefox, load them as
// soon initialization is done so that translation works before the Zotero pane is opened.
(Zotero.isStandalone ? Zotero.uiReadyPromise : Zotero.initializationPromise)
// See above
(!Zotero.test ? Zotero.uiReadyPromise : Zotero.initializationPromise)
.then(() => {
setTimeout(async function () {
try {
@ -847,11 +848,12 @@ Zotero.Schema = new function(){
await Zotero.SearchConditions.init();
// Update item type menus in every open window
// TODO: Remove?
Zotero.Schema.schemaUpdatePromise.then(function () {
var enumerator = Services.wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
let win = enumerator.getNext();
win.document.getElementById('zotero-editpane-item-box').buildItemTypeMenu();
//win.document.getElementById('zotero-editpane-item-box').buildItemTypeMenu();
}
});
}

View file

@ -54,7 +54,16 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
this.startupError;
Object.defineProperty(this, 'startupErrorHandler', {
get: () => _startupErrorHandler,
enumerable: true
enumerable: true,
configurable: true
});
Object.defineProperty(this, 'resourcesDir', {
get: () => {
// AChrome is app/chrome
return FileUtils.getDir('AChrom', []).parent.parent.path;
},
enumerable: true,
configurable: true
});
this.version;
this.platform;
@ -107,7 +116,8 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
this.unlockDeferred.resolve();
}
},
enumerable: true
enumerable: true,
configurable: true
}
);

View file

@ -1,7 +1,7 @@
content zotero-unit content/
resource zotero-unit resource/
resource zotero-unit-tests tests/
content zotero-unit test/content/
resource zotero-unit test/resource/
resource zotero-unit-tests test/tests/
component {b8570031-be5e-46e8-9785-38cd50a5d911} components/zotero-unit.js
component {b8570031-be5e-46e8-9785-38cd50a5d911} test/components/zotero-unit.js
contract @mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit {b8570031-be5e-46e8-9785-38cd50a5d911}
category command-line-handler m-zotero-unit @mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit

View file

@ -23,7 +23,7 @@
***** END LICENSE BLOCK *****
*/
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/ComponentUtils.jsm");
function ZoteroUnit() {
this.wrappedJSObject = this;
@ -56,4 +56,4 @@ ZoteroUnit.prototype = {
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ZoteroUnit]);
var NSGetFactory = ComponentUtils.generateNSGetFactory([ZoteroUnit]);

View file

@ -557,11 +557,10 @@ function initPDFToolsPath() {
* (i.e., test/tests/data)
*/
function getTestDataDirectory() {
var resource = Services.io.getProtocolHandler("resource").
QueryInterface(Components.interfaces.nsIResProtocolHandler),
resURI = Services.io.newURI("resource://zotero-unit-tests/data", null, null);
return Services.io.newURI(resource.resolveURI(resURI), null, null).
QueryInterface(Components.interfaces.nsIFileURL).file;
var file = Zotero.File.pathToFile(Zotero.resourcesDir);
file.append('tests');
file.append('data');
return file;
}
function getTestDataUrl(path) {

View file

@ -15,18 +15,18 @@ function makePath {
eval $__assignTo="'$__path'"
}
if [ -z "$FX_EXECUTABLE" ]; then
if [ -z "$Z_EXECUTABLE" ]; then
if [ "`uname`" == "Darwin" ]; then
FX_EXECUTABLE="$( dirname "$ROOT_DIR" )/zotero-standalone-build/xulrunner/Firefox.app/Contents/MacOS/firefox"
Z_EXECUTABLE="$( dirname "$ROOT_DIR" )/zotero-standalone-build/staging/Zotero.app/Contents/MacOS/zotero"
else
FX_EXECUTABLE="$( dirname "$ROOT_DIR" )/zotero-standalone-build/xulrunner/firefox-x86_64/firefox"
Z_EXECUTABLE="$( dirname "$ROOT_DIR" )/zotero-standalone-build/staging/Zotero-x86_64/zotero"
fi
fi
if [ -z "$DISPLAY" ]; then
FX_ARGS=""
Z_ARGS=""
else
FX_ARGS="--class=ZTestFirefox"
Z_ARGS="--class=ZTestFirefox"
fi
function usage {
@ -42,7 +42,7 @@ Options
-h display this help
-s TEST start at the given test
-t generate test data and quit
-x FX_EXECUTABLE path to Firefox executable (default: $FX_EXECUTABLE)
-x EXECUTABLE path to Zotero executable (default: $Z_EXECUTABLE)
TESTS set of tests to run (default: all)
DONE
exit 1
@ -53,10 +53,10 @@ DEBUG_LEVEL=5
while getopts "bcd:e:fg:hs:tx:" opt; do
case $opt in
b)
FX_ARGS="$FX_ARGS -ZoteroSkipBundledFiles"
Z_ARGS="$Z_ARGS -ZoteroSkipBundledFiles"
;;
c)
FX_ARGS="$FX_ARGS -jsconsole -noquit"
Z_ARGS="$Z_ARGS -jsconsole -noquit"
;;
d)
DEBUG=true
@ -66,10 +66,10 @@ while getopts "bcd:e:fg:hs:tx:" opt; do
if [[ -z "$OPTARG" ]] || [[ ${OPTARG:0:1} = "-" ]]; then
usage
fi
FX_ARGS="$FX_ARGS -stopAtTestFile $OPTARG"
Z_ARGS="$Z_ARGS -stopAtTestFile $OPTARG"
;;
f)
FX_ARGS="$FX_ARGS -bail"
Z_ARGS="$Z_ARGS -bail"
;;
g)
GREP="$OPTARG"
@ -81,13 +81,13 @@ while getopts "bcd:e:fg:hs:tx:" opt; do
if [[ -z "$OPTARG" ]] || [[ ${OPTARG:0:1} = "-" ]]; then
usage
fi
FX_ARGS="$FX_ARGS -startAtTestFile $OPTARG"
Z_ARGS="$Z_ARGS -startAtTestFile $OPTARG"
;;
t)
FX_ARGS="$FX_ARGS -makeTestData"
Z_ARGS="$Z_ARGS -makeTestData"
;;
x)
FX_EXECUTABLE="$OPTARG"
Z_EXECUTABLE="$OPTARG"
;;
*)
usage
@ -115,13 +115,9 @@ ulimit -n 4096
# Set up profile directory
TEMPDIR="`mktemp -d 2>/dev/null || mktemp -d -t 'zotero-unit'`"
PROFILE="$TEMPDIR/profile"
mkdir -p "$PROFILE/extensions"
mkdir -p "$PROFILE"
makePath ZOTERO_PATH "$ROOT_DIR/build"
echo "$ZOTERO_PATH" > "$PROFILE/extensions/zotero@chnm.gmu.edu"
makePath ZOTERO_UNIT_PATH "$ZOTERO_PATH/test"
echo "$ZOTERO_UNIT_PATH" > "$PROFILE/extensions/zotero-unit@zotero.org"
# Create data directory
mkdir "$TEMPDIR/Zotero"
@ -144,9 +140,7 @@ if [ ! -f "$PDF_TOOLS_CACHE_DIR/$PDF_TOOLS_VERSION" ]; then
fi
cp -R $PDF_TOOLS_CACHE_DIR $PDF_TOOLS_DIR
# Add default prefs, which are apparently no longer read from extensions in Firefox 60
cat "$ZOTERO_PATH/defaults/preferences/zotero.js" | sed 's/^pref/user_pref/g' > "$PROFILE/prefs.js"
touch "$PROFILE/prefs.js"
cat <<EOF >> "$PROFILE/prefs.js"
user_pref("app.update.enabled", false);
user_pref("extensions.autoDisableScopes", 0);
@ -181,11 +175,11 @@ EOF
# -v flag on Windows makes Firefox process hang
if [ -z $IS_CYGWIN ]; then
echo "`MOZ_NO_REMOTE=1 NO_EM_RESTART=1 \"$FX_EXECUTABLE\" -v`"
echo "`MOZ_NO_REMOTE=1 NO_EM_RESTART=1 \"$Z_EXECUTABLE\" -v`"
fi
if [ -n "$CI" ]; then
FX_ARGS="$FX_ARGS -ZoteroAutomatedTest -ZoteroTestTimeout 15000"
Z_ARGS="$Z_ARGS -ZoteroAutomatedTest -ZoteroTestTimeout 15000"
fi
# Clean up on exit
@ -201,9 +195,11 @@ if [[ -z "$CI" ]] && ! ps | grep scripts/build.js | grep -v grep > /dev/null; th
echo
fi
ZOTERO_INCLUDE_TESTS=1 $( dirname "$ROOT_DIR" )/zotero-standalone-build/scripts/dir_build -q
makePath FX_PROFILE "$PROFILE"
MOZ_NO_REMOTE=1 NO_EM_RESTART=1 "$FX_EXECUTABLE" -profile "$FX_PROFILE" \
-chrome chrome://zotero-unit/content/runtests.html -test "$TESTS" -grep "$GREP" -ZoteroTest $FX_ARGS
MOZ_NO_REMOTE=1 NO_EM_RESTART=1 "$Z_EXECUTABLE" -profile "$FX_PROFILE" -jsconsole \
-chrome chrome://zotero-unit/content/runtests.html -test "$TESTS" -grep "$GREP" -ZoteroTest $Z_ARGS
# Check for success
test -e "$PROFILE/success"