mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
Use web standard Permissions API (#3200)
This commit is contained in:
parent
2598f9c68d
commit
efd7e78af3
15 changed files with 362 additions and 306 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
||||
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
||||
|
||||
const knownPermissions: Deno.Permission[] = [
|
||||
const knownPermissions: Deno.PermissionName[] = [
|
||||
"run",
|
||||
"read",
|
||||
"write",
|
||||
|
@ -11,18 +11,31 @@ const knownPermissions: Deno.Permission[] = [
|
|||
];
|
||||
|
||||
for (const grant of knownPermissions) {
|
||||
testPerm({ [grant]: true }, function envGranted(): void {
|
||||
const perms = Deno.permissions();
|
||||
assert(perms !== null);
|
||||
for (const perm in perms) {
|
||||
assertEquals(perms[perm], perm === grant);
|
||||
}
|
||||
testPerm({ [grant]: true }, async function envGranted(): Promise<void> {
|
||||
const status0 = await Deno.permissions.query({ name: grant });
|
||||
assert(status0 != null);
|
||||
assertEquals(status0.state, "granted");
|
||||
|
||||
Deno.revokePermission(grant);
|
||||
|
||||
const revoked = Deno.permissions();
|
||||
for (const perm in revoked) {
|
||||
assertEquals(revoked[perm], false);
|
||||
}
|
||||
const status1 = await Deno.permissions.revoke({ name: grant });
|
||||
assert(status1 != null);
|
||||
assertEquals(status1.state, "prompt");
|
||||
});
|
||||
}
|
||||
|
||||
test(async function permissionInvalidName(): Promise<void> {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await Deno.permissions.query({ name: "foo" as any });
|
||||
} catch (e) {
|
||||
assert(e.name === "TypeError");
|
||||
}
|
||||
});
|
||||
|
||||
test(async function permissionNetInvalidUrl(): Promise<void> {
|
||||
try {
|
||||
// Invalid url causes TypeError.
|
||||
await Deno.permissions.query({ name: "net", url: ":" });
|
||||
} catch (e) {
|
||||
assert(e.name === "TypeError");
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue