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

Switching RequestFinished event handling to use IReponse object #2577

Closed
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
13 changes: 7 additions & 6 deletions src/Playwright.Tests/BrowserContextNetworkEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ public async Task BrowserContextEventsRequestfinished()
await using var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();

var request = await page.RunAndWaitForRequestFinishedAsync(() => page.GotoAsync(Server.EmptyPage));
Assert.AreEqual(Server.EmptyPage, request.Url);
var response = await page.RunAndWaitForRequestFinishedAsync(() => page.GotoAsync(Server.EmptyPage));
Assert.AreEqual(Server.EmptyPage, response.Url);

var response = await request.ResponseAsync();
Assert.NotNull(response);
Assert.NotNull(request.Frame);
Assert.AreEqual(Server.EmptyPage, request.Frame.Url);
Assert.IsNull(request.Failure);
Assert.NotNull(response.Frame);
Assert.NotNull(response.Request.Frame);
Assert.AreEqual(Server.EmptyPage, response.Frame.Url);
Assert.AreEqual(Server.EmptyPage, response.Request.Frame.Url);
Assert.IsNull(response.Request.Failure);
}

/// <playwright-file>browsercontext-network-event.spec.ts</playwright-file>
Expand Down
16 changes: 8 additions & 8 deletions src/Playwright.Tests/ResourceTimingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public async Task ShouldWork()
{
await using var context = await NewContext();
var page = await context.NewPageAsync();
var (request, _) = await TaskUtils.WhenAll(
var (response, _) = await TaskUtils.WhenAll(
page.WaitForRequestFinishedAsync(),
page.GotoAsync(Server.EmptyPage));

var timing = request.Timing;
var timing = response.Request.Timing;

VerifyConnectionTimingConsistency(timing);
Assert.GreaterOrEqual(timing.RequestStart, timing.ConnectEnd);
Expand All @@ -67,14 +67,14 @@ public async Task ShouldWorkForSubresource()
{
await using var context = await NewContext();
var page = await context.NewPageAsync();
var requests = new List<IRequest>();
var responses = new List<IResponse>();

page.RequestFinished += (_, e) => requests.Add(e);
page.RequestFinished += (_, e) => responses.Add(e);
await page.GotoAsync(Server.Prefix + "/one-style.html");

Assert.AreEqual(2, requests.Count);
Assert.AreEqual(2, responses.Count);

var timing = requests[1].Timing;
var timing = responses[1].Request.Timing;

VerifyConnectionTimingConsistency(timing);

Expand All @@ -90,11 +90,11 @@ public async Task ShouldWorkForSSL()
{
await using var context = await NewContext(new() { IgnoreHTTPSErrors = true });
var page = await context.NewPageAsync();
var (request, _) = await TaskUtils.WhenAll(
var (response, _) = await TaskUtils.WhenAll(
page.WaitForRequestFinishedAsync(),
page.GotoAsync(HttpsServer.Prefix + "/empty.html"));

var timing = request.Timing;
var timing = response.Request.Timing;
VerifyConnectionTimingConsistency(timing);
Assert.GreaterOrEqual(timing.RequestStart, timing.ConnectEnd);
Assert.GreaterOrEqual(timing.ResponseStart, timing.RequestStart);
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright/API/Generated/IBrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public partial interface IBrowserContext
/// page, use <see cref="IPage.RequestFinished"/>.
/// </para>
/// </summary>
event EventHandler<IRequest> RequestFinished;
event EventHandler<IResponse> RequestFinished;

/// <summary>
/// <para>
Expand Down
12 changes: 6 additions & 6 deletions src/Playwright/API/Generated/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public partial interface IPage
/// and <c>requestfinished</c>.
/// </para>
/// </summary>
event EventHandler<IRequest> RequestFinished;
event EventHandler<IResponse> RequestFinished;

/// <summary>
/// <para>
Expand Down Expand Up @@ -3002,28 +3002,28 @@ public partial interface IPage

/// <summary>
/// <para>
/// Performs action and waits for a <see cref="IRequest"/> to finish loading. If predicate
/// is provided, it passes <see cref="IRequest"/> value into the <c>predicate</c> function
/// Waits for a <see cref="IRequest"/> to finish loading. If predicate
/// is provided, it passes <see cref="IResponse"/> value into the <c>predicate</c> function
/// and waits for <c>predicate(request)</c> to return a truthy value. Will throw an
/// error if the page is closed before the <see cref="IPage.RequestFinished"/> event
/// is fired.
/// </para>
/// </summary>
/// <param name="options">Call options</param>
Task<IRequest> WaitForRequestFinishedAsync(PageWaitForRequestFinishedOptions? options = default);
Task<IResponse> WaitForRequestFinishedAsync(PageWaitForRequestFinishedOptions? options = default);

/// <summary>
/// <para>
/// Performs action and waits for a <see cref="IRequest"/> to finish loading. If predicate
/// is provided, it passes <see cref="IRequest"/> value into the <c>predicate</c> function
/// is provided, it passes <see cref="IResponse"/> value into the <c>predicate</c> function
/// and waits for <c>predicate(request)</c> to return a truthy value. Will throw an
/// error if the page is closed before the <see cref="IPage.RequestFinished"/> event
/// is fired.
/// </para>
/// </summary>
/// <param name="action">Action that triggers the event.</param>
/// <param name="options">Call options</param>
Task<IRequest> RunAndWaitForRequestFinishedAsync(Func<Task> action, PageRunAndWaitForRequestFinishedOptions? options = default);
Task<IResponse> RunAndWaitForRequestFinishedAsync(Func<Task> action, PageRunAndWaitForRequestFinishedOptions? options = default);

/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public PageRunAndWaitForRequestFinishedOptions(PageRunAndWaitForRequestFinishedO

/// <summary>
/// <para>
/// Receives the <see cref="IRequest"/> object and resolves to truthy value when the
/// Receives the <see cref="IResponse"/> object and resolves to truthy value when the
/// waiting should resolve.
/// </para>
/// </summary>
[JsonPropertyName("predicate")]
public Func<IRequest, bool>? Predicate { get; set; }
public Func<IResponse, bool>? Predicate { get; set; }

/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public PageWaitForRequestFinishedOptions(PageWaitForRequestFinishedOptions clone

/// <summary>
/// <para>
/// Receives the <see cref="IRequest"/> object and resolves to truthy value when the
/// Receives the <see cref="IResponse"/> object and resolves to truthy value when the
/// waiting should resolve.
/// </para>
/// </summary>
[JsonPropertyName("predicate")]
public Func<IRequest, bool>? Predicate { get; set; }
public Func<IResponse, bool>? Predicate { get; set; }

/// <summary>
/// <para>
Expand Down
8 changes: 4 additions & 4 deletions src/Playwright/Core/BrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ internal BrowserContext(IChannelOwner parent, string guid, BrowserContextInitial
{
e.Request.SetResponseEndTiming(e.ResponseEndTiming);
e.Request.Sizes = e.RequestSizes;
_requestFinishedImpl?.Invoke(this, e.Request);
e.Page?.FireRequestFinished(e.Request);
_requestFinishedImpl?.Invoke(this, e.Response);
e.Page?.FireRequestFinished(e.Response);
e.Response?.ReportFinished();
};
Channel.Response += (_, e) =>
Expand All @@ -105,7 +105,7 @@ internal BrowserContext(IChannelOwner parent, string guid, BrowserContextInitial

private event EventHandler<IResponse> _responseImpl;

private event EventHandler<IRequest> _requestFinishedImpl;
private event EventHandler<IResponse> _requestFinishedImpl;

private event EventHandler<IRequest> _requestFailedImpl;

Expand All @@ -125,7 +125,7 @@ public event EventHandler<IResponse> Response
remove => this._responseImpl = UpdateEventHandler("response", this._responseImpl, value, false);
}

public event EventHandler<IRequest> RequestFinished
public event EventHandler<IResponse> RequestFinished
{
add => this._requestFinishedImpl = UpdateEventHandler("requestFinished", this._requestFinishedImpl, value, true);
remove => this._requestFinishedImpl = UpdateEventHandler("requestFinished", this._requestFinishedImpl, value, false);
Expand Down
10 changes: 5 additions & 5 deletions src/Playwright/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal Page(IChannelOwner parent, string guid, PageInitializer initializer) :

private event EventHandler<IResponse> _responseImpl;

private event EventHandler<IRequest> _requestFinishedImpl;
private event EventHandler<IResponse> _requestFinishedImpl;

private event EventHandler<IRequest> _requestFailedImpl;

Expand All @@ -157,7 +157,7 @@ public event EventHandler<IResponse> Response
remove => this._responseImpl = UpdateEventHandler("response", this._responseImpl, value, false);
}

public event EventHandler<IRequest> RequestFinished
public event EventHandler<IResponse> RequestFinished
{
add => this._requestFinishedImpl = UpdateEventHandler("requestFinished", this._requestFinishedImpl, value, true);
remove => this._requestFinishedImpl = UpdateEventHandler("requestFinished", this._requestFinishedImpl, value, false);
Expand Down Expand Up @@ -354,7 +354,7 @@ public Task<IRequest> WaitForRequestAsync(Regex urlOrPredicate, PageWaitForReque
public Task<IRequest> WaitForRequestAsync(Func<IRequest, bool> urlOrPredicate, PageWaitForRequestOptions options = default)
=> InnerWaitForEventAsync(PageEvent.Request, null, e => urlOrPredicate(e), options?.Timeout);

public Task<IRequest> WaitForRequestFinishedAsync(PageWaitForRequestFinishedOptions options = default)
public Task<IResponse> WaitForRequestFinishedAsync(PageWaitForRequestFinishedOptions options = default)
=> InnerWaitForEventAsync(PageEvent.RequestFinished, null, options?.Predicate, options?.Timeout);

public Task<IResponse> WaitForResponseAsync(string urlOrPredicate, PageWaitForResponseOptions options = default)
Expand All @@ -381,7 +381,7 @@ public Task<IFileChooser> RunAndWaitForFileChooserAsync(Func<Task> action, PageR
public Task<IPage> RunAndWaitForPopupAsync(Func<Task> action, PageRunAndWaitForPopupOptions options = default)
=> InnerWaitForEventAsync(PageEvent.Popup, action, options?.Predicate, options?.Timeout);

public Task<IRequest> RunAndWaitForRequestFinishedAsync(Func<Task> action, PageRunAndWaitForRequestFinishedOptions options = default)
public Task<IResponse> RunAndWaitForRequestFinishedAsync(Func<Task> action, PageRunAndWaitForRequestFinishedOptions options = default)
=> InnerWaitForEventAsync(PageEvent.RequestFinished, action, options?.Predicate, options?.Timeout);

public Task<IWebSocket> RunAndWaitForWebSocketAsync(Func<Task> action, PageRunAndWaitForWebSocketOptions options = default)
Expand Down Expand Up @@ -984,7 +984,7 @@ internal void OnFrameNavigated(Frame frame)

internal void FireRequestFailed(IRequest request) => _requestFailedImpl?.Invoke(this, request);

internal void FireRequestFinished(IRequest request) => _requestFinishedImpl?.Invoke(this, request);
internal void FireRequestFinished(IResponse response) => _requestFinishedImpl?.Invoke(this, response);

internal void FireResponse(IResponse response) => _responseImpl?.Invoke(this, response);

Expand Down
2 changes: 1 addition & 1 deletion src/Playwright/Core/PageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class PageEvent
/// <summary>
/// <see cref="PlaywrightEvent{T}"/> representing a <see cref="IPage.RequestFinished"/>.
/// </summary>
public static PlaywrightEvent<IRequest> RequestFinished { get; } = new() { Name = "RequestFinished" };
public static PlaywrightEvent<IResponse> RequestFinished { get; } = new() { Name = "RequestFinished" };

/// <summary>
/// <see cref="PlaywrightEvent{T}"/> representing a <see cref="IPage.Crash"/>.
Expand Down