-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sensors: Add virtual sensor-related commands to testdriver
Spec PR: w3c/sensors#470 The Generic Sensor spec used to have an Automation section, but it leaked implementation-specific details and was not implemented anywhere. The changes above have been implemented in Chromium and there are pending patches there to convert the existing Generic Sensor web tests in WPT to the new virtual sensor model, which entirely removes the dependency on Mojo mocks and makes the tests more interoperable. This PR adds the required infrastructure to manipulate virtual sensors from testdriver. The 4 new commands correspond to the 4 WebDriver extension commands added by the spec PR above. This change was co-authored with @JuhaVainio. Related to #9686.
- Loading branch information
Raphael Kubo da Costa
committed
Oct 10, 2023
1 parent
28cb182
commit 0dd2d80
Showing
10 changed files
with
427 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
infrastructure/metadata/infrastructure/testdriver/virtual_sensors.https.html.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# The tests below require test_driver.set_permission() support in addition to | ||
# support for the virtual sensor calls themselves. | ||
[virtual_sensors.https.html] | ||
[Test that virtual sensors can be created and removed.] | ||
expected: | ||
if product != "chrome": FAIL | ||
|
||
[Test that unavailable virtual sensors can be created.] | ||
expected: | ||
if product != "chrome": FAIL | ||
|
||
[Test that minimum frequency setting works and virtual sensor information can be fetched.] | ||
expected: | ||
if product != "chrome": FAIL | ||
|
||
[Test that virtual sensors can be updated.] | ||
expected: | ||
if product != "chrome": FAIL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>TestDriver virtual sensors methods</title> | ||
<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"; | ||
|
||
promise_test(async t => { | ||
const sensorType = 'gyroscope'; | ||
await test_driver.set_permission({name: sensorType}, 'granted'); | ||
await test_driver.create_virtual_sensor(sensorType); | ||
|
||
const sensor = new Gyroscope(); | ||
t.add_cleanup(async () => { | ||
sensor.stop(); | ||
await test_driver.remove_virtual_sensor(sensorType); | ||
}); | ||
const watcher = new EventWatcher(t, sensor, ['activate']); | ||
|
||
sensor.start(); | ||
await watcher.wait_for('activate'); | ||
}, "Test that virtual sensors can be created and removed."); | ||
|
||
promise_test(async t => { | ||
const sensorType = 'gyroscope'; | ||
await test_driver.set_permission({name: sensorType}, 'granted'); | ||
await test_driver.create_virtual_sensor(sensorType, {connected: false}); | ||
|
||
const sensor = new Gyroscope(); | ||
t.add_cleanup(async () => { | ||
sensor.stop(); | ||
await test_driver.remove_virtual_sensor(sensorType); | ||
}); | ||
|
||
const watcher = new EventWatcher(t, sensor, ['error']); | ||
sensor.start(); | ||
const error = await watcher.wait_for('error'); | ||
assert_equals(error.error.name, 'NotReadableError'); | ||
}, "Test that unavailable virtual sensors can be created."); | ||
|
||
promise_test(async t => { | ||
const sensorType = 'gyroscope'; | ||
const minSamplingFrequency = 6.0; | ||
|
||
await test_driver.set_permission({name: sensorType}, 'granted'); | ||
await test_driver.create_virtual_sensor(sensorType, {minSamplingFrequency}); | ||
|
||
const sensor = new Gyroscope({frequency: 5.0}); | ||
t.add_cleanup(async () => { | ||
sensor.stop(); | ||
await test_driver.remove_virtual_sensor(sensorType); | ||
}); | ||
|
||
const watcher = new EventWatcher(t, sensor, ['activate', 'reading', 'error']); | ||
sensor.start(); | ||
await watcher.wait_for('activate'); | ||
|
||
const info = await test_driver.get_virtual_sensor_information(sensorType); | ||
|
||
assert_equals(info['isReadingData'], true); | ||
assert_equals(info['requestedSamplingFrequency'], minSamplingFrequency); | ||
}, "Test that minimum frequency setting works and virtual sensor information can be fetched."); | ||
|
||
promise_test(async t => { | ||
const sensorType = 'accelerometer'; | ||
await test_driver.set_permission({name: sensorType}, 'granted'); | ||
await test_driver.create_virtual_sensor(sensorType); | ||
|
||
const sensor = new Accelerometer(); | ||
t.add_cleanup(async () => { | ||
sensor.stop(); | ||
await test_driver.remove_virtual_sensor(sensorType); | ||
}); | ||
|
||
const watcher = new EventWatcher(t, sensor, ['activate', 'reading', 'error']); | ||
sensor.start(); | ||
await watcher.wait_for('activate'); | ||
|
||
const reading = {'x': 1.0, 'y': 2.0, 'z': 3.0}; | ||
test_driver.update_virtual_sensor(sensorType, reading); | ||
|
||
await watcher.wait_for('reading'); | ||
assert_equals(sensor.x, reading.x); | ||
assert_equals(sensor.y, reading.y); | ||
assert_equals(sensor.z, reading.z); | ||
}, "Test that virtual sensors can be updated."); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.