From 25816c1c5012eeabe682d211f1b70a354bd37206 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 5 Feb 2025 14:15:31 +0100 Subject: [PATCH] add tests --- .../browsercontext-storage-state.spec.ts | 30 ++++++++++++++++++- tests/library/global-fetch-cookie.spec.ts | 20 ++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/library/browsercontext-storage-state.spec.ts b/tests/library/browsercontext-storage-state.spec.ts index 27c446a2f4..04a1eee02c 100644 --- a/tests/library/browsercontext-storage-state.spec.ts +++ b/tests/library/browsercontext-storage-state.spec.ts @@ -83,9 +83,25 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) => route.fulfill({ body: '' }).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((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(); }); diff --git a/tests/library/global-fetch-cookie.spec.ts b/tests/library/global-fetch-cookie.spec.ts index e802c32334..f2f522a619 100644 --- a/tests/library/global-fetch-cookie.spec.ts +++ b/tests/library/global-fetch-cookie.spec.ts @@ -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' } + } + ], + } + ] + } + ], }, ] };