Skip to content

Commit

Permalink
keyboard fuzzer should not trigger events if active element changes, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 26, 2018
1 parent 8d4b12e commit f0f1fb7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/accessibility/KeyboardFuzzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define( require => {
this.keyStateTracker = new KeyStateTracker();
this.keysPressedEachFrame = 100;
this.keyupListeners = [];
this.guaranteeNewUpdate = false; // when true, `chooseNextElement` will 100% give a new focused element.

// @private {HTMLElement}
this.currentElement = null;
Expand All @@ -66,13 +67,14 @@ define( require => {
if ( this.currentElement === null ) {
this.currentElement = document.activeElement;
}
else if ( this.random.nextDouble() < NEXT_ELEMENT_THRESHOLD ) {
else if ( this.guaranteeNewUpdate || this.random.nextDouble() < NEXT_ELEMENT_THRESHOLD ) {

// before we change focus to the next item, press "keyup" on all elements we had.
this.clearListeners();
var nextFocusable = AccessibilityUtil.getRandomFocusable();
nextFocusable.focus();
this.currentElement = nextFocusable;
this.guaranteeNewUpdate = false;
}
}

Expand Down Expand Up @@ -142,6 +144,10 @@ define( require => {
var elementWithFocus = document.activeElement;

for ( let i = 0; i < this.keysPressedEachFrame; i++ ) {
if ( elementWithFocus !== document.activeElement ) {
this.guaranteeNewUpdate = true;
break;
}

if ( keyboardTestingSchema[ elementWithFocus.tagName ] ) {

Expand Down

0 comments on commit f0f1fb7

Please sign in to comment.