Skip to content

Commit

Permalink
feat(webdriver): implement page.setCacheEnabled (#12691)
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
  • Loading branch information
OrKoN and juliandescottes authored Jul 5, 2024
1 parent 820512e commit e44d900
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 6 additions & 0 deletions packages/puppeteer-core/src/bidi/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ export class BidiPage extends Page {
}

override async setCacheEnabled(enabled?: boolean): Promise<void> {
if (!this.#browserContext.browser().cdpSupported) {
await this.#frame.browsingContext.setCacheBehavior(
enabled ? 'default' : 'bypass'
);
return;
}
// TODO: handle CDP-specific cases such as mprach.
await this._client().send('Network.setCacheDisabled', {
cacheDisabled: !enabled,
Expand Down
12 changes: 12 additions & 0 deletions packages/puppeteer-core/src/bidi/core/BrowsingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ export class BrowsingContext extends EventEmitter<{
});
}

@throwIfDisposed<BrowsingContext>(context => {
// SAFETY: Disposal implies this exists.
return context.#reason!;
})
async setCacheBehavior(cacheBehavior: 'default' | 'bypass'): Promise<void> {
// @ts-expect-error not in BiDi types yet.
await this.#session.send('network.setCacheBehavior', {
contexts: [this.id],
cacheBehavior,
});
}

@throwIfDisposed<BrowsingContext>(context => {
// SAFETY: Disposal implies this exists.
return context.#reason!;
Expand Down
14 changes: 0 additions & 14 deletions test/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2911,20 +2911,6 @@
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.setCacheEnabled should enable or disable the cache based on the state passed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.setCacheEnabled should stay disabled when toggling request interception on/off",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.setCacheEnabled should stay disabled when toggling request interception on/off",
"platforms": ["darwin", "linux", "win32"],
Expand Down

0 comments on commit e44d900

Please sign in to comment.