Sam Goto | f8d3bd8 | 2019-03-27 17:44:48 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <link rel="help" href="https://github.com/samuelgoto/idle-detection"> |
| 3 | <title>Tests the Idle Detection API</title> |
| 4 | <script src="../resources/testharness.js"></script> |
| 5 | <script src="../resources/testharnessreport.js"></script> |
| 6 | <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| 7 | <script src="file:///gen/mojo/public/mojom/base/string16.mojom.js"></script> |
| 8 | <script src="file:///gen/mojo/public/mojom/base/time.mojom.js"></script> |
| 9 | <script src="file:///gen/third_party/blink/public/mojom/idle/idle_manager.mojom.js"></script> |
| 10 | <script src="../external/wpt/idle-detection/mock.js"></script> |
| 11 | <script> |
| 12 | 'use strict'; |
| 13 | |
| 14 | promise_test(async t => { |
| 15 | let monitor; |
| 16 | |
| 17 | expect(addMonitor).andReturn((threshold, monitorPtr) => { |
| 18 | monitor = monitorPtr; |
| 19 | return Promise.resolve({ |
| 20 | state: { |
| 21 | user: UserIdleState.ACTIVE, |
| 22 | screen: ScreenIdleState.UNLOCKED |
| 23 | } |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | |
| 28 | let detector = new IdleDetector({threshold: 60}); |
| 29 | |
| 30 | let watcher = new EventWatcher(t, detector, ["change"]); |
| 31 | |
| 32 | await detector.start(); |
| 33 | |
| 34 | // Waits for the first event. |
| 35 | await watcher.wait_for("change"); |
| 36 | |
| 37 | assert_equals(detector.state.user, "active"); |
| 38 | |
| 39 | testRunner.setPageVisibility("hidden"); |
| 40 | |
| 41 | monitor.update({ |
| 42 | user: UserIdleState.IDLE, |
| 43 | screen: ScreenIdleState.UNLOCKED |
| 44 | }); |
| 45 | |
| 46 | // Assert that the detector works while the page is not visible. |
| 47 | await watcher.wait_for("change"); |
| 48 | assert_equals(detector.state.user, "idle"); |
| 49 | |
| 50 | testRunner.setPageVisibility("visible"); |
| 51 | |
| 52 | monitor.update({ |
| 53 | user: UserIdleState.ACTIVE, |
| 54 | screen: ScreenIdleState.UNLOCKED |
| 55 | }); |
| 56 | |
| 57 | await watcher.wait_for("change"); |
| 58 | assert_equals(detector.state.user, "active"); |
| 59 | |
| 60 | detector.stop(); |
| 61 | |
| 62 | }, 'Page visibility.'); |
| 63 | |
| 64 | </script> |