Commit 7753bf7a authored by Francois Beaufort's avatar Francois Beaufort Committed by Commit Bot

[DevTools] Handle new Camera PanTiltZoom permission

This CL adds the camera pan tilt zoom permission to devtools browser
protocol.

Spec: https://github.com/w3c/permissions/pull/204

Bug: 1136778
Change-Id: Ic11990413e2ceeeceb7da5c03930cd4049189b97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460898Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#816497}
parent 35231f04
......@@ -146,6 +146,9 @@ Response PermissionDescriptorToPermissionType(
if (name == "geolocation") {
*permission_type = PermissionType::GEOLOCATION;
} else if (name == "camera") {
if (descriptor->GetPanTiltZoom(false))
*permission_type = PermissionType::CAMERA_PAN_TILT_ZOOM;
else
*permission_type = PermissionType::VIDEO_CAPTURE;
} else if (name == "microphone") {
*permission_type = PermissionType::AUDIO_CAPTURE;
......@@ -224,6 +227,9 @@ Response FromProtocolPermissionType(
*out_type = PermissionType::AUDIO_CAPTURE;
} else if (type == protocol::Browser::PermissionTypeEnum::VideoCapture) {
*out_type = PermissionType::VIDEO_CAPTURE;
} else if (type ==
protocol::Browser::PermissionTypeEnum::VideoCapturePanTiltZoom) {
*out_type = PermissionType::CAMERA_PAN_TILT_ZOOM;
} else if (type == protocol::Browser::PermissionTypeEnum::BackgroundSync) {
*out_type = PermissionType::BACKGROUND_SYNC;
} else if (type == protocol::Browser::PermissionTypeEnum::Flash) {
......
......@@ -826,6 +826,7 @@ domain Browser
protectedMediaIdentifier
sensors
videoCapture
videoCapturePanTiltZoom
idleDetection
wakeLockScreen
wakeLockSystem
......@@ -850,6 +851,8 @@ domain Browser
optional boolean userVisibleOnly
# For "clipboard" permission, may specify allowWithoutSanitization.
optional boolean allowWithoutSanitization
# For "camera" permission, may specify panTiltZoom.
optional boolean panTiltZoom
# Set permission settings for given origin.
experimental command setPermission
......
Test that permissions could be granted
- Granted: ["geolocation"]
- Granted: ["audioCapture"]
- Granted: ["geolocation","audioCapture"]
- Granted: ["geolocation","audioCapture","videoCapturePanTiltZoom"]
- Failed to grant: ["eee"] error: Unknown permission type: eee
- Resetting all permissions
[
......@@ -12,12 +12,16 @@ Test that permissions could be granted
[4] : CHANGED 'geolocation': denied
]
[
[0] : geolocation: granted
[1] : geolocation: denied
[2] : microphone: granted
[3] : geolocation: granted
[4] : microphone: granted
[5] : geolocation: denied
[6] : microphone: denied
[0] : {"name":"geolocation"}: granted
[1] : {"name":"geolocation"}: denied
[2] : {"name":"microphone"}: granted
[3] : {"name":"geolocation"}: granted
[4] : {"name":"microphone"}: granted
[5] : {"name":"camera","panTiltZoom":true}: granted
[6] : {"name":"geolocation"}: denied
[7] : {"name":"microphone"}: denied
[8] : {"name":"camera","panTiltZoom":true}: denied
[9] : {"name":"camera","panTiltZoom":false}: denied
[10] : {"name":"camera"}: denied
]
......@@ -17,19 +17,21 @@
});
await grant('geolocation');
await waitPermission('geolocation', 'granted');
await waitPermission({name: 'geolocation'}, 'granted');
await grant('audioCapture');
await Promise.all([
waitPermission('geolocation', 'denied'),
waitPermission('microphone', 'granted'),
waitPermission({name: 'geolocation'}, 'denied'),
waitPermission({name: 'microphone'}, 'granted'),
]);
await grant('geolocation', 'audioCapture');
await grant('geolocation', 'audioCapture', 'videoCapturePanTiltZoom');
await Promise.all([
waitPermission('geolocation', 'granted'),
waitPermission('microphone', 'granted'),
waitPermission({name: 'geolocation'}, 'granted'),
waitPermission({name: 'microphone'}, 'granted'),
waitPermission({name: 'camera', panTiltZoom: true}, 'granted'),
waitPermission({name: 'camera', panTiltZoom: false}, 'granted'),
waitPermission({name: 'camera'}, 'granted'),
]);
await grant('eee');
......@@ -37,8 +39,11 @@
testRunner.log('- Resetting all permissions');
await dp.Browser.resetPermissions();
await Promise.all([
waitPermission('geolocation', 'denied'),
waitPermission('microphone', 'denied'),
waitPermission({name: 'geolocation'}, 'denied'),
waitPermission({name: 'microphone'}, 'denied'),
waitPermission({name: 'camera', panTiltZoom: true}, 'denied'),
waitPermission({name: 'camera', panTiltZoom: false}, 'denied'),
waitPermission({name: 'camera'}, 'denied'),
]);
testRunner.log(await session.evaluate(() => window.subscriptionChanges));
......@@ -57,14 +62,14 @@
testRunner.log('- Granted: ' + JSON.stringify(permissions));
}
async function waitPermission(name, state) {
await session.evaluateAsync(async (permission, state) => {
const result = await navigator.permissions.query({name: permission});
async function waitPermission(descriptor, state) {
await session.evaluateAsync(async (descriptor, state) => {
const result = await navigator.permissions.query(descriptor);
if (result.state && result.state === state)
window.messages.push(`${permission}: ${result.state}`);
window.messages.push(`${JSON.stringify(descriptor)}: ${result.state}`);
else
window.messages.push(`Failed to set ${permission} to state: ${state}`);
}, name, state);
}, descriptor, state);
}
})
......@@ -10,6 +10,7 @@ Test that permissions can be changed
- Set: {"name":"midi","sysex":false} to denied
- Set: {"name":"midi","sysex":false} to prompt
- Set: {"name":"push","userVisibleOnly":true} to granted
- Set: {"name":"camera","panTiltZoom":true} to granted
- Set: {"name":"geolocation"} to granted
- Set: {"name":"geolocation"} to denied
[
......@@ -26,6 +27,7 @@ Test that permissions can be changed
[10] : {"name":"midi","sysex":false}: prompt
[11] : {"name":"midi","sysex":true}: prompt
[12] : {"name":"push","userVisibleOnly":true}: granted
[13] : {"name":"geolocation"}: granted
[13] : {"name":"camera","panTiltZoom":true}: granted
[14] : {"name":"geolocation"}: granted
]
......@@ -66,9 +66,14 @@
await dp.Browser.resetPermissions();
// Test "push" permissions userVisibleOnly=true is supported.
await set({name: 'push', userVisibleOnly: true}, 'granted'),
await waitPermission({name: 'push', userVisibleOnly: true}, 'granted'),
await dp.Browser.resetPermissions()
await set({name: 'push', userVisibleOnly: true}, 'granted');
await waitPermission({name: 'push', userVisibleOnly: true}, 'granted');
await dp.Browser.resetPermissions();
// Test "camera" permission panTiltZoom=true is supported.
await set({name: 'camera', panTiltZoom: true}, 'granted');
await waitPermission({name: 'camera', panTiltZoom: true}, 'granted');
await dp.Browser.resetPermissions();
// Cross-origin test.
await setWithName('geolocation', 'granted');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment