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

idle-detection: Implement requestPermission() method #25399

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion idle-detection/basics.tentative.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

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

promise_test(async t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
relative_worker_frame_path;

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

promise_test(async t => {
Expand Down
Original file line number Diff line number Diff line change
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: 'notifications' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
});

promise_test(async t => {
Expand Down
Original file line number Diff line number Diff line change
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: 'notifications' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
});

promise_test(async t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
same_origin_src;

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

promise_test(async t => {
Expand Down
38 changes: 24 additions & 14 deletions idle-detection/idle-permission.tentative.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@
'use strict';

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

let detector = new IdleDetector();
await promise_rejects_dom(t, 'NotAllowedError', detector.start());
}, "Deny notifications permission should work.");
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: 'notifications' }, 'granted', false);
await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);

let detector = new IdleDetector();
await detector.start();
let detector = new IdleDetector();
await detector.start();

assert_true(['active', 'idle'].includes(detector.userState),
'has a valid user state');
assert_true(['locked', 'unlocked'].includes(detector.screenState),
'has a valid screen state');
}, "Grant notifications permission should work.");
assert_true(
['active', 'idle'].includes(detector.userState),
'has a valid user state');
assert_true(
['locked', 'unlocked'].includes(detector.screenState),
'has a valid screen state');
}, 'Granting idle-detection permission should allow access.');

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

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

await test_driver.bless('request permission');
let state = await IdleDetector.requestPermission();
assert_equals(state, 'prompt');
}, 'The idle-detection permission cannot be requested without a user gesture');
2 changes: 1 addition & 1 deletion idle-detection/idlharness-worker.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ idl_test(
['idle-detection.tentative'],
['dom', 'html'],
async (idl_array, t) => {
await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

promise_setup(async t => {
await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
if (isChromiumBased) {
await loadChromiumResources();
}
Expand Down
1 change: 1 addition & 0 deletions interfaces/idle-detection.tentative.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ enum ScreenIdleState {
readonly attribute UserIdleState? userState;
readonly attribute ScreenIdleState? screenState;
attribute EventHandler onchange;
[Exposed=Window] static Promise<PermissionState> requestPermission();
Promise<any> start(optional IdleOptions options = {});
};