Skip to content

Commit 71d627a

Browse files
authored
[test] Convert browser_harness.html to async/await. NFC (#26877)
1 parent f2cd302 commit 71d627a

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

test/browser_harness.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
}
2424
</style>
2525
<script>
26-
var COMMAND_PREFIX = 'COMMAND:';
2726
var counter = 0;
28-
function check() {
29-
fetch('/check')
30-
.then((rsp) => rsp.text())
31-
.then((responseText) => {
32-
if (responseText.startsWith(COMMAND_PREFIX)) {
33-
var url = responseText.substr(COMMAND_PREFIX.length);
34-
iframe.src = url;
35-
document.getElementById('count').textContent = counter++;
36-
}
37-
// Polling for the next test to start: we just keep asking if we
38-
// should load a new page, since the iframe doesn't currently have
39-
// a way to tell us it completed (even if it did, we'd need to poll
40-
// the server to know when the next test page is ready to load).
41-
// (A timeout value of 100msecs has been seen to stall test
42-
// browser.test_audio_worklet_worker on Chrome)
43-
setTimeout(check, 200);
44-
})
45-
.catch(() => {
46-
document.body.innerHTML = 'Tests complete. View log in console.';
47-
// Attempt to close the main window. This works on chrome
48-
// but fails on firefox with: `Scripts may not close windows that
49-
// were not opened by script.`
50-
window.close();
51-
});
27+
async function check() {
28+
try {
29+
const rsp = await fetch('/check');
30+
const responseText = await rsp.text();
31+
32+
const COMMAND_PREFIX = 'COMMAND:';
33+
if (responseText.startsWith(COMMAND_PREFIX)) {
34+
var url = responseText.substr(COMMAND_PREFIX.length);
35+
iframe.src = url;
36+
document.getElementById('count').textContent = counter++;
37+
}
38+
// Polling for the next test to start: we just keep asking if we
39+
// should load a new page, since the iframe doesn't currently have
40+
// a way to tell us it completed (even if it did, we'd need to poll
41+
// the server to know when the next test page is ready to load).
42+
// (A timeout value of 100msecs has been seen to stall test
43+
// browser.test_audio_worklet_worker on Chrome)
44+
setTimeout(check, 200);
45+
} catch {
46+
document.body.innerHTML = 'Tests complete. View log in console.';
47+
// Attempt to close the main window. This works on chrome
48+
// but fails on firefox with: `Scripts may not close windows that
49+
// were not opened by script.`
50+
window.close();
51+
}
5252
}
5353
document.addEventListener('DOMContentLoaded', check);
5454
</script>

0 commit comments

Comments
 (0)