18
18
package org .openqa .selenium .grid .router ;
19
19
20
20
import com .google .common .collect .ImmutableMap ;
21
+ import com .google .common .collect .ImmutableSet ;
21
22
22
23
import org .junit .jupiter .api .AfterEach ;
23
24
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 ;
25
28
import org .openqa .selenium .ImmutableCapabilities ;
26
29
import org .openqa .selenium .events .EventBus ;
27
30
import org .openqa .selenium .events .local .GuavaEventBus ;
50
53
import java .util .UUID ;
51
54
import java .util .concurrent .CountDownLatch ;
52
55
import java .util .concurrent .atomic .AtomicReference ;
56
+ import java .util .function .Supplier ;
57
+ import java .util .stream .Stream ;
53
58
54
59
import static java .util .concurrent .TimeUnit .SECONDS ;
55
60
import static org .assertj .core .api .Assertions .assertThat ;
56
61
import static org .openqa .selenium .remote .http .HttpMethod .GET ;
57
62
58
- class ProxyCdpTest {
63
+ class ProxyWebsocketTest {
59
64
60
65
private final HttpHandler nullHandler = req -> new HttpResponse ();
61
66
private final Config emptyConfig = new MapConfig (Collections .emptyMap ());
62
67
private Server <?> proxyServer ;
63
68
private SessionMap sessions ;
64
69
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
+
65
83
@ BeforeEach
66
84
public void setUp () {
67
85
Tracer tracer = DefaultTestTracer .createTracer ();
@@ -81,8 +99,12 @@ public void tearDown() {
81
99
proxyServer .stop ();
82
100
}
83
101
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
+
86
108
HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
87
109
88
110
// Create a backend server which will capture any incoming text message
@@ -96,7 +118,7 @@ void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedEx
96
118
97
119
// Now! Send a message. We expect it to eventually show up in the backend
98
120
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 (){})) {
100
122
101
123
socket .sendText ("Cheese!" );
102
124
@@ -105,8 +127,11 @@ void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedEx
105
127
}
106
128
}
107
129
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 );
110
135
HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
111
136
112
137
Server <?> backend = createBackendServer (new CountDownLatch (1 ), new AtomicReference <>(), "Asiago" , emptyConfig );
@@ -119,7 +144,7 @@ void shouldForwardTextMessageFromServerToLocalEnd() throws URISyntaxException, I
119
144
CountDownLatch latch = new CountDownLatch (1 );
120
145
AtomicReference <String > text = new AtomicReference <>();
121
146
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 () {
123
148
@ Override
124
149
public void onText (CharSequence data ) {
125
150
text .set (data .toString ());
@@ -134,10 +159,11 @@ public void onText(CharSequence data) {
134
159
}
135
160
}
136
161
137
- @ Test
138
- void shouldBeAbleToSendMessagesOverSecureWebSocket ()
162
+ @ ParameterizedTest
163
+ @ MethodSource ("data" )
164
+ void shouldBeAbleToSendMessagesOverSecureWebSocket (Supplier <String > values )
139
165
throws URISyntaxException , InterruptedException {
140
-
166
+ setFields ( values );
141
167
Config secureConfig = new MapConfig (ImmutableMap .of (
142
168
"server" , ImmutableMap .of (
143
169
"https-self-signed" , true )));
@@ -158,7 +184,7 @@ void shouldBeAbleToSendMessagesOverSecureWebSocket()
158
184
CountDownLatch latch = new CountDownLatch (1 );
159
185
AtomicReference <String > text = new AtomicReference <>();
160
186
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 () {
162
188
@ Override
163
189
public void onText (CharSequence data ) {
164
190
text .set (data .toString ());
0 commit comments