|
18 | 18 | package org.openqa.selenium.grid.data; |
19 | 19 |
|
20 | 20 | import java.io.Serializable; |
21 | | -import java.util.Arrays; |
22 | | -import java.util.List; |
23 | 21 | import java.util.Objects; |
24 | 22 | import org.openqa.selenium.Capabilities; |
25 | 23 |
|
|
44 | 42 | */ |
45 | 43 | public class DefaultSlotMatcher implements SlotMatcher, Serializable { |
46 | 44 |
|
47 | | - /* |
48 | | - List of prefixed extension capabilities we never should try to match, they should be |
49 | | - matched in the Node or in the browser driver. |
50 | | - */ |
51 | | - private static final List<String> EXTENSION_CAPABILITIES_PREFIXES = |
52 | | - Arrays.asList("goog:", "moz:", "ms:", "se:"); |
53 | | - |
54 | 45 | @Override |
55 | 46 | public boolean matches(Capabilities stereotype, Capabilities capabilities) { |
56 | 47 |
|
@@ -93,25 +84,21 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) { |
93 | 84 |
|
94 | 85 | private Boolean initialMatch(Capabilities stereotype, Capabilities capabilities) { |
95 | 86 | return stereotype.getCapabilityNames().stream() |
96 | | - // Matching of extension capabilities is implementation independent. Skip them |
97 | | - .filter(name -> !name.contains(":")) |
98 | | - // Platform matching is special, we do it later |
99 | | - .filter(name -> !"platformName".equalsIgnoreCase(name)) |
100 | | - .map( |
101 | | - name -> { |
102 | | - if (capabilities.getCapability(name) instanceof String) { |
103 | | - return stereotype |
104 | | - .getCapability(name) |
105 | | - .toString() |
106 | | - .equalsIgnoreCase(capabilities.getCapability(name).toString()); |
107 | | - } else { |
108 | | - return capabilities.getCapability(name) == null |
109 | | - || Objects.equals( |
110 | | - stereotype.getCapability(name), capabilities.getCapability(name)); |
111 | | - } |
112 | | - }) |
113 | | - .reduce(Boolean::logicalAnd) |
114 | | - .orElse(true); |
| 87 | + // Matching of extension capabilities is implementation independent. Skip them |
| 88 | + .filter(name -> !name.contains(":")) |
| 89 | + // Platform matching is special, we do it later |
| 90 | + .filter(name -> !"platformName".equalsIgnoreCase(name)) |
| 91 | + .filter(name -> capabilities.getCapability(name) != null) |
| 92 | + .map(name -> { |
| 93 | + if (stereotype.getCapability(name) instanceof String && |
| 94 | + capabilities.getCapability(name) instanceof String) { |
| 95 | + return ((String) stereotype.getCapability(name)) |
| 96 | + .equalsIgnoreCase((String) capabilities.getCapability(name)); |
| 97 | + } |
| 98 | + return Objects.equals(stereotype.getCapability(name), capabilities.getCapability(name)); |
| 99 | + }) |
| 100 | + .reduce(Boolean::logicalAnd) |
| 101 | + .orElse(true); |
115 | 102 | } |
116 | 103 |
|
117 | 104 | private Boolean managedDownloadsEnabled(Capabilities stereotype, Capabilities capabilities) { |
@@ -145,29 +132,22 @@ private Boolean platformVersionMatch(Capabilities stereotype, Capabilities capab |
145 | 132 | } |
146 | 133 |
|
147 | 134 | private Boolean extensionCapabilitiesMatch(Capabilities stereotype, Capabilities capabilities) { |
148 | | - /* |
149 | | - We match extension capabilities when they are not prefixed with any of the |
150 | | - EXTENSION_CAPABILITIES_PREFIXES items. Also, we match them only when the capabilities |
151 | | - of the new session request contains that specific extension capability. |
152 | | - */ |
153 | 135 | return stereotype.getCapabilityNames().stream() |
154 | | - .filter(name -> name.contains(":")) |
155 | | - .filter(name -> capabilities.asMap().containsKey(name)) |
156 | | - .filter(name -> EXTENSION_CAPABILITIES_PREFIXES.stream().noneMatch(name::contains)) |
157 | | - .map( |
158 | | - name -> { |
159 | | - if (capabilities.getCapability(name) instanceof String) { |
160 | | - return stereotype |
161 | | - .getCapability(name) |
162 | | - .toString() |
163 | | - .equalsIgnoreCase(capabilities.getCapability(name).toString()); |
164 | | - } else { |
165 | | - return capabilities.getCapability(name) == null |
166 | | - || Objects.equals( |
167 | | - stereotype.getCapability(name), capabilities.getCapability(name)); |
168 | | - } |
169 | | - }) |
170 | | - .reduce(Boolean::logicalAnd) |
171 | | - .orElse(true); |
| 136 | + .filter(name -> name.contains(":")) |
| 137 | + .filter(name -> capabilities.getCapability(name) != null) |
| 138 | + .map(name -> { |
| 139 | + if (stereotype.getCapability(name) instanceof String && |
| 140 | + capabilities.getCapability(name) instanceof String) { |
| 141 | + return ((String) stereotype.getCapability(name)) |
| 142 | + .equalsIgnoreCase((String) capabilities.getCapability(name)); |
| 143 | + } |
| 144 | + if (capabilities.getCapability(name) instanceof Number || |
| 145 | + capabilities.getCapability(name) instanceof Boolean) { |
| 146 | + return Objects.equals(stereotype.getCapability(name), capabilities.getCapability(name)); |
| 147 | + } |
| 148 | + return true; |
| 149 | + }) |
| 150 | + .reduce(Boolean::logicalAnd) |
| 151 | + .orElse(true); |
172 | 152 | } |
173 | 153 | } |
0 commit comments