Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screen Wake Lock] Remove web driver set_permission usage #36122

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
8 changes: 3 additions & 5 deletions screen-wake-lock/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ idl_test(
['screen-wake-lock'],
['dom', 'html'],
async idl_array => {
await test_driver.bless("screen wake lock");
self.sentinel = await navigator.wakeLock.request('screen');
await self.sentinel.release();
idl_array.add_objects({ Navigator: ['navigator'] });

idl_array.add_objects({
WakeLock: ['navigator.wakeLock'],
WakeLockSentinel: ['sentinel'],
});

await test_driver.set_permission(
{ name: 'screen-wake-lock' }, 'granted');
self.sentinel = await navigator.wakeLock.request('screen');
self.sentinel.release();
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="/permissions-policy/resources/permissions-policy.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<body>
<script>
"use strict";

Expand All @@ -17,9 +18,9 @@
const header = 'Permissions-Policy header "screen-wake-lock=*"';

promise_test(async t => {
await test_driver.set_permission(
{ name: 'screen-wake-lock' }, 'granted');
await navigator.wakeLock.request('screen').then(lock => lock.release());
await test_driver.bless("screen wake lock");
const lock = await navigator.wakeLock.request('screen');
await lock.release();
}, `${header} allows the top-level document.`);

async_test(t => {
Expand All @@ -42,6 +43,5 @@
'screen-wake-lock'
);
}, `${header} allows cross-origin iframes.`);

</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
const header = 'Permissions-Policy header "screen-wake-lock=self"';

promise_test(async t => {
await test_driver.set_permission(
{ name: 'screen-wake-lock' }, 'granted');
await navigator.wakeLock.request('screen').then(lock => lock.release());
await test_driver.bless("screen wake lock");
const lock = await navigator.wakeLock.request('screen');
await lock.release();
}, `${header} allows the top-level document.`);

async_test(t => {
Expand Down
5 changes: 0 additions & 5 deletions screen-wake-lock/wakelock-insecure-context.any.js

This file was deleted.

9 changes: 9 additions & 0 deletions screen-wake-lock/wakelock-insecure-context.http.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_false("WakeLock" in self, "'WakeLock' must not be exposed");
}, "Wake Lock API is not exposed in an insecure context");
</script>
46 changes: 25 additions & 21 deletions screen-wake-lock/wakelock-onrelease.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@
<script src="/resources/testdriver-vendor.js"></script>
<script>
promise_test(async t => {
await test_driver.set_permission({name: 'screen-wake-lock'}, 'granted');

await test_driver.bless("screen wake lock");
const lock = await navigator.wakeLock.request("screen");
return new Promise(resolve => {
const releaseEventPromise = new Promise(resolve => {
lock.onrelease = resolve;
lock.release();
}).then(ev => {
assert_class_string(ev, "Event", "release() must fire an Event object");
assert_equals(ev.target, lock, "The event's target must be the lock that was acquired");
assert_true(ev.isTrusted);
assert_false(ev.bubbles);
assert_false(ev.cancelable);
});
}, "Test onreleased event's basic properties");

promise_test(async t => {
await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
await lock.release();
const ev = await releaseEventPromise;
assert_class_string(ev, "Event", "release() must fire an Event object");
assert_equals(ev.target, lock, "The event's target must be the lock that was acquired");
assert_true(ev.isTrusted);
assert_false(ev.bubbles);
assert_false(ev.cancelable);
}, "Test onreleased event firing and attributes");

promise_test(async ()=>{
await test_driver.bless("screen wake lock");
const lock = await navigator.wakeLock.request("screen");

let releaseFired = false;
lock.onrelease = t.step_func(() => {
releaseFired = true;
let result = "";
const releaseEventPromise = new Promise(resolve => {
lock.onrelease = () => {
result += "onrelease event fired";
resolve();
}
});

const releasePromise = lock.release();
assert_true(releaseFired, "The 'release' event fires immediately after release() is called");
const releasePromise = lock.release().then(() => {
result += " then release promise resolved";
});

return releasePromise;
await Promise.all([releaseEventPromise, releasePromise]);
assert_equals(result, "onrelease event fired then release promise resolved");
}, "Ensure onreleased is called before WakeLockSentinel.release() resolves");
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved

</script>

2 changes: 1 addition & 1 deletion screen-wake-lock/wakelock-released.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="/resources/testdriver-vendor.js"></script>
<script>
promise_test(async t => {
await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
await test_driver.bless("screen wake lock");

const lock = await navigator.wakeLock.request("screen");
assert_false(lock.released, "lock.released must be false on creation");
Expand Down
10 changes: 6 additions & 4 deletions screen-wake-lock/wakelock-request-denied.https.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<!DOCTYPE html>
<html>
<body>

<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>
<body>
<script>
'use strict';

promise_test(async t => {
await test_driver.set_permission({name: 'screen-wake-lock'}, 'denied');
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
return promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen'));
await promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen'));
await test_driver.bless("screen wake lock");
const lock = await navigator.wakeLock.request('screen');
await lock.release();
}, 'Denied requests should abort with NotAllowedError');
</script>
</body>
Expand Down

This file was deleted.

24 changes: 24 additions & 0 deletions screen-wake-lock/wakelock-type.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<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>
<body>
<script>
promise_test(async (t) => {
await test_driver.bless("request wake lock");
const lock = await navigator.wakeLock.request();
assert_equals(lock.type, "screen", "Must be screen by default");
await lock.release();
}, "'type' parameter in WakeLock.request() defaults to 'screen'");

promise_test(async (t) => {
const invalidTypes = ["invalid", null, 123, {}, "", true];
for (const invalidType of invalidTypes) {
await promise_rejects_js(
t,
TypeError,
navigator.wakeLock.request(invalidType)
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
);
}
}, "'TypeError' is thrown when set an invalid wake lock type");
</script>
21 changes: 0 additions & 21 deletions screen-wake-lock/wakelock-type.https.window.js

This file was deleted.