Skip to content

Commit 05039ab

Browse files
committed
[grid] Update proxy test to include bidi
1 parent 1fe43fa commit 05039ab

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

java/test/org/openqa/selenium/grid/router/ProxyCdpTest.java renamed to java/test/org/openqa/selenium/grid/router/ProxyWebsocketTest.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
package org.openqa.selenium.grid.router;
1919

2020
import com.google.common.collect.ImmutableMap;
21+
import com.google.common.collect.ImmutableSet;
2122

2223
import org.junit.jupiter.api.AfterEach;
2324
import org.junit.jupiter.api.BeforeEach;
24-
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.provider.Arguments;
27+
import org.junit.jupiter.params.provider.MethodSource;
2528
import org.openqa.selenium.ImmutableCapabilities;
2629
import org.openqa.selenium.events.EventBus;
2730
import org.openqa.selenium.events.local.GuavaEventBus;
@@ -50,18 +53,33 @@
5053
import java.util.UUID;
5154
import java.util.concurrent.CountDownLatch;
5255
import java.util.concurrent.atomic.AtomicReference;
56+
import java.util.function.Supplier;
57+
import java.util.stream.Stream;
5358

5459
import static java.util.concurrent.TimeUnit.SECONDS;
5560
import static org.assertj.core.api.Assertions.assertThat;
5661
import static org.openqa.selenium.remote.http.HttpMethod.GET;
5762

58-
class ProxyCdpTest {
63+
class ProxyWebsocketTest {
5964

6065
private final HttpHandler nullHandler = req -> new HttpResponse();
6166
private final Config emptyConfig = new MapConfig(Collections.emptyMap());
6267
private Server<?> proxyServer;
6368
private SessionMap sessions;
6469

70+
private String protocol;
71+
72+
public static Stream<Arguments> data() {
73+
Supplier<String> s1 = () -> "cdp";
74+
Supplier<String> s2 = () -> "bidi";
75+
76+
return ImmutableSet.of(s1, s2).stream().map(Arguments::of);
77+
}
78+
79+
public void setFields(Supplier<String> values) {
80+
this.protocol = values.get();
81+
}
82+
6583
@BeforeEach
6684
public void setUp() {
6785
Tracer tracer = DefaultTestTracer.createTracer();
@@ -81,8 +99,12 @@ public void tearDown() {
8199
proxyServer.stop();
82100
}
83101

84-
@Test
85-
void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedException {
102+
@ParameterizedTest
103+
@MethodSource("data")
104+
void shouldForwardTextMessageToServer(Supplier<String> values)
105+
throws URISyntaxException, InterruptedException {
106+
setFields(values);
107+
86108
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
87109

88110
// Create a backend server which will capture any incoming text message
@@ -96,7 +118,7 @@ void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedEx
96118

97119
// Now! Send a message. We expect it to eventually show up in the backend
98120
try (WebSocket socket = clientFactory.createClient(proxyServer.getUrl())
99-
.openSocket(new HttpRequest(GET, String.format("/session/%s/cdp", id)), new WebSocket.Listener(){})) {
121+
.openSocket(new HttpRequest(GET, String.format("/session/%s/" + protocol, id)), new WebSocket.Listener(){})) {
100122

101123
socket.sendText("Cheese!");
102124

@@ -105,8 +127,11 @@ void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedEx
105127
}
106128
}
107129

108-
@Test
109-
void shouldForwardTextMessageFromServerToLocalEnd() throws URISyntaxException, InterruptedException {
130+
@ParameterizedTest
131+
@MethodSource("data")
132+
void shouldForwardTextMessageFromServerToLocalEnd(Supplier<String> values)
133+
throws URISyntaxException, InterruptedException {
134+
setFields(values);
110135
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
111136

112137
Server<?> backend = createBackendServer(new CountDownLatch(1), new AtomicReference<>(), "Asiago", emptyConfig);
@@ -119,7 +144,7 @@ void shouldForwardTextMessageFromServerToLocalEnd() throws URISyntaxException, I
119144
CountDownLatch latch = new CountDownLatch(1);
120145
AtomicReference<String> text = new AtomicReference<>();
121146
try(WebSocket socket = clientFactory.createClient(proxyServer.getUrl())
122-
.openSocket(new HttpRequest(GET, String.format("/session/%s/cdp", id)), new WebSocket.Listener() {
147+
.openSocket(new HttpRequest(GET, String.format("/session/%s/" + protocol, id)), new WebSocket.Listener() {
123148
@Override
124149
public void onText(CharSequence data) {
125150
text.set(data.toString());
@@ -134,10 +159,11 @@ public void onText(CharSequence data) {
134159
}
135160
}
136161

137-
@Test
138-
void shouldBeAbleToSendMessagesOverSecureWebSocket()
162+
@ParameterizedTest
163+
@MethodSource("data")
164+
void shouldBeAbleToSendMessagesOverSecureWebSocket(Supplier<String> values)
139165
throws URISyntaxException, InterruptedException {
140-
166+
setFields(values);
141167
Config secureConfig = new MapConfig(ImmutableMap.of(
142168
"server", ImmutableMap.of(
143169
"https-self-signed", true)));
@@ -158,7 +184,7 @@ void shouldBeAbleToSendMessagesOverSecureWebSocket()
158184
CountDownLatch latch = new CountDownLatch(1);
159185
AtomicReference<String> text = new AtomicReference<>();
160186
try (WebSocket socket = clientFactory.createClient(secureProxyServer.getUrl())
161-
.openSocket(new HttpRequest(GET, String.format("/session/%s/cdp", id)), new WebSocket.Listener() {
187+
.openSocket(new HttpRequest(GET, String.format("/session/%s/" + protocol, id)), new WebSocket.Listener() {
162188
@Override
163189
public void onText(CharSequence data) {
164190
text.set(data.toString());

0 commit comments

Comments
 (0)