Skip to content

Commit

Permalink
Create permissions test suite with IDL tests (web-platform-tests#9301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Honry authored and David Heiberg committed Jun 7, 2018
1 parent 828b447 commit 6b7772a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
53 changes: 53 additions & 0 deletions interfaces/permissions.idl
@@ -0,0 +1,53 @@
// GENERATED CONTENT - DO NOT EDIT
// Content of this file was automatically extracted from the
// "Permissions" spec.
// See: https://w3c.github.io/permissions/

dictionary PermissionDescriptor {
required PermissionName name;
};

enum PermissionState {
"granted",
"denied",
"prompt",
};

[Exposed=(Window,Worker)]
interface PermissionStatus : EventTarget {
readonly attribute PermissionState state;
attribute EventHandler onchange;
};

[Exposed=(Window)]
partial interface Navigator {
readonly attribute Permissions permissions;
};

[Exposed=(Worker)]
partial interface WorkerNavigator {
readonly attribute Permissions permissions;
};

[Exposed=(Window,Worker)]
interface Permissions {
Promise<PermissionStatus> query(object permissionDesc);
};

dictionary PushPermissionDescriptor : PermissionDescriptor {
boolean userVisibleOnly = false;
};

dictionary MidiPermissionDescriptor : PermissionDescriptor {
boolean sysex = false;
};

dictionary DevicePermissionDescriptor : PermissionDescriptor {
DOMString deviceId;
};

dictionary PermissionSetParameters {
required PermissionDescriptor descriptor;
required PermissionState state;
boolean oneRealm = false;
};
3 changes: 3 additions & 0 deletions permissions/OWNERS
@@ -0,0 +1,3 @@
@jyasskin
@mounirlamouri
@marcoscaceres
38 changes: 38 additions & 0 deletions permissions/interfaces.any.js
@@ -0,0 +1,38 @@
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js

"use strict";

if (self.importScripts) {
importScripts("/resources/testharness.js");
importScripts("/resources/WebIDLParser.js", "/resources/idlharness.js");
}

// https://w3c.github.io/permissions/#idl-index

promise_test(async () => {

const permissions_idl = await fetch("/interfaces/permissions.idl")
.then(response => response.text());
const idl_array = new IdlArray();

idl_array.add_untested_idls('interface Navigator {};');
idl_array.add_untested_idls('[Exposed=(Window,Worker)] interface EventTarget {};');
idl_array.add_untested_idls('interface EventHandler {};');
idl_array.add_untested_idls('interface WorkerNavigator {};');
idl_array.add_idls(permissions_idl);

self.permissionStatus = await navigator.permissions.query({ name: "geolocation" });

if (self.GLOBAL.isWorker()) {
idl_array.add_objects({ WorkerNavigator: ['navigator'] });
} else {
idl_array.add_objects({ Navigator: ['navigator'] });
}

idl_array.add_objects({
Permissions: ['navigator.permissions'],
PermissionStatus: ['permissionStatus']
});
idl_array.test();
}, "Test IDL implementation of Permissions API");

0 comments on commit 6b7772a

Please sign in to comment.