mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-21 19:12:10 +01:00
- fixed edge case in jsonP rewriting where no callback name is supplied only ? but body has normal jsonP callback (url = https://geolocation.onetrust.com/cookieconsentpub/v1/geo/countries/EU?callback=?) - made the `!self.__WB_pmw` server side inject match the client side one done via wombat - added regex's for eval override to JSWombatProxyRules wombat: - added eval override in order to ensure AD network JS does not lockup the browser (cnn.com) - added returning a proxied value for window.parent from the window proxy object in order to ensure AD network JS does not lock up browser (cnn.com, boston.com, et. al.) - ensured that the read only storageArea property of 'StorageEvents' fired by the custom storage class is present (spec) - ensured that userland cannot create new instances of Storage and that localStorage instanceof Storage works with our override (spec) - ensured that assignments to SomeElement.[innerHTML|outerHTML], iframe.srcdoc, or style.textContent are more correctly handled in particular doing script.[innerHTML|outerHTML] = <JS> - ensured that the test used in the isArgumentsObj function does not throw errors IFF the pages JS has made it so when toString is called (linkedin.com) - ensured that Web Worker construction when using the optional options object, the options get supplied to the create worker (spec) - ensured that the expected TypeError exception thrown from DomConstructors of overridden interfaces are thrown when their pre-conditions are not met (spec) - ensured that wombat worker rewriting skipes data urls which should not be rewritten - ensured the bound function returned by the window function is the same on subsequent retrievals fixes #474 tests: - added direct testing of wombat's parts
226 lines
6.4 KiB
JavaScript
226 lines
6.4 KiB
JavaScript
import test from 'ava';
|
|
import TestHelper from './helpers/testHelper';
|
|
|
|
/**
|
|
* @type {TestHelper}
|
|
*/
|
|
let helper = null;
|
|
|
|
test.before(async t => {
|
|
helper = await TestHelper.init(t, true);
|
|
});
|
|
|
|
test.beforeEach(async t => {
|
|
t.context.sandbox = helper.sandbox();
|
|
t.context.testPage = helper.testPage();
|
|
t.context.server = helper.server();
|
|
await t.context.sandbox.evaluate(() => {
|
|
window.fakeWombat = {
|
|
$wbwindow: {
|
|
WB_wombat_location: {
|
|
href: 'bogus url'
|
|
}
|
|
},
|
|
storage_listeners: {
|
|
sEvents: [],
|
|
map(sEvent) {
|
|
this.sEvents.push(sEvent);
|
|
}
|
|
}
|
|
};
|
|
});
|
|
});
|
|
|
|
test.after.always(async t => {
|
|
await helper.stop();
|
|
});
|
|
|
|
test('Storage - creation: should not throw errors', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const creationPromise = sandbox.evaluate(() => {
|
|
new Storage();
|
|
});
|
|
await t.notThrowsAsync(creationPromise);
|
|
});
|
|
|
|
test('Storage - post creation: internal values should not be exposed', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
return { ...storage };
|
|
});
|
|
t.deepEqual(testResult, {});
|
|
});
|
|
|
|
test('Storage - getItem: the item set should be retrievable', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key = 'a';
|
|
const value = 'b';
|
|
storage.setItem(key, value);
|
|
return storage.getItem(key) === value;
|
|
});
|
|
t.true(testResult);
|
|
});
|
|
|
|
test('Storage - setItem: the item set should be mapped and an storage event fired', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key = 'a';
|
|
const value = 'b';
|
|
storage.setItem(key, value);
|
|
const events = window.fakeWombat.storage_listeners.sEvents;
|
|
const event = events[0];
|
|
return {
|
|
stored: storage.data[key] === value,
|
|
numEvents: events.length,
|
|
key: event.key === key,
|
|
newValue: event.newValue === value,
|
|
oldValue: event.oldValue === null,
|
|
storageArea: event.storageArea === storage,
|
|
url: event.url === 'bogus url'
|
|
};
|
|
});
|
|
t.deepEqual(testResult, {
|
|
stored: true,
|
|
numEvents: 1,
|
|
key: true,
|
|
newValue: true,
|
|
oldValue: true,
|
|
storageArea: true,
|
|
url: true
|
|
});
|
|
});
|
|
|
|
test('Storage - removeItem: the item set should be removable and an event should be fired indicating removal', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key = 'a';
|
|
const value = 'b';
|
|
storage.setItem(key, value);
|
|
storage.removeItem(key);
|
|
const events = window.fakeWombat.storage_listeners.sEvents;
|
|
const event = events[1];
|
|
return {
|
|
stored: storage.data[key] === undefined,
|
|
numEvents: events.length,
|
|
key: event.key === key,
|
|
newValue: event.newValue === null,
|
|
oldValue: event.oldValue === value,
|
|
storageArea: event.storageArea === storage,
|
|
url: event.url === 'bogus url'
|
|
};
|
|
});
|
|
t.deepEqual(testResult, {
|
|
stored: true,
|
|
numEvents: 2,
|
|
key: true,
|
|
newValue: true,
|
|
oldValue: true,
|
|
storageArea: true,
|
|
url: true
|
|
});
|
|
});
|
|
|
|
test('Storage - clear: should clear all stored items and an event should be fired indicating clearing', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key = 'a';
|
|
const value = 'b';
|
|
storage.setItem(key, value);
|
|
storage.clear();
|
|
const events = window.fakeWombat.storage_listeners.sEvents;
|
|
const event = events[1];
|
|
return {
|
|
numEvents: events.length,
|
|
key: event.key === null,
|
|
newValue: event.newValue === null,
|
|
oldValue: event.oldValue === null,
|
|
storageArea: event.storageArea === storage,
|
|
url: event.url === 'bogus url'
|
|
};
|
|
});
|
|
t.deepEqual(testResult, {
|
|
numEvents: 2,
|
|
key: true,
|
|
newValue: true,
|
|
oldValue: true,
|
|
storageArea: true,
|
|
url: true
|
|
});
|
|
});
|
|
|
|
test('Storage - key: should return the correct key given the keys index', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key1 = 'a1';
|
|
const key2 = 'a2';
|
|
const value1 = 'b1';
|
|
const value2 = 'b2';
|
|
storage.setItem(key1, value1);
|
|
storage.setItem(key2, value2);
|
|
return (
|
|
storage.key(0) === key1 &&
|
|
storage.key(1) === key2 &&
|
|
storage.key(2) === null
|
|
);
|
|
});
|
|
t.true(testResult);
|
|
});
|
|
|
|
test('Storage - fireEvent: should fire a StorageEvent with the supplied arguments', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
storage.fireEvent('a', 'b', 'c');
|
|
const events = window.fakeWombat.storage_listeners.sEvents;
|
|
const event = events[0];
|
|
return {
|
|
numEvents: events.length,
|
|
key: event.key === 'a',
|
|
newValue: event.newValue === 'c',
|
|
oldValue: event.oldValue === 'b',
|
|
storageArea: event.storageArea === storage,
|
|
url: event.url === 'bogus url'
|
|
};
|
|
});
|
|
t.deepEqual(testResult, {
|
|
numEvents: 1,
|
|
key: true,
|
|
newValue: true,
|
|
oldValue: true,
|
|
storageArea: true,
|
|
url: true
|
|
});
|
|
});
|
|
|
|
test('Storage - valueOf: should return the correct value', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
fakeWombat.$wbwindow['bogus value'] = storage;
|
|
return storage.valueOf() === storage;
|
|
});
|
|
t.true(testResult);
|
|
});
|
|
|
|
test('Storage - length: should return the correct value', async t => {
|
|
const { sandbox, server } = t.context;
|
|
const testResult = await sandbox.evaluate(() => {
|
|
const storage = new Storage(window.fakeWombat, 'bogus value');
|
|
const key1 = 'a1';
|
|
const key2 = 'a2';
|
|
const value1 = 'b1';
|
|
const value2 = 'b2';
|
|
storage.setItem(key1, value1);
|
|
storage.setItem(key2, value2);
|
|
return storage.length;
|
|
});
|
|
t.is(testResult, 2);
|
|
});
|