Skip to content

Commit

Permalink
Roll Chromium to r588429 (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Sep 27, 2018
1 parent cf1500f commit 339c7dc
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 42 deletions.
5 changes: 4 additions & 1 deletion lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs
Expand Up @@ -8,6 +8,7 @@ namespace PuppeteerSharp.Tests
public class PuppeteerBrowserBaseTest : PuppeteerBaseTest, IAsyncLifetime
{
protected Browser Browser { get; set; }
protected LaunchOptions DefaultOptions { get; set; }

public PuppeteerBrowserBaseTest(ITestOutputHelper output) : base(output)
{
Expand All @@ -21,7 +22,9 @@ public PuppeteerBrowserBaseTest(ITestOutputHelper output) : base(output)
}

public virtual async Task InitializeAsync()
=> Browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions(), TestConstants.LoggerFactory);
=> Browser = await Puppeteer.LaunchAsync(
DefaultOptions ?? TestConstants.DefaultBrowserOptions(),
TestConstants.LoggerFactory);

public virtual async Task DisposeAsync() => await Browser.CloseAsync();
}
Expand Down
76 changes: 76 additions & 0 deletions lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using PuppeteerSharp.Helpers;
using Xunit;
using Xunit.Abstractions;

namespace PuppeteerSharp.Tests.PuppeteerTests
{
[Collection("PuppeteerLoaderFixture collection")]
public class IgnoreHttpsErrorsTests : PuppeteerPageBaseTest
{
public IgnoreHttpsErrorsTests(ITestOutputHelper output) : base(output)
{
DefaultOptions = TestConstants.DefaultBrowserOptions();
DefaultOptions.IgnoreHTTPSErrors = true;
}

[Fact]
public async Task ShouldWork()
{
var response = await Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.NotNull(response.SecurityDetails);
Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol);
}

[Fact]
public async Task NetworkRedirectsShouldReportSecurityDetails()
{
var responses = new List<Response>();
HttpsServer.SetRedirect("/plzredirect", "/empty.html");

Page.Response += (sender, e) => responses.Add(e.Response);

await Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect");

Assert.Equal(2, responses.Count);
Assert.Equal(HttpStatusCode.Found, responses[0].Status);
Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol);
}

[Fact]
public async Task ShouldWorkWithRequestInterception()
{
await Page.SetRequestInterceptionAsync(true);
Page.Request += async (sender, e) => await e.Request.ContinueAsync();
var response = await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.OK, response.Status);
}

[Fact]
public async Task ShouldWorkWithMixedContent()
{
HttpsServer.SetRoute("/mixedcontent.html", async (context) =>
{
await context.Response.WriteAsync($"<iframe src='{TestConstants.EmptyPage}'></iframe>");
});
await Page.GoToAsync(TestConstants.HttpsPrefix + "/mixedcontent.html", new NavigationOptions
{
WaitUntil = new[] { WaitUntilNavigation.Load }
});
Assert.Equal(2, Page.Frames.Length);
// Make sure blocked iframe has functional execution context
// @see https://github.com/GoogleChrome/puppeteer/issues/2709
Assert.Equal(3, await Page.Frames[0].EvaluateExpressionAsync<int>("1 + 2"));
Assert.Equal(5, await Page.Frames[1].EvaluateExpressionAsync<int>("2 + 3"));
}
}
}
38 changes: 0 additions & 38 deletions lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerLaunchTests.cs
Expand Up @@ -17,44 +17,6 @@ public class PuppeteerLaunchTests : PuppeteerBaseTest
{
public PuppeteerLaunchTests(ITestOutputHelper output) : base(output) { }

[Fact]
public async Task ShouldSupportIgnoreHTTPSErrorsOption()
{
var options = TestConstants.DefaultBrowserOptions();
options.IgnoreHTTPSErrors = true;

using (var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory))
using (var page = await browser.NewPageAsync())
{
var response = await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.NotNull(response.SecurityDetails);
Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol);
}
}

[Fact]
public async Task NetworkRedirectsShouldReportSecurityDetails()
{
var responses = new List<Response>();
var options = TestConstants.DefaultBrowserOptions();
options.IgnoreHTTPSErrors = true;

HttpsServer.SetRedirect("/plzredirect", "/empty.html");

using (var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory))
using (var page = await browser.NewPageAsync())
{
page.Response += (sender, e) => responses.Add(e.Response);

await page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect");

Assert.Equal(2, responses.Count);
Assert.Equal(HttpStatusCode.Found, responses[0].Status);
Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol);
}
}

[Fact]
public async Task ShouldWorkInRealLife()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/BrowserFetcher.cs
Expand Up @@ -36,7 +36,7 @@ public class BrowserFetcher
/// <summary>
/// Default chromiumg revision.
/// </summary>
public const int DefaultRevision = 579032;
public const int DefaultRevision = 588429;

/// <summary>
/// Gets the downloads folder.
Expand Down
13 changes: 13 additions & 0 deletions lib/PuppeteerSharp/Messaging/NetworkGetResponseBodyResponse.cs
@@ -0,0 +1,13 @@
using System;
using Newtonsoft.Json;

namespace PuppeteerSharp.Messaging
{
internal class NetworkGetResponseBodyResponse
{
[JsonProperty("body")]
public string Body { get; set; }
[JsonProperty("base64Encoded")]
public bool Base64Encoded { get; set; }
}
}
8 changes: 6 additions & 2 deletions lib/PuppeteerSharp/Response.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using PuppeteerSharp.Messaging;

namespace PuppeteerSharp
{
Expand Down Expand Up @@ -101,12 +103,14 @@ public async ValueTask<string> BufferAsync()

try
{
var response = await _client.SendAsync("Network.getResponseBody", new Dictionary<string, object>
var response = await _client.SendAsync<NetworkGetResponseBodyResponse>("Network.getResponseBody", new Dictionary<string, object>
{
{"requestId", Request.RequestId}
}).ConfigureAwait(false);

_buffer = response.body.ToString();
_buffer = response.Base64Encoded
? Encoding.UTF8.GetString(Convert.FromBase64String(response.Body))
: response.Body;
}
catch (Exception ex)
{
Expand Down

0 comments on commit 339c7dc

Please sign in to comment.