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
49 changes: 22 additions & 27 deletions dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,9 @@ public Task<HandleUserPromptResult> HandleUserPromptAsync(HandleUserPromptOption
return BiDi.BrowsingContext.HandleUserPromptAsync(this, options);
}

public Task<GetTreeResult> GetTreeAsync(BrowsingContextGetTreeOptions? options = null)
public Task<GetTreeResult> GetTreeAsync(ContextGetTreeOptions? options = null)
{
GetTreeOptions getTreeOptions = new(options)
{
Root = this
};

return BiDi.BrowsingContext.GetTreeAsync(getTreeOptions);
return BiDi.BrowsingContext.GetTreeAsync(ContextGetTreeOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationStartedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -139,7 +134,7 @@ public Task<Subscription> OnNavigationStartedAsync(Func<NavigationInfo, Task> ha
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationStartedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -150,7 +145,7 @@ public Task<Subscription> OnNavigationStartedAsync(Action<NavigationInfo> handle
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnFragmentNavigatedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -161,7 +156,7 @@ public Task<Subscription> OnFragmentNavigatedAsync(Func<NavigationInfo, Task> ha
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnFragmentNavigatedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -172,7 +167,7 @@ public Task<Subscription> OnFragmentNavigatedAsync(Action<NavigationInfo> handle
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnHistoryUpdatedAsync(Func<HistoryUpdatedEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -183,7 +178,7 @@ public Task<Subscription> OnHistoryUpdatedAsync(Func<HistoryUpdatedEventArgs, Ta
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnHistoryUpdatedAsync(Action<HistoryUpdatedEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -194,7 +189,7 @@ public Task<Subscription> OnHistoryUpdatedAsync(Action<HistoryUpdatedEventArgs>
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDomContentLoadedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -205,7 +200,7 @@ public Task<Subscription> OnDomContentLoadedAsync(Func<NavigationInfo, Task> han
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDomContentLoadedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -216,7 +211,7 @@ public Task<Subscription> OnDomContentLoadedAsync(Action<NavigationInfo> handler
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnLoadAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -227,7 +222,7 @@ public Task<Subscription> OnLoadAsync(Action<NavigationInfo> handler, ContextSub
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnLoadAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -238,7 +233,7 @@ public Task<Subscription> OnLoadAsync(Func<NavigationInfo, Task> handler, Contex
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDownloadWillBeginAsync(Action<DownloadWillBeginEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -249,7 +244,7 @@ public Task<Subscription> OnDownloadWillBeginAsync(Action<DownloadWillBeginEvent
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDownloadWillBeginAsync(Func<DownloadWillBeginEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -260,7 +255,7 @@ public Task<Subscription> OnDownloadWillBeginAsync(Func<DownloadWillBeginEventAr
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDownloadEndAsync(Action<DownloadEndEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -271,7 +266,7 @@ public Task<Subscription> OnDownloadEndAsync(Action<DownloadEndEventArgs> handle
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnDownloadEndAsync(Func<DownloadEndEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -282,7 +277,7 @@ public Task<Subscription> OnDownloadEndAsync(Func<DownloadEndEventArgs, Task> ha
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationAbortedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -293,7 +288,7 @@ public Task<Subscription> OnNavigationAbortedAsync(Action<NavigationInfo> handle
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationAbortedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -304,7 +299,7 @@ public Task<Subscription> OnNavigationAbortedAsync(Func<NavigationInfo, Task> ha
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationFailedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -315,7 +310,7 @@ public Task<Subscription> OnNavigationFailedAsync(Action<NavigationInfo> handler
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationFailedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -326,7 +321,7 @@ public Task<Subscription> OnNavigationFailedAsync(Func<NavigationInfo, Task> han
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationCommittedAsync(Action<NavigationInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -337,7 +332,7 @@ public Task<Subscription> OnNavigationCommittedAsync(Action<NavigationInfo> hand
{
handler(e);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public Task<Subscription> OnNavigationCommittedAsync(Func<NavigationInfo, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -348,7 +343,7 @@ public Task<Subscription> OnNavigationCommittedAsync(Func<NavigationInfo, Task>
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(this));
}, ContextSubscriptionOptions.WithContext(options, this));
}

public bool Equals(BrowsingContext? other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Task<Subscription> OnFileDialogOpenedAsync(Func<FileDialogInfo, Task> han
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnFileDialogOpenedAsync(Action<FileDialogInfo> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -60,6 +60,6 @@ public Task<Subscription> OnFileDialogOpenedAsync(Action<FileDialogInfo> handler
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task<Subscription> OnEntryAddedAsync(Func<Log.LogEntry, Task> handler, Co
{
return logModule.OnEntryAddedAsync(async args =>
{
if (args.Source.Context?.Equals(context) is true)
if (context.Equals(args.Source.Context))
{
await handler(args).ConfigureAwait(false);
}
Expand All @@ -40,7 +40,7 @@ public Task<Subscription> OnEntryAddedAsync(Action<Log.LogEntry> handler, Contex
{
return logModule.OnEntryAddedAsync(args =>
{
if (args.Source.Context?.Equals(context) is true)
if (context.Equals(args.Source.Context))
{
handler(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,14 @@ await interception.OnAuthRequiredAsync(
return interception;
}

public Task<AddDataCollectorResult> AddDataCollectorAsync(IEnumerable<DataType> dataTypes, int maxEncodedDataSize, BrowsingContextAddDataCollectorOptions? options = null)
public Task<AddDataCollectorResult> AddDataCollectorAsync(IEnumerable<DataType> dataTypes, int maxEncodedDataSize, ContextAddDataCollectorOptions? options = null)
{
AddDataCollectorOptions addDataCollectorOptions = new(options)
{
Contexts = [context]
};

return networkModule.AddDataCollectorAsync(dataTypes, maxEncodedDataSize, addDataCollectorOptions);
return networkModule.AddDataCollectorAsync(dataTypes, maxEncodedDataSize, ContextAddDataCollectorOptions.WithContext(options, context));
}

public Task<SetCacheBehaviorResult> SetCacheBehaviorAsync(CacheBehavior behavior, BrowsingContextSetCacheBehaviorOptions? options = null)
public Task<SetCacheBehaviorResult> SetCacheBehaviorAsync(CacheBehavior behavior, ContextSetCacheBehaviorOptions? options = null)
{
SetCacheBehaviorOptions setCacheBehaviorOptions = new(options)
{
Contexts = [context]
};

return networkModule.SetCacheBehaviorAsync(behavior, setCacheBehaviorOptions);
return networkModule.SetCacheBehaviorAsync(behavior, ContextSetCacheBehaviorOptions.WithContext(options, context));
}

public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -108,7 +98,7 @@ public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventAr
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnBeforeRequestSentAsync(Action<BeforeRequestSentEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -119,7 +109,7 @@ public Task<Subscription> OnBeforeRequestSentAsync(Action<BeforeRequestSentEvent
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnResponseStartedAsync(Func<ResponseStartedEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -130,7 +120,7 @@ public Task<Subscription> OnResponseStartedAsync(Func<ResponseStartedEventArgs,
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnResponseStartedAsync(Action<ResponseStartedEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -141,7 +131,7 @@ public Task<Subscription> OnResponseStartedAsync(Action<ResponseStartedEventArgs
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnResponseCompletedAsync(Func<ResponseCompletedEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -152,7 +142,7 @@ public Task<Subscription> OnResponseCompletedAsync(Func<ResponseCompletedEventAr
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnResponseCompletedAsync(Action<ResponseCompletedEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -163,7 +153,7 @@ public Task<Subscription> OnResponseCompletedAsync(Action<ResponseCompletedEvent
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnFetchErrorAsync(Func<FetchErrorEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -174,7 +164,7 @@ public Task<Subscription> OnFetchErrorAsync(Func<FetchErrorEventArgs, Task> hand
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnFetchErrorAsync(Action<FetchErrorEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -185,7 +175,7 @@ public Task<Subscription> OnFetchErrorAsync(Action<FetchErrorEventArgs> handler,
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnAuthRequiredAsync(Func<AuthRequiredEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -196,7 +186,7 @@ public Task<Subscription> OnAuthRequiredAsync(Func<AuthRequiredEventArgs, Task>
{
await handler(e).ConfigureAwait(false);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}

public Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs> handler, ContextSubscriptionOptions? options = null)
Expand All @@ -207,12 +197,12 @@ public Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs> hand
{
handler(e);
}
}, options.WithContext(context));
}, ContextSubscriptionOptions.WithContext(options, context));
}
}

public sealed record InterceptRequestOptions : BrowsingContextAddInterceptOptions;
public sealed class InterceptRequestOptions : ContextAddInterceptOptions;

public sealed record InterceptResponseOptions : BrowsingContextAddInterceptOptions;
public sealed class InterceptResponseOptions : ContextAddInterceptOptions;

public sealed record InterceptAuthOptions : BrowsingContextAddInterceptOptions;
public sealed class InterceptAuthOptions : ContextAddInterceptOptions;
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,14 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext;

public sealed class BrowsingContextScriptModule(BrowsingContext context, ScriptModule scriptModule)
{
public async Task<AddPreloadScriptResult> AddPreloadScriptAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, BrowsingContextAddPreloadScriptOptions? options = null)
public Task<AddPreloadScriptResult> AddPreloadScriptAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, ContextAddPreloadScriptOptions? options = null)
{
AddPreloadScriptOptions addPreloadScriptOptions = new(options)
{
Contexts = [context]
};

return await scriptModule.AddPreloadScriptAsync(functionDeclaration, addPreloadScriptOptions).ConfigureAwait(false);
return scriptModule.AddPreloadScriptAsync(functionDeclaration, ContextAddPreloadScriptOptions.WithContext(options, context));
}

public async Task<GetRealmsResult> GetRealmsAsync(GetRealmsOptions? options = null)
public Task<GetRealmsResult> GetRealmsAsync(ContextGetRealmsOptions? options = null)
{
options ??= new();

options.Context = context;

return await scriptModule.GetRealmsAsync(options).ConfigureAwait(false);
return scriptModule.GetRealmsAsync(ContextGetRealmsOptions.WithContext(options, context));
}

public Task<EvaluateResult> EvaluateAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null)
Expand Down
Loading