3737import com .github .benmanes .caffeine .cache .Ticker ;
3838import com .google .common .annotations .VisibleForTesting ;
3939import com .google .common .collect .ImmutableList ;
40- import com .google .common .collect .ImmutableMap ;
4140import java .io .Closeable ;
4241import java .io .File ;
4342import java .io .IOException ;
@@ -580,8 +579,8 @@ private boolean managedDownloadsRequested(Capabilities capabilities) {
580579 private Capabilities setDownloadsDirectory (TemporaryFilesystem downloadsTfs , Capabilities caps ) {
581580 File tempDir = downloadsTfs .createTempDir ("download" , "" );
582581 if (Browser .CHROME .is (caps ) || Browser .EDGE .is (caps )) {
583- ImmutableMap <String , Serializable > map =
584- ImmutableMap .of (
582+ Map <String , Serializable > map =
583+ Map .of (
585584 "download.prompt_for_download" ,
586585 false ,
587586 "download.default_directory" ,
@@ -592,8 +591,8 @@ private Capabilities setDownloadsDirectory(TemporaryFilesystem downloadsTfs, Cap
592591 return appendPrefs (caps , optionsKey , map );
593592 }
594593 if (Browser .FIREFOX .is (caps )) {
595- ImmutableMap <String , Serializable > map =
596- ImmutableMap .of (
594+ Map <String , Serializable > map =
595+ Map .of (
597596 "browser.download.folderList" , 2 , "browser.download.dir" , tempDir .getAbsolutePath ());
598597 return appendPrefs (caps , "moz:firefoxOptions" , map );
599598 }
@@ -752,9 +751,7 @@ public HttpResponse downloadFile(HttpRequest req, SessionId id) {
752751 }
753752 }
754753
755- /**
756- * User wants to list files that can be downloaded
757- */
754+ /** User wants to list files that can be downloaded */
758755 private HttpResponse listDownloadedFiles (File downloadsDirectory ) {
759756 List <String > collected =
760757 Arrays .stream (Optional .ofNullable (downloadsDirectory .listFiles ()).orElse (new File [] {}))
@@ -766,38 +763,40 @@ private HttpResponse listDownloadedFiles(File downloadsDirectory) {
766763 }
767764
768765 private HttpResponse getDownloadedFile (HttpRequest req , File downloadsDirectory )
769- throws IOException {
766+ throws IOException {
770767 String raw = string (req );
771768 if (raw .isEmpty ()) {
772769 throw new WebDriverException (
773- "Please specify file to download in payload as {\" name\" : \" fileToDownload\" }" );
770+ "Please specify file to download in payload as {\" name\" : \" fileToDownload\" }" );
774771 }
775772 Map <String , Object > incoming = JSON .toType (raw , Json .MAP_TYPE );
776773 String filename =
777- Optional .ofNullable (incoming .get ("name" ))
778- .map (Object ::toString )
779- .orElseThrow (
780- () ->
781- new WebDriverException (
782- "Please specify file to download in payload as {\" name\" :"
783- + " \" fileToDownload\" }" ));
774+ Optional .ofNullable (incoming .get ("name" ))
775+ .map (Object ::toString )
776+ .orElseThrow (
777+ () ->
778+ new WebDriverException (
779+ "Please specify file to download in payload as {\" name\" :"
780+ + " \" fileToDownload\" }" ));
784781 File [] allFiles =
785- Optional .ofNullable (downloadsDirectory .listFiles ((dir , name ) -> name .equals (filename )))
786- .orElse (new File [] {});
782+ Optional .ofNullable (downloadsDirectory .listFiles ((dir , name ) -> name .equals (filename )))
783+ .orElse (new File [] {});
787784 if (allFiles .length == 0 ) {
788785 throw new WebDriverException (
789- String .format (
790- "Cannot find file [%s] in directory %s." ,
791- filename , downloadsDirectory .getAbsolutePath ()));
786+ String .format (
787+ "Cannot find file [%s] in directory %s." ,
788+ filename , downloadsDirectory .getAbsolutePath ()));
792789 }
793790 if (allFiles .length != 1 ) {
794791 throw new WebDriverException (
795- String .format ("Expected there to be only 1 file. There were: %s." , allFiles .length ));
792+ String .format ("Expected there to be only 1 file. There were: %s." , allFiles .length ));
796793 }
797794 String content = Zip .zip (allFiles [0 ]);
798- Map <String , Object > data = Map .of (
799- "filename" , filename ,
800- "contents" , content );
795+ Map <String , Object > data =
796+ Map .of (
797+ "filename" , filename ,
798+ "file" , getFileInfo (allFiles [0 ]),
799+ "contents" , content );
801800 Map <String , Map <String , Object >> result = Map .of ("value" , data );
802801 return new HttpResponse ().setContent (asJson (result ));
803802 }
@@ -844,7 +843,7 @@ public HttpResponse uploadFile(HttpRequest req, SessionId id) {
844843 String .format ("Expected there to be only 1 file. There were: %s" , allFiles .length ));
845844 }
846845
847- ImmutableMap <String , Object > result = ImmutableMap .of ("value" , allFiles [0 ].getAbsolutePath ());
846+ Map <String , Object > result = Map .of ("value" , allFiles [0 ].getAbsolutePath ());
848847
849848 return new HttpResponse ().setContent (asJson (result ));
850849 }
@@ -1078,13 +1077,17 @@ private boolean decrementSessionCount() {
10781077 }
10791078
10801079 private Map <String , Object > toJson () {
1081- return ImmutableMap .of (
1082- "id" , getId (),
1083- "uri" , externalUri ,
1084- "maxSessions" , maxSessionCount ,
1085- "draining" , isDraining (),
1080+ return Map .of (
1081+ "id" ,
1082+ getId (),
1083+ "uri" ,
1084+ externalUri ,
1085+ "maxSessions" ,
1086+ maxSessionCount ,
1087+ "draining" ,
1088+ isDraining (),
10861089 "capabilities" ,
1087- factories .stream ().map (SessionSlot ::getStereotype ).collect (Collectors .toSet ()));
1090+ factories .stream ().map (SessionSlot ::getStereotype ).collect (Collectors .toSet ()));
10881091 }
10891092
10901093 public static class Builder {
0 commit comments