Skip to content

Commit

Permalink
Add cookie tests (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored May 19, 2019
1 parent de7e0dd commit e215805
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task ShouldWork()
Assert.Equal(new[] { "hello", "world" }, values);
}

[Fact]
public async Task ShouldWorkForNonBlankPage()
{
// Instantiate an object
Expand Down
42 changes: 42 additions & 0 deletions lib/PuppeteerSharp.Tests/PageTests/Cookies/CookiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,48 @@ public async Task ShouldGetACookie()
Assert.True(cookie.Session);
}

[Fact]
public async Task ShouldProperlyReportHttpOnlyCookie()
{
Server.SetRoute("/empty.html", context =>
{
context.Response.Headers["Set-Cookie"] = ";HttpOnly; Path=/";
return Task.CompletedTask;
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Page.GetCookiesAsync();
Assert.Single(cookies);
Assert.True(cookies[0].HttpOnly);
}

[Fact]
public async Task ShouldProperlyReportSStrictSameSiteCookie()
{
Server.SetRoute("/empty.html", context =>
{
context.Response.Headers["Set-Cookie"] = ";SameSite=Strict";
return Task.CompletedTask;
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Page.GetCookiesAsync();
Assert.Single(cookies);
Assert.Equal(SameSite.Strict, cookies[0].SameSite);
}

[Fact]
public async Task ShouldProperlyReportLaxSameSiteCookie()
{
Server.SetRoute("/empty.html", context =>
{
context.Response.Headers["Set-Cookie"] = ";SameSite=Lax";
return Task.CompletedTask;
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Page.GetCookiesAsync();
Assert.Single(cookies);
Assert.Equal(SameSite.Lax, cookies[0].SameSite);
}

[Fact]
public async Task ShouldGetMultipleCookies()
{
Expand Down

0 comments on commit e215805

Please sign in to comment.