mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
test: support setCSP and enable a test (#26)
This commit is contained in:
parent
28a4be86a4
commit
adc49e496a
@ -40,6 +40,7 @@ public class Server implements HttpHandler {
|
|||||||
|
|
||||||
private final Map<String, CompletableFuture<Request>> requestSubscribers = Collections.synchronizedMap(new HashMap<>());
|
private final Map<String, CompletableFuture<Request>> requestSubscribers = Collections.synchronizedMap(new HashMap<>());
|
||||||
private final Map<String, Auth> auths = Collections.synchronizedMap(new HashMap<>());
|
private final Map<String, Auth> auths = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
private final Map<String, String> csp = Collections.synchronizedMap(new HashMap<>());
|
||||||
private final Map<String, HttpHandler> routes = Collections.synchronizedMap(new HashMap<>());
|
private final Map<String, HttpHandler> routes = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
private static class Auth {
|
private static class Auth {
|
||||||
@ -90,6 +91,10 @@ public class Server implements HttpHandler {
|
|||||||
auths.put(path, new Auth(user, password));
|
auths.put(path, new Auth(user, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCSP(String path, String csp) {
|
||||||
|
this.csp.put(path, csp);
|
||||||
|
}
|
||||||
|
|
||||||
static class Request {
|
static class Request {
|
||||||
public final String method;
|
public final String method;
|
||||||
// TODO: make a copy to ensure thread safety?
|
// TODO: make a copy to ensure thread safety?
|
||||||
@ -175,6 +180,9 @@ public class Server implements HttpHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (csp.containsKey(path)) {
|
||||||
|
exchange.getResponseHeaders().put("Content-Security-Policy", singletonList(csp.get(path)));
|
||||||
|
}
|
||||||
File file = new File(resourcesDir, path.substring(1));
|
File file = new File(resourcesDir, path.substring(1));
|
||||||
exchange.getResponseHeaders().put("Content-Type", singletonList(mimeType(file)));
|
exchange.getResponseHeaders().put("Content-Type", singletonList(mimeType(file)));
|
||||||
try (FileInputStream input = new FileInputStream(file)) {
|
try (FileInputStream input = new FileInputStream(file)) {
|
||||||
|
@ -192,15 +192,12 @@ public class TestWaitForFunction {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldWorkWithStrictCSPPolicy() {
|
void shouldWorkWithStrictCSPPolicy() {
|
||||||
// TODO:
|
server.setCSP("/empty.html", "script-src " + server.PREFIX);
|
||||||
// server.setCSP("/empty.html", "script-src " + server.PREFIX);
|
page.navigate(server.EMPTY_PAGE);
|
||||||
// page.navigate(server.EMPTY_PAGE);
|
|
||||||
// let error = null;
|
Deferred<JSHandle> result = page.waitForFunction("() => window['__FOO'] === 'hit'");
|
||||||
//
|
page.evaluate("() => window['__FOO'] = 'hit'");
|
||||||
// page.waitForFunction(() => window['__FOO'] === 'hit', {}, {polling: 'raf'}).catch(e => error = e),
|
result.get();
|
||||||
// page.evaluate("() => window['__FOO'] = 'hit'")
|
|
||||||
//
|
|
||||||
// assertNull(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shouldThrowOnBadPollingValue() {
|
void shouldThrowOnBadPollingValue() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user