Skip to content

Commit c83de44

Browse files
committed
implement BiDi setCacheBehavior for java bindings
1 parent 10119a9 commit c83de44

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.openqa.selenium.bidi.network.FetchError;
3636
import org.openqa.selenium.bidi.network.ProvideResponseParameters;
3737
import org.openqa.selenium.bidi.network.ResponseDetails;
38+
import org.openqa.selenium.bidi.network.SetCacheBehaviorParameters;
3839
import org.openqa.selenium.internal.Require;
3940

4041
public class Network implements AutoCloseable {
@@ -137,6 +138,10 @@ public void provideResponse(ProvideResponseParameters parameters) {
137138
this.bidi.send(new Command<>("network.provideResponse", parameters.toMap()));
138139
}
139140

141+
public void setCacheBehavior(SetCacheBehaviorParameters parameters) {
142+
this.bidi.send(new Command<>("network.setCacheBehavior", parameters.toMap()));
143+
}
144+
140145
public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer) {
141146
if (browsingContextIds.isEmpty()) {
142147
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+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
import java.util.List;
21+
import java.util.Map;
22+
import org.openqa.selenium.internal.Require;
23+
24+
public class SetCacheBehaviorParameters {
25+
private final CacheBehavior cacheBehavior;
26+
private final List<String> contexts;
27+
28+
public SetCacheBehaviorParameters(CacheBehavior cacheBehavior) {
29+
this(cacheBehavior, null);
30+
}
31+
32+
public SetCacheBehaviorParameters(CacheBehavior cacheBehavior, List<String> contexts) {
33+
this.cacheBehavior = Require.nonNull("Cache behavior", cacheBehavior);
34+
this.contexts = contexts;
35+
}
36+
37+
public Map<String, Object> toMap() {
38+
Map<String, Object> map = Map.of("cacheBehavior", cacheBehavior.toString());
39+
40+
if (contexts != null && !contexts.isEmpty()) {
41+
return Map.of("cacheBehavior", cacheBehavior.toString(), "contexts", contexts);
42+
}
43+
44+
return map;
45+
}
46+
}

0 commit comments

Comments
 (0)