0

Convert existing device posture web tests to test_driver

The purpose of this change is start using WebDriver. WebDriver commands
for Device Posture are defined in
https://www.w3.org/TR/device-posture/#automation

third_party/blink/web_tests/http/tests/inspector-protocol/device-posture/device-posture-default.js
was not converted because other tests already had same code and read
posture through navigator.devicePosture.type.

Bug: 330376761
Change-Id: Iae11dde0e2556cf56e1648f0011109f997178810
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5471734
Commit-Queue: Alexis Menard <alexis.menard@intel.com>
Reviewed-by: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Auto-Submit: Juha J Vainio <juha.j.vainio@intel.com>
Reviewed-by: Alexis Menard <alexis.menard@intel.com>
Cr-Commit-Position: refs/heads/main@{#1291947}
This commit is contained in:
Juha Vainio
2024-04-24 17:03:34 +00:00
committed by Chromium LUCI CQ
parent 5b4a117e8c
commit e49c60394e
12 changed files with 104 additions and 122 deletions

@ -0,0 +1,23 @@
<!DOCTYPE html>
<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) => {
t.add_cleanup(async () => {
await test_driver.clear_device_posture();
});
const watcher = new EventWatcher(t, navigator.devicePosture, ['change']);
const postures = ['folded', 'continuous', 'folded'];
for (const posture of postures) {
await Promise.all([
watcher.wait_for('change'),
test_driver.set_device_posture(posture)
]);
assert_equals(posture, navigator.devicePosture.type);
}
}, 'Tests the Device Posture API change event handler.');
</script>

@ -0,0 +1,29 @@
<!DOCTYPE html>
<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) => {
t.add_cleanup(async () => {
await test_driver.clear_device_posture();
});
const originalPosture = navigator.devicePosture.type;
const posture = originalPosture ? 'folded' : 'continuous';
const watcher = new EventWatcher(t, navigator.devicePosture, ['change']);
await Promise.all([
watcher.wait_for('change'),
test_driver.set_device_posture(posture)
]);
assert_equals(navigator.devicePosture.type, posture);
await Promise.all([
watcher.wait_for('change'),
test_driver.clear_device_posture()
]);
assert_equals(navigator.devicePosture.type, originalPosture);
}, 'Tests that device posture override can be removed.');
</script>

@ -0,0 +1,25 @@
<!DOCTYPE html>
<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) => {
t.add_cleanup(async () => {
await test_driver.clear_device_posture();
});
assert_equals(navigator.devicePosture.type, 'continuous');
const promise = new Promise(resolve => {
navigator.devicePosture.addEventListener(
'change',
() => { resolve(navigator.devicePosture.type); },
{ once: true }
);
});
await test_driver.set_device_posture('folded');
assert_equals(await promise, 'folded');
}, 'Tests the Device Posture API addEventListener change event handler.');
</script>

@ -0,0 +1,27 @@
<!DOCTYPE html>
<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) => {
t.add_cleanup(async () => {
await test_driver.clear_device_posture();
});
assert_equals(navigator.devicePosture.type, 'continuous');
assert_true(matchMedia('(device-posture: continuous)').matches);
const foldedMQL = window.matchMedia('(device-posture: folded)');
const promise = new Promise(resolve => {
foldedMQL.addEventListener(
'change',
() => { resolve(foldedMQL.matches); },
{ once: true }
);
});
await test_driver.set_device_posture('folded');
assert_true(await promise);
}, 'Tests the Device Posture API Media Query change event handler.');
</script>

@ -1,4 +0,0 @@
Test the Device Posture API change event handler.
Initial Device Posture Type: continuous
Updated Device Posture Type from change event: folded

@ -1,24 +0,0 @@
(async function(/** @type {import('test_runner').TestRunner} */ testRunner) {
const {dp, session} = await testRunner.startBlank(
`Test the Device Posture API change event handler.`);
testRunner.log('Initial Device Posture Type: ' + await session.evaluate('navigator.devicePosture.type'));
const postureReceived = session.evaluateAsync(`
new Promise(resolve => {
navigator.devicePosture.onchange = function() {
resolve(navigator.devicePosture.type);
}
})
`);
await dp.Emulation.setDeviceMetricsOverride({
width: 0,
height: 0,
deviceScaleFactor: 2.5,
mobile: true,
scale: 1.,
devicePosture: {type : 'folded'}
});
testRunner.log(
`Updated Device Posture Type from change event: ${await postureReceived}`);
testRunner.completeTest();
})

@ -1,4 +0,0 @@
Test the Device Posture API default javascript API.
Initial Device Posture Type: continuous
Updated Device Posture Type: folded

@ -1,16 +0,0 @@
(async function(/** @type {import('test_runner').TestRunner} */ testRunner) {
const {dp, session} = await testRunner.startBlank(
`Test the Device Posture API default javascript API.`);
testRunner.log('Initial Device Posture Type: ' + await session.evaluate('navigator.devicePosture.type'));
await dp.Emulation.setDeviceMetricsOverride({
width: 0,
height: 0,
deviceScaleFactor: 2.5,
mobile: true,
scale: 1.,
devicePosture: {type : 'folded'}
});
testRunner.log('Updated Device Posture Type: ' + await session.evaluate('navigator.devicePosture.type'));
testRunner.completeTest();
})

@ -1,4 +0,0 @@
Test the Device Posture API change event handler.
Initial Device Posture Type: continuous
Updated Device Posture Type from addeventlistener change event: folded

@ -1,26 +0,0 @@
(async function(/** @type {import('test_runner').TestRunner} */ testRunner) {
const {dp, session} = await testRunner.startBlank(
`Test the Device Posture API change event handler.`);
testRunner.log('Initial Device Posture Type: ' + await session.evaluate('navigator.devicePosture.type'));
const postureReceived = session.evaluateAsync(`
new Promise(resolve => {
navigator.devicePosture.addEventListener(
'change',
() => { resolve(navigator.devicePosture.type); },
{ once: true }
);
});
`);
await dp.Emulation.setDeviceMetricsOverride({
width: 0,
height: 0,
deviceScaleFactor: 2.5,
mobile: true,
scale: 1.,
devicePosture: {type : 'folded'}
});
testRunner.log(
`Updated Device Posture Type from addeventlistener change event: ${await postureReceived}`);
testRunner.completeTest();
})

@ -1,8 +0,0 @@
Test the Device Posture API change event handler.
Initial Device Posture Type: continuous
matchMedia('(device-posture: continuous)').matches :
true
matchMedia('(device-posture: folded)').matches :
false
Media Query change event folded matches: true

@ -1,36 +0,0 @@
(async function(/** @type {import('test_runner').TestRunner} */ testRunner) {
const {dp, session} = await testRunner.startBlank(
`Test the Device Posture API change event handler.`);
testRunner.log('Initial Device Posture Type: ' + await session.evaluate('navigator.devicePosture.type'));
testRunner.log(`matchMedia('(device-posture: continuous)').matches :`);
testRunner.log(await session.evaluate(`(window.matchMedia('(device-posture: continuous)').matches)`));
testRunner.log(`matchMedia('(device-posture: folded)').matches :`);
testRunner.log(await session.evaluate(`
const foldedMQL = window.matchMedia('(device-posture: folded)');
foldedMQL.matches;
`));
const mediaQueryPostureChanged = session.evaluateAsync(`
new Promise(resolve => {
foldedMQL.addEventListener(
'change',
() => { resolve(foldedMQL.matches); },
{ once: true }
);
})
`);
await dp.Emulation.setDeviceMetricsOverride({
width: 0,
height: 0,
deviceScaleFactor: 2.5,
mobile: true,
scale: 1.,
devicePosture: {type : 'folded'}
});
testRunner.log(
`Media Query change event folded matches: ${await mediaQueryPostureChanged}`);
testRunner.completeTest();
})