You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New feature (non-breaking change which adds functionality and tests!)
PR Type
Enhancement
Description
Fix downloadWillBegin event signature to use proper event args
Implement new downloadEnd event with polymorphic event args
Add comprehensive tests for both download events
Create JSON converters for proper serialization
Diagram Walkthrough
flowchart LR
A["BrowsingContext"] --> B["OnDownloadWillBeginAsync"]
A --> C["OnDownloadEndAsync"]
B --> D["DownloadWillBeginEventArgs"]
C --> E["DownloadEndEventArgs"]
E --> F["DownloadCanceledEventArgs"]
E --> G["DownloadCompleteEventArgs"]
H["JSON Converter"] --> E
I["Tests"] --> B
I --> C
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Unimplemented serialization
Description: The custom JSON converter throws NotImplementedException on serialization for DownloadEndEventArgs.Write, which could cause a runtime crash if the type is ever serialized (e.g., logged or echoed back); consider implementing or explicitly preventing serialization paths. DownloadEndEventArgsConverter.cs [41-44]
In the Read method, throw a JsonException for unknown status discriminators instead of returning null to prevent silent failures and improve error handling.
public override DownloadEndEventArgs? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- return reader.GetDiscriminator("status") switch+ var discriminator = reader.GetDiscriminator("status");+ return discriminator switch
{
"canceled" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo<DownloadCanceledEventArgs>()),
"complete" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo<DownloadCompleteEventArgs>()),
- _ => null,+ _ => throw new JsonException($"Unknown 'status' discriminator '{discriminator}' for DownloadEndEventArgs."),
};
}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies that returning null for an unknown discriminator can hide issues. Throwing an exception improves robustness by making failures explicit, which is a good practice for deserialization logic.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
https://w3c.github.io/webdriver-bidi/#event-browsingContext-downloadWillBegin
https://w3c.github.io/webdriver-bidi/#event-browsingContext-downloadEnd
💥 What does this PR do?
Fix
downloadWillBeginevent signature, implementdownloadEndevent. Adding tests.🔄 Types of changes
PR Type
Enhancement
Description
Fix
downloadWillBeginevent signature to use proper event argsImplement new
downloadEndevent with polymorphic event argsAdd comprehensive tests for both download events
Create JSON converters for proper serialization
Diagram Walkthrough
File Walkthrough
BrowsingContext.cs
Update download event method signaturesdotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs
OnDownloadWillBeginAsyncmethod signatures to useDownloadWillBeginEventArgsOnDownloadEndAsyncmethods for both sync and async handlersBrowsingContextModule.cs
Update module download event subscriptionsdotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs
OnDownloadWillBeginAsyncmethod signatures to use proper eventargs
OnDownloadEndAsyncmethods subscribing tobrowsingContext.downloadEndDownloadEndEventArgs.cs
Create download end event args classesdotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs
DownloadEndEventArgsDownloadCanceledEventArgsandDownloadCompleteEventArgsderived types
DownloadWillBeginEventArgs.cs
Create download will begin event argsdotnet/src/webdriver/BiDi/BrowsingContext/DownloadWillBeginEventArgs.cs
DownloadWillBeginEventArgsrecord with suggested filenameIBaseNavigationInfointerface for navigation contextDownloadEndEventArgsConverter.cs
Create polymorphic download end converterdotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/DownloadEndEventArgsConverter.cs
DownloadEndEventArgscanceledandcompletestatus discriminatorsBroker.cs
Register download end event converterdotnet/src/webdriver/BiDi/Communication/Broker.cs
DownloadEndEventArgsConverterfor polymorphic JSONserialization
BiDiJsonSerializerContext.cs
Register download event types for serializationdotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs
BrowsingContextEventsTest.cs
Add download events integration testsdotnet/test/common/BiDi/BrowsingContext/BrowsingContextEventsTest.cs
downloadWillBeginevent with file download simulationdownloadEndevent verifying completion and filepath