Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[headless] Added onfocus/onblur tests to headless mode tests.
This ensures that onfocus/onblur notifications in new headless mode work as expected. Bug: 1375950 Change-Id: I78608f6b8ad1453b6e5d6b5cc58b9feb568dd2ce Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4188813 Commit-Queue: Peter Kvitek <kvitekp@chromium.org> Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Cr-Commit-Position: refs/heads/main@{#1096442}
- Loading branch information
Peter Kvitek
authored and
Chromium LUCI CQ
committed
Jan 24, 2023
1 parent
67d8f59
commit b2e5b83
Showing
7 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
chrome/browser/headless/test/data/protocol/input/focus-blur-notifications-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Tests focus/blur notifications. | ||
onfocus button1 | ||
onblur button1 | ||
onfocus button2 | ||
onblur button2 | ||
onfocus button1 | ||
onblur button1 | ||
onfocus button2 | ||
quit |
28 changes: 28 additions & 0 deletions
28
chrome/browser/headless/test/data/protocol/input/focus-blur-notifications.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
(async function(testRunner) { | ||
const {page, session, dp} = | ||
await testRunner.startBlank('Tests focus/blur notifications.'); | ||
|
||
await dp.Runtime.enable(); | ||
|
||
dp.Runtime.onConsoleAPICalled(data => { | ||
const text = data.params.args[0].value; | ||
testRunner.log(text); | ||
if (text === 'quit') { | ||
testRunner.completeTest(); | ||
} | ||
}); | ||
|
||
await dp.Page.enable(); | ||
|
||
// Chrome optimizes away onfocus/onblur notifications if the target page | ||
// is not active, so activate it explicitly. Note that this is not needed | ||
// for the old headless which implicitly sets focus to a navigated page. | ||
dp.Page.bringToFront(); | ||
|
||
dp.Page.navigate( | ||
{url: testRunner.url('/resources/focus-blur-notifications.html')}); | ||
}) |
45 changes: 45 additions & 0 deletions
45
chrome/browser/headless/test/data/protocol/input/resources/focus-blur-notifications.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<script> | ||
let counter = 0; | ||
|
||
function onLoad() { | ||
setTimeout(swapFocus, 0); | ||
} | ||
|
||
function swapFocus() { | ||
const id = 'button' + (1 + (counter++ & 1)); | ||
document.getElementById(id).focus(); | ||
|
||
if (counter === 4) { | ||
console.log('quit'); | ||
} else { | ||
setTimeout(swapFocus, 0); | ||
} | ||
} | ||
|
||
function onFocus(id) { | ||
console.log('onfocus ' + id); | ||
} | ||
function onBlur(id) { | ||
console.log('onblur ' + id); | ||
} | ||
</script> | ||
|
||
<body onload="onLoad()"> | ||
<div> | ||
<button id="button1" class="button" | ||
onfocus="onFocus('button1')" onblur="onBlur('button1')"> | ||
Button1 | ||
</button> | ||
</div> | ||
<div> | ||
<button id="button2" class="button" | ||
onfocus="onFocus('button2')" onblur="onBlur('button2')"> | ||
Button2 | ||
</button> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
|
9 changes: 6 additions & 3 deletions
9
headless/test/data/protocol/input/focus-blur-notifications-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
Tests focus/blur notifications. | ||
onload | ||
onfocus button1 | ||
onblur button1 | ||
onblur button1 | ||
onfocus button2 | ||
onblur button2 | ||
onfocus button1 | ||
onblur button1 | ||
onblur button1 | ||
onfocus button2 | ||
quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters