mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
Update web-platform-tests to revision b7a8b84debb42268ea95a45bdad8f727d1facdf7
This commit is contained in:
parent
ba929208e4
commit
953dbda9a6
215 changed files with 6409 additions and 1644 deletions
|
@ -1,19 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<link rel="help" href="https://github.com/inexorabletash/idle-detection">
|
||||
<link rel="help" href="https://github.com/samuelgoto/idle-detection">
|
||||
<title>Tests the Idle Detection API</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
|
||||
<script src="/gen/mojo/public/mojom/base/string16.mojom.js"></script>
|
||||
<script src="/gen/mojo/public/mojom/base/time.mojom.js"></script>
|
||||
<script src="/gen/third_party/blink/public/platform/modules/idle/idle_manager.mojom.js"></script>
|
||||
<script src="/gen/third_party/blink/public/mojom/idle/idle_manager.mojom.js"></script>
|
||||
<script src="mock.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
promise_test(async t => {
|
||||
// Basic test that expects navigator.idle.query() to call internally
|
||||
// addMonitor, which in turn will return an ACTIVE state.
|
||||
// Basic test that expects start() to call internally
|
||||
// addMonitor, which in turn return an ACTIVE state.
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
|
@ -23,36 +23,58 @@ promise_test(async t => {
|
|||
});
|
||||
});
|
||||
|
||||
let status = await navigator.idle.query({threshold: 10});
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
assert_equals(status.state.user, "active");
|
||||
assert_equals(status.state.screen, "locked");
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
await detector.start();
|
||||
|
||||
// Waits for the first event.
|
||||
await watcher.wait_for("change");
|
||||
|
||||
assert_equals(detector.state.user, "active");
|
||||
assert_equals(detector.state.screen, "locked");
|
||||
|
||||
detector.stop();
|
||||
}, 'query()');
|
||||
|
||||
promise_test(async t => {
|
||||
// Verifies that an event is thrown when a change of state from IDLE to ACTIVE
|
||||
// is detected.
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
let first = Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
|
||||
t.step_timeout(() => {
|
||||
monitorPtr.update({
|
||||
user: UserIdleState.IDLE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
});
|
||||
}, 0);
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
|
||||
return first;
|
||||
});
|
||||
|
||||
let monitor = await navigator.idle.query({threshold: 10});
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
await new EventWatcher(t, monitor, ["change"]).wait_for("change");
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
assert_equals(monitor.state.user, "idle");
|
||||
assert_equals(monitor.state.screen, "unlocked");
|
||||
await detector.start();
|
||||
|
||||
// Wait for the initial state.
|
||||
await watcher.wait_for("change");
|
||||
|
||||
// Wait for the first change in state.
|
||||
await watcher.wait_for("change");
|
||||
|
||||
assert_equals(detector.state.user, "idle");
|
||||
assert_equals(detector.state.screen, "unlocked");
|
||||
|
||||
detector.stop();
|
||||
}, 'updates once');
|
||||
|
||||
|
||||
|
@ -60,6 +82,13 @@ promise_test(async t => {
|
|||
// Simulates the user being active, going idle and then going back active
|
||||
// again.
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
let first = Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
|
||||
// Updates the client once with the user idle.
|
||||
t.step_timeout(() => {
|
||||
monitorPtr.update({
|
||||
|
@ -74,25 +103,27 @@ promise_test(async t => {
|
|||
screen: ScreenIdleState.UNLOCKED
|
||||
});
|
||||
}, 1);
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
return first;
|
||||
});
|
||||
|
||||
let monitor = await navigator.idle.query({threshold: 10});
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
let watcher = new EventWatcher(t, monitor, ["change"]);
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
// waits for the first event.
|
||||
await detector.start();
|
||||
|
||||
// Waits for the initial state.
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(monitor.state.user, "idle");
|
||||
|
||||
// waits for the second event.
|
||||
// Waits for the first event.
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(monitor.state.user, "active");
|
||||
assert_equals(detector.state.user, "idle");
|
||||
|
||||
// Waits for the second event.
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(detector.state.user, "active");
|
||||
|
||||
detector.stop();
|
||||
}, 'updates twice');
|
||||
|
||||
promise_test(async t => {
|
||||
|
@ -106,28 +137,140 @@ promise_test(async t => {
|
|||
});
|
||||
});
|
||||
|
||||
let monitor = await navigator.idle.query({threshold: 10});
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
assert_equals(monitor.state.screen, "locked");
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
await detector.start();
|
||||
|
||||
// waits for the initial state.
|
||||
await watcher.wait_for("change");
|
||||
|
||||
assert_equals(detector.state.screen, "locked");
|
||||
|
||||
detector.stop();
|
||||
}, 'locked screen');
|
||||
|
||||
promise_test(async t => {
|
||||
// Simulates the service becoming unavailable.
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// leave the renderer deliberately hanging by not resolve()-ing.
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.LOCKED
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
let event = new Promise((resolve, reject) => {
|
||||
detector.onchange = resolve;
|
||||
});
|
||||
|
||||
await detector.start();
|
||||
|
||||
// Waits for the first event.
|
||||
await event;
|
||||
|
||||
assert_equals(detector.state.user, "active");
|
||||
assert_equals(detector.state.screen, "locked");
|
||||
|
||||
detector.stop();
|
||||
}, 'IdleDetector.onchange');
|
||||
|
||||
promise_test(async t => {
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let error = new Promise((resolve, reject) => {
|
||||
navigator.idle.query({threshold: 10})
|
||||
.then((e) => {reject("unexpected response :(")})
|
||||
.catch((e) => {resolve(e.message)});
|
||||
});
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
// simulates what happens when the service is unavailable.
|
||||
close();
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
assert_equals(await error, "Idle detection not available");
|
||||
}, "service unavailable");
|
||||
</script>
|
||||
// Calling start() multiple times should be safe.
|
||||
await detector.start();
|
||||
await detector.start();
|
||||
await detector.start();
|
||||
await detector.start();
|
||||
|
||||
// waits for the initial state.
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(detector.state.user, "active");
|
||||
assert_equals(detector.state.screen, "unlocked");
|
||||
|
||||
// Calling stop() multiple times should be safe.
|
||||
detector.stop();
|
||||
detector.stop();
|
||||
detector.stop();
|
||||
detector.stop();
|
||||
}, 'Safe to call start() or stop() multiple times');
|
||||
|
||||
promise_test(async t => {
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
// Calling stop() before start() is a no-op.
|
||||
detector.stop();
|
||||
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
await detector.start();
|
||||
|
||||
// waits for the initial state.
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(detector.state.user, "active");
|
||||
assert_equals(detector.state.screen, "unlocked");
|
||||
|
||||
detector.stop();
|
||||
}, 'Calling stop() after start() is a no-op');
|
||||
|
||||
promise_test(async t => {
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.ACTIVE,
|
||||
screen: ScreenIdleState.UNLOCKED
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let detector = new IdleDetector({threshold: 10});
|
||||
|
||||
let watcher = new EventWatcher(t, detector, ["change"]);
|
||||
|
||||
await detector.start();
|
||||
await watcher.wait_for("change");
|
||||
detector.stop();
|
||||
|
||||
expect(addMonitor).andReturn((threshold, monitorPtr) => {
|
||||
return Promise.resolve({
|
||||
state: {
|
||||
user: UserIdleState.IDLE,
|
||||
screen: ScreenIdleState.LOCKED
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Restarting the monitor.
|
||||
await detector.start();
|
||||
await watcher.wait_for("change");
|
||||
assert_equals(detector.state.user, "idle");
|
||||
assert_equals(detector.state.screen, "locked");
|
||||
|
||||
detector.stop();
|
||||
}, 'Calling start() after stop(): re-starting monitor.');
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue