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
Include comprehensive test coverage for all scenarios
Diagram Walkthrough
flowchart LR
A["BrowserModule"] --> B["SetDownloadBehaviorCommand"]
B --> C["DownloadBehavior Types"]
C --> D["DownloadBehaviorAllowed"]
C --> E["DownloadBehaviorDenied"]
F["JSON Serialization"] --> B
G["Tests"] --> A
The command parameter serialization for SetDownloadBehaviorCommand is incorrect. The implementation uses a nested, polymorphic object structure instead of the flat JSON structure with behavior and downloadPath fields required by the WebDriver BiDi specification.
Why: The suggestion correctly identifies a critical serialization issue where the implemented JSON structure for SetDownloadBehaviorCommand parameters does not match the WebDriver BiDi specification, rendering the command incompatible.
High
Possible issue
Align download behavior models with spec
Update the SetDownloadBehaviorParameters and DownloadBehaviorAllowed records to match the BiDi specification by making the behavior parameter non-nullable, renaming DestinationFolder to DownloadPath, making it optional, and adding correct JSON serialization attributes.
Why: The suggestion correctly identifies that the data models do not align with the BiDi specification, fixing nullability, property names, and optionality, which is critical for correct serialization and functionality.
High
Update method calls for new models
In BrowserModule.cs, update the SetDownloadBehaviorAllowedAsync overload to pass new DownloadBehaviorAllowed(null) instead of null for the behavior parameter to align with model changes and prevent a runtime error.
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
{
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
{
- var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);+ var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(null), options?.UserContexts);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}
public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
{
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}
Apply / Chat
Suggestion importance[1-10]: 9
__
Why: This suggestion fixes a bug where a null value was passed for a required parameter, which would cause a runtime failure. The proposed change correctly instantiates the behavior object, ensuring the feature works as intended.
High
Learned best practice
Validate required string parameter
Guard destinationFolder with null/empty/whitespace validation and throw a precise exception message before constructing parameters.
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
{
+ if (string.IsNullOrWhiteSpace(destinationFolder))+ {+ throw new ArgumentException("destinationFolder is required and must be a non-empty path.", nameof(destinationFolder));+ }+
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}
Apply / Chat
Suggestion importance[1-10]: 6
__
Why:
Relevant best practice - Validate inputs early to prevent null/invalid state; check required string parameters for null/empty before use.
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/#command-browser-setDownloadBehavior
💥 What does this PR do?
Implements
SetDownloadBehaviorcommand.💡 Additional Considerations
Not yet supported by browsers, but I verified locally whether we serialize command properly.
🔄 Types of changes
PR Type
Enhancement
Description
Implement WebDriver BiDi
SetDownloadBehaviorcommandAdd support for allowed/denied download behaviors
Include comprehensive test coverage for all scenarios
Diagram Walkthrough
File Walkthrough
BrowserModule.cs
Add SetDownloadBehavior methods to BrowserModuledotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
SetDownloadBehaviorCommand.cs
Create SetDownloadBehavior command infrastructuredotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs
BiDiJsonSerializerContext.cs
Register command for JSON serializationdotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs
BrowserTest.cs
Add comprehensive SetDownloadBehavior testsdotnet/test/common/BiDi/Browser/BrowserTest.cs