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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 using net::URLRequestFailedJob; 87 using net::URLRequestFailedJob;
88 using net::URLRequestTestJob; 88 using net::URLRequestTestJob;
89 89
90 namespace { 90 namespace {
91 91
92 // Returns true if |text| is displayed on the page |browser| is currently 92 // Returns true if |text| is displayed on the page |browser| is currently
93 // displaying. Uses "innerText", so will miss hidden text, and whitespace 93 // displaying. Uses "innerText", so will miss hidden text, and whitespace
94 // space handling may be weird. 94 // space handling may be weird.
95 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser, 95 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
96 const std::string& text) { 96 const std::string& text) {
97 std::string command = base::StringPrintf( 97 // clang-format off
98 "var textContent = document.body.innerText.toLowerCase();" 98 std::string command = base::StringPrintf(R"(
99 "var hasText = textContent.indexOf('%s'.toLowerCase()) >= 0;" 99 function isNodeVisible(node) {
100 "domAutomationController.send(hasText);", 100 if (!node || node.classList.contains('hidden'))
101 text.c_str()); 101 return false;
102 if (!node.parentElement)
103 return true;
104 // Otherwise, we must check all parent nodes
105 return isNodeVisible(node.parentElement);
106 }
107 var node = document.evaluate("//*[contains(text(),'%s')]", document,
108 null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
109 domAutomationController.send(isNodeVisible(node));
110 )", text.c_str());
111 // clang-format on
102 bool result = false; 112 bool result = false;
103 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 113 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
104 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); 114 browser->tab_strip_model()->GetActiveWebContents(), command, &result));
105 return result; 115 return result;
106 } 116 }
107 117
108 // Expands the more box on the currently displayed error page. 118 // Expands the more box on the currently displayed error page.
109 void ToggleHelpBox(Browser* browser) { 119 void ToggleHelpBox(Browser* browser) {
110 EXPECT_TRUE(content::ExecuteScript( 120 EXPECT_TRUE(content::ExecuteScript(
111 browser->tab_strip_model()->GetActiveWebContents(), 121 browser->tab_strip_model()->GetActiveWebContents(),
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 GURL test_url("http://error.page.auto.reload"); 1123 GURL test_url("http://error.page.auto.reload");
1114 const int kRequestsToFail = 3; 1124 const int kRequestsToFail = 3;
1115 InstallInterceptor(test_url, kRequestsToFail); 1125 InstallInterceptor(test_url, kRequestsToFail);
1116 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 1126 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
1117 browser(), test_url, 2); 1127 browser(), test_url, 2);
1118 1128
1119 EXPECT_EQ(2, interceptor()->failures()); 1129 EXPECT_EQ(2, interceptor()->failures());
1120 EXPECT_EQ(2, interceptor()->requests()); 1130 EXPECT_EQ(2, interceptor()->requests());
1121 1131
1122 ToggleHelpBox(browser()); 1132 ToggleHelpBox(browser());
1123 EXPECT_TRUE(IsDisplayingText(browser(), l10n_util::GetStringUTF8( 1133 EXPECT_TRUE(IsDisplayingText(
1124 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); 1134 browser(), l10n_util::GetStringUTF8(
1135 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
1125 1136
1126 content::WebContents* web_contents = 1137 content::WebContents* web_contents =
1127 browser()->tab_strip_model()->GetActiveWebContents(); 1138 browser()->tab_strip_model()->GetActiveWebContents();
1128 content::TestNavigationObserver nav_observer(web_contents, 1); 1139 content::TestNavigationObserver nav_observer(web_contents, 1);
1129 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( 1140 web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
1130 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); 1141 base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
1131 nav_observer.Wait(); 1142 nav_observer.Wait();
1132 EXPECT_FALSE(IsDisplayingText(browser(), l10n_util::GetStringUTF8( 1143 EXPECT_FALSE(IsDisplayingText(
1133 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); 1144 browser(), l10n_util::GetStringUTF8(
1145 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
1134 } 1146 }
1135 1147
1136 // Make sure that a same document navigation does not cause issues with the 1148 // Make sure that a same document navigation does not cause issues with the
1137 // auto-reload timer. Note that this test was added due to this case causing 1149 // auto-reload timer. Note that this test was added due to this case causing
1138 // a crash. On regression, this test may hang due to a crashed renderer. 1150 // a crash. On regression, this test may hang due to a crashed renderer.
1139 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, IgnoresSameDocumentNavigation) { 1151 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, IgnoresSameDocumentNavigation) {
1140 GURL test_url("http://error.page.auto.reload"); 1152 GURL test_url("http://error.page.auto.reload");
1141 InstallInterceptor(test_url, 2); 1153 InstallInterceptor(test_url, 2);
1142 1154
1143 // Wait for the error page and first autoreload, which happens immediately. 1155 // Wait for the error page and first autoreload, which happens immediately.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 Http09WeirdPortEnabled) { 1542 Http09WeirdPortEnabled) {
1531 const char kHttp09Response[] = "JumboShrimp"; 1543 const char kHttp09Response[] = "JumboShrimp";
1532 ASSERT_TRUE(embedded_test_server()->Start()); 1544 ASSERT_TRUE(embedded_test_server()->Start());
1533 ui_test_utils::NavigateToURL( 1545 ui_test_utils::NavigateToURL(
1534 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") + 1546 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") +
1535 kHttp09Response)); 1547 kHttp09Response));
1536 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response)); 1548 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response));
1537 } 1549 }
1538 1550
1539 } // namespace 1551 } // namespace
OLDNEW
« 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