-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Possibility to reset viewport #16601
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
Open
nvborisenko
wants to merge
10
commits into
SeleniumHQ:trunk
Choose a base branch
from
nvborisenko:bidi-setviewport-null
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−4
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6188f60
[dotnet] [bidi] Possibility to reset viewport
nvborisenko 62db608
Always send nullable viewport
nvborisenko 40ae3e2
Merge remote-tracking branch 'upstream/trunk' into bidi-setviewport-null
nvborisenko ff134d0
Optional
nvborisenko b5529fd
Simplified
nvborisenko 8951622
Format
nvborisenko 30574a5
Use TryGetValue
nvborisenko f7e5002
Update OptionalConverter.cs
nvborisenko 821941c
Advanced tests
nvborisenko 92d7863
Update BrowsingContextTest.cs
nvborisenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
dotnet/src/webdriver/BiDi/Json/Converters/OptionalConverter.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // <copyright file="OptionalConverter.cs" company="Selenium Committers"> | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // </copyright> | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace OpenQA.Selenium.BiDi.Json.Converters; | ||
|
|
||
| public sealed class OptionalConverter<T> : JsonConverter<Optional<T>> | ||
| { | ||
| public override Optional<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.Null) | ||
| { | ||
| reader.Read(); // consume null | ||
| return new Optional<T>(default!); | ||
| } | ||
|
|
||
| T value = JsonSerializer.Deserialize<T>(ref reader, options)!; | ||
| return new Optional<T>(value); | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, Optional<T> value, JsonSerializerOptions options) | ||
| { | ||
| if (value.TryGetValue(out var optionalValue)) | ||
| { | ||
| JsonSerializer.Serialize(writer, optionalValue, options); | ||
| } | ||
| else | ||
| { | ||
| writer.WriteNullValue(); | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // <copyright file="Optional.cs" company="Selenium Committers"> | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // </copyright> | ||
|
|
||
| using System; | ||
|
|
||
| namespace OpenQA.Selenium.BiDi; | ||
|
|
||
| public readonly record struct Optional<T> | ||
| { | ||
| private readonly T _value; | ||
| public bool HasValue { get; } | ||
|
|
||
| public T Value => HasValue | ||
| ? _value | ||
| : throw new InvalidOperationException("Optional has no value. Check IsSet first."); | ||
|
|
||
| public Optional(T value) | ||
| { | ||
| _value = value; | ||
| HasValue = true; | ||
| } | ||
|
|
||
| public bool TryGetValue(out T value) | ||
| { | ||
| value = _value; | ||
| return HasValue; | ||
| } | ||
|
|
||
| // implicit conversion from T -> Optional<T> | ||
| public static implicit operator Optional<T>(T value) => new(value); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readonly struct, do we see issues? There are limitations of its use. I propose to be safe and don't use it.