Skip to content

Commit

Permalink
Partition cookie test
Browse files Browse the repository at this point in the history
  • Loading branch information
igvk committed Nov 17, 2024
1 parent 4d43dbc commit 01efcf8
Showing 1 changed file with 38 additions and 0 deletions.
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

0 comments on commit 01efcf8

Please sign in to comment.