Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) return 'node not found'; |
|
mmenke
2017/05/05 14:47:20
nit: split condition onto two lines.
mmenke
2017/05/05 14:47:20
This seems a little weird to me.
Can we instead d
Nate Fischer
2017/05/05 17:05:55
Done.
Nate Fischer
2017/05/05 17:05:55
Done.
| |
| 101 text.c_str()); | 101 if (node.classList.contains('hidden')) return false; |
| 102 // Otherwise, we must check all parent nodes | |
| 103 var parentVisibility = isNodeVisible(node.parentElement); | |
| 104 if (parentVisibility === 'node not found') { | |
| 105 return true; // none of the parents are set invisible | |
| 106 } | |
|
mmenke
2017/05/05 14:47:20
nit: Just for consistency with this file, may wan
Nate Fischer
2017/05/05 17:05:56
Done.
| |
| 107 return parentVisibility; | |
| 108 } | |
| 109 var node = document.evaluate("//*[contains(text(),'%s')]", document, | |
| 110 null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
| 111 var isVisible = Boolean(node && isNodeVisible(node)); | |
|
mmenke
2017/05/05 14:52:44
If you follow my suggestions above, this just beco
Nate Fischer
2017/05/05 17:05:56
Done.
| |
| 112 domAutomationController.send(isVisible); | |
| 113 )", text.c_str()); | |
| 114 // clang-format on | |
| 102 bool result = false; | 115 bool result = false; |
| 103 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 116 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 104 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); | 117 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); |
| 105 return result; | 118 return result; |
| 106 } | 119 } |
| 107 | 120 |
| 108 // Expands the more box on the currently displayed error page. | 121 // Expands the more box on the currently displayed error page. |
| 109 void ToggleHelpBox(Browser* browser) { | 122 void ToggleHelpBox(Browser* browser) { |
| 110 EXPECT_TRUE(content::ExecuteScript( | 123 EXPECT_TRUE(content::ExecuteScript( |
| 111 browser->tab_strip_model()->GetActiveWebContents(), | 124 browser->tab_strip_model()->GetActiveWebContents(), |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 GURL test_url("http://error.page.auto.reload"); | 1129 GURL test_url("http://error.page.auto.reload"); |
| 1117 const int kRequestsToFail = 3; | 1130 const int kRequestsToFail = 3; |
| 1118 InstallInterceptor(test_url, kRequestsToFail); | 1131 InstallInterceptor(test_url, kRequestsToFail); |
| 1119 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 1132 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 1120 browser(), test_url, 2); | 1133 browser(), test_url, 2); |
| 1121 | 1134 |
| 1122 EXPECT_EQ(2, interceptor()->failures()); | 1135 EXPECT_EQ(2, interceptor()->failures()); |
| 1123 EXPECT_EQ(2, interceptor()->requests()); | 1136 EXPECT_EQ(2, interceptor()->requests()); |
| 1124 | 1137 |
| 1125 ToggleHelpBox(browser()); | 1138 ToggleHelpBox(browser()); |
| 1126 EXPECT_TRUE(IsDisplayingText(browser(), l10n_util::GetStringUTF8( | 1139 EXPECT_TRUE(IsDisplayingText( |
| 1127 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); | 1140 browser(), l10n_util::GetStringUTF8( |
| 1141 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); | |
| 1128 | 1142 |
| 1129 content::WebContents* web_contents = | 1143 content::WebContents* web_contents = |
| 1130 browser()->tab_strip_model()->GetActiveWebContents(); | 1144 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1131 content::TestNavigationObserver nav_observer(web_contents, 1); | 1145 content::TestNavigationObserver nav_observer(web_contents, 1); |
| 1132 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 1146 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( |
| 1133 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); | 1147 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); |
| 1134 nav_observer.Wait(); | 1148 nav_observer.Wait(); |
| 1135 EXPECT_FALSE(IsDisplayingText(browser(), l10n_util::GetStringUTF8( | 1149 EXPECT_FALSE(IsDisplayingText( |
| 1136 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); | 1150 browser(), l10n_util::GetStringUTF8( |
| 1151 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER))); | |
| 1137 } | 1152 } |
| 1138 | 1153 |
| 1139 // Make sure that a same document navigation does not cause issues with the | 1154 // Make sure that a same document navigation does not cause issues with the |
| 1140 // auto-reload timer. Note that this test was added due to this case causing | 1155 // auto-reload timer. Note that this test was added due to this case causing |
| 1141 // a crash. On regression, this test may hang due to a crashed renderer. | 1156 // a crash. On regression, this test may hang due to a crashed renderer. |
| 1142 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, IgnoresSameDocumentNavigation) { | 1157 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, IgnoresSameDocumentNavigation) { |
| 1143 GURL test_url("http://error.page.auto.reload"); | 1158 GURL test_url("http://error.page.auto.reload"); |
| 1144 InstallInterceptor(test_url, 2); | 1159 InstallInterceptor(test_url, 2); |
| 1145 | 1160 |
| 1146 // Wait for the error page and first autoreload, which happens immediately. | 1161 // Wait for the error page and first autoreload, which happens immediately. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 Http09WeirdPortEnabled) { | 1548 Http09WeirdPortEnabled) { |
| 1534 const char kHttp09Response[] = "JumboShrimp"; | 1549 const char kHttp09Response[] = "JumboShrimp"; |
| 1535 ASSERT_TRUE(embedded_test_server()->Start()); | 1550 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1536 ui_test_utils::NavigateToURL( | 1551 ui_test_utils::NavigateToURL( |
| 1537 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") + | 1552 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") + |
| 1538 kHttp09Response)); | 1553 kHttp09Response)); |
| 1539 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response)); | 1554 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response)); |
| 1540 } | 1555 } |
| 1541 | 1556 |
| 1542 } // namespace | 1557 } // namespace |
| OLD | NEW |