/**
* Base path for resources. The default value is correct for non-worker WPT, but standalone and
* workers must access resources using a different base path, so this is overridden in
* `test_worker-worker.ts` and `standalone.ts`.
*/
let baseResourcePath = './resources';
let crossOriginHost = '';
function getAbsoluteBaseResourcePath(path: string) {
// Path is already an absolute one.
if (path[0] === '/') {
return path;
}
// Path is relative
const relparts = window.location.pathname.split('/');
relparts.pop();
const pathparts = path.split('/');
let i;
for (i = 0; i < pathparts.length; ++i) {
switch (pathparts[i]) {
case '':
break;
case '.':
break;
case '..':
relparts.pop();
break;
default:
relparts.push(pathparts[i]);
break;
}
}
return relparts.join('/');
}
function runningOnLocalHost(): boolean {
const hostname = window.location.hostname;
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1';
}
/**
* Get a path to a resource in the `resources` directory relative to the current execution context
* (html file or worker .js file), for `fetch()`, ``, `