Merge branch '4.0'
This commit is contained in:
commit
5bcce8ba82
|
@ -27,6 +27,9 @@
|
||||||
var TEST_RUN_TIMEOUT = 600000;
|
var TEST_RUN_TIMEOUT = 600000;
|
||||||
var EXPORTED_SYMBOLS = ["Zotero_TranslatorTesters"];
|
var EXPORTED_SYMBOLS = ["Zotero_TranslatorTesters"];
|
||||||
|
|
||||||
|
// For debugging specific translators by label
|
||||||
|
var includeTranslators = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Zotero;
|
Zotero;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -35,11 +38,16 @@ try {
|
||||||
|
|
||||||
Zotero_TranslatorTesters = new function() {
|
Zotero_TranslatorTesters = new function() {
|
||||||
const TEST_TYPES = ["web", "import", "export", "search"];
|
const TEST_TYPES = ["web", "import", "export", "search"];
|
||||||
|
var collectedResults = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs all tests
|
* Runs all tests
|
||||||
*/
|
*/
|
||||||
this.runAllTests = function(numConcurrentTests, skipTranslators, doneCallback) {
|
this.runAllTests = function (numConcurrentTests, skipTranslators, writeDataCallback) {
|
||||||
|
var id = Math.random() * (100000000 - 1) + 1;
|
||||||
|
|
||||||
|
waitForDialog();
|
||||||
|
|
||||||
if(!Zotero) {
|
if(!Zotero) {
|
||||||
Zotero = Components.classes["@zotero.org/Zotero;1"]
|
Zotero = Components.classes["@zotero.org/Zotero;1"]
|
||||||
.getService(Components.interfaces.nsISupports).wrappedJSObject;
|
.getService(Components.interfaces.nsISupports).wrappedJSObject;
|
||||||
|
@ -54,13 +62,14 @@ Zotero_TranslatorTesters = new function() {
|
||||||
return function(translators) {
|
return function(translators) {
|
||||||
try {
|
try {
|
||||||
for(var i=0; i<translators.length; i++) {
|
for(var i=0; i<translators.length; i++) {
|
||||||
if(skipTranslators && !skipTranslators[translators[i].translatorID]) {
|
if (includeTranslators.length
|
||||||
testers.push(new Zotero_TranslatorTester(translators[i], type));
|
&& !includeTranslators.includes(translators[i].label)) continue;
|
||||||
}
|
if (skipTranslators && skipTranslators[translators[i].translatorID]) continue;
|
||||||
|
testers.push(new Zotero_TranslatorTester(translators[i], type));
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!(--waitingForTranslators)) {
|
if(!(--waitingForTranslators)) {
|
||||||
runTesters(testers, numConcurrentTests, doneCallback);
|
runTesters(testers, numConcurrentTests, id, writeDataCallback);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
|
@ -74,21 +83,10 @@ Zotero_TranslatorTesters = new function() {
|
||||||
/**
|
/**
|
||||||
* Runs a specific set of tests
|
* Runs a specific set of tests
|
||||||
*/
|
*/
|
||||||
function runTesters(testers, numConcurrentTests, doneCallback) {
|
function runTesters(testers, numConcurrentTests, id, writeDataCallback) {
|
||||||
var testersRunning = 0;
|
var testersRunning = 0;
|
||||||
var results = []
|
var results = []
|
||||||
|
|
||||||
if("getLocaleCollation" in Zotero) {
|
|
||||||
var collation = Zotero.getLocaleCollation();
|
|
||||||
var strcmp = function(a, b) {
|
|
||||||
return collation.compareString(1, a, b);
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
var strcmp = function (a, b) {
|
|
||||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var testerDoneCallback = function(tester) {
|
var testerDoneCallback = function(tester) {
|
||||||
try {
|
try {
|
||||||
if(tester.pending.length) return;
|
if(tester.pending.length) return;
|
||||||
|
@ -97,26 +95,13 @@ Zotero_TranslatorTesters = new function() {
|
||||||
|
|
||||||
// Done translating, so serialize test results
|
// Done translating, so serialize test results
|
||||||
testersRunning--;
|
testersRunning--;
|
||||||
results.push(tester.serialize());
|
let results = tester.serialize();
|
||||||
|
let last = !testers.length && !testersRunning;
|
||||||
|
collectData(id, results, last, writeDataCallback);
|
||||||
|
|
||||||
if(testers.length) {
|
if(testers.length) {
|
||||||
// Run next tester if one is available
|
// Run next tester if one is available
|
||||||
runNextTester();
|
runNextTester();
|
||||||
} else if(testersRunning === 0) {
|
|
||||||
// Testing is done, so sort results
|
|
||||||
results = results.sort(function(a, b) {
|
|
||||||
if(a.type !== b.type) {
|
|
||||||
return TEST_TYPES.indexOf(a.type) - TEST_TYPES.indexOf(b.type);
|
|
||||||
}
|
|
||||||
return strcmp(a.label, b.label);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Call done callback
|
|
||||||
doneCallback({
|
|
||||||
"browser":Zotero.browser,
|
|
||||||
"version":Zotero.version,
|
|
||||||
"results":results
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
|
@ -125,6 +110,9 @@ Zotero_TranslatorTesters = new function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var runNextTester = function() {
|
var runNextTester = function() {
|
||||||
|
if (!testers.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
testersRunning++;
|
testersRunning++;
|
||||||
Zotero.debug("Testing "+testers[0].translator.label);
|
Zotero.debug("Testing "+testers[0].translator.label);
|
||||||
testers.shift().runTests(testerDoneCallback);
|
testers.shift().runTests(testerDoneCallback);
|
||||||
|
@ -134,6 +122,58 @@ Zotero_TranslatorTesters = new function() {
|
||||||
runNextTester();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectData(id, results, last, writeDataCallback) {
|
||||||
|
if (!collectedResults[id]) {
|
||||||
|
collectedResults[id] = [];
|
||||||
|
}
|
||||||
|
collectedResults[id].push(results);
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Only do the below every x collections, or if last == true
|
||||||
|
//
|
||||||
|
// Sort results
|
||||||
|
if ("getLocaleCollation" in Zotero) {
|
||||||
|
let collation = Zotero.getLocaleCollation();
|
||||||
|
var strcmp = function (a, b) {
|
||||||
|
return collation.compareString(1, a, b);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var strcmp = function (a, b) {
|
||||||
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
collectedResults[id].sort(function (a, b) {
|
||||||
|
if (a.type !== b.type) {
|
||||||
|
return TEST_TYPES.indexOf(a.type) - TEST_TYPES.indexOf(b.type);
|
||||||
|
}
|
||||||
|
return strcmp(a.label, b.label);
|
||||||
|
});
|
||||||
|
|
||||||
|
writeDataCallback(collectedResults[id], last);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +236,7 @@ Zotero_TranslatorTester = function(translator, type, debugCallback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Zotero_TranslatorTester.DEFER_DELAY = 30000; // Delay for deferred tests
|
Zotero_TranslatorTester.DEFER_DELAY = 20000; // Delay for deferred tests
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes document objects, which contain cyclic references, and other fields to be ignored from items
|
* Removes document objects, which contain cyclic references, and other fields to be ignored from items
|
||||||
|
@ -362,7 +402,7 @@ Zotero_TranslatorTester.prototype.fetchPageAndRunTest = function(test, testDoneC
|
||||||
createInstance(Components.interfaces.nsITimer);
|
createInstance(Components.interfaces.nsITimer);
|
||||||
timer.initWithCallback({"notify":function() {
|
timer.initWithCallback({"notify":function() {
|
||||||
try {
|
try {
|
||||||
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
if (hiddenBrowser) Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}}, TEST_RUN_TIMEOUT, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
}}, TEST_RUN_TIMEOUT, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||||
|
|
||||||
|
@ -383,10 +423,7 @@ Zotero_TranslatorTester.prototype.fetchPageAndRunTest = function(test, testDoneC
|
||||||
+ (Zotero_TranslatorTester.DEFER_DELAY/1000)
|
+ (Zotero_TranslatorTester.DEFER_DELAY/1000)
|
||||||
+ " second(s) for page content to settle"
|
+ " second(s) for page content to settle"
|
||||||
);
|
);
|
||||||
Zotero.setTimeout(
|
Zotero.setTimeout(() => runTest(doc), Zotero_TranslatorTester.DEFER_DELAY);
|
||||||
function() {runTest(hiddenBrowser.contentDocument) },
|
|
||||||
Zotero_TranslatorTester.DEFER_DELAY, true
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
runTest(doc);
|
runTest(doc);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -257,7 +257,22 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
|
||||||
&& this._translate.document.location.toString() === urls[i]) {
|
&& this._translate.document.location.toString() === urls[i]) {
|
||||||
// Document is attempting to reload itself
|
// Document is attempting to reload itself
|
||||||
Zotero.debug("Translate: Attempted to load the current document using processDocuments; using loaded document instead");
|
Zotero.debug("Translate: Attempted to load the current document using processDocuments; using loaded document instead");
|
||||||
processor(this._translate.document, urls[i]);
|
// This fixes document permissions issues in translation-server when translators call
|
||||||
|
// processDocuments() on the original URL (e.g., AOSIC)
|
||||||
|
// DEBUG: Why is this necessary? (see below also)
|
||||||
|
if (Zotero.isServer) {
|
||||||
|
processor(
|
||||||
|
translate._sandboxManager.wrap(
|
||||||
|
Zotero.Translate.DOMWrapper.unwrap(
|
||||||
|
this._translate.document
|
||||||
|
)
|
||||||
|
),
|
||||||
|
urls[i]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processor(this._translate.document, urls[i]);
|
||||||
|
}
|
||||||
urls.splice(i, 1);
|
urls.splice(i, 1);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +283,11 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
|
||||||
if(!processor) return;
|
if(!processor) return;
|
||||||
|
|
||||||
var newLoc = doc.location;
|
var newLoc = doc.location;
|
||||||
if(Zotero.isFx && !Zotero.isBookmarklet && (protocol != newLoc.protocol || host != newLoc.host)) {
|
if((Zotero.isFx && !Zotero.isBookmarklet && (protocol != newLoc.protocol || host != newLoc.host))
|
||||||
|
// This fixes document permissions issues in translation-server when translators call
|
||||||
|
// processDocuments() on same-domain URLs (e.g., some of the Code4Lib tests).
|
||||||
|
// DEBUG: Is there a better fix for this?
|
||||||
|
|| Zotero.isServer) {
|
||||||
// Cross-site; need to wrap
|
// Cross-site; need to wrap
|
||||||
processor(translate._sandboxManager.wrap(doc), newLoc.toString());
|
processor(translate._sandboxManager.wrap(doc), newLoc.toString());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
2016-08-14 00:15:00
|
2016-09-06 03:45:00
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8f534c9bf19920001ecc2d83eff0357ba6b86786
|
Subproject commit e102b02ae99d8111e44d981d19518ad1f4ded69b
|
Loading…
Reference in New Issue
Block a user