add tests

This commit is contained in:
Simon Knott 2025-02-05 14:15:31 +01:00
parent 92dc2bba2f
commit 25816c1c50
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 48 additions and 2 deletions

View file

@ -83,9 +83,25 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) =>
route.fulfill({ body: '<html></html>' }).catch(() => {});
});
await page1.goto('https://www.example.com');
await page1.evaluate(() => {
await page1.evaluate(async () => {
localStorage['name1'] = 'value1';
document.cookie = 'username=John Doe';
await new Promise((resolve, reject) => {
const openRequest = indexedDB.open('db', 42);
openRequest.onupgradeneeded = () => {
openRequest.result.createObjectStore('store');
};
openRequest.onsuccess = () => {
const request = openRequest.result.transaction('store', 'readwrite')
.objectStore('store')
.put('foo', 'bar');
request.addEventListener('success', resolve);
request.addEventListener('error', reject);
};
});
return document.cookie;
});
@ -104,6 +120,18 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) =>
expect(localStorage).toEqual({ name1: 'value1' });
const cookie = await page2.evaluate('document.cookie');
expect(cookie).toEqual('username=John Doe');
const idbValue = await page2.evaluate(() => new Promise<string>((resolve, reject) => {
const openRequest = indexedDB.open('db', 42);
openRequest.addEventListener('success', () => {
const db = openRequest.result;
const transaction = db.transaction('store', 'readonly');
const getRequest = transaction.objectStore('store').get('bar');
getRequest.addEventListener('success', () => resolve(getRequest.result));
getRequest.addEventListener('error', () => reject(getRequest.error));
});
openRequest.addEventListener('error', () => reject(openRequest.error));
}));
expect(idbValue).toEqual('foo');
await context2.close();
});

View file

@ -352,7 +352,25 @@ it('should preserve local storage on import/export of storage state', async ({ p
name: 'name1',
value: 'value1'
}],
indexedDB: [],
indexedDB: [
{
name: 'db',
version: 5,
stores: [
{
name: 'store',
keyPath: 'id',
autoIncrement: false,
indexes: [],
records: [
{
value: { id: 'foo', name: 'John Doe' }
}
],
}
]
}
],
},
]
};