Skip to content

Commit 754b4a9

Browse files
[wpt] Ensure compute pressure/generic sensor tests satisfy focus check
Some tests currently assume the testharness browsing context is initially focused. Opening the BC with WebDriver's "New Window" command [0] instead of `window.open(...)` broke such tests because the command doesn't run focusing steps [1]. To fix #50622, ensure the testharness document starts with focus by sending a click [2] during test setup. A few `test()`s have been fixed up into `promise_test()`s so that they're compatible with `promise_setup()`. The bug doesn't surface with `--product=headless_shell` because headless shell doesn't seem to have a focusable address bar. [0]: https://www.w3.org/TR/webdriver/#new-window [1]: https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps [2]: https://w3c.github.io/uievents/#event-type-click Bug: 392539092 Test: run_wpt_tests.py --product=chrome external/wpt/compute-pressure/ Change-Id: I8728ef42733c08cafe555b666c56c4b85d4b0304 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6341204 Reviewed-by: Arnaud Mandy <arnaud.mandy@intel.com> Commit-Queue: Jonathan Lee <jonathanjlee@google.com> Cr-Commit-Position: refs/heads/main@{#1430924}
1 parent 626d3af commit 754b4a9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

compute-pressure/compute_pressure_detached_iframe.https.window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
test(() => {
11+
promise_test(async () => {
1212
const iframe = document.createElement('iframe');
1313
document.body.appendChild(iframe);
1414
const frame_window = iframe.contentWindow;

compute-pressure/resources/common.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ switch (_globalScope) {
136136
throw new Error(`Invalid variant '${_globalScope}'`);
137137
}
138138

139+
promise_setup(async () => {
140+
// Ensure window's document has focus so that the global under test can
141+
// receive data.
142+
await test_driver.click(document.documentElement);
143+
});
144+
139145
const pressure_test =
140146
_pressureTestHelper.pressure_test.bind(_pressureTestHelper);
141147
const mark_as_done = _pressureTestHelper.mark_as_done.bind(_pressureTestHelper);

generic-sensor/generic-sensor-tests.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ function runGenericSensorTests(sensorData, readingData) {
3636
}, name, properties);
3737
}
3838

39+
promise_setup(async () => {
40+
// Ensure window's document has focus so that the global under test can
41+
// receive data.
42+
await test_driver.click(document.documentElement);
43+
});
44+
3945
sensor_test(async t => {
4046
await test_driver.set_permission({name: permissionName}, 'denied');
4147

@@ -614,7 +620,7 @@ function runGenericSensorTests(sensorData, readingData) {
614620
immediately accessible to all sensors.`);
615621

616622
// Re-enable after https://github.com/w3c/sensors/issues/361 is fixed.
617-
// test(() => {
623+
// promise_test(async () => {
618624
// assert_throws_dom("NotSupportedError",
619625
// () => { new sensorType({invalid: 1}) });
620626
// assert_throws_dom("NotSupportedError",
@@ -626,7 +632,7 @@ function runGenericSensorTests(sensorData, readingData) {
626632
// }, `${sensorName}: throw 'NotSupportedError' for an unsupported sensor\
627633
// option.`);
628634

629-
test(() => {
635+
promise_test(async () => {
630636
const invalidFreqs = ['invalid', NaN, Infinity, -Infinity, {}];
631637
invalidFreqs.map(freq => {
632638
assert_throws_js(

0 commit comments

Comments
 (0)