From efd7e78af3fc086dfdec51738905665d38d08eb4 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 28 Oct 2019 00:22:53 +0900 Subject: Use web standard Permissions API (#3200) --- cli/js/permissions_test.ts | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'cli/js/permissions_test.ts') diff --git a/cli/js/permissions_test.ts b/cli/js/permissions_test.ts index 6511c2dcb..d9ba538f0 100644 --- a/cli/js/permissions_test.ts +++ b/cli/js/permissions_test.ts @@ -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 { + 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 { + 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 { + try { + // Invalid url causes TypeError. + await Deno.permissions.query({ name: "net", url: ":" }); + } catch (e) { + assert(e.name === "TypeError"); + } +}); -- cgit v1.2.3