Skip to content

Commit

Permalink
Introduce a jre-based app server for testing
Browse files Browse the repository at this point in the history
Eventually, the goal is to untangle ourselves from Jetty
entirely. The first step is to start replacing the test
usages with something that doesn't depend on a third
party library. Fortunately, since java 6 both OpenJDK
and the Oracle JDK have shipped with an HTTP server as
part of their own APIs. This has been exposed via a
JPMS module, and so it should be safe to rely on since I
don't think any of the developers use the IBM JDK for
development work.
  • Loading branch information
shs96c committed Aug 7, 2018
1 parent f4d4451 commit 1229d40
Show file tree
Hide file tree
Showing 14 changed files with 801 additions and 33 deletions.
2 changes: 1 addition & 1 deletion common/src/web/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</script>
</head>
<body>
<form action="/common/upload" method="post" name="upload_form"
<form action="upload" method="post" name="upload_form"
target="upload_target" enctype="multipart/form-data"
onsubmit="onUploadSubmit();">
<div>
Expand Down
6 changes: 4 additions & 2 deletions java/client/test/org/openqa/selenium/environment/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BUILD FILE SYNTAX: SKYLARK
java_library(name = 'environment',
srcs = glob(['*.java', 'webserver/*.java'], exclude = ['**/*Test.java']),
srcs = glob(['*.java', 'webserver/*.java'], exclude = ['**/*Test.java', '**/*TestBase.java']),
provided_deps = [
'//third_party/java/servlet:javax.servlet-api',
],
Expand Down Expand Up @@ -31,7 +31,9 @@ java_binary(name = 'webserver',

java_test(name = "webserver-test",
srcs = [
"webserver/AppServerTest.java",
"webserver/AppServerTestBase.java",
"webserver/JettyAppServerTest.java",
"webserver/JreAppServerTest.java",
],
vm_args = [
'-Dselenium.browser=ff',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.nio.charset.StandardCharsets;

@RunWith(JUnit4.class)
public class AppServerTest {
public abstract class AppServerTestBase {
private static final String APPCACHE_MIME_TYPE = "text/cache-manifest";
private AppServer server;
private static WebDriver driver;
Expand All @@ -55,10 +55,12 @@ public static void startDriver() {

@Before
public void startServer() {
server = new JettyAppServer();
server = createAppServer();
server.start();
}

protected abstract AppServer createAppServer();

@After
public void stopServer() {
server.stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.environment.webserver;

import static java.nio.charset.StandardCharsets.UTF_16LE;

import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.util.function.BiConsumer;

public class EncodingHandler implements BiConsumer<HttpRequest, HttpResponse> {

@Override
public void accept(HttpRequest request, HttpResponse response) {
// Data should be transferred using UTF-8. Pick a different encoding
response.setHeader("Content-Type", "text/html;charset=UTF-16LE");

StringBuilder text = new StringBuilder("<html><title>Character encoding (UTF 16)</title>")
.append("<body><p id='text'>")
.append("\u05E9\u05DC\u05D5\u05DD") // "Shalom"
.append("</p></body></html>");

response.setContent(text.toString().getBytes(UTF_16LE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.environment.webserver;

public class JettyAppServerTest extends AppServerTestBase {

@Override
protected AppServer createAppServer() {
return new JettyAppServer();
}
}
Loading

0 comments on commit 1229d40

Please sign in to comment.