Skip to content

Commit

Permalink
[sensor] Set permissions in WPT tests
Browse files Browse the repository at this point in the history
Thanks to the new set_permission method on test_runner, this CL
makes sure the sensor WPT tests with first granted permission and
adds tests for sensor permission status.

Change-Id: Id72e60f92043986c3fe3517faf0c79716a1f03c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2104654
Reviewed-by: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Cr-Commit-Position: refs/heads/master@{#751207}
  • Loading branch information
Honry authored and chromium-wpt-export-bot committed Mar 18, 2020
1 parent 175d843 commit d18df87
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
32 changes: 32 additions & 0 deletions generic-sensor/generic-sensor-permission.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>sensor: permission</title>
<link rel="help" href="https://w3c.github.io/sensors/"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>

"use strict";

for (const entry of ['accelerometer', 'gyroscope',
'magnetometer', 'ambient-light-sensor']) {
promise_test(async t => {
await test_driver.set_permission({ name: entry }, 'denied', false);

const status = await navigator.permissions.query({ name: entry });
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
}, `Deny ${entry} permission should work.`);

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

const status = await navigator.permissions.query({ name: entry });
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "granted");
}, `Grant ${entry} permission should work.`);
};

</script>
2 changes: 2 additions & 0 deletions generic-sensor/resources/generic-sensor-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const loadChromiumResources = async () => {
'/gen/mojo/public/mojom/base/string16.mojom.js',
'/gen/services/device/public/mojom/sensor.mojom.js',
'/gen/services/device/public/mojom/sensor_provider.mojom.js',
'/resources/testdriver.js',
'/resources/testdriver-vendor.js',
'/resources/chromium/generic_sensor_mocks.js',
];

Expand Down
15 changes: 6 additions & 9 deletions resources/chromium/generic_sensor_mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,15 @@ var GenericSensorTest = (() => {
Object.freeze(this); // Make it immutable.
}

initialize() {
async initialize() {
if (testInternal.initialized)
throw new Error('Call reset() before initialize().');

if (window.testRunner) {
// Grant sensor permissions for Chromium testrunner.
['accelerometer', 'gyroscope',
'magnetometer', 'ambient-light-sensor'].forEach((entry) => {
window.testRunner.setPermission(entry, 'granted',
location.origin, location.origin);
});
}
// Grant sensor permissions for Chromium testdriver.
for (const entry of ['accelerometer', 'gyroscope',
'magnetometer', 'ambient-light-sensor']) {
await test_driver.set_permission({ name: entry }, 'granted', false);
};

testInternal.sensorProvider = new MockSensorProvider;
testInternal.initialized = true;
Expand Down

0 comments on commit d18df87

Please sign in to comment.