1313// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1414// KIND, either express or implied. See the License for the
1515// specific language governing permissions and limitations
16- // under the License.
16+ // under the License.writeTo
1717
1818package org .openqa .selenium .remote ;
1919
20+ import static com .google .common .collect .ImmutableMap .of ;
2021import static io .appium .java_client .remote .MobileCapabilityType .FORCE_MJSONWP ;
2122import static java .nio .charset .StandardCharsets .UTF_8 ;
22- import static java .util .Arrays .asList ;
2323import static java .util .Optional .ofNullable ;
2424import static java .util .stream .Collectors .toList ;
2525import static org .openqa .selenium .json .Json .LIST_OF_MAPS_TYPE ;
6767import java .util .*;
6868import java .util .function .Function ;
6969import java .util .function .Predicate ;
70- import java .util .logging .Logger ;
7170import java .util .regex .Pattern ;
7271import java .util .stream .Collectors ;
7372import java .util .stream .Stream ;
7473
7574
7675public class NewSessionPayload implements Closeable {
7776
78- private static final Logger LOG = Logger .getLogger (NewSessionPayload .class .getName ());
7977 private static final List <String > APPIUM_CAPABILITIES = ImmutableList .<String >builder ()
8078 .addAll (getAppiumCapabilities (MobileCapabilityType .class ))
8179 .addAll (getAppiumCapabilities (AndroidMobileCapabilityType .class ))
@@ -86,7 +84,6 @@ public class NewSessionPayload implements Closeable {
8684 private final Set <CapabilityTransform > transforms ;
8785 private final boolean forceMobileJSONWP ;
8886
89- private static final Dialect DEFAULT_DIALECT = Dialect .OSS ;
9087 private final static Predicate <String > ACCEPTED_W3C_PATTERNS = Stream .of (
9188 "^[\\ w-]+:.*$" ,
9289 "^acceptInsecureCerts$" ,
@@ -104,7 +101,6 @@ public class NewSessionPayload implements Closeable {
104101
105102 private final Json json = new Json ();
106103 private final FileBackedOutputStream backingStore ;
107- private final ImmutableSet <Dialect > dialects ;
108104
109105 private static List <String > getAppiumCapabilities (Class <?> capabilityList ) {
110106 return Arrays .stream (capabilityList .getDeclaredFields ()).map (field -> {
@@ -118,31 +114,21 @@ private static List<String> getAppiumCapabilities(Class<?> capabilityList) {
118114 }
119115
120116 public static NewSessionPayload create (Capabilities caps ) throws IOException {
121- // We need to convert the capabilities into a new session payload. At this point we're dealing
122- // with references, so I'm Just Sure This Will Be Fine.
123117 boolean forceMobileJSONWP = ofNullable (caps .getCapability (FORCE_MJSONWP ))
124118 .map (o -> {
125119 if (Boolean .class .isAssignableFrom (o .getClass ())) {
126120 return Boolean .class .cast (o );
127121 }
128122 return false ;
129123 }).orElse (false );
124+
130125 HashMap <String , ?> capabilityMap = new HashMap <>(caps .asMap ());
131126 capabilityMap .remove (FORCE_MJSONWP );
132- return create (ImmutableMap .of ("desiredCapabilities" , capabilityMap ), forceMobileJSONWP );
133- }
134-
135- public static NewSessionPayload create (Map <String , ?> source , boolean forceMobileJSONWP ) throws IOException {
136- Objects .requireNonNull (source , "Payload must be set" );
137-
127+ Map <String , ?> source = of ("desiredCapabilities" , capabilityMap );
138128 String json = new Json ().toJson (source );
139129 return new NewSessionPayload (new StringReader (json ), forceMobileJSONWP );
140130 }
141131
142- public static NewSessionPayload create (Reader source , boolean forceMobileJSONWP ) throws IOException {
143- return new NewSessionPayload (source , forceMobileJSONWP );
144- }
145-
146132 private NewSessionPayload (Reader source , boolean forceMobileJSONWP ) throws IOException {
147133 this .forceMobileJSONWP = forceMobileJSONWP ;
148134 // Dedicate up to 10% of all RAM or 20% of available RAM (whichever is smaller) to storing this
@@ -184,7 +170,6 @@ private NewSessionPayload(Reader source, boolean forceMobileJSONWP) throws IOExc
184170 if (getAlwaysMatch () != null || getFirstMatches () != null ) {
185171 dialects .add (Dialect .W3C );
186172 }
187- this .dialects = dialects .build ();
188173
189174 validate ();
190175 }
@@ -304,28 +289,6 @@ private void writeMetaData(JsonOutput out) throws IOException {
304289 }
305290 }
306291
307- private void streamW3CProtocolParameters (JsonOutput out , Map <String , Object > des ) {
308- // Technically we should be building up a combination of "alwaysMatch" and "firstMatch" options.
309- // We're going to do a little processing to figure out what we might be able to do, and assume
310- // that people don't really understand the difference between required and desired (which is
311- // commonly the case). Wish us luck. Looking at the current implementations, people may have
312- // set options for multiple browsers, in which case a compliant W3C remote end won't start
313- // a session. If we find this, then we create multiple firstMatch capabilities. Furrfu.
314- // The table of options are:
315- //
316- // Chrome: chromeOptions
317- // Firefox: moz:.*, firefox_binary, firefox_profile, marionette
318- // Edge: none given
319- // IEDriver: ignoreZoomSetting, initialBrowserUrl, enableElementCacheCleanup,
320- // browserAttachTimeout, enablePersistentHover, requireWindowFocus, logFile, logLevel, host,
321- // extractPath, silent, ie.*
322- // Opera: operaOptions
323- // SafariDriver: safari.options
324- //
325- // We can't use the constants defined in the classes because it would introduce circular
326- // dependencies between the remote library and the implementations. Yay!
327- }
328-
329292 /**
330293 * Stream the {@link Capabilities} encoded in the payload used to create this instance. The
331294 * {@link Stream} will start with a {@link Capabilities} object matching the OSS capabilities, and
@@ -351,10 +314,6 @@ public Stream<Capabilities> stream() throws IOException {
351314 .map (ImmutableCapabilities ::new );
352315 }
353316
354- public ImmutableSet <Dialect > getDownstreamDialects () {
355- return dialects .isEmpty () ? ImmutableSet .of (DEFAULT_DIALECT ) : dialects ;
356- }
357-
358317 @ Override
359318 public void close () throws IOException {
360319 backingStore .reset ();
@@ -417,14 +376,7 @@ private Stream<Map<String, Object>> getW3C() throws IOException {
417376 .map (first -> ImmutableMap .<String , Object >builder ().putAll (always ).putAll (first ).build ())
418377 .map (this ::applyTransforms )
419378 .map (map -> map .entrySet ().stream ()
420- .filter (entry -> {
421- if (forceMobileJSONWP ) {
422- return ACCEPTED_W3C_PATTERNS .test (entry .getKey ());
423- }
424- else {
425- return true ;
426- }
427- })
379+ .filter (entry -> !forceMobileJSONWP || ACCEPTED_W3C_PATTERNS .test (entry .getKey ()))
428380 .map ((Function <Map .Entry <String , Object >, Map .Entry <String , Object >>) stringObjectEntry ->
429381 new Map .Entry <String , Object >() {
430382 @ Override
@@ -451,7 +403,7 @@ public Object setValue(Object value) {
451403 fromOss = Stream .of ();
452404 }
453405
454- Stream <Map <String , Object >> fromW3c = null ;
406+ Stream <Map <String , Object >> fromW3c ;
455407 Map <String , Object > alwaysMatch = getAlwaysMatch ();
456408 Collection <Map <String , Object >> firsts = getFirstMatches ();
457409
0 commit comments