Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -186,6 +187,43 @@ await Page.SetCookieAsync(new CookieParam
Assert.That(cookie.Session, Is.True);
}

[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set a cookie with a partitionKey")]
public async Task ShouldSetACookieWithAPartitionKey()
{
var options = TestConstants.DefaultBrowserOptions();
options.AcceptInsecureCerts = true;

await using var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory);
await using var page = await browser.NewPageAsync();
await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
var url = new Uri(page.Url);
var key = url.GetLeftPart(UriPartial.Authority);
await page.SetCookieAsync(new CookieParam
{
Url = url.AbsoluteUri,
Name = "partitionCookie",
Value = "partition",
Secure = true,
PartitionKey = key,
});
var cookies = await page.GetCookiesAsync();
Assert.That(cookies, Has.Exactly(1).Items);
var cookie = cookies.First();
Assert.That(cookie.Name, Is.EqualTo("partitionCookie"));
Assert.That(cookie.Value, Is.EqualTo("partition"));
Assert.That(cookie.Domain, Is.EqualTo(url.Host));
Assert.That(cookie.Path, Is.EqualTo("/"));
Assert.That(cookie.Expires, Is.EqualTo(-1));
Assert.That(cookie.Size, Is.EqualTo(24));
Assert.That(cookie.HttpOnly, Is.False);
Assert.That(cookie.Secure, Is.True);
Assert.That(cookie.Session, Is.True);
Assert.That(cookie.SourceScheme, Is.EqualTo(CookieSourceScheme.Secure));
if (TestConstants.IsChrome)
key = url.GetComponents(UriComponents.Scheme | UriComponents.Host, UriFormat.UriEscaped);
Assert.That(cookie.PartitionKey, Is.EqualTo(key));
}

[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should not set a cookie on a blank page")]
public async Task ShouldNotSetACookieOnABlankPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void Write(
{
if (value != null && writer != null)
{
writer.WriteStartObject("partitionKey");
writer.WriteStartObject();
writer.WriteString("topLevelSite", value);
writer.WriteBoolean("hasCrossSiteAncestor", false);
writer.WriteEndObject();
Expand Down
Loading