Skip to content

Commit

Permalink
Exclude favicon from tests (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Mar 8, 2019
1 parent 60a0ba6 commit 1b6d718
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 38 deletions.
68 changes: 68 additions & 0 deletions lib/PuppeteerSharp.Tests/NetworkTests/PageEventRequestTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace PuppeteerSharp.Tests.NetworkTests
{
[Collection("PuppeteerLoaderFixture collection")]
public class PageEventRequestTests : PuppeteerPageBaseTest
{
public PageEventRequestTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ShouldFireForNavigationRequests()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Single(requests);
}

[Fact]
public async Task ShouldFireForIframes()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);

await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
Assert.Equal(2, requests.Count);
}

[Fact]
public async Task ShouldFireForFetches()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);
await Page.EvaluateExpressionAsync("fetch('/empty.html')");
Assert.Equal(2, requests.Count);
}
}
}
71 changes: 71 additions & 0 deletions lib/PuppeteerSharp.Tests/NetworkTests/RequestFrameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace PuppeteerSharp.Tests.NetworkTests
{
[Collection("PuppeteerLoaderFixture collection")]
public class RequestFrameTests : PuppeteerPageBaseTest
{
public RequestFrameTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ShouldWorkForMainFrameNavigationRequests()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Single(requests);
Assert.Equal(Page.MainFrame, requests[0].Frame);
}

[Fact]
public async Task ShouldWorkForSubframeNavigationRequest()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);

await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
Assert.Equal(2, requests.Count);
Assert.Equal(Page.FirstChildFrame(), requests[1].Frame);
}

[Fact]
public async Task ShouldWorkForFetchRequests()
{
var requests = new List<Request>();
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};

await Page.GoToAsync(TestConstants.EmptyPage);
await Page.EvaluateExpressionAsync("fetch('/empty.html')");
Assert.Equal(2, requests.Count);
Assert.Equal(Page.MainFrame, requests[0].Frame);
}
}
}
36 changes: 0 additions & 36 deletions lib/PuppeteerSharp.Tests/PageTests/Events/RequestTests.cs

This file was deleted.

16 changes: 14 additions & 2 deletions lib/PuppeteerSharp.Tests/PageTests/GotoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ await Task.WhenAll(
public async Task ShouldNavigateToDataURLAndFireDataURLRequests()
{
var requests = new List<Request>();
Page.Request += (sender, e) => requests.Add(e.Request);
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};
var dataUrl = "data:text/html,<div>yo</div>";
var response = await Page.GoToAsync(dataUrl);
Assert.Equal(HttpStatusCode.OK, response.Status);
Expand All @@ -313,7 +319,13 @@ public async Task ShouldNavigateToDataURLAndFireDataURLRequests()
public async Task ShouldNavigateToURLWithHashAndFireRequestsWithoutHash()
{
var requests = new List<Request>();
Page.Request += (sender, e) => requests.Add(e.Request);
Page.Request += (sender, e) =>
{
if (!TestUtils.IsFavicon(e.Request))
{
requests.Add(e.Request);
}
};
var response = await Page.GoToAsync(TestConstants.EmptyPage + "#hash");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(TestConstants.EmptyPage, response.Url);
Expand Down
1 change: 1 addition & 0 deletions lib/PuppeteerSharp.Tests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ internal static async Task WaitForCookieInChromiumFileAsync(string path, string
await Task.Delay(100);
}
}
internal static bool IsFavicon(Request request) => request.Url.Contains("favicon.ico");
}
}

0 comments on commit 1b6d718

Please sign in to comment.