fune/testing/web-platform/tests/idle-detection/basics.tentative.https.any.js
Ayu Ishii 59a78c104f Bug 1539463 [wpt PR 16033] - [idle] Add a threshold minimum of 60 seconds in IdleDetector, a=testonly
Automatic update from web-platform-tests
[idle] Add a threshold minimum of 60 seconds in IdleDetector

This change adds a minimum threshold of 60 seconds to prevent sites from
observing user signals such as typing cadence, or identifying users
with physical or cognitive imparments that may require more time to
interact with user agents and content.

Bug: 939883
Change-Id: I3ab19b2f7d6711c14356575d338819f501eafb9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1535286
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643965}

--

wpt-commits: ea7981d4c3eb888bcc3d19b0270937c06b92e4f6
wpt-pr: 16033
2019-04-24 11:30:54 +01:00

94 lines
2.4 KiB
JavaScript

// META: title=Idle Detection API: Basics
'use strict';
promise_test(async t => {
let status = new IdleDetector();
let watcher = new EventWatcher(t, status, ["change"]);
await status.start();
await watcher.wait_for("change");
assert_true(['active', 'idle'].includes(status.state.user),
'status has a valid user state');
assert_true(['locked', 'unlocked'].includes(status.state.screen),
'status has a valid screen state');
}, 'start() basics');
promise_test(async t => {
let used = false;
new IdleDetector({
get threshold() {
used = true;
return 60;
}
});
assert_true(used, 'constructor options "threshold" member was used');
}, 'constructor uses threshold property');
promise_test(async t => {
try {
new IdleDetector({threshold: 0});
assert_unreached('Threshold under 60 should reject');
} catch (error) {
assert_equals(error.name, 'TypeError');
}
}, 'constructor throws with invalid threshold (0)');
promise_test(async t => {
try {
new IdleDetector({threshold: 59});
assert_unreached('Threshold under 60 should reject');
} catch (error) {
assert_equals(error.name, 'TypeError');
}
}, 'constructor throws with threshold below minimum (59)');
promise_test(async t => {
new IdleDetector({threshold: 60});
}, 'constructor allows threshold (60)');
promise_test(async t => {
new IdleDetector({threshold: 61});
}, 'constructor allows threshold (61)');
promise_test(async t => {
try {
new IdleDetector({threshold: null});
assert_unreached('Threshold of null should reject');
} catch (error) {
assert_equals(error.name, 'TypeError');
}
}, 'constructor throws with invalid threshold (null)');
promise_test(async t => {
try {
new IdleDetector({threshold: -1});
assert_unreached('Threshold of negative numbers should reject');
} catch (error) {
assert_equals(error.name, 'TypeError');
}
}, 'constructor throws with invalid threshold (-1)');
promise_test(async t => {
try {
new IdleDetector({threshold: NaN});
assert_unreached('Threshold of NaN should reject');
} catch (error) {
assert_equals(error.name, 'TypeError');
}
}, 'constructor throws with invalid threshold (NaN)');
promise_test(async t => {
new IdleDetector();
}, 'constructor uses a default value for the threshold when none is passed');
promise_test(async t => {
new IdleDetector({threshold: undefined});
}, 'constructor uses a default value for the threshold');