Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6269)

Unified Diff: chrome/browser/net/errorpage_browsertest.cc

Issue 2860583002: Properly check visibility of check_connection_header (Closed)
Patch Set: Address reviewer comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/errorpage_browsertest.cc
diff --git a/chrome/browser/net/errorpage_browsertest.cc b/chrome/browser/net/errorpage_browsertest.cc
index b6eca0914fdc7cffc4fa76f8154f3f96dc30f4b7..a328daa7a7dfc4324c4c843aba8d212e2036ee76 100644
--- a/chrome/browser/net/errorpage_browsertest.cc
+++ b/chrome/browser/net/errorpage_browsertest.cc
@@ -94,11 +94,21 @@ namespace {
// space handling may be weird.
bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
const std::string& text) {
- std::string command = base::StringPrintf(
- "var textContent = document.body.innerText.toLowerCase();"
- "var hasText = textContent.indexOf('%s'.toLowerCase()) >= 0;"
- "domAutomationController.send(hasText);",
- text.c_str());
+ // clang-format off
+ std::string command = base::StringPrintf(R"(
+ function isNodeVisible(node) {
+ if (!node || node.classList.contains('hidden'))
+ return false;
+ if (!node.parentElement)
+ return true;
+ // Otherwise, we must check all parent nodes
+ return isNodeVisible(node.parentElement);
+ }
+ var node = document.evaluate("//*[contains(text(),'%s')]", document,
+ null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+ domAutomationController.send(isNodeVisible(node));
+ )", text.c_str());
+ // clang-format on
bool result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
browser->tab_strip_model()->GetActiveWebContents(), command, &result));
@@ -1120,8 +1130,9 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, ManualReloadNotSuppressed) {
EXPECT_EQ(2, interceptor()->requests());
ToggleHelpBox(browser());
- EXPECT_TRUE(IsDisplayingText(browser(), l10n_util::GetStringUTF8(
- IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
+ EXPECT_TRUE(IsDisplayingText(
+ browser(), l10n_util::GetStringUTF8(
+ IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
@@ -1129,8 +1140,9 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, ManualReloadNotSuppressed) {
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
nav_observer.Wait();
- EXPECT_FALSE(IsDisplayingText(browser(), l10n_util::GetStringUTF8(
- IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
+ EXPECT_FALSE(IsDisplayingText(
+ browser(), l10n_util::GetStringUTF8(
+ IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
}
// Make sure that a same document navigation does not cause issues with the
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698