Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
checkFocusDesktop : function (widget) {
// the active element after selecting something in the popup on desktops
// must be the text field in the widget
var activeElement = this.testWindow.document.activeElement;
this.assertTrue(ariaUtilsDom.isAncestor(activeElement, widget.getDom()), "Widget " + widget.$class
+ " should be focused");
this.assertEquals(activeElement.tagName.toLowerCase(), "input", "The input in widget " + widget.$class
+ " should be focused");
},
checkFocusDesktop : function (widget) {
// the active element after selecting something in the popup on desktops
// must be the text field in the widget
var activeElement = this.testWindow.document.activeElement;
this.assertTrue(ariaUtilsDom.isAncestor(activeElement, widget.getDom()), "Widget " + widget.$class
+ " should be focused");
this.assertEquals(activeElement.tagName.toLowerCase(), "input", "The input in widget " + widget.$class
+ " should be focused");
},
_isFocused : function (element, strict) {
// ---------------------------------------------------------- processing
var activeElement = this._getActiveElement();
var result;
if (strict) {
result = activeElement === element;
} else {
result = ariaUtilsDom.isAncestor(activeElement, element);
}
// -------------------------------------------------------------- return
return result;
},
// --------------------------------------------------- destructuring
var ancestor = this._currentNode;
var document = Aria.$window.document;
var focusedElement = document.activeElement;
var textContent = focusedElement.textContent || focusedElement.innerText;
// ------------------------------------------------------ processing
var result;
var message;
// -----------------------------------------------------------------
result = ariaUtilsDom.isAncestor(focusedElement, ancestor);
message = 'Focused element should%1be contained inside the element';
var subtitution;
if (shouldBeContained) {
subtitution = ' ';
} else {
subtitution = ' not ';
result = !result;
}
message = subst(message, subtitution);
this.assertTrue(result, message);
// -----------------------------------------------------------------
result = !!(expectedTextContent === textContent);
this.assertTruthy(listBoxElt, "no item has the listbox role");
for (var i = 0, l = optionsElt.length; i < l; i++) {
var curOption = optionsElt[i];
this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
}
}
}
var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
var ariaActiveDescendantElt;
if (ariaActiveDescendant) {
ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
var selectedIdx = listWidget._cfg.selectedIndex;
this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");
var labelFromWidget = listWidget._cfg.items[selectedIdx].label;
this.assertEquals(labelFromDom, labelFromWidget);
}
},
for (var i = 0, l = optionsElt.length; i < l; i++) {
var curOption = optionsElt[i];
this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
}
}
}
var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
var ariaActiveDescendantElt;
if (ariaActiveDescendant) {
ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
var selectedIdx = listWidget._cfg.selectedIndex;
this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");
var labelFromWidget = listWidget._cfg.items[selectedIdx].label;
this.assertEquals(labelFromDom, labelFromWidget);
}
},
for (var i = 0, l = childrenWithRole.length; i < l; i++) {
var curChild = childrenWithRole[i];
var curRole = curChild.getAttribute("role");
this.assertTrue(curRole === "listbox" || curRole === "option");
if (curRole == "listbox") {
this.assertFalsy(listBoxElt, "several items have the listbox role");
listBoxElt = curChild;
} else if (curRole == "option") {
optionsElt.push(curChild);
}
}
this.assertEquals(listWidget._cfg.items.length, optionsElt.length, "the number of items in listWidget._cfg.items (%1) is not the same as the number of DOM element with role=option (%2)");
this.assertTruthy(listBoxElt, "no item has the listbox role");
for (var i = 0, l = optionsElt.length; i < l; i++) {
var curOption = optionsElt[i];
this.assertTrue(domUtils.isAncestor(curOption, listBoxElt), "option not inside the listbox element: " + curOption.id);
}
}
}
var ariaActiveDescendant = inputElt.getAttribute("aria-activedescendant");
var ariaActiveDescendantElt;
if (ariaActiveDescendant) {
ariaActiveDescendantElt = this.testDocument.getElementById(ariaActiveDescendant);
this.assertTruthy(ariaActiveDescendantElt, "the id specified in aria-activedescendant was not found in the document");
this.assertEquals(ariaActiveDescendantElt.getAttribute("role"), "option", "the aria-activedescendant element does not have the option role");
this.assertTruthy(ariaOwnsElt, "aria-activedescendant is defined but aria-owns is not defined or not found");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, ariaOwnsElt), "the aria-activedescendant element is not inside the aria-owns element");
this.assertTrue(domUtils.isAncestor(ariaActiveDescendantElt, listBoxElt), "the aria-activedescendant element is not inside the listbox element");
var selectedIdx = listWidget._cfg.selectedIndex;
this.assertTrue(selectedIdx > -1, "unexpected value of listWidget._cfg.selectedIdx: " + selectedIdx);
var labelFromDom = (ariaActiveDescendantElt.textContent || ariaActiveDescendantElt.innerText).replace(/^\s*(.*?)\s*$/,"$1");