OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var timeOrigin; |
| 6 var sensor; |
| 7 |
| 8 function notifyTestDone() { |
| 9 window.domAutomationController.send(true); |
| 10 } |
| 11 |
| 12 function onAmbientLightReadingChange() { |
| 13 if (sensor.illuminance == 50 && |
| 14 sensor.timestamp > timeOrigin && |
| 15 sensor.timestamp < window.performance.now()) { |
| 16 pass(); |
| 17 } else { |
| 18 fail(); |
| 19 } |
| 20 notifyTestDone(); |
| 21 } |
| 22 |
| 23 function onSensorFailed() { |
| 24 notifyTestDone(); |
| 25 } |
| 26 |
| 27 function triggerSensorStart() { |
| 28 sensor = new AmbientLightSensor(); |
| 29 timeOrigin = window.performance.now(); |
| 30 sensor.onchange = |
| 31 onAmbientLightReadingChange; |
| 32 sensor.onerror = onSensorFailed; |
| 33 sensor.start(); |
| 34 } |
| 35 |
| 36 function pass() { |
| 37 document.getElementById('status').innerHTML = 'PASS'; |
| 38 document.location = '#pass'; |
| 39 } |
| 40 |
| 41 function fail() { |
| 42 document.location = '#fail'; |
| 43 } |
| 44 |
OLD | NEW |