Skip to content

Commit

Permalink
Remove oneRealm arg from set_permission
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored and gsnedders committed Dec 2, 2022
1 parent e4885ed commit bb7292b
Show file tree
Hide file tree
Showing 41 changed files with 70 additions and 136 deletions.
6 changes: 2 additions & 4 deletions docs/writing-tests/testdriver.md
Expand Up @@ -206,15 +206,13 @@ _Note: these special-key codepoints are not necessarily what you would expect. F

### set_permission

Usage: `test_driver.set_permission(descriptor, state, one_realm=false, context=null)`
Usage: `test_driver.set_permission(descriptor, state, context=null)`
* _descriptor_: a
[PermissionDescriptor](https://w3c.github.io/permissions/#dictdef-permissiondescriptor)
or derived object
* _state_: a
[PermissionState](https://w3c.github.io/permissions/#enumdef-permissionstate)
value
* _one_realm_: a boolean that indicates whether the permission settings
apply to only one realm
* context: a WindowProxy for the browsing context in which to perform the call

This function causes permission requests and queries for the status of a
Expand All @@ -226,5 +224,5 @@ Example:

``` js
await test_driver.set_permission({ name: "background-fetch" }, "denied");
await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted", true);
await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted");
```
4 changes: 2 additions & 2 deletions generic-sensor/generic-sensor-permission.https.html
Expand Up @@ -13,15 +13,15 @@
for (const entry of ['accelerometer', 'gyroscope',
'magnetometer', 'ambient-light-sensor']) {
promise_test(async t => {
await test_driver.set_permission({ name: entry }, 'denied', false);
await test_driver.set_permission({ name: entry }, 'denied');

const status = await navigator.permissions.query({ name: entry });
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
}, `Deny ${entry} permission should work.`);

promise_test(async t => {
await test_driver.set_permission({ name: entry }, 'granted', false);
await test_driver.set_permission({ name: entry }, 'granted');

const status = await navigator.permissions.query({ name: entry });
assert_class_string(status, "PermissionStatus");
Expand Down
Expand Up @@ -17,8 +17,7 @@
promise_test(async (t) => {
await test_driver.set_permission(
{ name: "geolocation" },
"granted",
false
"granted"
);

const posError = await new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion idle-detection/basics.tentative.https.window.js
Expand Up @@ -5,7 +5,7 @@
'use strict';

promise_setup(async t => {
await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
await test_driver.set_permission({name: 'idle-detection'}, 'granted');
})

promise_test(async t => {
Expand Down
Expand Up @@ -21,7 +21,7 @@
relative_worker_frame_path;

promise_setup(async () => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');
});

promise_test(async t => {
Expand Down
Expand Up @@ -17,7 +17,7 @@
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;

promise_setup(async () => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');
});

promise_test(async t => {
Expand Down
Expand Up @@ -17,7 +17,7 @@
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;

promise_setup(async () => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');
});

promise_test(async t => {
Expand Down
Expand Up @@ -14,7 +14,7 @@
same_origin_src;

promise_setup(async () => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');
});

promise_test(async t => {
Expand Down
6 changes: 3 additions & 3 deletions idle-detection/idle-permission.tentative.https.window.js
Expand Up @@ -3,14 +3,14 @@
'use strict';

promise_test(async t => {
await test_driver.set_permission({name: 'idle-detection'}, 'denied', false);
await test_driver.set_permission({name: 'idle-detection'}, 'denied');

let detector = new IdleDetector();
await promise_rejects_dom(t, 'NotAllowedError', detector.start());
}, 'Denying idle-detection permission should block access.');

promise_test(async t => {
await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
await test_driver.set_permission({name: 'idle-detection'}, 'granted');

let detector = new IdleDetector();
await detector.start();
Expand All @@ -24,7 +24,7 @@ promise_test(async t => {
}, 'Granting idle-detection permission should allow access.');

promise_test(async t => {
await test_driver.set_permission({name: 'idle-detection'}, 'prompt', false);
await test_driver.set_permission({name: 'idle-detection'}, 'prompt');

await promise_rejects_dom(t, 'NotAllowedError', IdleDetector.requestPermission());

Expand Down
2 changes: 1 addition & 1 deletion idle-detection/idlharness-worker.https.window.js
Expand Up @@ -4,7 +4,7 @@
'use strict';

promise_test(async t => {
await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
await test_driver.set_permission({name: 'idle-detection'}, 'granted');

await fetch_tests_from_worker(new Worker('resources/idlharness-worker.js'));
}, 'Run idlharness tests in a worker.');
2 changes: 1 addition & 1 deletion idle-detection/idlharness.https.window.js
Expand Up @@ -11,7 +11,7 @@ idl_test(
['idle-detection'],
['dom', 'html'],
async (idl_array, t) => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');

self.idle = new IdleDetector();
let watcher = new EventWatcher(t, self.idle, ["change"]);
Expand Down
2 changes: 1 addition & 1 deletion idle-detection/interceptor.https.html
Expand Up @@ -11,7 +11,7 @@
'use strict';

promise_setup(async t => {
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted');
if (isChromiumBased) {
await loadChromiumResources();
}
Expand Down
@@ -1,8 +1,8 @@
[set_permission.https.html]
[Grant Permission for one realm]
[Grant Permission]
expected:
if product != "chrome": FAIL

[Deny Permission, omit one realm]
[Deny Permission]
expected:
if product != "chrome": FAIL
20 changes: 13 additions & 7 deletions infrastructure/testdriver/set_permission.https.html
@@ -1,17 +1,23 @@
<!DOCTYPE html>
<meta charset="utf-8">
<meta charset="utf-8" />
<title>TestDriver set_permission method</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<script>
promise_test(t => {
return test_driver.set_permission({name: "ambient-light-sensor"}, "granted", true);
}, "Grant Permission for one realm");
const descriptor = { name: "geolocation" };

promise_test(t => {
return test_driver.set_permission({name: "push", userVisibleOnly: true}, "denied");
}, "Deny Permission, omit one realm");
promise_test(async (t) => {
await test_driver.set_permission(descriptor, "granted");
permission = await navigator.permissions.query(descriptor);
assert_equals(permission.state, "granted");
}, "Grant Permission");

promise_test(async (t) => {
await test_driver.set_permission(descriptor, "denied");
permission = await navigator.permissions.query(descriptor);
assert_equals(permission.state, "denied");
}, "Deny Permission");
</script>
Expand Up @@ -11,7 +11,7 @@

image_capture_test(async t => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
exposureMode : 'manual',
Expand Down Expand Up @@ -96,7 +96,7 @@

image_capture_test(async t => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'denied', false);
'denied');

let stream = await navigator.mediaDevices.getUserMedia({video: true});
let videoTrack = stream.getVideoTracks()[0];
Expand Down
Expand Up @@ -11,7 +11,7 @@
var makePromiseTest = function(getConstraint) {
image_capture_test(async (t, imageCaptureTest) => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

imageCaptureTest.mockImageCapture().state().supportsTorch = false;

Expand Down
Expand Up @@ -13,7 +13,7 @@

image_capture_test(async (t, imageCaptureTest) => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
exposureMode : 'manual',
Expand Down
6 changes: 3 additions & 3 deletions mediacapture-image/MediaStreamTrack-clone.https.html
Expand Up @@ -11,7 +11,7 @@
// original, with a mock Mojo service implementation.
image_capture_test(async (t, imageCaptureTest) => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
exposureMode : 'manual',
Expand Down Expand Up @@ -126,7 +126,7 @@
// when cloning a MediaStreamTrack.
image_capture_test(async (t, imageCaptureTest) => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

let stream = await navigator.mediaDevices.getUserMedia({video: true});
let originalVideoTrack = stream.getVideoTracks()[0];
Expand Down Expand Up @@ -199,7 +199,7 @@
// when cloning a MediaStreamTrack.
image_capture_test(async (t, imageCaptureTest) => {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

let stream = await navigator.mediaDevices.getUserMedia({video: true});
let originalVideoTrack = stream.getVideoTracks()[0];
Expand Down
Expand Up @@ -16,7 +16,7 @@
image_capture_test(async (t, imageCaptureTest) => {
const ptzPermission = hasPanTiltZoomPermissionGranted ? 'granted' : 'denied';
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
ptzPermission, false);
ptzPermission);

let mockCapabilities = imageCaptureTest.mockImageCapture().state();

Expand Down
Expand Up @@ -32,7 +32,7 @@
function makePromiseTest(constraint) {
image_capture_test(async function(t) {
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
'granted', false);
'granted');

let stream = await navigator.mediaDevices.getUserMedia({video: true});
let videoTrack = stream.getVideoTracks()[0];
Expand Down
2 changes: 1 addition & 1 deletion mediacapture-image/MediaStreamTrack-getSettings.https.html
Expand Up @@ -17,7 +17,7 @@
image_capture_test(async (t, imageCaptureTest) => {
const ptzPermission = hasPanTiltZoomPermissionGranted ? 'granted' : 'denied';
await test_driver.set_permission({name: 'camera', panTiltZoom: true},
ptzPermission, false);
ptzPermission);

let mockSettings = imageCaptureTest.mockImageCapture().state();

Expand Down
2 changes: 1 addition & 1 deletion mediacapture-streams/permission-helper.js
Expand Up @@ -4,7 +4,7 @@
async function setMediaPermission(status="granted", scope=["camera", "microphone"]) {
try {
for (let s of scope) {
await test_driver.set_permission({ name: s }, status, true);
await test_driver.set_permission({ name: s }, status);
}
} catch (e) {
const noSetPermissionSupport = typeof e === "string" && e.match(/set_permission not implemented/);
Expand Down
Expand Up @@ -7,8 +7,7 @@
test_driver.set_test_context(window.parent);
await test_driver.set_permission(
{ name: "geolocation" },
"granted",
false
"granted"
);
let enabled = true;
try {
Expand Down
Expand Up @@ -6,7 +6,7 @@
Promise.resolve().then(async () => {
try {
await test_driver.set_permission(
{ name: 'screen-wake-lock' }, 'granted', false);
{ name: 'screen-wake-lock' }, 'granted');

const wakeLock = await navigator.wakeLock.request("screen");
await wakeLock.release();
Expand Down
2 changes: 1 addition & 1 deletion resources/chromium/generic_sensor_mocks.js
Expand Up @@ -490,7 +490,7 @@ self.GenericSensorTest = (() => {
for (const entry
of ['accelerometer', 'gyroscope', 'magnetometer',
'ambient-light-sensor']) {
await test_driver.set_permission({name: entry}, 'granted', false);
await test_driver.set_permission({name: entry}, 'granted');
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/chromium/nfc-mock.js
Expand Up @@ -410,7 +410,7 @@ self.WebNFCTest = (() => {
throw new Error('Call reset() before initialize().');

// Grant nfc permissions for Chromium testdriver.
await test_driver.set_permission({ name: 'nfc' }, 'granted', false);
await test_driver.set_permission({ name: 'nfc' }, 'granted');

if (testInternal.mockNFC == null) {
testInternal.mockNFC = new MockNFC();
Expand Down
12 changes: 5 additions & 7 deletions resources/testdriver.js
Expand Up @@ -398,24 +398,22 @@
*
* @example
* await test_driver.set_permission({ name: "background-fetch" }, "denied");
* await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted", true);
* await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted");
*
* @param {Object} descriptor - a `PermissionDescriptor
* <https://w3c.github.io/permissions/#dictdef-permissiondescriptor>`_
* object
* @param {PermissionDescriptor} descriptor - a `PermissionDescriptor
* <https://w3c.github.io/permissions/#dom-permissiondescriptor>`_
* dictionary.
* @param {String} state - the state of the permission
* @param {boolean} one_realm - Optional. Whether the permission applies to only one realm
* @param {WindowProxy} context - Browsing context in which
* to run the call, or null for the current
* browsing context.
* @returns {Promise} fulfilled after the permission is set, or rejected if setting the
* permission fails
*/
set_permission: function(descriptor, state, one_realm=false, context=null) {
set_permission: function(descriptor, state, context=null) {
let permission_params = {
descriptor,
state,
oneRealm: one_realm,
};
return window.test_driver_internal.set_permission(permission_params, context);
},
Expand Down
4 changes: 2 additions & 2 deletions screen-details/screen_enumeration_permission.https.window.js
Expand Up @@ -4,15 +4,15 @@
"use strict";

promise_test(async t => {
await test_driver.set_permission({ name: "window-placement" }, "denied", false);
await test_driver.set_permission({ name: "window-placement" }, "denied");

const status = await navigator.permissions.query({ name:"window-placement" });
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
}, "Deny window management permission should work.");

promise_test(async t => {
await test_driver.set_permission({ name: "window-placement" }, "granted", false);
await test_driver.set_permission({ name: "window-placement" }, "granted");

const status = await navigator.permissions.query({ name: "window-placement" });
assert_class_string(status, "PermissionStatus");
Expand Down
Expand Up @@ -30,8 +30,7 @@
// periodicSync.register() waits until the permission is granted, which
// is deferred during prerendering so the test would trivially pass without
// the permission.
await test_driver.set_permission({name: 'periodic-background-sync'}, 'granted',
location.origin, location.origin);
await test_driver.set_permission({name: 'periodic-background-sync'}, 'granted');

// Install the service worker first to test periodicSync.register in the
// prerendering page.
Expand Down
Expand Up @@ -21,7 +21,7 @@
// is deferred during prerendering so the test would trivially pass without
// the permission.
await test_driver.set_permission(
{name: 'midi', sysex: true}, 'granted', true);
{name: 'midi', sysex: true}, 'granted');

const gotMessage = new Promise(resolve => {
bc.addEventListener('message', e => {
Expand Down

0 comments on commit bb7292b

Please sign in to comment.