2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-09 05:00:18 -04:00
|
|
|
|
|
|
|
import { unitTest, assert, assertThrowsAsync } from "./test_util.ts";
|
2019-10-27 11:22:53 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(async function permissionInvalidName(): Promise<void> {
|
2020-07-09 05:00:18 -04:00
|
|
|
await assertThrowsAsync(async () => {
|
|
|
|
// @ts-expect-error name should not accept "foo"
|
|
|
|
await navigator.permissions.query({ name: "foo" });
|
|
|
|
}, TypeError);
|
2019-10-27 11:22:53 -04:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(async function permissionNetInvalidUrl(): Promise<void> {
|
2020-07-09 05:00:18 -04:00
|
|
|
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);
|
2019-10-27 11:22:53 -04:00
|
|
|
});
|