fix(reuse): reset Origin Private File System API
This commit is contained in:
parent
94348bb3c5
commit
88e6d380bd
|
|
@ -1662,7 +1662,7 @@ export class Frame extends SdkObject {
|
|||
}
|
||||
|
||||
async resetStorageForCurrentOriginBestEffort(newStorage: channels.OriginStorage | undefined) {
|
||||
const context = await this._utilityContext();
|
||||
const context = await this._mainContext();
|
||||
await context.evaluate(async ({ ls }) => {
|
||||
// Clean DOMStorage.
|
||||
sessionStorage.clear();
|
||||
|
|
@ -1692,6 +1692,14 @@ export class Frame extends SdkObject {
|
|||
if (db.name)
|
||||
indexedDB.deleteDatabase(db.name!);
|
||||
}
|
||||
|
||||
try {
|
||||
// Clean StorageManager
|
||||
const root = await navigator.storage.getDirectory();
|
||||
// @ts-expect-error
|
||||
for await (const [name] of await root.entries())
|
||||
await root.removeEntry(name, { recursive: true });
|
||||
} catch (e) {}
|
||||
}, { ls: newStorage?.localStorage }).catch(() => {});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,16 @@
|
|||
*/
|
||||
|
||||
import { browserTest, expect } from '../config/browserTest';
|
||||
import type { BrowserContext } from '@playwright/test';
|
||||
import type { BrowserContext, BrowserContextOptions } from '@playwright/test';
|
||||
|
||||
const test = browserTest.extend<{ reusedContext: () => Promise<BrowserContext> }>({
|
||||
const test = browserTest.extend<{ reusedContext: (options?: BrowserContextOptions) => Promise<BrowserContext> }>({
|
||||
reusedContext: async ({ browserType, browser }, use) => {
|
||||
await use(async () => {
|
||||
await use(async (options: BrowserContextOptions = {}) => {
|
||||
const defaultContextOptions = (browserType as any)._defaultContextOptions;
|
||||
const context = await (browser as any)._newContextForReuse(defaultContextOptions);
|
||||
const context = await (browser as any)._newContextForReuse({
|
||||
...defaultContextOptions,
|
||||
...options,
|
||||
});
|
||||
return context;
|
||||
});
|
||||
},
|
||||
|
|
@ -235,6 +238,34 @@ test('should reset mouse position', async ({ reusedContext, browserName, platfor
|
|||
await expect(page.locator('#two')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
|
||||
});
|
||||
|
||||
test('should reset Origin Private File System', async ({ reusedContext, httpsServer, browserName }) => {
|
||||
test.skip(browserName === 'webkit', 'getDirectory is not supported in ephemeral context in WebKit https://github.com/microsoft/playwright/issues/18235#issuecomment-1289792576');
|
||||
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29901' });
|
||||
|
||||
let context = await reusedContext({ ignoreHTTPSErrors: true });
|
||||
let page = await context.newPage();
|
||||
await page.goto(httpsServer.EMPTY_PAGE);
|
||||
await page.evaluate(async () => {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
await root.getDirectoryHandle('someDirectoryName', { create: true });
|
||||
await root.getFileHandle('foo.txt', { create: true });
|
||||
});
|
||||
|
||||
context = await reusedContext({ ignoreHTTPSErrors: true });
|
||||
page = await context.newPage();
|
||||
await page.goto(httpsServer.EMPTY_PAGE);
|
||||
|
||||
const { directoryExits, fileExits } = await page.evaluate(async () => {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
let directoryExits = true, fileExits = true;
|
||||
await root.getDirectoryHandle('someDirectoryName').catch(() => { directoryExits = false; });
|
||||
await root.getFileHandle('foo.txt').catch(() => { fileExits = false; });
|
||||
return { directoryExits, fileExits };
|
||||
});
|
||||
expect(directoryExits).toBe(false);
|
||||
expect(fileExits).toBe(false);
|
||||
});
|
||||
|
||||
test('should reset tracing', async ({ reusedContext, trace }, testInfo) => {
|
||||
test.skip(trace === 'on');
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ test('should clean storage', async ({ runInlineTest }) => {
|
|||
let lastContextGuid;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('**/*', route => route.fulfill('<html></html>'));
|
||||
await page.route('**/*', route => route.fulfill({ body: '<html></html>', contentType: 'text/html' }));
|
||||
await page.goto('http://example.com');
|
||||
});
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ test('should restore localStorage', async ({ runInlineTest }) => {
|
|||
});
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('**/*', route => route.fulfill('<html></html>'));
|
||||
await page.route('**/*', route => route.fulfill({ body: '<html></html>', contentType: 'text/html' }));
|
||||
await page.goto('http://example.com');
|
||||
});
|
||||
|
||||
|
|
@ -330,7 +330,7 @@ test('should clean db', async ({ runInlineTest }) => {
|
|||
let lastContextGuid;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('**/*', route => route.fulfill('<html></html>'));
|
||||
await page.route('**/*', route => route.fulfill({ body: '<html></html>', contentType: 'text/html' }));
|
||||
await page.goto('http://example.com');
|
||||
});
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ test('should restore cookies', async ({ runInlineTest }) => {
|
|||
});
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('**/*', route => route.fulfill('<html></html>'));
|
||||
await page.route('**/*', route => route.fulfill({ body: '<html></html>', contentType: 'text/html' }));
|
||||
await page.goto('http://example.com');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue