UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

111 lines (94 loc) 4.56 kB
<!DOCTYPE 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 */ <span id='Siesta-Test-Browser-Role-CanGetElementFromPoint'>/** </span>@class Siesta.Test.Browser.Role.CanGetElementFromPoint */ Role(&#39;Siesta.Test.Browser.Role.CanGetElementFromPoint&#39;, { requires : [ &#39;$&#39; ], does : [ Siesta.Util.Role.CanCalculatePageScroll ], has : { }, methods : { <span id='Siesta-Test-Browser-Role-CanGetElementFromPoint-method-elementFromPoint'> /** </span> * This method will return the top-most DOM element at the specified coordinates from the test page. If * the resulting element is an iframe and `shallow` argument is not passed as `true` * it&#39;ll query the iframe for its element from the local point inside it. * * @param {Number} x The X coordinate, relative to the viewport area (currently visible part of the page) * @param {Number} y The Y coordinate, relative to the viewport area (currently visible part of the page) * @param {Boolean} [shallow] Pass `true` to _not_ check nested iframes if an element at the original coordinates is an iframe. * * @return {HTMLElement} The top-most element at the specified position on the test page */ elementFromPoint : function (viewportX, viewportY, shallow, fallbackEl, fullInfo) { var queryRoot = this.global.document; var el = queryRoot.elementFromPoint(viewportX, viewportY) var localX = viewportX var localY = viewportY if (!shallow) { // If we found IFRAME or shadow root and its not a `shallow` request, try to dig deeper // Web component shadow root might return its own shadowRoot if empty while (el &amp;&amp; (el.nodeName.toUpperCase() === &#39;IFRAME&#39; || (el.shadowRoot &amp;&amp; el.shadowRoot !== queryRoot))) { // if found iframe is loaded from different domain // just accessing its &quot;el.contentWindow.document&quot; property will throw exception try { queryRoot = this.getQueryableContainerForNestedContext(el); if (el.nodeName.toUpperCase() === &#39;IFRAME&#39;) { var pageOffset = this.$(el).offset(); localX = viewportX - this.pageXtoViewportX(pageOffset.left) localY = viewportY - this.pageYtoViewportY(pageOffset.top) } el = queryRoot.elementFromPoint(localX, localY); // If nothing is found inside the shadowRoot, return outer web component element if (!el &amp;&amp; typeof queryRoot.constructor === &#39;ShadowRoot&#39;) { fallbackEl = queryRoot.host; } } catch (e) { // digging deeper failed likely due to DOMException of x-domain iframe , restore the local coordinates localX = viewportX localY = viewportY break; } } } // final fallback to the provided element or to the &lt;body&gt; element el = el || fallbackEl || this.getBodyElement(); return fullInfo ? { el : el, // viewport coords in the inner frame localXY : [localX, localY], // viewport coords in the top frame (seems not needed, as just the input values are reused) globalXY : [viewportX, viewportY] } : el } } }); </pre> </body> </html>