Skip to content

Commit

Permalink
[idle] Merge IdleState attributes into IdleDetector
Browse files Browse the repository at this point in the history
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 <reillyg@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#767107}
  • Loading branch information
reillyeon authored and chromium-wpt-export-bot committed May 9, 2020
1 parent d23d904 commit 3a7b40e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 48 deletions.
14 changes: 7 additions & 7 deletions idle-detection/basics.tentative.https.window.js
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 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 = {});
};
16 changes: 8 additions & 8 deletions idle-detection/idle-permission.tentative.https.window.js
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.");
1 change: 0 additions & 1 deletion idle-detection/idlharness.https.window.js
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 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
1 change: 0 additions & 1 deletion idle-detection/resources/idlharness-worker.js
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 3a7b40e

Please sign in to comment.