forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DirectSockets] Add self-contained WPTs for the Direct Sockets API
Bug: 338475101 Change-Id: I4441e18da6590937dad8edd4933d7ba46e08c10c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5513762 Commit-Queue: Andrew Rayskiy <[email protected]> Reviewed-by: Weizhong Xia <[email protected]> Cr-Commit-Position: refs/heads/main@{#1296893}
- Loading branch information
1 parent
fb37d2f
commit 34dfef8
Showing
11 changed files
with
196 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
spec: https://github.com/WICG/direct-sockets/blob/main/docs/explainer.md | ||
suggested_reviewers: | ||
- ewilligers | ||
- mgiuca | ||
- phoglenix | ||
- greengrape |
38 changes: 25 additions & 13 deletions
38
direct-sockets/disabled-by-permissions-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Sockets test: Can be disabled by permissions policy</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
</head> | ||
<body> | ||
<script src="disabled-by-permissions-policy.js"></script> | ||
</body> | ||
</html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
|
||
'use strict'; | ||
|
||
test(() => { | ||
assert_throws_dom("NotAllowedError", () => { | ||
new TCPSocket("127.0.0.1", 53); | ||
}, "constructor should throw"); | ||
}, "TCPSocket disabled by permissions-policy"); | ||
|
||
test(() => { | ||
assert_throws_dom("NotAllowedError", () => { | ||
new UDPSocket({ remoteAddress: "127.0.0.1", remotePort: 53 }); | ||
}, "constructor should throw"); | ||
}, "UDPSocket disabled by permissions-policy"); | ||
|
||
test(() => { | ||
assert_throws_dom("NotAllowedError", () => { | ||
new TCPServerSocket("127.0.0.1"); | ||
}, "constructor should throw"); | ||
}, "TCPServerSocket disabled by permissions-policy"); | ||
|
||
</script> |
2 changes: 1 addition & 1 deletion
2
direct-sockets/disabled-by-permissions-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Cross-Origin-Opener-Policy: same-origin | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Permissions-Policy: direct-sockets=() | ||
Permissions-Policy: direct-sockets=() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/test-only-api.js"></script> | ||
<script> | ||
'use strict'; | ||
|
||
promise_test(async () => { | ||
const kPacket = "I'm a netcat. Meow-meow!" | ||
|
||
const serverSocket = new TCPServerSocket("127.0.0.1"); | ||
const { localPort } = await serverSocket.opened; | ||
|
||
const clientSocket = new TCPSocket("127.0.0.1", localPort); | ||
const acceptedSocket = await (async () => { | ||
const { readable } = await serverSocket.opened; | ||
const reader = readable.getReader(); | ||
const { value: acceptedSocket, done } = await reader.read(); | ||
assert_false(done); | ||
reader.releaseLock(); | ||
return acceptedSocket; | ||
})(); | ||
|
||
const encoder = new TextEncoder(); | ||
const decoder = new TextDecoder(); | ||
|
||
const readPacket = async socket => { | ||
const { readable } = await socket.opened; | ||
const reader = readable.getReader(); | ||
let result = ""; | ||
while (result.length < kPacket.length) { | ||
const { value, done } = await reader.read(); | ||
assert_false(done); | ||
result += decoder.decode(value); | ||
} | ||
assert_equals(result, kPacket); | ||
reader.releaseLock(); | ||
}; | ||
|
||
const sendPacket = async socket => { | ||
const { writable } = await socket.opened; | ||
const writer = writable.getWriter(); | ||
await writer.ready; | ||
await writer.write(encoder.encode(kPacket)); | ||
writer.releaseLock(); | ||
}; | ||
|
||
const acceptedSocketEcho = (async () => { | ||
await readPacket(acceptedSocket); | ||
await sendPacket(acceptedSocket); | ||
})(); | ||
|
||
const clientSocketSend = (async () => { | ||
await sendPacket(clientSocket); | ||
})(); | ||
|
||
const clientSocketReceive = (async () => { | ||
await readPacket(clientSocket); | ||
})(); | ||
|
||
await clientSocketReceive; | ||
|
||
await clientSocket.close(); | ||
await acceptedSocket.close(); | ||
await serverSocket.close(); | ||
|
||
}, 'TCPSocket exchanges packets with TCPServerSocket'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Cross-Origin-Opener-Policy: same-origin | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Permissions-Policy: direct-sockets=(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/test-only-api.js"></script> | ||
<script> | ||
'use strict'; | ||
|
||
promise_test(async () => { | ||
const kRequiredDatagrams = 150; | ||
const kRequiredBytes = | ||
kRequiredDatagrams * (kRequiredDatagrams + 1) / 2; | ||
|
||
const boundSocket = new UDPSocket({ localAddress: "127.0.0.1" }); | ||
const { localPort: boundLocalPort } = await boundSocket.opened; | ||
|
||
const connectedSocket = new UDPSocket({ | ||
remoteAddress: "127.0.0.1", | ||
remotePort: boundLocalPort, | ||
}); | ||
|
||
const { | ||
localAddress: clientAddress, | ||
localPort: clientPort | ||
} = await connectedSocket.opened; | ||
|
||
const boundEchoLoop = (async() => { | ||
let bytesEchoed = 0; | ||
|
||
const { readable, writable } = await boundSocket.opened; | ||
const reader = readable.getReader(); | ||
const writer = writable.getWriter(); | ||
|
||
while (bytesEchoed < kRequiredBytes) { | ||
const { value: { data, remoteAddress, remotePort }, done } = await reader.read(); | ||
assert_false(done); | ||
assert_equals(remoteAddress, clientAddress); | ||
assert_equals(remotePort, clientPort); | ||
for (let index = 0; index < data.length; index++) { | ||
assert_equals(data[index], bytesEchoed % 256); | ||
bytesEchoed++; | ||
} | ||
await writer.write({ data, remoteAddress, remotePort }); | ||
} | ||
|
||
assert_equals(bytesEchoed, kRequiredBytes); | ||
reader.releaseLock(); | ||
writer.releaseLock(); | ||
})(); | ||
|
||
const connectedSendLoop = (async () => { | ||
let bytesWritten = 0; | ||
let chunkLength = 0; | ||
|
||
const { writable } = await connectedSocket.opened; | ||
const writer = writable.getWriter(); | ||
|
||
while (bytesWritten < kRequiredBytes) { | ||
chunkLength = Math.min(chunkLength + 1, kRequiredBytes - bytesWritten); | ||
let chunk = new Uint8Array(chunkLength); | ||
for (let index = 0; index < chunkLength; index++) { | ||
chunk[index] = bytesWritten % 256; | ||
bytesWritten++; | ||
} | ||
await writer.ready; | ||
await writer.write({ data: chunk }); | ||
} | ||
assert_equals(bytesWritten, kRequiredBytes); | ||
writer.releaseLock(); | ||
})(); | ||
|
||
const connectedReadLoop = (async () => { | ||
let bytesRead = 0; | ||
|
||
const { readable } = await connectedSocket.opened; | ||
const reader = readable.getReader(); | ||
|
||
while (bytesRead < kRequiredBytes) { | ||
const { value: { data }, done } = await reader.read(); | ||
assert_false(done); | ||
for (let index = 0; index < data.length; index++) { | ||
assert_equals(data[index], bytesRead % 256); | ||
bytesRead++; | ||
} | ||
} | ||
assert_equals(bytesRead, kRequiredBytes); | ||
|
||
reader.releaseLock(); | ||
})(); | ||
|
||
await connectedReadLoop; | ||
|
||
await boundSocket.close(); | ||
await connectedSocket.close(); | ||
}, "UDPSocket (connected) exchanges datagrams with UDPSocket (bound)"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Cross-Origin-Opener-Policy: same-origin | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Permissions-Policy: direct-sockets=(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.