mirror of
https://github.com/zotero/zotero.git
synced 2026-12-02 00:47:18 +00:00
An incompletely applied update can start code from the previous version with the new version's resources. Record the version in both the code and a bundled resource file, and on a mismatch at startup, invalidate caches and restart. If the mismatch remains after the restart, show an error telling people to reinstall. Also send the versions with the next repository check so we can try to figure out what's causing this. https://forums.zotero.org/discussion/134539/error-message-when-opening-zotero
137 lines
5.2 KiB
JavaScript
137 lines
5.2 KiB
JavaScript
"use strict";
|
|
|
|
describe("Zotero", function() {
|
|
describe("#getBuildMismatchStartupAction()", function () {
|
|
var matching = { js: '10.0.9', resources: '10.0.9', app: '10.0.9' };
|
|
var mismatched = { js: '10.0.8', resources: '10.0.9', app: '10.0.8' };
|
|
|
|
it("should restart on a new mismatch and record the versions", function () {
|
|
assert.deepEqual(
|
|
Zotero.getBuildMismatchStartupAction(mismatched, null),
|
|
['restart', { before: mismatched }]
|
|
);
|
|
});
|
|
|
|
it("should continue if a restart resolved the mismatch and record the versions", function () {
|
|
assert.deepEqual(
|
|
Zotero.getBuildMismatchStartupAction(matching, { before: mismatched }),
|
|
['continue', { before: mismatched, after: matching }]
|
|
);
|
|
});
|
|
|
|
it("should show an error if a restart didn't resolve the mismatch", function () {
|
|
var stillMismatched = { js: '10.0.9', resources: '10.0.9', app: '10.0.8' };
|
|
assert.deepEqual(
|
|
Zotero.getBuildMismatchStartupAction(stillMismatched, { before: mismatched }),
|
|
['error', { before: mismatched, after: stillMismatched }]
|
|
);
|
|
// Later startups show the error again without restarting
|
|
assert.deepEqual(
|
|
Zotero.getBuildMismatchStartupAction(
|
|
stillMismatched, { before: mismatched, after: stillMismatched }
|
|
),
|
|
['error', null]
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("#restoreZoteroPaneProgressMeter()", function () {
|
|
// A token captures the current display state, so taking one and immediately
|
|
// restoring it reads the state without changing it
|
|
function getProgressState() {
|
|
let token = Zotero.showZoteroPaneProgressMeter(undefined);
|
|
Zotero.restoreZoteroPaneProgressMeter(token);
|
|
return token;
|
|
}
|
|
|
|
afterEach(function () {
|
|
Zotero.hideZoteroPaneOverlays();
|
|
});
|
|
|
|
it("should restore nested progress displays to their previous owners", function () {
|
|
let token1 = Zotero.showZoteroPaneProgressMeter("One", true);
|
|
Zotero.updateZoteroPaneProgressMeter(30);
|
|
let token2 = Zotero.showZoteroPaneProgressMeter("Two");
|
|
|
|
// The new display should start with no percentage, so that a first update
|
|
// matching the previous meter's position isn't suppressed
|
|
assert.isNull(getProgressState().percentage);
|
|
|
|
// Restoring an outer token while an inner display is up should do nothing
|
|
Zotero.restoreZoteroPaneProgressMeter(token1);
|
|
assert.isTrue(Zotero.locked);
|
|
|
|
// Restoring the inner token should re-show the outer display, including its
|
|
// meter position, which is stored scaled by 10
|
|
Zotero.restoreZoteroPaneProgressMeter(token2);
|
|
let state = getProgressState();
|
|
assert.equal(state.message, "One");
|
|
assert.isTrue(state.determinate);
|
|
assert.equal(state.percentage, 300);
|
|
|
|
// Now the outer token can restore, unlocking the pane
|
|
Zotero.restoreZoteroPaneProgressMeter(token1);
|
|
assert.isFalse(Zotero.locked);
|
|
});
|
|
|
|
it("should capture a meter switched to indeterminate by updateZoteroPaneProgressMeter()", function () {
|
|
let token1 = Zotero.showZoteroPaneProgressMeter("One", true);
|
|
Zotero.updateZoteroPaneProgressMeter(null);
|
|
let token2 = Zotero.showZoteroPaneProgressMeter("Two");
|
|
assert.isFalse(token2.determinate);
|
|
assert.isNull(token2.percentage);
|
|
|
|
Zotero.restoreZoteroPaneProgressMeter(token2);
|
|
let state = getProgressState();
|
|
assert.isFalse(state.determinate);
|
|
assert.isNull(state.percentage);
|
|
|
|
Zotero.restoreZoteroPaneProgressMeter(token1);
|
|
assert.isFalse(Zotero.locked);
|
|
});
|
|
|
|
it("should capture a meter switched to determinate by updateZoteroPaneProgressMeter()", function () {
|
|
let token1 = Zotero.showZoteroPaneProgressMeter("One");
|
|
Zotero.updateZoteroPaneProgressMeter(40);
|
|
let token2 = Zotero.showZoteroPaneProgressMeter("Two");
|
|
assert.isTrue(token2.determinate);
|
|
assert.equal(token2.percentage, 400);
|
|
|
|
Zotero.restoreZoteroPaneProgressMeter(token2);
|
|
let state = getProgressState();
|
|
assert.isTrue(state.determinate);
|
|
assert.equal(state.percentage, 400);
|
|
|
|
Zotero.restoreZoteroPaneProgressMeter(token1);
|
|
assert.isFalse(Zotero.locked);
|
|
});
|
|
});
|
|
|
|
|
|
describe("VersionHeader", function () {
|
|
describe("#update()", function () {
|
|
var majorMinorVersion;
|
|
|
|
before(function () {
|
|
majorMinorVersion = Zotero.version.replace(/(\d+\.\d+).*/, '$1');
|
|
});
|
|
|
|
it("should replace app name with Firefox", function () {
|
|
var platformVersion = Services.appinfo.platformVersion.match(/^\d+/)[0] + '.0';
|
|
var ua1 = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 ${Zotero.clientName}/${Zotero.version}`;
|
|
var ua2 = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/${platformVersion} ${Zotero.clientName}/${Zotero.version}`;
|
|
assert.equal(Zotero.VersionHeader.update(ua1), ua2);
|
|
});
|
|
|
|
it("should show Chrome user agent unchanged", function () {
|
|
var ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36';
|
|
assert.equal(Zotero.VersionHeader.update(ua), ua);
|
|
});
|
|
|
|
it("should show Firefox user agent unchanged", function () {
|
|
var ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0';
|
|
assert.equal(Zotero.VersionHeader.update(ua), ua);
|
|
});
|
|
});
|
|
});
|
|
});
|