Commit 7d9968e7 authored by Ian Struiksma's avatar Ian Struiksma Committed by Commit Bot

Clean up temporary logging iframe in automation_helper

For some sites they overload console commands, so we
create an iframe to log element info for debugging.

We need to make sure to remove that iframe afterwards, or
we build up a collection of them that might affect elements
on the page, particularly on lower resolutions.

Bug: 984664
Change-Id: I2f81cd8e563c4ca275f561efe94bb03027ee0d8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884815
Auto-Submit: Ian Struiksma <ianstruiksma@google.com>
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711370}
parent aa7cd162
...@@ -25,15 +25,15 @@ const automation_helper = (function() { ...@@ -25,15 +25,15 @@ const automation_helper = (function() {
this.DomElementReadyState.visible | this.DomElementReadyState.visible |
this.DomElementReadyState.enabled | this.DomElementReadyState.enabled |
this.DomElementReadyState.on_top) { this.DomElementReadyState.on_top) {
let isReady = true;
// Some sites override the console function locally, // Some sites override the console function locally,
// this ensures our function can write to log // this ensures our function can write to log
var frame = document.createElement('iframe'); var frame = document.createElement('iframe');
try {
document.body.appendChild(frame); document.body.appendChild(frame);
console = frame.contentWindow.console; console = frame.contentWindow.console;
const element = getElementFunction(); const element = getElementFunction();
let isReady = true;
let logDataArr = []; let logDataArr = [];
logDataArr.push('[Element (' + xpath + ')]'); logDataArr.push('[Element (' + xpath + ')]');
if (element) { if (element) {
...@@ -66,10 +66,10 @@ const automation_helper = (function() { ...@@ -66,10 +66,10 @@ const automation_helper = (function() {
// As coordinates, use the center of the element, minus the // As coordinates, use the center of the element, minus the
// window offset in case the element is outside the view. // window offset in case the element is outside the view.
rect.left + rect.width / 2, rect.top + rect.height / 2); rect.left + rect.width / 2, rect.top + rect.height / 2);
const isOnTop = target.contains(topElement) || const isTop = target.contains(topElement) ||
target.isSameNode(topElement); target.isSameNode(topElement);
isReady = isReady && isOnTop; isReady = isReady && isTop;
logDataArr.push('[OnTop:' + isOnTop + ':' + topElement.localName + ']'); logDataArr.push('[OnTop:' + isTop + ':' + topElement.localName + ']');
} }
if (state_flags & this.DomElementReadyState.enabled) { if (state_flags & this.DomElementReadyState.enabled) {
const isEnabled = !element.disabled; const isEnabled = !element.disabled;
...@@ -82,6 +82,10 @@ const automation_helper = (function() { ...@@ -82,6 +82,10 @@ const automation_helper = (function() {
} }
logDataArr.push('[FinalReady:' + isReady + ']'); logDataArr.push('[FinalReady:' + isReady + ']');
console.log(logDataArr.join("")); console.log(logDataArr.join(""));
} finally {
// Remove our temporary console iframe
frame.remove();
}
return isReady; return isReady;
}; };
......
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