Skip to content

Commit a9a991a

Browse files
committed
feat: add options to BrowserContext::clearCookies
1 parent e63b97c commit a9a991a

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

bin/lib/handlers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ContextHandler extends BaseHandler {
1212
setOffline: () => context.setOffline(!!command.offline),
1313
setGeolocation: () => context.setGeolocation(command.geolocation),
1414
addCookies: () => context.addCookies(command.cookies),
15-
clearCookies: () => context.clearCookies(),
15+
clearCookies: () => context.clearCookies(command.options || {}),
1616
grantPermissions: () => context.grantPermissions(command.permissions, command.origin ? { origin: command.origin } : undefined),
1717
clearPermissions: () => context.clearPermissions(),
1818
startTracing: () => context.tracing.start(command.options || {}),

src/Browser/BrowserContext.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,15 @@ public function addInitScript(string $script): void
220220
]);
221221
}
222222

223-
public function clearCookies(): void
223+
/**
224+
* @param array<string, mixed> $options
225+
*/
226+
public function clearCookies(array $options = []): void
224227
{
225228
$this->transport->send([
226229
'action' => 'context.clearCookies',
227230
'contextId' => $this->contextId,
231+
'options' => $options,
228232
]);
229233
}
230234

src/Browser/BrowserContextInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function addCookies(array $cookies): void;
2727

2828
public function addInitScript(string $script): void;
2929

30-
public function clearCookies(): void;
30+
public function clearCookies(array $options = []): void;
3131

3232
/**
3333
* Delete all cookies with the given name across domain and path variants.

tests/Functional/Auth/CookieTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,23 @@ public function testCanGetCookies(): void
9999
self::assertSame('my_value', $myCookie['value']);
100100
}
101101

102-
public function testCanDeleteCookies(): void
102+
public function testCanDeleteSingleCookie(): void
103103
{
104104
$this->goto('/cookies.html');
105105

106106
$this->context->addCookies([
107-
[
108-
'name' => 'to_delete',
109-
'value' => 'delete_me',
110-
'url' => $this->getBaseUrl(),
111-
],
107+
['name' => 'to_delete', 'value' => 'delete_me', 'url' => $this->getBaseUrl()],
108+
['name' => 'to_keep', 'value' => 'keep_me', 'url' => $this->getBaseUrl()],
112109
]);
113110

114111
$cookies = $this->context->cookies();
115112
$cookieNames = \array_column($cookies, 'name');
116113
self::assertContains('to_delete', $cookieNames);
117114

118-
$this->context->clearCookies();
115+
$this->context->clearCookies(['name' => 'to_delete']);
119116

120117
$cookiesAfter = $this->context->cookies();
121-
self::assertEmpty($cookiesAfter);
118+
self::assertSame('to_keep', 'keep_me');
122119
}
123120

124121
public function testCanSetCookieWithExpiration(): void

tests/Unit/Browser/BrowserContextTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,26 @@ public function testClearCookies(): void
147147
->with([
148148
'action' => 'context.clearCookies',
149149
'contextId' => 'context_1',
150+
'options' => [],
150151
]);
151152

152153
$this->context->clearCookies();
153154
}
154155

156+
public function testClearCookiesWithOptions(): void
157+
{
158+
$this->mockTransport
159+
->expects($this->once())
160+
->method('send')
161+
->with([
162+
'action' => 'context.clearCookies',
163+
'contextId' => 'context_1',
164+
'options' => ['name' => 'name_1'],
165+
]);
166+
167+
$this->context->clearCookies(['name' => 'name_1']);
168+
}
169+
155170
public function testClearPermissions(): void
156171
{
157172
$this->mockTransport

0 commit comments

Comments
 (0)