Skip to content

Commit

Permalink
Bug 1636000 [wpt PR 23447] - [idle] Merge IdleState attributes into I…
Browse files Browse the repository at this point in the history
…dleDetector, a=testonly

Automatic update from web-platform-tests
[idle] Merge IdleState attributes into IdleDetector

The IdleState interface adds unnecessary overhead (code size and memory
usage). These attributes can be added directly to the IdleDetector
interface.

Explainer PR: WICG/idle-detection#22

Bug: 878979
Change-Id: Ic92f5fff0ee540d640dc009d391a60c372490bfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2186655
Commit-Queue: Reilly Grant <[email protected]>
Auto-Submit: Reilly Grant <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Ayu Ishii <[email protected]>
Cr-Commit-Position: refs/heads/master@{#767107}

--

wpt-commits: 3a7b40eb73bf5359adf0d378b71d36488885057f
wpt-pr: 23447
  • Loading branch information
reillyeon authored and moz-wptsync-bot committed May 20, 2020
1 parent 79ff71a commit 5eba865
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ promise_setup(async t => {
})

promise_test(async t => {
let status = new IdleDetector();
let watcher = new EventWatcher(t, status, ["change"]);
let detector = new IdleDetector();
let watcher = new EventWatcher(t, detector, ["change"]);
let initial_state = watcher.wait_for("change");

await status.start();
await detector.start();
await initial_state;

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');
assert_true(['active', 'idle'].includes(detector.userState),
'has a valid user state');
assert_true(['locked', 'unlocked'].includes(detector.screenState),
'has a valid screen state');
}, 'start() basics');

promise_test(async t => {
Expand Down
29 changes: 11 additions & 18 deletions testing/web-platform/tests/idle-detection/idle-detection.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@ dictionary IdleOptions {
AbortSignal signal;
};

[
SecureContext,
Exposed=(Window,Worker)
] interface IdleDetector : EventTarget {
constructor();
readonly attribute IdleState state;
attribute EventHandler onchange;
Promise<any> start(optional IdleOptions options = {});
};

[
SecureContext,
Exposed=(Window,Worker)
] interface IdleState {
readonly attribute UserIdleState user;
readonly attribute ScreenIdleState screen;
};

enum UserIdleState {
"active",
"idle"
Expand All @@ -30,3 +12,14 @@ enum ScreenIdleState {
"locked",
"unlocked"
};

[
SecureContext,
Exposed=(Window,Worker)
] interface IdleDetector : EventTarget {
constructor();
readonly attribute UserIdleState? userState;
readonly attribute ScreenIdleState? screenState;
attribute EventHandler onchange;
Promise<any> start(optional IdleOptions options = {});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ promise_test(async t => {
await test_driver.set_permission(
{ name: 'notifications' }, 'denied', false);

let status = new IdleDetector();
await promise_rejects_dom(t, 'NotAllowedError', status.start());
let detector = new IdleDetector();
await promise_rejects_dom(t, 'NotAllowedError', detector.start());
}, "Deny notifications permission should work.");

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

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

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');
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.");
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ promise_test(async (t) => {

idl_array.add_objects({
IdleDetector: ['idle'],
IdleState: ['idle.state']
});

idl_array.test();
Expand Down
26 changes: 13 additions & 13 deletions testing/web-platform/tests/idle-detection/interceptor.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
await detector.start({ signal: controller.signal });
await initial_state;

assert_equals(detector.state.user, "active");
assert_equals(detector.state.screen, "locked");
assert_equals(detector.userState, "active");
assert_equals(detector.screenState, "locked");

controller.abort();
}, 'start()');
Expand Down Expand Up @@ -75,8 +75,8 @@
// Wait for the first change in state.
await watcher.wait_for("change");

assert_equals(detector.state.user, "idle");
assert_equals(detector.state.screen, "unlocked");
assert_equals(detector.userState, "idle");
assert_equals(detector.screenState, "unlocked");

controller.abort();
}, 'updates once');
Expand Down Expand Up @@ -120,11 +120,11 @@

// Waits for the first event.
await watcher.wait_for("change");
assert_equals(detector.state.user, "idle");
assert_equals(detector.userState, "idle");

// Waits for the second event.
await watcher.wait_for("change");
assert_equals(detector.state.user, "active");
assert_equals(detector.userState, "active");

controller.abort();
}, 'updates twice');
Expand All @@ -148,7 +148,7 @@
await detector.start({ signal: controller.signal });
await initial_state;

assert_equals(detector.state.screen, "locked");
assert_equals(detector.screenState, "locked");

controller.abort();
}, 'locked screen');
Expand All @@ -175,8 +175,8 @@
// Waits for the first event.
await event;

assert_equals(detector.state.user, "active");
assert_equals(detector.state.screen, "locked");
assert_equals(detector.userState, "active");
assert_equals(detector.screenState, "locked");

controller.abort();
}, 'IdleDetector.onchange');
Expand All @@ -203,8 +203,8 @@
await start_promise;

await initial_state;
assert_equals(detector.state.user, "active");
assert_equals(detector.state.screen, "unlocked");
assert_equals(detector.userState, "active");
assert_equals(detector.screenState, "unlocked");

// Calling abort() multiple times is safe.
controller.abort();
Expand Down Expand Up @@ -268,8 +268,8 @@
initial_state = watcher.wait_for("change");
await detector.start({ signal: controller.signal });
await initial_state;
assert_equals(detector.state.user, "idle");
assert_equals(detector.state.screen, "locked");
assert_equals(detector.userState, "idle");
assert_equals(detector.screenState, "locked");

controller.abort();
}, 'Calling start() after stop(): re-starting monitor.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ idl_test(

idl_array.add_objects({
IdleDetector: ['idle'],
IdleState: ['idle.state']
});
}
);
Expand Down

0 comments on commit 5eba865

Please sign in to comment.