siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
109 lines (88 loc) • 3.87 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js">/*
Siesta 5.6.1
Copyright(c) 2009-2022 Bryntum AB
https://bryntum.com/contact
https://bryntum.com/products/siesta/license
*/
// requires "global" attribute
Role('Siesta.Test.Browser.Role.CanWorkWithKeyboard', {
has : {
},
methods : {
isTextInput : function(node) {
// somehow "node.nodeName" is empty sometimes in IE10
var name = node.nodeName && node.nodeName.toLowerCase();
if (name === 'textarea') return true;
if (name === 'input') {
var type = String(node.type).toLowerCase()
return type === 'password' ||
type === 'number' ||
type === 'search' ||
type === 'text' ||
type === 'url' ||
type === 'tel' ||
type === 'month' ||
type === 'time' ||
type === 'date' ||
type === 'datetime' ||
type === 'week' ||
type === 'email';
}
return false
},
isEditableNode : function(node) {
return node.ownerDocument.designMode.toLowerCase() === 'on' || node.isContentEditable;
},
// private
isReadableKey: function (keyCode) {
var KC = Siesta.Test.UserAgent.KeyCodes();
return !KC.isNav(keyCode) && !KC.isSpecial(keyCode);
},
activeElement : function (notAllowBody, fallbackEl, elOrDoc) {
var doc = elOrDoc && this.typeOf(elOrDoc) === 'HTMLDocument' ? elOrDoc : this.getQueryableContainer(elOrDoc)
var focusedEl = doc.activeElement;
// 1. In IE10,11 it seems activeElement cannot be trusted as it sometimes returns an empty object with no properties.
// Try to detect this case and use the fallback el
// 2. Sometimes receiving <body> from this method does not make sense either - use fallback el as well
if (!focusedEl || !focusedEl.nodeName || !focusedEl.tagName || (focusedEl === doc.body && notAllowBody)) {
focusedEl = fallbackEl;
}
// For iframes, we need to grab the activeElement of the frame (if in the same domain)
if (focusedEl) {
if (String(focusedEl.tagName).toLowerCase() === 'iframe') {
try {
if (focusedEl.contentDocument && focusedEl.contentDocument.body) {
focusedEl = this.activeElement(notAllowBody, fallbackEl, focusedEl.contentDocument)
}
}
catch (e) {
}
}
else if (focusedEl.shadowRoot) {
return this.activeElement(notAllowBody, fallbackEl, focusedEl.shadowRoot);
}
}
return focusedEl || doc.body
}
}
});
</pre>
</body>
</html>