-
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
38 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
lib/PuppeteerSharp.Tests/NetworkTests/PageEventRequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
lib/PuppeteerSharp.Tests/NetworkTests/RequestFrameTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters