Merge pull request #14634 from Snuffleupagus/Driver-run-fetch

Replace XMLHttpRequest usage with the Fetch API in `Driver.run`
This commit is contained in:
Tim van der Meij 2022-03-06 13:32:17 +01:00 committed by GitHub
commit 7d53a40c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -368,12 +368,19 @@ class Driver {
this._log(`Harness thinks this browser is ${this.browser}\n`); this._log(`Harness thinks this browser is ${this.browser}\n`);
this._log('Fetching manifest "' + this.manifestFile + '"... '); this._log('Fetching manifest "' + this.manifestFile + '"... ');
const r = new XMLHttpRequest(); if (this.delay > 0) {
r.open("GET", this.manifestFile, false); this._log("\nDelaying for " + this.delay + " ms...\n");
r.onreadystatechange = () => { }
if (r.readyState === 4) { // When gathering the stats the numbers seem to be more reliable
// if the browser is given more time to start.
setTimeout(async () => {
const response = await fetch(this.manifestFile);
if (!response.ok) {
throw new Error(response.statusText);
}
this._log("done\n"); this._log("done\n");
this.manifest = JSON.parse(r.responseText); this.manifest = await response.json();
if (this.testFilter?.length || this.xfaOnly) { if (this.testFilter?.length || this.xfaOnly) {
this.manifest = this.manifest.filter(item => { this.manifest = this.manifest.filter(item => {
if (this.testFilter.includes(item.id)) { if (this.testFilter.includes(item.id)) {
@ -387,15 +394,6 @@ class Driver {
} }
this.currentTask = 0; this.currentTask = 0;
this._nextTask(); this._nextTask();
}
};
if (this.delay > 0) {
this._log("\nDelaying for " + this.delay + " ms...\n");
}
// When gathering the stats the numbers seem to be more reliable
// if the browser is given more time to start.
setTimeout(function () {
r.send(null);
}, this.delay); }, this.delay);
} }