Commit 3d74f72c authored by ntfschr's avatar ntfschr Committed by Commit bot

Properly check the visibility of elements in browsertests

No change in production logic.

Visibility of elements must be checked by recursively checking the
visibility of parent elements, since any element inside an invisible
element will also be invisible.

This issue does not present itself in the Desktop layout, because
.hidden is defined differently (with display: none). Since the mobile
layout defines it with opacity, we need to recursively check parents.

It's not sufficient to check the opacity value itself, because CSS
transitions may not have finished by the time we check. Instead, we
simply check the CSS class and trust it to hide things properly.

BUG=716542

Review-Url: https://codereview.chromium.org/2845423002
Cr-Commit-Position: refs/heads/master@{#468111}
parent 94297f25
...@@ -562,13 +562,26 @@ class SafeBrowsingBlockingPageBrowserTest ...@@ -562,13 +562,26 @@ class SafeBrowsingBlockingPageBrowserTest
if (!rfh) if (!rfh)
return VISIBILITY_ERROR; return VISIBILITY_ERROR;
std::unique_ptr<base::Value> value = content::ExecuteScriptAndGetValue( // clang-format off
rfh, "var node = document.getElementById('" + node_id + std::string jsFindVisibility = R"(
"');\n" (function isNodeVisible(node) {
"if (node)\n" if (!node) return 'node not found';
" node.offsetWidth > 0 && node.offsetHeight > 0;" if (node.offsetWidth === 0 || node.offsetHeight === 0) return false;
"else\n" // Do not check opacity, since the css transition may actually leave
" 'node not found';\n"); // opacity at 0 after it's been unhidden
if (node.classList.contains('hidden')) return false;
// Otherwise, we must check all parent nodes
var parentVisibility = isNodeVisible(node.parentElement);
if (parentVisibility === 'node not found') {
return true; // none of the parents are set invisible
}
return parentVisibility;
}(document.getElementById(')" + node_id + R"(')));)";
// clang-format on
std::unique_ptr<base::Value> value =
content::ExecuteScriptAndGetValue(rfh, jsFindVisibility);
if (!value.get()) if (!value.get())
return VISIBILITY_ERROR; return VISIBILITY_ERROR;
......
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