2022-03-11 17:07:02 -05:00
|
|
|
import { assertEquals } from "../../../../test_util/std/testing/asserts.ts";
|
|
|
|
|
|
|
|
const permissions: Deno.PermissionName[] = [
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"net",
|
|
|
|
"env",
|
|
|
|
"run",
|
|
|
|
"ffi",
|
|
|
|
"hrtime",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const name of permissions) {
|
|
|
|
Deno.bench({
|
|
|
|
name: `${name} false`,
|
|
|
|
permissions: {
|
|
|
|
[name]: false,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
2022-03-11 17:07:02 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.bench({
|
|
|
|
name: `${name} true`,
|
|
|
|
permissions: {
|
|
|
|
[name]: true,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
if (n === name) {
|
|
|
|
assertEquals(status.state, "granted");
|
|
|
|
} else {
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 17:07:02 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|