Skip to content

Commit 1782506

Browse files
authored
Merge branch 'trunk' into fix-install-data
2 parents d7ef9d7 + 535f96f commit 1782506

File tree

11 files changed

+204
-2
lines changed

11 files changed

+204
-2
lines changed

dotnet/src/webdriver/BiDi/Communication/Command.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace OpenQA.Selenium.BiDi.Communication;
5656
[JsonDerivedType(typeof(Modules.Network.ProvideResponseCommand), "network.provideResponse")]
5757
[JsonDerivedType(typeof(Modules.Network.ContinueWithAuthCommand), "network.continueWithAuth")]
5858
[JsonDerivedType(typeof(Modules.Network.RemoveInterceptCommand), "network.removeIntercept")]
59+
[JsonDerivedType(typeof(Modules.Network.SetCacheBehaviorCommand), "network.setCacheBehavior")]
5960

6061
[JsonDerivedType(typeof(Modules.Script.AddPreloadScriptCommand), "script.addPreloadScript")]
6162
[JsonDerivedType(typeof(Modules.Script.RemovePreloadScriptCommand), "script.removePreloadScript")]

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task
6969
return intercept;
7070
}
7171

72+
public Task SetCacheBehaviorAsync(CacheBehavior behavior, BrowsingContextSetCacheBehaviorOptions? options = null)
73+
{
74+
SetCacheBehaviorOptions setCacheBehaviorOptions = new(options)
75+
{
76+
Contexts = [context]
77+
};
78+
79+
return networkModule.SetCacheBehaviorAsync(behavior, setCacheBehaviorOptions);
80+
}
81+
7282
public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, SubscriptionOptions? options = null)
7383
{
7484
return networkModule.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] });

dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArg
6868
return intercept;
6969
}
7070

71+
public async Task SetCacheBehaviorAsync(CacheBehavior behavior, SetCacheBehaviorOptions? options = null)
72+
{
73+
var @params = new SetCacheBehaviorCommandParameters(behavior);
74+
75+
if (options is not null)
76+
{
77+
@params.Contexts = options.Contexts;
78+
}
79+
80+
await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
81+
}
82+
7183
public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
7284
{
7385
var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// <copyright file="SetCacheBehaviorCommand.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System.Collections.Generic;
21+
using OpenQA.Selenium.BiDi.Communication;
22+
23+
#nullable enable
24+
25+
namespace OpenQA.Selenium.BiDi.Modules.Network;
26+
27+
internal class SetCacheBehaviorCommand(SetCacheBehaviorCommandParameters @params) : Command<SetCacheBehaviorCommandParameters>(@params);
28+
29+
internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior) : CommandParameters
30+
{
31+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
32+
}
33+
34+
public record SetCacheBehaviorOptions : CommandOptions
35+
{
36+
public SetCacheBehaviorOptions()
37+
{
38+
39+
}
40+
41+
internal SetCacheBehaviorOptions(BrowsingContextSetCacheBehaviorOptions? options)
42+
{
43+
44+
}
45+
46+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
47+
}
48+
49+
public record BrowsingContextSetCacheBehaviorOptions
50+
{
51+
52+
}
53+
54+
public enum CacheBehavior
55+
{
56+
Default,
57+
Bypass
58+
}

dotnet/test/common/BiDi/Network/NetworkTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,11 @@ public async Task CanFailRequest()
211211

212212
Assert.That(action, Throws.TypeOf<BiDiException>().With.Message.Contain("net::ERR_FAILED").Or.Message.Contain("NS_ERROR_ABORT"));
213213
}
214+
215+
[Test]
216+
public void CanSetCacheBehavior()
217+
{
218+
Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
219+
Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
220+
}
214221
}

java/CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v4.28.1
2+
======
3+
* [java]: Add Locale.ROOT to avoid port formatting issues for all drivers (#15121)
4+
* [grid]: Grid UI could not open session live view (#15132)
5+
16
v4.28.0
27
======
38
* Add CDP for Chrome 132 and remove 129

java/src/org/openqa/selenium/bidi/module/Network.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Collections;
2121
import java.util.HashSet;
22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
2425
import java.util.function.Consumer;
@@ -30,6 +31,7 @@
3031
import org.openqa.selenium.bidi.HasBiDi;
3132
import org.openqa.selenium.bidi.network.AddInterceptParameters;
3233
import org.openqa.selenium.bidi.network.BeforeRequestSent;
34+
import org.openqa.selenium.bidi.network.CacheBehavior;
3335
import org.openqa.selenium.bidi.network.ContinueRequestParameters;
3436
import org.openqa.selenium.bidi.network.ContinueResponseParameters;
3537
import org.openqa.selenium.bidi.network.FetchError;
@@ -137,6 +139,22 @@ public void provideResponse(ProvideResponseParameters parameters) {
137139
this.bidi.send(new Command<>("network.provideResponse", parameters.toMap()));
138140
}
139141

142+
public void setCacheBehavior(CacheBehavior cacheBehavior) {
143+
Require.nonNull("Cache behavior", cacheBehavior);
144+
this.bidi.send(
145+
new Command<>(
146+
"network.setCacheBehavior", Map.of("cacheBehavior", cacheBehavior.toString())));
147+
}
148+
149+
public void setCacheBehavior(CacheBehavior cacheBehavior, List<String> contexts) {
150+
Require.nonNull("Cache behavior", cacheBehavior);
151+
Require.nonNull("Contexts", contexts);
152+
this.bidi.send(
153+
new Command<>(
154+
"network.setCacheBehavior",
155+
Map.of("cacheBehavior", cacheBehavior.toString(), "contexts", contexts)));
156+
}
157+
140158
public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer) {
141159
if (browsingContextIds.isEmpty()) {
142160
this.bidi.addListener(beforeRequestSentEvent, consumer);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.network;
19+
20+
public enum CacheBehavior {
21+
DEFAULT("default"),
22+
BYPASS("bypass");
23+
24+
private final String behavior;
25+
26+
CacheBehavior(String behavior) {
27+
this.behavior = behavior;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return behavior;
33+
}
34+
}

java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.Duration;
2525
import java.time.temporal.ChronoUnit;
26+
import java.util.Collections;
2627
import java.util.concurrent.CountDownLatch;
2728
import java.util.concurrent.TimeUnit;
2829
import org.junit.jupiter.api.Disabled;
@@ -32,6 +33,9 @@
3233
import org.openqa.selenium.TimeoutException;
3334
import org.openqa.selenium.UsernameAndPassword;
3435
import org.openqa.selenium.WebDriverException;
36+
import org.openqa.selenium.WindowType;
37+
import org.openqa.selenium.bidi.BiDiException;
38+
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
3539
import org.openqa.selenium.bidi.module.Network;
3640
import org.openqa.selenium.support.ui.ExpectedConditions;
3741
import org.openqa.selenium.testing.JupiterTestBase;
@@ -264,4 +268,56 @@ void canFailRequest() {
264268
assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class);
265269
}
266270
}
271+
272+
@Test
273+
@NeedsFreshDriver
274+
void canSetCacheBehaviorToBypass() {
275+
try (Network network = new Network(driver)) {
276+
page = appServer.whereIs("basicAuth");
277+
278+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
279+
String contextId = context.getId();
280+
281+
network.setCacheBehavior(CacheBehavior.BYPASS, Collections.singletonList(contextId));
282+
}
283+
}
284+
285+
@Test
286+
@NeedsFreshDriver
287+
void canSetCacheBehaviorToDefault() {
288+
try (Network network = new Network(driver)) {
289+
page = appServer.whereIs("basicAuth");
290+
291+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
292+
String contextId = context.getId();
293+
294+
network.setCacheBehavior(CacheBehavior.DEFAULT, Collections.singletonList(contextId));
295+
}
296+
}
297+
298+
@Test
299+
@NeedsFreshDriver
300+
void canSetCacheBehaviorWithNoContextId() {
301+
try (Network network = new Network(driver)) {
302+
page = appServer.whereIs("basicAuth");
303+
304+
network.setCacheBehavior(CacheBehavior.BYPASS);
305+
network.setCacheBehavior(CacheBehavior.DEFAULT);
306+
}
307+
}
308+
309+
@Test
310+
@NeedsFreshDriver
311+
void throwsExceptionForInvalidContext() {
312+
try (Network network = new Network(driver)) {
313+
page = appServer.whereIs("basicAuth");
314+
315+
assertThatThrownBy(
316+
() ->
317+
network.setCacheBehavior(
318+
CacheBehavior.DEFAULT, Collections.singletonList("invalid-context")))
319+
.isInstanceOf(BiDiException.class)
320+
.hasMessageContaining("no such frame");
321+
}
322+
}
267323
}

java/version.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SE_VERSION = "4.29.0-SNAPSHOT"
1+
SE_VERSION = "4.28.1"
22
TOOLS_JAVA_VERSION = "17"

0 commit comments

Comments
 (0)