Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6199)

Unified Diff: chrome/test/data/generic_sensor/sensor.js

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: rebase + blink reformat Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/generic_sensor/sensor.js
diff --git a/chrome/test/data/generic_sensor/sensor.js b/chrome/test/data/generic_sensor/sensor.js
new file mode 100644
index 0000000000000000000000000000000000000000..d75578d12d0292ad889c0796e21f6c21983aa1c1
--- /dev/null
+++ b/chrome/test/data/generic_sensor/sensor.js
@@ -0,0 +1,44 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var timeOrigin;
+var sensor;
+
+function notifyTestDone() {
+ window.domAutomationController.send(true);
+}
+
+function onAmbientLightReadingChange() {
+ if (sensor.illuminance == 50 &&
+ sensor.timestamp > timeOrigin &&
+ sensor.timestamp < window.performance.now()) {
+ pass();
+ } else {
+ fail();
+ }
+ notifyTestDone();
+}
+
+function onSensorFailed() {
+ notifyTestDone();
+}
+
+function triggerSensorStart() {
+ sensor = new AmbientLightSensor();
+ timeOrigin = window.performance.now();
+ sensor.onchange =
+ onAmbientLightReadingChange;
+ sensor.onerror = onSensorFailed;
+ sensor.start();
+}
+
+function pass() {
+ document.getElementById('status').innerHTML = 'PASS';
+ document.location = '#pass';
+}
+
+function fail() {
+ document.location = '#fail';
+}
+

Powered by Google App Engine
This is Rietveld 408576698