Use new HTTP.processDocuments() in translatorTester
This commit is contained in:
parent
d5261841be
commit
23cf6bd007
1 changed files with 17 additions and 46 deletions
|
@ -391,54 +391,25 @@ Zotero_TranslatorTester.prototype._runTestsRecursively = function(testDoneCallba
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the page for a given test and runs it
|
* Fetches the page for a given test and runs it
|
||||||
|
*
|
||||||
* This function is only applicable in Firefox; it is overridden in translator_global.js in Chrome
|
* This function is only applicable in Firefox; it is overridden in translator_global.js in Chrome
|
||||||
* and Safari
|
* and Safari.
|
||||||
* @param {Object} test Test to execute
|
*
|
||||||
* @param {Document} doc DOM document to test against
|
* @param {Object} test - Test to execute
|
||||||
* @param {Function} testDoneCallback A callback to be executed when test is complete
|
* @param {Function} testDoneCallback - A callback to be executed when test is complete
|
||||||
*/
|
*/
|
||||||
Zotero_TranslatorTester.prototype.fetchPageAndRunTest = function(test, testDoneCallback) {
|
Zotero_TranslatorTester.prototype.fetchPageAndRunTest = function (test, testDoneCallback) {
|
||||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
Zotero.HTTP.processDocuments(
|
||||||
createInstance(Components.interfaces.nsITimer);
|
test.url,
|
||||||
timer.initWithCallback({"notify":function() {
|
(doc) => {
|
||||||
try {
|
this.runTest(test, doc, function (obj, test, status, message) {
|
||||||
if (hiddenBrowser) Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
testDoneCallback(obj, test, status, message);
|
||||||
} catch(e) {}
|
});
|
||||||
}}, TEST_RUN_TIMEOUT, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
}
|
||||||
|
)
|
||||||
var me = this;
|
.catch(function (e) {
|
||||||
var runTest = function(doc) {
|
testDoneCallback(this, test, "failed", "Translation failed to initialize: " + e);
|
||||||
me.runTest(test, doc, function(obj, test, status, message) {
|
}.bind(this))
|
||||||
try {
|
|
||||||
timer.cancel();
|
|
||||||
} catch(e) {};
|
|
||||||
if(hiddenBrowser) Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
|
||||||
testDoneCallback(obj, test, status, message);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var hiddenBrowser = Zotero.HTTP.loadDocuments(test.url,
|
|
||||||
function(doc) {
|
|
||||||
if(test.defer) {
|
|
||||||
me._debug(this, "TranslatorTesting: Waiting "
|
|
||||||
+ (Zotero_TranslatorTester.DEFER_DELAY/1000)
|
|
||||||
+ " second(s) for page content to settle"
|
|
||||||
);
|
|
||||||
Zotero.setTimeout(() => runTest(doc), Zotero_TranslatorTester.DEFER_DELAY);
|
|
||||||
} else {
|
|
||||||
runTest(doc);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
function(e) {
|
|
||||||
testDoneCallback(this, test, "failed", "Translation failed to initialize: "+e);
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
// No hidden browser returned from translation-server processDocuments()
|
|
||||||
if (hiddenBrowser) {
|
|
||||||
hiddenBrowser.docShell.allowMetaRedirects = true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue