Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude favicon from tests #994

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}