Skip to content
Merged
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
16 changes: 9 additions & 7 deletions dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ public sealed class GetClientWindowsOptions : CommandOptions;

public sealed record GetClientWindowsResult : EmptyResult, IReadOnlyList<ClientWindowInfo>
{
private readonly IReadOnlyList<ClientWindowInfo> _clientWindows;

internal GetClientWindowsResult(IReadOnlyList<ClientWindowInfo> clientWindows)
{
_clientWindows = clientWindows;
ClientWindows = clientWindows;
}

public ClientWindowInfo this[int index] => _clientWindows[index];
public IReadOnlyList<ClientWindowInfo> ClientWindows { get; }

public ClientWindowInfo this[int index] => ClientWindows[index];

public int Count => ClientWindows.Count;


public int Count => _clientWindows.Count;

public IEnumerator<ClientWindowInfo> GetEnumerator() => _clientWindows.GetEnumerator();
public IEnumerator<ClientWindowInfo> GetEnumerator() => ClientWindows.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (_clientWindows as IEnumerable).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => (ClientWindows as IEnumerable).GetEnumerator();
}
14 changes: 7 additions & 7 deletions dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public class GetUserContextsOptions : CommandOptions;

public sealed record GetUserContextsResult : EmptyResult, IReadOnlyList<UserContextInfo>
{
private readonly IReadOnlyList<UserContextInfo> _userContexts;

internal GetUserContextsResult(IReadOnlyList<UserContextInfo> userContexts)
{
_userContexts = userContexts;
UserContexts = userContexts;
}

public UserContextInfo this[int index] => _userContexts[index];
public IReadOnlyList<UserContextInfo> UserContexts { get; }

public UserContextInfo this[int index] => UserContexts[index];

public int Count => _userContexts.Count;
public int Count => UserContexts.Count;

public IEnumerator<UserContextInfo> GetEnumerator() => _userContexts.GetEnumerator();
public IEnumerator<UserContextInfo> GetEnumerator() => UserContexts.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (_userContexts as IEnumerable).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => (UserContexts as IEnumerable).GetEnumerator();
}
3 changes: 1 addition & 2 deletions dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// under the License.
// </copyright>

using System.Collections.Generic;
using System.Threading.Tasks;
using System;

Expand Down Expand Up @@ -117,7 +116,7 @@ public Task HandleUserPromptAsync(HandleUserPromptOptions? options = null)
return BiDi.BrowsingContext.HandleUserPromptAsync(this, options);
}

public Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(BrowsingContextGetTreeOptions? options = null)
public Task<GetTreeResult> GetTreeAsync(BrowsingContextGetTreeOptions? options = null)
{
GetTreeOptions getTreeOptions = new(options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Communication;

Expand Down Expand Up @@ -91,13 +90,11 @@ public async Task SetViewportAsync(BrowsingContext context, SetViewportOptions?
await Broker.ExecuteCommandAsync(new SetViewportCommand(@params), options).ConfigureAwait(false);
}

public async Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(GetTreeOptions? options = null)
public async Task<GetTreeResult> GetTreeAsync(GetTreeOptions? options = null)
{
var @params = new GetTreeCommandParameters(options?.MaxDepth, options?.Root);

var getTreeResult = await Broker.ExecuteCommandAsync<GetTreeCommand, GetTreeResult>(new GetTreeCommand(@params), options).ConfigureAwait(false);

return getTreeResult.Contexts;
return await Broker.ExecuteCommandAsync<GetTreeCommand, GetTreeResult>(new GetTreeCommand(@params), options).ConfigureAwait(false);
}

public async Task<PrintResult> PrintAsync(BrowsingContext context, PrintOptions? options = null)
Expand Down
19 changes: 18 additions & 1 deletion dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// </copyright>

using OpenQA.Selenium.BiDi.Communication;
using System.Collections;
using System.Collections.Generic;

namespace OpenQA.Selenium.BiDi.BrowsingContext;
Expand Down Expand Up @@ -46,4 +47,20 @@ public sealed record BrowsingContextGetTreeOptions
public long? MaxDepth { get; set; }
}

public sealed record GetTreeResult(IReadOnlyList<BrowsingContextInfo> Contexts) : EmptyResult;
public sealed record GetTreeResult : EmptyResult, IReadOnlyList<BrowsingContextInfo>
{
internal GetTreeResult(IReadOnlyList<BrowsingContextInfo> contexts)
{
Contexts = contexts;
}

public IReadOnlyList<BrowsingContextInfo> Contexts { get; }

public BrowsingContextInfo this[int index] => Contexts[index];

public int Count => Contexts.Count;

public IEnumerator<BrowsingContextInfo> GetEnumerator() => Contexts.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (Contexts as IEnumerable).GetEnumerator();
}
14 changes: 7 additions & 7 deletions dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public sealed class LocateNodesOptions : CommandOptions

public sealed record LocateNodesResult : EmptyResult, IReadOnlyList<Script.NodeRemoteValue>
{
private readonly IReadOnlyList<Script.NodeRemoteValue> _nodes;

internal LocateNodesResult(IReadOnlyList<Script.NodeRemoteValue> nodes)
{
_nodes = nodes;
Nodes = nodes;
}

public Script.NodeRemoteValue this[int index] => _nodes[index];
public IReadOnlyList<Script.NodeRemoteValue> Nodes { get; }

public Script.NodeRemoteValue this[int index] => Nodes[index];

public int Count => _nodes.Count;
public int Count => Nodes.Count;

public IEnumerator<Script.NodeRemoteValue> GetEnumerator() => _nodes.GetEnumerator();
public IEnumerator<Script.NodeRemoteValue> GetEnumerator() => Nodes.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => (Nodes as IEnumerable).GetEnumerator();
}
1 change: 1 addition & 0 deletions dotnet/src/webdriver/BiDi/Communication/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal Broker(BiDi bidi, Uri url)
new Json.Converters.Enumerable.GetUserContextsResultConverter(),
new Json.Converters.Enumerable.GetClientWindowsResultConverter(),
new Json.Converters.Enumerable.GetRealmsResultConverter(),
new Json.Converters.Enumerable.GetTreeResultConverter(),
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <copyright file="GetTreeResultConverter.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 OpenQA.Selenium.BiDi.BrowsingContext;
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class GetTreeResultConverter : JsonConverter<GetTreeResult>
{
public override GetTreeResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var doc = JsonDocument.ParseValue(ref reader);
var contexts = doc.RootElement.GetProperty("contexts").Deserialize(options.GetTypeInfo<IReadOnlyList<BrowsingContextInfo>>());

return new GetTreeResult(contexts!);
}

public override void Write(Utf8JsonWriter writer, GetTreeResult value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
14 changes: 7 additions & 7 deletions dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ public sealed class GetCookiesOptions : CommandOptions

public sealed record GetCookiesResult : EmptyResult, IReadOnlyList<Network.Cookie>
{
private readonly IReadOnlyList<Network.Cookie> _cookies;

internal GetCookiesResult(IReadOnlyList<Network.Cookie> cookies, PartitionKey partitionKey)
{
_cookies = cookies;
Cookies = cookies;
PartitionKey = partitionKey;
}

public IReadOnlyList<Network.Cookie> Cookies { get; }

public PartitionKey PartitionKey { get; init; }

public Network.Cookie this[int index] => _cookies[index];
public Network.Cookie this[int index] => Cookies[index];

public int Count => _cookies.Count;
public int Count => Cookies.Count;

public IEnumerator<Network.Cookie> GetEnumerator() => _cookies.GetEnumerator();
public IEnumerator<Network.Cookie> GetEnumerator() => Cookies.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (_cookies as IEnumerable).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => (Cookies as IEnumerable).GetEnumerator();
}

public sealed record CookieFilter
Expand Down