diff --git a/src/Playwright/Core/APIRequestContext.cs b/src/Playwright/Core/APIRequestContext.cs index e10f64b03f..c01e5703eb 100644 --- a/src/Playwright/Core/APIRequestContext.cs +++ b/src/Playwright/Core/APIRequestContext.cs @@ -35,13 +35,13 @@ namespace Microsoft.Playwright.Core; -internal class APIRequestContext : ChannelOwnerBase, IAPIRequestContext +internal class APIRequestContext : ChannelOwner, IAPIRequestContext { internal readonly Tracing _tracing; internal APIRequest _request; - public APIRequestContext(ChannelOwnerBase parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid) + public APIRequestContext(ChannelOwner parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid) { _tracing = initializer.Tracing; } @@ -161,7 +161,6 @@ private bool IsJsonParsable(string dataString) } } - [MethodImpl(MethodImplOptions.NoInlining)] public Task DeleteAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "DELETE")); diff --git a/src/Playwright/Core/AndroidDevice.cs b/src/Playwright/Core/AndroidDevice.cs index 05ef136231..9106ce11f5 100644 --- a/src/Playwright/Core/AndroidDevice.cs +++ b/src/Playwright/Core/AndroidDevice.cs @@ -27,9 +27,9 @@ namespace Microsoft.Playwright.Core; -internal class AndroidDevice : ChannelOwnerBase +internal class AndroidDevice : ChannelOwner { - internal AndroidDevice(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid) + internal AndroidDevice(ChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid) { } } diff --git a/src/Playwright/Core/Artifact.cs b/src/Playwright/Core/Artifact.cs index 101ef351b2..d3e9855246 100644 --- a/src/Playwright/Core/Artifact.cs +++ b/src/Playwright/Core/Artifact.cs @@ -33,9 +33,9 @@ namespace Microsoft.Playwright.Core; -internal class Artifact : ChannelOwnerBase +internal class Artifact : ChannelOwner { - internal Artifact(ChannelOwnerBase parent, string guid, ArtifactInitializer initializer) : base(parent, guid) + internal Artifact(ChannelOwner parent, string guid, ArtifactInitializer initializer) : base(parent, guid) { AbsolutePath = initializer.AbsolutePath; } diff --git a/src/Playwright/Core/AssertionsBase.cs b/src/Playwright/Core/AssertionsBase.cs index 90760a4fe2..3cf4e2b19e 100644 --- a/src/Playwright/Core/AssertionsBase.cs +++ b/src/Playwright/Core/AssertionsBase.cs @@ -47,24 +47,24 @@ public AssertionsBase(ILocator actual, bool isNot) IsNot = isNot; } - protected bool IsNot { get; private set; } + protected bool IsNot { get; } - internal Locator ActualLocator { get; private set; } + protected Locator ActualLocator { get; } - internal async Task ExpectImplAsync(string expression, ExpectedTextValue textValue, object expected, string message, FrameExpectOptions options) + protected async Task ExpectImplAsync(string expression, ExpectedTextValue textValue, object expected, string message, FrameExpectOptions options) { await ExpectImplAsync(expression, new ExpectedTextValue[] { textValue }, expected, message, options).ConfigureAwait(false); } - internal async Task ExpectImplAsync(string expression, ExpectedTextValue[] expectedText, object expected, string message, FrameExpectOptions options) + protected async Task ExpectImplAsync(string expression, ExpectedTextValue[] expectedText, object expected, string message, FrameExpectOptions options) { - options = options ?? new(); + options ??= new(); options.ExpectedText = expectedText; options.IsNot = IsNot; await ExpectImplAsync(expression, options, expected, message).ConfigureAwait(false); } - internal async Task ExpectImplAsync(string expression, FrameExpectOptions expectOptions, object expected, string message) + protected async Task ExpectImplAsync(string expression, FrameExpectOptions expectOptions, object expected, string message) { if (expectOptions.Timeout == null) { @@ -87,7 +87,7 @@ internal async Task ExpectImplAsync(string expression, FrameExpectOptions expect } } - internal ExpectedTextValue ExpectedRegex(Regex pattern, ExpectedTextValue options = null) + protected ExpectedTextValue ExpectedRegex(Regex pattern, ExpectedTextValue options = null) { if (pattern == null) { @@ -100,7 +100,7 @@ internal ExpectedTextValue ExpectedRegex(Regex pattern, ExpectedTextValue option return textValue; } - internal FrameExpectOptions ConvertToFrameExpectOptions(object source) => ClassUtils.Clone(source); + protected FrameExpectOptions ConvertToFrameExpectOptions(object source) => ClassUtils.Clone(source); private string FormatValue(object value) { @@ -122,6 +122,6 @@ private string FormatValue(object value) return value.ToString(); } - internal static void SetDefaultTimeout(float timeout) + public static void SetDefaultTimeout(float timeout) => _defaultTimeout = timeout; } diff --git a/src/Playwright/Core/BindingCall.cs b/src/Playwright/Core/BindingCall.cs index d102fbc081..863dc965b0 100644 --- a/src/Playwright/Core/BindingCall.cs +++ b/src/Playwright/Core/BindingCall.cs @@ -33,13 +33,13 @@ namespace Microsoft.Playwright.Core; -internal class BindingCall : ChannelOwnerBase +internal class BindingCall : ChannelOwner { private static readonly Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult"); private readonly BindingCallInitializer _initializer; - public BindingCall(ChannelOwnerBase parent, string guid, BindingCallInitializer initializer) : base(parent, guid) + public BindingCall(ChannelOwner parent, string guid, BindingCallInitializer initializer) : base(parent, guid) { _initializer = initializer; } diff --git a/src/Playwright/Core/Browser.cs b/src/Playwright/Core/Browser.cs index 7d6ebce455..5224b00aae 100644 --- a/src/Playwright/Core/Browser.cs +++ b/src/Playwright/Core/Browser.cs @@ -36,7 +36,7 @@ namespace Microsoft.Playwright.Core; -internal class Browser : ChannelOwnerBase, IBrowser +internal class Browser : ChannelOwner, IBrowser { private readonly BrowserInitializer _initializer; private readonly TaskCompletionSource _closedTcs = new(); @@ -44,7 +44,7 @@ internal class Browser : ChannelOwnerBase, IBrowser internal BrowserType _browserType; internal string _closeReason; - internal Browser(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid) + internal Browser(ChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid) { IsConnected = true; _initializer = initializer; diff --git a/src/Playwright/Core/BrowserContext.cs b/src/Playwright/Core/BrowserContext.cs index a61edfade5..757437230f 100644 --- a/src/Playwright/Core/BrowserContext.cs +++ b/src/Playwright/Core/BrowserContext.cs @@ -38,12 +38,12 @@ namespace Microsoft.Playwright.Core; -internal class BrowserContext : ChannelOwnerBase, IBrowserContext +internal class BrowserContext : ChannelOwner, IBrowserContext { private readonly TaskCompletionSource _closeTcs = new(); private readonly Dictionary _bindings = new(); private readonly BrowserContextInitializer _initializer; - internal readonly Tracing _tracing; + private readonly Tracing _tracing; internal readonly IAPIRequestContext _request; private readonly IDictionary _harRecorders = new Dictionary(); internal readonly List _serviceWorkers = new(); @@ -55,7 +55,7 @@ internal class BrowserContext : ChannelOwnerBase, IBrowserContext internal TimeoutSettings _timeoutSettings = new(); - internal BrowserContext(ChannelOwnerBase parent, string guid, BrowserContextInitializer initializer) : base(parent, guid) + internal BrowserContext(ChannelOwner parent, string guid, BrowserContextInitializer initializer) : base(parent, guid) { _browser = parent as Browser; _browser?._contexts.Add(this); diff --git a/src/Playwright/Core/BrowserType.cs b/src/Playwright/Core/BrowserType.cs index f704d53bec..4cf3d95c89 100644 --- a/src/Playwright/Core/BrowserType.cs +++ b/src/Playwright/Core/BrowserType.cs @@ -34,11 +34,11 @@ namespace Microsoft.Playwright.Core; -internal class BrowserType : ChannelOwnerBase, IBrowserType +internal class BrowserType : ChannelOwner, IBrowserType { private readonly BrowserTypeInitializer _initializer; - internal BrowserType(ChannelOwnerBase parent, string guid, BrowserTypeInitializer initializer) : base(parent, guid) + internal BrowserType(ChannelOwner parent, string guid, BrowserTypeInitializer initializer) : base(parent, guid) { _initializer = initializer; } diff --git a/src/Playwright/Core/CDPSession.cs b/src/Playwright/Core/CDPSession.cs index cf1a23f5d7..0e2de9dbb4 100644 --- a/src/Playwright/Core/CDPSession.cs +++ b/src/Playwright/Core/CDPSession.cs @@ -32,11 +32,11 @@ namespace Microsoft.Playwright.Core; -internal class CDPSession : ChannelOwnerBase, ICDPSession +internal class CDPSession : ChannelOwner, ICDPSession { private readonly Dictionary _cdpSessionEvents = new(); - public CDPSession(ChannelOwnerBase parent, string guid) : base(parent, guid) + public CDPSession(ChannelOwner parent, string guid) : base(parent, guid) { } diff --git a/src/Playwright/Core/Dialog.cs b/src/Playwright/Core/Dialog.cs index 90224b8565..fbdd46831a 100644 --- a/src/Playwright/Core/Dialog.cs +++ b/src/Playwright/Core/Dialog.cs @@ -30,11 +30,11 @@ namespace Microsoft.Playwright.Core; -internal class Dialog : ChannelOwnerBase, IDialog +internal class Dialog : ChannelOwner, IDialog { private readonly DialogInitializer _initializer; - public Dialog(ChannelOwnerBase parent, string guid, DialogInitializer initializer) : base(parent, guid) + public Dialog(ChannelOwner parent, string guid, DialogInitializer initializer) : base(parent, guid) { _initializer = initializer; } diff --git a/src/Playwright/Core/ElementHandle.cs b/src/Playwright/Core/ElementHandle.cs index 4b9dffc1c2..37ea99e443 100644 --- a/src/Playwright/Core/ElementHandle.cs +++ b/src/Playwright/Core/ElementHandle.cs @@ -36,8 +36,7 @@ namespace Microsoft.Playwright.Core; internal class ElementHandle : JSHandle, IElementHandle { - - internal ElementHandle(ChannelOwnerBase parent, string guid, ElementHandleInitializer initializer) : base(parent, guid, initializer) + internal ElementHandle(ChannelOwner parent, string guid, ElementHandleInitializer initializer) : base(parent, guid, initializer) { } diff --git a/src/Playwright/Core/EvaluateArgumentGuidElement.cs b/src/Playwright/Core/EvaluateArgumentGuidElement.cs deleted file mode 100644 index 63a89e3434..0000000000 --- a/src/Playwright/Core/EvaluateArgumentGuidElement.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * MIT License - * - * Copyright (c) Microsoft Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace Microsoft.Playwright.Core; - -internal class EvaluateArgumentGuidElement -{ - public string Guid { get; set; } -} diff --git a/src/Playwright/Core/Frame.cs b/src/Playwright/Core/Frame.cs index 8c31df9e96..55650c4106 100644 --- a/src/Playwright/Core/Frame.cs +++ b/src/Playwright/Core/Frame.cs @@ -40,12 +40,12 @@ namespace Microsoft.Playwright.Core; -internal class Frame : ChannelOwnerBase, IFrame +internal class Frame : ChannelOwner, IFrame { private readonly List _loadStates = new(); internal readonly List _childFrames = new(); - internal Frame(ChannelOwnerBase parent, string guid, FrameInitializer initializer) : base(parent, guid) + internal Frame(ChannelOwner parent, string guid, FrameInitializer initializer) : base(parent, guid) { Url = initializer.Url; Name = initializer.Name; @@ -1044,7 +1044,6 @@ public ILocator GetByTitle(Regex text, FrameGetByTitleOptions options = null) internal class SelectOptionValueProtocol { - #nullable enable [JsonPropertyName("value")] public string? Value { get; set; } @@ -1069,3 +1068,19 @@ internal static SelectOptionValueProtocol From(SelectOptionValue value) }; } } + +internal class FrameNavigatedEventArgs +{ + public string Name { get; set; } + + public string Url { get; set; } + + public string Error { get; set; } + + internal NavigateDocument NewDocument { get; set; } +} + +internal class NavigateDocument +{ + public Request Request { get; set; } +} diff --git a/src/Playwright/Core/FrameNavigatedEventArgs.cs b/src/Playwright/Core/FrameNavigatedEventArgs.cs deleted file mode 100644 index 1220a917c1..0000000000 --- a/src/Playwright/Core/FrameNavigatedEventArgs.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - * MIT License - * - * Copyright (c) Microsoft Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace Microsoft.Playwright.Core; - -internal class FrameNavigatedEventArgs -{ - public string Name { get; set; } - - public string Url { get; set; } - - public string Error { get; set; } - - internal NavigateDocument NewDocument { get; set; } -} - -internal class NavigateDocument -{ - public Request Request { get; set; } -} diff --git a/src/Playwright/Core/HarRouter.cs b/src/Playwright/Core/HarRouter.cs index 04e6a77163..6040d4061f 100644 --- a/src/Playwright/Core/HarRouter.cs +++ b/src/Playwright/Core/HarRouter.cs @@ -29,7 +29,7 @@ namespace Microsoft.Playwright.Core; -internal class HarRouter +internal sealed class HarRouter { private readonly LocalUtils _localUtils; diff --git a/src/Playwright/Core/JSHandle.cs b/src/Playwright/Core/JSHandle.cs index a45da03666..cf5b2fd07d 100644 --- a/src/Playwright/Core/JSHandle.cs +++ b/src/Playwright/Core/JSHandle.cs @@ -32,14 +32,14 @@ namespace Microsoft.Playwright.Core; -internal class JSHandle : ChannelOwnerBase, IJSHandle +internal class JSHandle : ChannelOwner, IJSHandle { - internal JSHandle(ChannelOwnerBase parent, string guid, JSHandleInitializer initializer) : base(parent, guid) + internal JSHandle(ChannelOwner parent, string guid, JSHandleInitializer initializer) : base(parent, guid) { Preview = initializer.Preview; } - internal string Preview { get; set; } + protected string Preview { get; set; } [MethodImpl(MethodImplOptions.NoInlining)] public IElementHandle AsElement() => this as IElementHandle; diff --git a/src/Playwright/Core/JsonPipe.cs b/src/Playwright/Core/JsonPipe.cs index baef0ab65c..5c90181483 100644 --- a/src/Playwright/Core/JsonPipe.cs +++ b/src/Playwright/Core/JsonPipe.cs @@ -33,11 +33,11 @@ namespace Microsoft.Playwright.Core; -internal class JsonPipe : ChannelOwnerBase +internal class JsonPipe : ChannelOwner { private readonly JsonPipeInitializer _initializer; - public JsonPipe(ChannelOwnerBase parent, string guid, JsonPipeInitializer initializer) : base(parent, guid) + public JsonPipe(ChannelOwner parent, string guid, JsonPipeInitializer initializer) : base(parent, guid) { _initializer = initializer; } diff --git a/src/Playwright/Core/LocalUtils.cs b/src/Playwright/Core/LocalUtils.cs index fb777c6b77..fa8b104d64 100644 --- a/src/Playwright/Core/LocalUtils.cs +++ b/src/Playwright/Core/LocalUtils.cs @@ -31,11 +31,11 @@ namespace Microsoft.Playwright.Core; -internal class LocalUtils : ChannelOwnerBase +internal class LocalUtils : ChannelOwner { internal readonly Dictionary _devices = new(); - public LocalUtils(ChannelOwnerBase parent, string guid, LocalUtilsInitializer initializer) : base(parent, guid) + public LocalUtils(ChannelOwner parent, string guid, LocalUtilsInitializer initializer) : base(parent, guid) { foreach (var entry in initializer.DeviceDescriptors) { diff --git a/src/Playwright/Core/Locator.cs b/src/Playwright/Core/Locator.cs index 2b2ff5504d..77ebef0893 100644 --- a/src/Playwright/Core/Locator.cs +++ b/src/Playwright/Core/Locator.cs @@ -371,10 +371,7 @@ private T ConvertOptions(object source, T inheritFrom = default) foreach (var sourceProperty in sourceType.GetProperties()) { var targetProperty = targetType.GetProperty(sourceProperty.Name); - if (targetProperty != null) - { - targetProperty.SetValue(target, sourceProperty.GetValue(source)); - } + targetProperty?.SetValue(target, sourceProperty.GetValue(source)); } } var strictProperty = targetType.GetProperty("Strict"); @@ -564,7 +561,7 @@ private static string EscapeForAttributeSelector(string value, bool exact) // cssEscape(value).replace(/\\ /g, ' ') // However, our attribute selectors do not conform to CSS parsing spec, // so we escape them differently. - var exactFlag = (exact == true) ? string.Empty : "i"; + var exactFlag = exact ? string.Empty : "i"; return $"\"{value.Replace("\\", "\\\\").Replace("\"", "\\\"")}\"{exactFlag}"; } diff --git a/src/Playwright/Core/LocatorAssertions.cs b/src/Playwright/Core/LocatorAssertions.cs index 75e1d526e1..74c5a4fe1a 100644 --- a/src/Playwright/Core/LocatorAssertions.cs +++ b/src/Playwright/Core/LocatorAssertions.cs @@ -75,11 +75,11 @@ public Task ToBeEnabledAsync(LocatorAssertionsToBeEnabledOptions options = null) public Task ToBeInViewportAsync(LocatorAssertionsToBeInViewportOptions options = null) { var frameExpectOptions = ConvertToFrameExpectOptions(options); - if (options != null && options.Ratio != null) + if (options?.Ratio != null) { frameExpectOptions.ExpectedNumber = (float)options.Ratio; } - return ExpectTrueAsync("to.be.in.viewport", $"Locator expected to be in viewport", frameExpectOptions); + return ExpectTrueAsync("to.be.in.viewport", "Locator expected to be in viewport", frameExpectOptions); } public Task ToBeVisibleAsync(LocatorAssertionsToBeVisibleOptions options = null) diff --git a/src/Playwright/Core/Page.cs b/src/Playwright/Core/Page.cs index be3484423e..d35dd44552 100644 --- a/src/Playwright/Core/Page.cs +++ b/src/Playwright/Core/Page.cs @@ -38,13 +38,9 @@ namespace Microsoft.Playwright.Core; -internal class Page : ChannelOwnerBase, IPage +internal class Page : ChannelOwner, IPage { private readonly List _frames = new(); - private readonly IAccessibility _accessibility; - private readonly IMouse _mouse; - private readonly IKeyboard _keyboard; - private readonly ITouchscreen _touchscreen; private readonly PageInitializer _initializer; internal readonly List _workers = new(); @@ -53,7 +49,7 @@ internal class Page : ChannelOwnerBase, IPage private Video _video; private string _closeReason; - internal Page(ChannelOwnerBase parent, string guid, PageInitializer initializer) : base(parent, guid) + internal Page(ChannelOwner parent, string guid, PageInitializer initializer) : base(parent, guid) { Context = (BrowserContext)parent; _timeoutSettings = new(Context._timeoutSettings); @@ -67,10 +63,10 @@ internal Page(ChannelOwnerBase parent, string guid, PageInitializer initializer) } IsClosed = initializer.IsClosed; - _accessibility = new Accessibility(this); - _keyboard = new Keyboard(this); - _touchscreen = new Touchscreen(this); - _mouse = new Mouse(this); + Accessibility = new Accessibility(this); + Keyboard = new Keyboard(this); + Touchscreen = new Touchscreen(this); + Mouse = new Mouse(this); APIRequest = Context._request; _initializer = initializer; @@ -173,29 +169,21 @@ public event EventHandler FileChooser public IAccessibility Accessibility { - get => _accessibility; - set => throw new NotSupportedException(); + get; } public IMouse Mouse { - get => _mouse; - set => throw new NotSupportedException(); + get; } public string Url => MainFrame.Url; public IReadOnlyList