From 54629a666fdce7c222ee69ae61ae12d6ed96b802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 11 Mar 2019 08:40:08 -0300 Subject: [PATCH] Add headers tests (#999) --- .../NetworkTests/RequestHeadersTests.cs | 21 +++++++++++++++ .../NetworkTests/ResponseHeadersTests.cs | 27 +++++++++++++++++++ .../Messaging/ResponsePayload.cs | 2 +- lib/PuppeteerSharp/Response.cs | 4 +-- 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 lib/PuppeteerSharp.Tests/NetworkTests/RequestHeadersTests.cs create mode 100644 lib/PuppeteerSharp.Tests/NetworkTests/ResponseHeadersTests.cs diff --git a/lib/PuppeteerSharp.Tests/NetworkTests/RequestHeadersTests.cs b/lib/PuppeteerSharp.Tests/NetworkTests/RequestHeadersTests.cs new file mode 100644 index 000000000..386e4f8df --- /dev/null +++ b/lib/PuppeteerSharp.Tests/NetworkTests/RequestHeadersTests.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace PuppeteerSharp.Tests.NetworkTests +{ + [Collection("PuppeteerLoaderFixture collection")] + public class RequestHeadersTests : PuppeteerPageBaseTest + { + public RequestHeadersTests(ITestOutputHelper output) : base(output) + { + } + + [Fact] + public async Task ShouldWork() + { + var response = await Page.GoToAsync(TestConstants.EmptyPage); + Assert.Contains("Chrome", response.Request.Headers["User-Agent"]); + } + } +} diff --git a/lib/PuppeteerSharp.Tests/NetworkTests/ResponseHeadersTests.cs b/lib/PuppeteerSharp.Tests/NetworkTests/ResponseHeadersTests.cs new file mode 100644 index 000000000..54585a91b --- /dev/null +++ b/lib/PuppeteerSharp.Tests/NetworkTests/ResponseHeadersTests.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace PuppeteerSharp.Tests.NetworkTests +{ + [Collection("PuppeteerLoaderFixture collection")] + public class ResponseHeadersTests : PuppeteerPageBaseTest + { + public ResponseHeadersTests(ITestOutputHelper output) : base(output) + { + } + + [Fact] + public async Task ShouldWork() + { + Server.SetRoute("/empty.html", (context) => + { + context.Response.Headers["foo"] = "bar"; + return Task.CompletedTask; + }); + + var response = await Page.GoToAsync(TestConstants.EmptyPage); + Assert.Contains("bar", response.Headers["foo"]); + } + } +} diff --git a/lib/PuppeteerSharp/Messaging/ResponsePayload.cs b/lib/PuppeteerSharp/Messaging/ResponsePayload.cs index 5adc81291..e5a18faac 100644 --- a/lib/PuppeteerSharp/Messaging/ResponsePayload.cs +++ b/lib/PuppeteerSharp/Messaging/ResponsePayload.cs @@ -7,7 +7,7 @@ namespace PuppeteerSharp.Messaging internal class ResponsePayload { public string Url { get; set; } - public Dictionary Headers { get; set; } + public Dictionary Headers { get; set; } public HttpStatusCode Status { get; set; } public SecurityDetails SecurityDetails { get; set; } public bool FromDiskCache { get; set; } diff --git a/lib/PuppeteerSharp/Response.cs b/lib/PuppeteerSharp/Response.cs index c8be59da4..9238e1ebe 100755 --- a/lib/PuppeteerSharp/Response.cs +++ b/lib/PuppeteerSharp/Response.cs @@ -31,7 +31,7 @@ internal Response( _fromDiskCache = responseMessage.FromDiskCache; FromServiceWorker = responseMessage.FromServiceWorker; - Headers = new Dictionary(); + Headers = new Dictionary(); if (responseMessage.Headers != null) { foreach (var keyValue in responseMessage.Headers) @@ -59,7 +59,7 @@ internal Response( /// An object with HTTP headers associated with the response. All header names are lower-case. /// /// The headers. - public Dictionary Headers { get; } + public Dictionary Headers { get; } /// /// Contains the status code of the response ///