Skip to content

Commit 339c7dc

Browse files
authored
Roll Chromium to r588429 (#643)
1 parent cf1500f commit 339c7dc

File tree

6 files changed

+100
-42
lines changed

6 files changed

+100
-42
lines changed

lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace PuppeteerSharp.Tests
88
public class PuppeteerBrowserBaseTest : PuppeteerBaseTest, IAsyncLifetime
99
{
1010
protected Browser Browser { get; set; }
11+
protected LaunchOptions DefaultOptions { get; set; }
1112

1213
public PuppeteerBrowserBaseTest(ITestOutputHelper output) : base(output)
1314
{
@@ -21,7 +22,9 @@ public PuppeteerBrowserBaseTest(ITestOutputHelper output) : base(output)
2122
}
2223

2324
public virtual async Task InitializeAsync()
24-
=> Browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions(), TestConstants.LoggerFactory);
25+
=> Browser = await Puppeteer.LaunchAsync(
26+
DefaultOptions ?? TestConstants.DefaultBrowserOptions(),
27+
TestConstants.LoggerFactory);
2528

2629
public virtual async Task DisposeAsync() => await Browser.CloseAsync();
2730
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Net;
7+
using System.Runtime.InteropServices;
8+
using System.Threading.Tasks;
9+
using Microsoft.AspNetCore.Http;
10+
using PuppeteerSharp.Helpers;
11+
using Xunit;
12+
using Xunit.Abstractions;
13+
14+
namespace PuppeteerSharp.Tests.PuppeteerTests
15+
{
16+
[Collection("PuppeteerLoaderFixture collection")]
17+
public class IgnoreHttpsErrorsTests : PuppeteerPageBaseTest
18+
{
19+
public IgnoreHttpsErrorsTests(ITestOutputHelper output) : base(output)
20+
{
21+
DefaultOptions = TestConstants.DefaultBrowserOptions();
22+
DefaultOptions.IgnoreHTTPSErrors = true;
23+
}
24+
25+
[Fact]
26+
public async Task ShouldWork()
27+
{
28+
var response = await Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
29+
Assert.Equal(HttpStatusCode.OK, response.Status);
30+
Assert.NotNull(response.SecurityDetails);
31+
Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol);
32+
}
33+
34+
[Fact]
35+
public async Task NetworkRedirectsShouldReportSecurityDetails()
36+
{
37+
var responses = new List<Response>();
38+
HttpsServer.SetRedirect("/plzredirect", "/empty.html");
39+
40+
Page.Response += (sender, e) => responses.Add(e.Response);
41+
42+
await Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect");
43+
44+
Assert.Equal(2, responses.Count);
45+
Assert.Equal(HttpStatusCode.Found, responses[0].Status);
46+
Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol);
47+
}
48+
49+
[Fact]
50+
public async Task ShouldWorkWithRequestInterception()
51+
{
52+
await Page.SetRequestInterceptionAsync(true);
53+
Page.Request += async (sender, e) => await e.Request.ContinueAsync();
54+
var response = await Page.GoToAsync(TestConstants.EmptyPage);
55+
Assert.Equal(HttpStatusCode.OK, response.Status);
56+
}
57+
58+
[Fact]
59+
public async Task ShouldWorkWithMixedContent()
60+
{
61+
HttpsServer.SetRoute("/mixedcontent.html", async (context) =>
62+
{
63+
await context.Response.WriteAsync($"<iframe src='{TestConstants.EmptyPage}'></iframe>");
64+
});
65+
await Page.GoToAsync(TestConstants.HttpsPrefix + "/mixedcontent.html", new NavigationOptions
66+
{
67+
WaitUntil = new[] { WaitUntilNavigation.Load }
68+
});
69+
Assert.Equal(2, Page.Frames.Length);
70+
// Make sure blocked iframe has functional execution context
71+
// @see https://github.com/GoogleChrome/puppeteer/issues/2709
72+
Assert.Equal(3, await Page.Frames[0].EvaluateExpressionAsync<int>("1 + 2"));
73+
Assert.Equal(5, await Page.Frames[1].EvaluateExpressionAsync<int>("2 + 3"));
74+
}
75+
}
76+
}

lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerLaunchTests.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,6 @@ public class PuppeteerLaunchTests : PuppeteerBaseTest
1717
{
1818
public PuppeteerLaunchTests(ITestOutputHelper output) : base(output) { }
1919

20-
[Fact]
21-
public async Task ShouldSupportIgnoreHTTPSErrorsOption()
22-
{
23-
var options = TestConstants.DefaultBrowserOptions();
24-
options.IgnoreHTTPSErrors = true;
25-
26-
using (var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory))
27-
using (var page = await browser.NewPageAsync())
28-
{
29-
var response = await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
30-
Assert.Equal(HttpStatusCode.OK, response.Status);
31-
Assert.NotNull(response.SecurityDetails);
32-
Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol);
33-
}
34-
}
35-
36-
[Fact]
37-
public async Task NetworkRedirectsShouldReportSecurityDetails()
38-
{
39-
var responses = new List<Response>();
40-
var options = TestConstants.DefaultBrowserOptions();
41-
options.IgnoreHTTPSErrors = true;
42-
43-
HttpsServer.SetRedirect("/plzredirect", "/empty.html");
44-
45-
using (var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory))
46-
using (var page = await browser.NewPageAsync())
47-
{
48-
page.Response += (sender, e) => responses.Add(e.Response);
49-
50-
await page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect");
51-
52-
Assert.Equal(2, responses.Count);
53-
Assert.Equal(HttpStatusCode.Found, responses[0].Status);
54-
Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol);
55-
}
56-
}
57-
5820
[Fact]
5921
public async Task ShouldWorkInRealLife()
6022
{

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class BrowserFetcher
3636
/// <summary>
3737
/// Default chromiumg revision.
3838
/// </summary>
39-
public const int DefaultRevision = 579032;
39+
public const int DefaultRevision = 588429;
4040

4141
/// <summary>
4242
/// Gets the downloads folder.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace PuppeteerSharp.Messaging
5+
{
6+
internal class NetworkGetResponseBodyResponse
7+
{
8+
[JsonProperty("body")]
9+
public string Body { get; set; }
10+
[JsonProperty("base64Encoded")]
11+
public bool Base64Encoded { get; set; }
12+
}
13+
}

lib/PuppeteerSharp/Response.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Net;
4+
using System.Text;
45
using System.Threading.Tasks;
56
using Newtonsoft.Json.Linq;
7+
using PuppeteerSharp.Messaging;
68

79
namespace PuppeteerSharp
810
{
@@ -101,12 +103,14 @@ public async ValueTask<string> BufferAsync()
101103

102104
try
103105
{
104-
var response = await _client.SendAsync("Network.getResponseBody", new Dictionary<string, object>
106+
var response = await _client.SendAsync<NetworkGetResponseBodyResponse>("Network.getResponseBody", new Dictionary<string, object>
105107
{
106108
{"requestId", Request.RequestId}
107109
}).ConfigureAwait(false);
108110

109-
_buffer = response.body.ToString();
111+
_buffer = response.Base64Encoded
112+
? Encoding.UTF8.GetString(Convert.FromBase64String(response.Body))
113+
: response.Body;
110114
}
111115
catch (Exception ex)
112116
{

0 commit comments

Comments
 (0)