<!DOCTYPE html>
<body>
This tests window.onFocus and window.onBlur handlers. It uses the testRunners ability to mimic bringing the window to the front and pushing it to the back.
<p><b>It is not intended to be run interactively:</b> when you run it interactively, you should see 'Window was blurred' and 'Window was focused' messages as you push the window to the back and bring it to the front, respectively.</p>
<ul id="console"></ul>
<script>
function log(message) {
const console = document.getElementById("console");
const li = document.createElement("li");
const text = document.createTextNode(message);
console.appendChild(li);
li.appendChild(text);
}
// Make sure the window is focused before starting the test.
if (window.testRunner)
testRunner.setWindowFocus(true);
window.onload = () => {
window.onfocus = () => log('Window was focused');
window.onblur = () => log('Window was blurred');
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setMainFrameIsFirstResponder(true);
testRunner.setWindowFocus(false);
testRunner.setWindowFocus(true);
testRunner.setWindowFocus(false);
}
}
</script>