2727
2828import com .google .common .base .Joiner ;
2929import com .google .common .net .HostAndPort ;
30-
3130import io .netty .handler .codec .http .FullHttpResponse ;
3231import io .netty .handler .codec .http .HttpRequest ;
33-
3432import java .net .URI ;
3533import java .net .URISyntaxException ;
3634import java .util .HashSet ;
3735import java .util .Set ;
38-
3936import org .junit .jupiter .api .Test ;
4037import org .openqa .selenium .netty .server .SimpleHttpServer ;
4138import org .openqa .selenium .remote .http .HttpMethod ;
@@ -85,19 +82,18 @@ public void canConfigureNoProxy() throws URISyntaxException, InterruptedExceptio
8582 @ NoDriverBeforeTest
8683 @ NoDriverAfterTest
8784 public void canConfigureProxyThroughPACFile () throws URISyntaxException , InterruptedException {
88- try (SimpleHttpServer helloServer = createSimpleHttpServer (
89- appServer . whereElseIs ( "mouseOver.html" ),
90- "<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>"
91- );
85+ try (SimpleHttpServer helloServer =
86+ createSimpleHttpServer (
87+ appServer . whereElseIs ( "mouseOver.html" ),
88+ "<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>" );
9289 SimpleHttpServer pacFileServer =
93- createPacfileServer (
94- "/proxy.pac" ,
95- Joiner .on ('\n' )
96- .join (
97- "function FindProxyForURL(url, host) {" ,
98- " return 'PROXY " + getHostAndPort (helloServer ) + "';" ,
99- "}" ));
100- ) {
90+ createPacfileServer (
91+ "/proxy.pac" ,
92+ Joiner .on ('\n' )
93+ .join (
94+ "function FindProxyForURL(url, host) {" ,
95+ " return 'PROXY " + getHostAndPort (helloServer ) + "';" ,
96+ "}" )); ) {
10197
10298 Proxy proxy = new Proxy ();
10399 proxy .setProxyAutoconfigUrl ("http://" + getHostAndPort (pacFileServer ) + "/proxy.pac" );
@@ -116,26 +112,25 @@ public void canConfigureProxyThroughPACFile() throws URISyntaxException, Interru
116112 @ Ignore (value = FIREFOX , travis = true )
117113 @ Ignore (value = CHROME , reason = "Flaky" )
118114 public void canUsePACThatOnlyProxiesCertainHosts ()
119- throws URISyntaxException , InterruptedException {
120- try (SimpleHttpServer helloServer = createSimpleHttpServer (
121- "/index.html" ,
122- "<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>"
123- );
124- SimpleHttpServer goodbyeServer = createSimpleHttpServer (
125- helloServer .baseUri ().resolve ("/index.html" ).toString (),
126- "<!DOCTYPE html><title>Goodbye</title><h3>Goodbye, world!</h3>"
127- );
128- SimpleHttpServer pacFileServer = createPacfileServer (
129- "/proxy.pac" ,
130- Joiner .on ('\n' )
131- .join (
132- "function FindProxyForURL(url, host) {" ,
133- " if (url.indexOf('" + getHostAndPort (helloServer ) + "') != -1) {" ,
134- " return 'PROXY " + getHostAndPort (goodbyeServer ) + "';" ,
135- " }" ,
136- " return 'DIRECT';" ,
137- "}" )
138- );) {
115+ throws URISyntaxException , InterruptedException {
116+ try (SimpleHttpServer helloServer =
117+ createSimpleHttpServer (
118+ "/index.html" , "<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>" );
119+ SimpleHttpServer goodbyeServer =
120+ createSimpleHttpServer (
121+ helloServer .baseUri ().resolve ("/index.html" ).toString (),
122+ "<!DOCTYPE html><title>Goodbye</title><h3>Goodbye, world!</h3>" );
123+ SimpleHttpServer pacFileServer =
124+ createPacfileServer (
125+ "/proxy.pac" ,
126+ Joiner .on ('\n' )
127+ .join (
128+ "function FindProxyForURL(url, host) {" ,
129+ " if (url.indexOf('" + getHostAndPort (helloServer ) + "') != -1) {" ,
130+ " return 'PROXY " + getHostAndPort (goodbyeServer ) + "';" ,
131+ " }" ,
132+ " return 'DIRECT';" ,
133+ "}" )); ) {
139134
140135 Proxy proxy = new Proxy ();
141136 proxy .setProxyAutoconfigUrl ("http://" + getHostAndPort (pacFileServer ) + "/proxy.pac" );
@@ -151,7 +146,7 @@ public void canUsePACThatOnlyProxiesCertainHosts()
151146 }
152147
153148 private SimpleHttpServer createSimpleHttpServer (String requestPath , String responseHtml )
154- throws URISyntaxException , InterruptedException {
149+ throws URISyntaxException , InterruptedException {
155150 SimpleHttpServer server = new SimpleHttpServer ();
156151 byte [] bytes = responseHtml .getBytes (UTF_8 );
157152
@@ -161,11 +156,12 @@ private SimpleHttpServer createSimpleHttpServer(String requestPath, String respo
161156 }
162157
163158 private SimpleHttpServer createPacfileServer (String requestPath , String responsePac )
164- throws URISyntaxException , InterruptedException {
165- SimpleHttpServer server = new SimpleHttpServer ();
159+ throws URISyntaxException , InterruptedException {
160+ SimpleHttpServer server = new SimpleHttpServer ();
166161 byte [] bytes = responsePac .getBytes (US_ASCII );
167162
168- server .registerEndpoint (HttpMethod .GET , requestPath , "application/x-ns-proxy-autoconfig" , bytes );
163+ server .registerEndpoint (
164+ HttpMethod .GET , requestPath , "application/x-ns-proxy-autoconfig" , bytes );
169165
170166 return server ;
171167 }
@@ -178,9 +174,7 @@ private static HostAndPort getHostAndPort(SimpleHttpServer server) {
178174 public static class FakeProxyServer extends SimpleHttpServer {
179175 private final Set <String > resources = new HashSet <>();
180176
181- public FakeProxyServer () throws URISyntaxException , InterruptedException {
182-
183- }
177+ public FakeProxyServer () throws URISyntaxException , InterruptedException {}
184178
185179 @ Override
186180 protected FullHttpResponse handleRequest (HttpRequest requested ) {
0 commit comments