mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
0d1a522a03
Revert changes to "net" permissions in regards to handling URLs
introduced in 15b0e61de
.
74 lines
2 KiB
TypeScript
74 lines
2 KiB
TypeScript
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
import {
|
|
assert,
|
|
assertEquals,
|
|
assertThrows,
|
|
assertThrowsAsync,
|
|
unitTest,
|
|
} from "./test_util.ts";
|
|
|
|
unitTest(async function permissionInvalidName() {
|
|
await assertThrowsAsync(async () => {
|
|
// deno-lint-ignore no-explicit-any
|
|
await Deno.permissions.query({ name: "foo" as any });
|
|
}, TypeError);
|
|
});
|
|
|
|
unitTest(async function permissionNetInvalidHost() {
|
|
await assertThrowsAsync(async () => {
|
|
await Deno.permissions.query({ name: "net", host: ":" });
|
|
}, URIError);
|
|
});
|
|
|
|
unitTest(async function permissionQueryReturnsEventTarget() {
|
|
const status = await Deno.permissions.query({ name: "hrtime" });
|
|
assert(["granted", "denied", "prompt"].includes(status.state));
|
|
let called = false;
|
|
status.addEventListener("change", () => {
|
|
called = true;
|
|
});
|
|
status.dispatchEvent(new Event("change"));
|
|
assert(called);
|
|
assert(status === (await Deno.permissions.query({ name: "hrtime" })));
|
|
});
|
|
|
|
unitTest(async function permissionQueryForReadReturnsSameStatus() {
|
|
const status1 = await Deno.permissions.query({
|
|
name: "read",
|
|
path: ".",
|
|
});
|
|
const status2 = await Deno.permissions.query({
|
|
name: "read",
|
|
path: ".",
|
|
});
|
|
assert(status1 === status2);
|
|
});
|
|
|
|
unitTest(function permissionsIllegalConstructor() {
|
|
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor.");
|
|
assertEquals(Deno.Permissions.length, 0);
|
|
});
|
|
|
|
unitTest(function permissionStatusIllegalConstructor() {
|
|
assertThrows(
|
|
() => new Deno.PermissionStatus(),
|
|
TypeError,
|
|
"Illegal constructor.",
|
|
);
|
|
assertEquals(Deno.PermissionStatus.length, 0);
|
|
});
|
|
|
|
unitTest(async function permissionURL() {
|
|
await Deno.permissions.query({
|
|
name: "read",
|
|
path: new URL(".", import.meta.url),
|
|
});
|
|
await Deno.permissions.query({
|
|
name: "write",
|
|
path: new URL(".", import.meta.url),
|
|
});
|
|
await Deno.permissions.query({
|
|
name: "run",
|
|
command: new URL(".", import.meta.url),
|
|
});
|
|
});
|