|
20 | 20 | import static java.net.HttpURLConnection.HTTP_OK;
|
21 | 21 | import static java.nio.charset.StandardCharsets.UTF_8;
|
22 | 22 | import static org.junit.Assert.assertEquals;
|
| 23 | +import static org.junit.Assert.assertFalse; |
23 | 24 | import static org.junit.Assert.assertTrue;
|
24 | 25 |
|
25 | 26 | import com.google.common.collect.ImmutableList;
|
|
33 | 34 | import org.openqa.selenium.remote.http.HttpClient;
|
34 | 35 | import org.openqa.selenium.remote.http.HttpRequest;
|
35 | 36 | import org.openqa.selenium.remote.http.HttpResponse;
|
| 37 | +import org.openqa.selenium.remote.http.W3CHttpCommandCodec; |
36 | 38 |
|
37 | 39 | import java.io.IOException;
|
| 40 | +import java.util.Collection; |
| 41 | +import java.util.HashSet; |
| 42 | +import java.util.List; |
38 | 43 | import java.util.Map;
|
| 44 | +import java.util.Set; |
| 45 | +import java.util.stream.Collectors; |
39 | 46 |
|
40 | 47 | @SuppressWarnings("unchecked")
|
41 | 48 | @RunWith(JUnit4.class)
|
@@ -187,6 +194,49 @@ public void shouldAddBothGeckoDriverAndW3CCapabilitiesToRootCapabilitiesProperty
|
187 | 194 | assertTrue(capabilities.containsKey("firstMatch"));
|
188 | 195 | }
|
189 | 196 |
|
| 197 | + @Test |
| 198 | + public void shouldNotIncludeNonProtocolExtensionKeys() throws IOException { |
| 199 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 200 | + caps.setCapability("se:option", "cheese"); |
| 201 | + caps.setCapability("option", "I like sausages"); |
| 202 | + caps.setCapability("browserName", "amazing cake browser"); |
| 203 | + |
| 204 | + Map<String, Object> params = ImmutableMap.of("desiredCapabilities", caps); |
| 205 | + Command command = new Command(null, DriverCommand.NEW_SESSION, params); |
| 206 | + |
| 207 | + HttpResponse response = new HttpResponse(); |
| 208 | + response.setStatus(HTTP_OK); |
| 209 | + response.setContent( |
| 210 | + "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}".getBytes(UTF_8)); |
| 211 | + RecordingHttpClient client = new RecordingHttpClient(response); |
| 212 | + |
| 213 | + new ProtocolHandshake().createSession(client, command); |
| 214 | + |
| 215 | + HttpRequest request = client.getRequest(); |
| 216 | + Map<String, Object> handshakeRequest = new Gson().fromJson( |
| 217 | + request.getContentString(), |
| 218 | + new TypeToken<Map<String, Object>>() {}.getType()); |
| 219 | + |
| 220 | + Object rawCaps = handshakeRequest.get("capabilities"); |
| 221 | + assertTrue(rawCaps instanceof Map); |
| 222 | + |
| 223 | + Map<?, ?> capabilities = (Map<?, ?>) rawCaps; |
| 224 | + |
| 225 | + Map<?, ?> always = (Map<?, ?>) capabilities.get("alwaysMatch"); |
| 226 | + List<Map<?, ?>> first = (List<Map<?, ?>>) capabilities.get("firstMatch"); |
| 227 | + |
| 228 | + // We don't care where they are, but we want to see "se:option" and not "option" |
| 229 | + Set<String> keys = new HashSet(always.keySet()); |
| 230 | + keys.addAll(first.stream() |
| 231 | + .map(Map::keySet) |
| 232 | + .flatMap(Collection::stream) |
| 233 | + .map(String::valueOf) |
| 234 | + .collect(Collectors.toSet())); |
| 235 | + assertTrue(keys.contains("browserName")); |
| 236 | + assertTrue(keys.contains("se:option")); |
| 237 | + assertFalse(keys.contains("options")); |
| 238 | + } |
| 239 | + |
190 | 240 | class RecordingHttpClient implements HttpClient {
|
191 | 241 |
|
192 | 242 | private final HttpResponse response;
|
|
0 commit comments