Skip to content

Commit

Permalink
Do not require each test to set up cleanup function
Browse files Browse the repository at this point in the history
Removed the requirement from all tests to set up cleanup function.

All tests are now wrapped around device_posture_test call. This enables
that adding of cleanup function for each test is done in one location.
  • Loading branch information
JuhaVainio committed Feb 22, 2024
1 parent 0ff7d73 commit 23376d3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions device-posture/device-posture.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
<script>
'use strict';

const originalPosture = navigator.devicePosture.type;
async function cleanup() {
await test_driver.set_device_posture(originalPosture);
function device_posture_test(func, name, properties) {
promise_test(async t => {
const originalPosture = navigator.devicePosture.type;
t.add_cleanup(async () => {
await test_driver.set_device_posture(originalPosture);
});

return func(t);
}, name, properties);
}

promise_test(async (t) => {
t.add_cleanup(cleanup);
device_posture_test(async (t) => {
const watcher = new EventWatcher(t, navigator.devicePosture, ['change']);
const postures = ['folded', 'continuous', 'folded'];
for (const posture of postures) {
Expand All @@ -28,8 +33,7 @@


// REFERENCE https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/http/tests/inspector-protocol/device-posture/device-posture-change-event.js
promise_test(async (t) => {
t.add_cleanup(cleanup);
device_posture_test(async (t) => {
assert_equals(navigator.devicePosture.type, 'continuous');

const promise = new Promise(resolve => {
Expand All @@ -42,16 +46,14 @@
}, 'Device posture test: device-posture-change-event.js.');

// REFERENCE https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/http/tests/inspector-protocol/device-posture/device-posture-default.js
promise_test(async (t) => {
t.add_cleanup(cleanup);
device_posture_test(async (t) => {
assert_equals(navigator.devicePosture.type, 'continuous');
await test_driver.set_device_posture('folded');
assert_equals(navigator.devicePosture.type, 'folded')
}, 'Device posture test: device-posture-default.js.');

// REFERENCE https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/http/tests/inspector-protocol/device-posture/device-posture-event-listener.js
promise_test(async (t) => {
t.add_cleanup(cleanup);
device_posture_test(async (t) => {
assert_equals(navigator.devicePosture.type, 'continuous');

const promise = new Promise(resolve => {
Expand All @@ -66,8 +68,7 @@
}, 'Device posture test: device-posture-event-listener.js.');

// REFERENCE https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/http/tests/inspector-protocol/device-posture/device-posture-media-queries.js
promise_test(async (t) => {
t.add_cleanup(cleanup);
device_posture_test(async (t) => {
assert_equals(navigator.devicePosture.type, 'continuous');
assert_true(matchMedia('(device-posture: continuous)').matches);

Expand Down

0 comments on commit 23376d3

Please sign in to comment.