mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 08:04:49 +01:00
wombat: - I: function overrides applied by wombat now better appear to be the original new function name same as originals when possible - I: WombatLocation now looks and behaves more like the original Location interface - I: The custom storage class now looks and behaves more like the original Storage - I: SVG image rewriting has been improved: both the href and xlink:href deprecated since SVG2 now rewritten always - I: document.open now handles the case of creation of a new window - I: Request object rewriting of the readonly href property is now correctly handled - I: EventTarget.addEventListener, removeEventListener overrides now preserve the original this argument of the wrapped listener - A: document.close override to ensure wombat is initialized after write or writeln usage - A: reconstruction of <doctype...> in rewriteHTMLComplete IFF it was included in the original string of HTML - A: document.body setter override to ensure rewriting of the new body or frameset - A: Attr.[value, nodeValue, textContent] added setter override to perform URL rewrites - A: SVGElements rewriting of the filter, style, xlink:href, href, and src attributes - A: HTMLTrackElement rewriting of the src attribute of the - A: HTMLQuoteElement and HTMLModElement rewriting of the cite attribute - A: Worklet.addModule: Loads JS module specified by a URL. - A: HTMLHyperlinkElementUtils overrides to the areaelement - A: ShadowRootoverrides to: innerHTML even though inherites from DocumentFragement and Node it still has innerHTML getter setter. - A: ShadowRoot, Element, DocumentFragment append, prepend: adds strings of HTML or a new Node inherited from ParentNode - A: StylePropertyMap override: New way to access and set CSS properties. - A: Response.redirecthttps rewriting of the URL argument. - A: UIEvent, MouseEvent, TouchEvent, KeyboardEvent, WheelEvent, InputEvent, and CompositionEven constructor and init{even-name} overrides in order to ensure that wombats JS Proxy usage does not affect their defined behaviors - A: XSLTProcessor override to ensure its usage is not affected by wombats JS Proxy usage. - A: navigator.unregisterProtocolHandler: Same override as existing navigator.registerProtocolHandler but from the inverse operation - A: PresentationRequest: Constructor takes a URL or an array of URLs. - A: EventSource and WebSocket override in order to ensure that they do not cause live leaks - A: overrides for the child node interface - Fix: autofetch worker creatation of the backing worker when it is operating within an execution context with a null origin tests: - A: 559 tests specific to wombat and client side rewritting pywb: - Fix: a few broken tests due to iana.org requiring a user agent in its requests rewrite: - introduced a new JSWorkerRewriter class in order to support rewriting via wombat workers in the context of all supported worker variants via - ensured rewriter app correctly sets the static prefix ci: - Modified travis.yml to specifically enumerate jobs documentation: - Documented new wombat, wombat proxy moded, wombat workers auto-fetch: - switched to mutation observer when in proxy mode so that the behaviors can operate in tandem with the autofetcher
160 lines
4.8 KiB
JavaScript
160 lines
4.8 KiB
JavaScript
import test from 'ava';
|
|
import { mpURL } from './helpers/testedValues';
|
|
import TestHelper from './helpers/testHelper';
|
|
|
|
/**
|
|
* @type {TestHelper}
|
|
*/
|
|
let helper = null;
|
|
|
|
test.before(async t => {
|
|
helper = await TestHelper.init(t);
|
|
await helper.initWombat();
|
|
});
|
|
|
|
test.beforeEach(async t => {
|
|
t.context.sandbox = helper.sandbox();
|
|
t.context.server = helper.server();
|
|
t.context.testPage = helper.testPage();
|
|
});
|
|
|
|
test.afterEach.always(async t => {
|
|
if (t.title.includes('SharedWorker')) {
|
|
await helper.fullRefresh();
|
|
} else {
|
|
await helper.ensureSandbox();
|
|
}
|
|
});
|
|
|
|
test.after.always(async t => {
|
|
await helper.stop();
|
|
});
|
|
|
|
test('XMLHttpRequest: should rewrite the URL argument of "open"', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const response = await sandbox.evaluate(async () => {
|
|
let reqDone;
|
|
let to;
|
|
const prom = new Promise(resolve => {
|
|
reqDone = resolve;
|
|
to = setTimeout(() => resolve(false), 5000);
|
|
});
|
|
const onLoad = () => {
|
|
clearTimeout(to);
|
|
reqDone(true);
|
|
};
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.addEventListener('load', onLoad);
|
|
xhr.open('GET', '/test');
|
|
xhr.send();
|
|
const loaded = await prom;
|
|
if (!loaded) throw new Error('no reply from server in 5 seconds');
|
|
return JSON.parse(xhr.responseText);
|
|
});
|
|
t.is(response.headers['x-pywb-requested-with'], 'XMLHttpRequest');
|
|
t.is(response.url, '/live/20180803160549mp_/https://tests.wombat.io/test');
|
|
});
|
|
|
|
test('XMLHttpRequest: should rewrite the "responseURL" property', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(async () => {
|
|
let reqDone;
|
|
let to;
|
|
const prom = new Promise(resolve => {
|
|
reqDone = resolve;
|
|
to = setTimeout(() => resolve(false), 5000);
|
|
});
|
|
const onLoad = () => {
|
|
clearTimeout(to);
|
|
reqDone(true);
|
|
};
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.addEventListener('load', onLoad);
|
|
xhr.open('GET', '/test');
|
|
xhr.send();
|
|
const loaded = await prom;
|
|
if (!loaded) throw new Error('no reply from server in 5 seconds');
|
|
return xhr.responseURL === 'https://tests.wombat.io/test';
|
|
});
|
|
t.true(result);
|
|
});
|
|
|
|
test('fetch: should rewrite the input argument when it is a string (URL)', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(async () => {
|
|
let to;
|
|
let response = await Promise.race([
|
|
fetch('/test'),
|
|
new Promise(resolve => {
|
|
to = setTimeout(() => resolve('timed out'), 5000);
|
|
})
|
|
]);
|
|
if (response === 'timed out')
|
|
throw new Error('no reply from server in 5 seconds');
|
|
clearTimeout(to);
|
|
const data = await response.json();
|
|
return data.url === '/live/20180803160549mp_/https://tests.wombat.io/test';
|
|
});
|
|
t.true(result);
|
|
});
|
|
|
|
test('fetch: should rewrite the input argument when it is an Request object', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(async () => {
|
|
let to;
|
|
let response = await Promise.race([
|
|
fetch(
|
|
new Request('/test', {
|
|
method: 'GET'
|
|
})
|
|
),
|
|
new Promise(resolve => {
|
|
to = setTimeout(() => resolve('timed out'), 5000);
|
|
})
|
|
]);
|
|
if (response === 'timed out')
|
|
throw new Error('no reply from server in 5 seconds');
|
|
clearTimeout(to);
|
|
const data = await response.json();
|
|
return data.url === '/live/20180803160549mp_/https://tests.wombat.io/test';
|
|
});
|
|
t.true(result);
|
|
});
|
|
|
|
test('fetch: should rewrite the input argument when it is a object with an href property', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(async () => {
|
|
let to;
|
|
let response = await Promise.race([
|
|
fetch({ href: '/test' }),
|
|
new Promise(resolve => {
|
|
to = setTimeout(() => resolve('timed out'), 10000);
|
|
})
|
|
]);
|
|
if (response === 'timed out')
|
|
throw new Error('no reply from server in 10 seconds');
|
|
clearTimeout(to);
|
|
const data = await response.json();
|
|
return data.url === '/live/20180803160549mp_/https://tests.wombat.io/test';
|
|
});
|
|
t.true(result);
|
|
});
|
|
|
|
test('Request: should rewrite the input argument to the constructor when it is a string (URL)', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(() => {
|
|
const req = new Request('/test', { method: 'GET' });
|
|
return req.url;
|
|
});
|
|
t.true(result === mpURL('https://tests.wombat.io/test'));
|
|
});
|
|
|
|
test('Request: should rewrite the input argument to the constructor when it is an object with a url property', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const result = await sandbox.evaluate(() => {
|
|
const req = new Request({ url: '/test' }, { method: 'GET' });
|
|
return req.url;
|
|
});
|
|
t.true(result === mpURL('https://tests.wombat.io/test'));
|
|
});
|