Commit 64440a46 authored by Hugo Holgersson's avatar Hugo Holgersson Committed by Commit Bot

Snav: Assert focus at keyup, not at setTimout(0, ...)

"... the default action MUST be to shift the document focus".
https://www.w3.org/TR/uievents/#event-type-keydown

As focus movement happens during keydown, once we got the
succeeding keyup-event, it's safe to assert activeElement.

Why not do the asserts at 'focusin' instead?
After 'keyup', we're safe to send another trigger-key.
(Most spatnav tests verify several focus movements).

Bug: 803086
Change-Id: I6927d61a9d323f5bd3fe8a6022aef2f6eca50521
Reviewed-on: https://chromium-review.googlesource.com/1188476Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Hugo Holgersson <hugoh@vewd.com>
Cr-Commit-Position: refs/heads/master@{#585855}
parent 97fe5556
...@@ -18,13 +18,6 @@ ...@@ -18,13 +18,6 @@
} }
} }
function moveFocusAsync(direction) {
return new Promise(function(resolve) {
triggerMove(direction);
setTimeout(resolve, 0);
});
}
function stepAndAssertMoves(expectedMoves, focusMoves) { function stepAndAssertMoves(expectedMoves, focusMoves) {
if (expectedMoves.length == 0) if (expectedMoves.length == 0)
return; return;
...@@ -32,19 +25,24 @@ ...@@ -32,19 +25,24 @@
let move = expectedMoves.shift(); let move = expectedMoves.shift();
let direction = move[0]; let direction = move[0];
let expectedId = move[1]; let expectedId = move[1];
// TODO: Use WebDriver's API instead of eventSender.
// Hopefully something like:
// test_driver.move_focus(direction).then(...)
async_test(t => { async_test(t => {
// TODO: Use WebDriver's API instead of eventSender. let checkFocus = t.step_func_done(function() {
// Hopefully something like: let expectedElement = document.getElementById(expectedId);
// test_driver.move_focus(direction).then(...) assert_equals(document.activeElement, expectedElement);
moveFocusAsync(direction).then(() => {
t.step(() => { // Kick off another async test before closing this one.
let expectedElement = document.getElementById(expectedId); stepAndAssertMoves(expectedMoves, focusMoves + 1);
assert_equals(document.activeElement, expectedElement);
// Kick off another async test before closing this one.
stepAndAssertMoves(expectedMoves, focusMoves + 1);
t.done();
});
}); });
// "... the default action MUST be to shift the document focus".
// https://www.w3.org/TR/uievents/#event-type-keydown
// Any focus movement must have happened during keydown, so once we got
// the succeeding keyup-event, it's safe to assert activeElement.
document.addEventListener('keyup', checkFocus, {once: true});
triggerMove(direction);
}, focusMoves + "th move: " + direction + '-key moves focus to ' + }, focusMoves + "th move: " + direction + '-key moves focus to ' +
'the element with id: ' + expectedId + '.'); 'the element with id: ' + expectedId + '.');
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment