| Index: chrome/browser/net/errorpage_browsertest.cc
|
| diff --git a/chrome/browser/net/errorpage_browsertest.cc b/chrome/browser/net/errorpage_browsertest.cc
|
| index a328daa7a7dfc4324c4c843aba8d212e2036ee76..d4ff2ac9decac2554b03f5887503fa77050eac21 100644
|
| --- a/chrome/browser/net/errorpage_browsertest.cc
|
| +++ b/chrome/browser/net/errorpage_browsertest.cc
|
| @@ -24,6 +24,7 @@
|
| #include "build/build_config.h"
|
| #include "chrome/browser/browsing_data/browsing_data_helper.h"
|
| #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
|
| +#include "chrome/browser/net/errorpage_test_util.h"
|
| #include "chrome/browser/net/net_error_diagnostics_dialog.h"
|
| #include "chrome/browser/net/url_request_mock_util.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -89,32 +90,6 @@ using net::URLRequestTestJob;
|
|
|
| namespace {
|
|
|
| -// Returns true if |text| is displayed on the page |browser| is currently
|
| -// displaying. Uses "innerText", so will miss hidden text, and whitespace
|
| -// space handling may be weird.
|
| -bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
|
| - const std::string& text) {
|
| - // 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));
|
| - return result;
|
| -}
|
| -
|
| // Expands the more box on the currently displayed error page.
|
| void ToggleHelpBox(Browser* browser) {
|
| EXPECT_TRUE(content::ExecuteScript(
|
| @@ -137,13 +112,14 @@ bool WARN_UNUSED_RESULT IsDisplayingDiagnosticsLink(Browser* browser) {
|
| // retrieved navigation corrections, and with the specified error string.
|
| void ExpectDisplayingLocalErrorPage(Browser* browser,
|
| const std::string& error_string) {
|
| - EXPECT_TRUE(IsDisplayingText(browser, error_string));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(browser, error_string));
|
|
|
| // Locally generated error pages should not have navigation corrections.
|
| - EXPECT_FALSE(IsDisplayingText(browser, "http://mock.http/title2.html"));
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(
|
| + browser, "http://mock.http/title2.html"));
|
|
|
| // Locally generated error pages should not have a link with search terms.
|
| - EXPECT_FALSE(IsDisplayingText(browser, "search query"));
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(browser, "search query"));
|
| }
|
|
|
| // Checks that the local error page is being displayed, without remotely
|
| @@ -157,13 +133,14 @@ void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) {
|
| // string.
|
| void ExpectDisplayingNavigationCorrections(Browser* browser,
|
| const std::string& error_string) {
|
| - EXPECT_TRUE(IsDisplayingText(browser, error_string));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(browser, error_string));
|
|
|
| // Check that the mock navigation corrections are displayed.
|
| - EXPECT_TRUE(IsDisplayingText(browser, "http://mock.http/title2.html"));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(
|
| + browser, "http://mock.http/title2.html"));
|
|
|
| // Check that the search terms are displayed as a link.
|
| - EXPECT_TRUE(IsDisplayingText(browser, "search query"));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(browser, "search query"));
|
|
|
| // The diagnostics button isn't displayed when corrections were
|
| // retrieved from a remote server.
|
| @@ -998,7 +975,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
|
| // With no navigation corrections to load, there's only one navigation.
|
| ui_test_utils::NavigateToURL(browser(), test_url);
|
| EXPECT_TRUE(ProbeStaleCopyValue(true));
|
| - EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(browser(),
|
| + GetShowSavedButtonLabel()));
|
| EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"),
|
| browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
|
|
|
| @@ -1014,7 +992,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
|
| // that there is no cached copy.
|
| ui_test_utils::NavigateToURLWithPost(browser(), test_url);
|
| EXPECT_TRUE(ProbeStaleCopyValue(false));
|
| - EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(
|
| + browser(), GetShowSavedButtonLabel()));
|
| EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
|
|
|
| // Clear the cache and reload the same URL; confirm the error page is told
|
| @@ -1026,7 +1005,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
|
| content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
|
| ui_test_utils::NavigateToURL(browser(), test_url);
|
| EXPECT_TRUE(ProbeStaleCopyValue(false));
|
| - EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(
|
| + browser(), GetShowSavedButtonLabel()));
|
| EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
|
| }
|
|
|
| @@ -1130,7 +1110,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, ManualReloadNotSuppressed) {
|
| EXPECT_EQ(2, interceptor()->requests());
|
|
|
| ToggleHelpBox(browser());
|
| - EXPECT_TRUE(IsDisplayingText(
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(
|
| browser(), l10n_util::GetStringUTF8(
|
| IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
|
|
|
| @@ -1140,7 +1120,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, ManualReloadNotSuppressed) {
|
| web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
| base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
|
| nav_observer.Wait();
|
| - EXPECT_FALSE(IsDisplayingText(
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(
|
| browser(), l10n_util::GetStringUTF8(
|
| IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)));
|
| }
|
| @@ -1280,7 +1260,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
|
|
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| browser(), test_url, 2);
|
| - EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
|
| + EXPECT_TRUE(errorpage_test_util::IsDisplayingText(browser(),
|
| + GetShowSavedButtonLabel()));
|
| EXPECT_TRUE(ProbeStaleCopyValue(true));
|
|
|
| // Confirm that loading the stale copy from the cache works.
|
| @@ -1301,7 +1282,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| browser(), test_url, 2);
|
| EXPECT_TRUE(ProbeStaleCopyValue(false));
|
| - EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
|
| + EXPECT_FALSE(errorpage_test_util::IsDisplayingText(
|
| + browser(), GetShowSavedButtonLabel()));
|
| }
|
|
|
| class ErrorPageOfflineTest : public ErrorPageTest {
|
| @@ -1504,7 +1486,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
|
| browser(),
|
| URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
|
| kHostname));
|
| - EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
|
| + EXPECT_TRUE(
|
| + errorpage_test_util::IsDisplayingText(browser(), kHostnameJSUnicode));
|
| }
|
|
|
| // Make sure HTTP/0.9 is disabled on non-default ports by default.
|
| @@ -1545,7 +1528,8 @@ IN_PROC_BROWSER_TEST_F(ErrorPageWithHttp09OnNonDefaultPortsTest,
|
| ui_test_utils::NavigateToURL(
|
| browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") +
|
| kHttp09Response));
|
| - EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response));
|
| + EXPECT_TRUE(
|
| + errorpage_test_util::IsDisplayingText(browser(), kHttp09Response));
|
| }
|
|
|
| } // namespace
|
|
|