blob: 0de6a774b2b4ef80127177608df07c6f8a43a836 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertThrowsAsync } from "./test_util.ts";
unitTest(async function permissionInvalidName(): Promise<void> {
await assertThrowsAsync(async () => {
// @ts-expect-error name should not accept "foo"
await navigator.permissions.query({ name: "foo" });
}, TypeError);
});
unitTest(async function permissionNetInvalidUrl(): Promise<void> {
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);
});
|