diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-07-09 19:00:18 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-09 05:00:18 -0400 |
commit | 202e7fa6ad366ee56a6d070e94eaecb6dbc745bf (patch) | |
tree | 745481e627ff691e0c196c18c310e54a8794badf /cli/tests | |
parent | e92cf5b9e8530f7edf5cb7b157e6334a013da10d (diff) |
feat: move unstable Deno.permissions to navigator.permissions (#6244)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/025_hrtime.ts | 2 | ||||
-rw-r--r-- | cli/tests/057_revoke_permissions.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/permissions_test.ts | 53 | ||||
-rw-r--r-- | cli/tests/unit/test_util.ts | 2 | ||||
-rwxr-xr-x | cli/tests/unit/unit_test_runner.ts | 2 |
5 files changed, 38 insertions, 25 deletions
diff --git a/cli/tests/025_hrtime.ts b/cli/tests/025_hrtime.ts index 9f60b7a77..fef39ffdb 100644 --- a/cli/tests/025_hrtime.ts +++ b/cli/tests/025_hrtime.ts @@ -1,5 +1,5 @@ window.onload = async (): Promise<void> => { console.log(performance.now() % 2 !== 0); - await Deno.permissions.revoke({ name: "hrtime" }); + await navigator.permissions.revoke({ name: "hrtime" }); console.log(performance.now() % 2 === 0); }; diff --git a/cli/tests/057_revoke_permissions.ts b/cli/tests/057_revoke_permissions.ts index de8deecb4..4a39112d2 100644 --- a/cli/tests/057_revoke_permissions.ts +++ b/cli/tests/057_revoke_permissions.ts @@ -18,11 +18,11 @@ export function assert(cond: unknown): asserts cond { function genFunc(grant: Deno.PermissionName): [string, () => Promise<void>] { const gen: () => Promise<void> = async function Granted(): Promise<void> { - const status0 = await Deno.permissions.query({ name: grant }); + const status0 = await navigator.permissions.query({ name: grant }); assert(status0 != null); assert(status0.state === "granted"); - const status1 = await Deno.permissions.revoke({ name: grant }); + const status1 = await navigator.permissions.revoke({ name: grant }); assert(status1 != null); assert(status1.state === "prompt"); }; diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 7528768a1..0de6a774b 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -1,27 +1,40 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { unitTest, assert } from "./test_util.ts"; + +import { unitTest, assert, assertThrowsAsync } from "./test_util.ts"; unitTest(async function permissionInvalidName(): Promise<void> { - let thrown = false; - try { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - await Deno.permissions.query({ name: "foo" as any }); - } catch (e) { - thrown = true; - assert(e instanceof Error); - } finally { - assert(thrown); - } + await assertThrowsAsync(async () => { + // @ts-expect-error name should not accept "foo" + await navigator.permissions.query({ name: "foo" }); + }, TypeError); }); unitTest(async function permissionNetInvalidUrl(): Promise<void> { - let thrown = false; - try { - await Deno.permissions.query({ name: "net", url: ":" }); - } catch (e) { - thrown = true; - assert(e instanceof URIError); - } finally { - assert(thrown); - } + await assertThrowsAsync(async () => { + await navigator.permissions.query({ name: "net", url: ":" }); + }, URIError); +}); + +unitTest(async function permissionQueryReturnsEventTarget(): Promise<void> { + const status = await navigator.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 navigator.permissions.query({ name: "hrtime" }))); +}); + +unitTest(async function permissionQueryForReadReturnsSameStatus() { + const status1 = await navigator.permissions.query({ + name: "read", + path: ".", + }); + const status2 = await navigator.permissions.query({ + name: "read", + path: ".", + }); + assert(status1 === status2); }); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 25da7a638..dd6c858d2 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -42,7 +42,7 @@ export function fmtPerms(perms: Permissions): string { } const isGranted = async (name: Deno.PermissionName): Promise<boolean> => - (await Deno.permissions.query({ name })).state === "granted"; + (await navigator.permissions.query({ name })).state === "granted"; export async function getProcessPermissions(): Promise<Permissions> { return { diff --git a/cli/tests/unit/unit_test_runner.ts b/cli/tests/unit/unit_test_runner.ts index b2e872200..c7c494278 100755 --- a/cli/tests/unit/unit_test_runner.ts +++ b/cli/tests/unit/unit_test_runner.ts @@ -49,7 +49,7 @@ async function dropWorkerPermissions( }); for (const perm of permsToDrop) { - await Deno.permissions.revoke({ name: perm }); + await navigator.permissions.revoke({ name: perm }); } } |