2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2022-07-20 06:30:41 -04:00
|
|
|
import { assertEquals, assertThrows, deferred, fail } from "./test_util.ts";
|
2020-11-25 09:17:46 -05:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: "none" }, function websocketPermissionless() {
|
2020-11-25 09:17:46 -05:00
|
|
|
assertThrows(
|
|
|
|
() => new WebSocket("ws://localhost"),
|
|
|
|
Deno.errors.PermissionDenied,
|
|
|
|
);
|
|
|
|
});
|
2022-07-20 06:30:41 -04:00
|
|
|
|
|
|
|
Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
|
|
|
|
const promise = deferred();
|
|
|
|
const ws = new WebSocket(new URL("ws://localhost:4242/"));
|
|
|
|
assertEquals(ws.url, "ws://localhost:4242/");
|
|
|
|
ws.onerror = () => fail();
|
|
|
|
ws.onopen = () => ws.close();
|
|
|
|
ws.onclose = () => {
|
|
|
|
promise.resolve();
|
|
|
|
};
|
|
|
|
await promise;
|
|
|
|
});
|