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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 return result; | 97 return result; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Expands the more box on the currently displayed error page. | 100 // Expands the more box on the currently displayed error page. |
| 101 void ToggleHelpBox(Browser* browser) { | 101 void ToggleHelpBox(Browser* browser) { |
| 102 EXPECT_TRUE(content::ExecuteScript( | 102 EXPECT_TRUE(content::ExecuteScript( |
| 103 browser->tab_strip_model()->GetActiveWebContents(), | 103 browser->tab_strip_model()->GetActiveWebContents(), |
| 104 "document.getElementById('details-button').click();")); | 104 "document.getElementById('details-button').click();")); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Returns true if |browser| is displaying the text representation of | |
| 108 // |error_code| on the current page. | |
| 109 bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser, | |
| 110 net::Error error_code) { | |
| 111 return IsDisplayingText(browser, net::ErrorToShortString(error_code)); | |
| 112 } | |
| 113 | |
| 114 // Returns true if the diagnostics link suggestion is displayed. | 107 // Returns true if the diagnostics link suggestion is displayed. |
| 115 bool WARN_UNUSED_RESULT IsDisplayingDiagnosticsLink(Browser* browser) { | 108 bool WARN_UNUSED_RESULT IsDisplayingDiagnosticsLink(Browser* browser) { |
| 116 std::string command = base::StringPrintf( | 109 std::string command = base::StringPrintf( |
| 117 "var diagnose_link = document.getElementById('diagnose-link');" | 110 "var diagnose_link = document.getElementById('diagnose-link');" |
| 118 "domAutomationController.send(diagnose_link != null);"); | 111 "domAutomationController.send(diagnose_link != null);"); |
| 119 bool result = false; | 112 bool result = false; |
| 120 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 113 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 121 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); | 114 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); |
| 122 return result; | 115 return result; |
| 123 } | 116 } |
| 124 | 117 |
| 125 // Checks that the local error page is being displayed, without remotely | 118 // Checks that the local error page is being displayed, without remotely |
| 126 // retrieved navigation corrections, and with the specified error code. | 119 // retrieved navigation corrections, and with the specified error string. |
| 127 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) { | 120 void ExpectDisplayingLocalErrorPage(Browser* browser, |
| 128 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); | 121 const std::string& error_string) { |
| 122 EXPECT_TRUE(IsDisplayingText(browser, error_string)); | |
| 129 | 123 |
| 130 // Locally generated error pages should not have navigation corrections. | 124 // Locally generated error pages should not have navigation corrections. |
| 131 EXPECT_FALSE(IsDisplayingText(browser, "http://mock.http/title2.html")); | 125 EXPECT_FALSE(IsDisplayingText(browser, "http://mock.http/title2.html")); |
| 132 | 126 |
| 133 // Locally generated error pages should not have a link with search terms. | 127 // Locally generated error pages should not have a link with search terms. |
| 134 EXPECT_FALSE(IsDisplayingText(browser, "search query")); | 128 EXPECT_FALSE(IsDisplayingText(browser, "search query")); |
| 135 } | 129 } |
| 136 | 130 |
| 131 // Checks that the local error page is being displayed, without remotely | |
| 132 // retrieved navigation corrections, and with the specified error code. | |
| 133 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) { | |
| 134 ExpectDisplayingLocalErrorPage(browser, net::ErrorToShortString(error_code)); | |
| 135 } | |
| 136 | |
| 137 // Checks that an error page with information retrieved from the navigation | 137 // Checks that an error page with information retrieved from the navigation |
| 138 // correction service is being displayed, with the specified specified error | 138 // correction service is being displayed, with the specified specified error |
| 139 // code. | 139 // string. |
| 140 void ExpectDisplayingNavigationCorrections(Browser* browser, | 140 void ExpectDisplayingNavigationCorrections(Browser* browser, |
| 141 net::Error error_code) { | 141 const std::string& error_string) { |
| 142 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); | 142 EXPECT_TRUE(IsDisplayingText(browser, error_string)); |
| 143 | 143 |
| 144 // Check that the mock navigation corrections are displayed. | 144 // Check that the mock navigation corrections are displayed. |
| 145 EXPECT_TRUE(IsDisplayingText(browser, "http://mock.http/title2.html")); | 145 EXPECT_TRUE(IsDisplayingText(browser, "http://mock.http/title2.html")); |
| 146 | 146 |
| 147 // Check that the search terms are displayed as a link. | 147 // Check that the search terms are displayed as a link. |
| 148 EXPECT_TRUE(IsDisplayingText(browser, "search query")); | 148 EXPECT_TRUE(IsDisplayingText(browser, "search query")); |
| 149 | 149 |
| 150 // The diagnostics button isn't displayed when corrections were | 150 // The diagnostics button isn't displayed when corrections were |
| 151 // retrieved from a remote server. | 151 // retrieved from a remote server. |
| 152 EXPECT_FALSE(IsDisplayingDiagnosticsLink(browser)); | 152 EXPECT_FALSE(IsDisplayingDiagnosticsLink(browser)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Checks that an error page with information retrieved from the navigation | |
| 156 // correction service is being displayed, with the specified specified error | |
| 157 // code. | |
| 158 void ExpectDisplayingNavigationCorrections(Browser* browser, | |
| 159 net::Error error_code) { | |
| 160 ExpectDisplayingNavigationCorrections(browser, | |
| 161 net::ErrorToShortString(error_code)); | |
| 162 } | |
| 163 | |
| 155 std::string GetShowSavedButtonLabel() { | 164 std::string GetShowSavedButtonLabel() { |
| 156 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); | 165 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); |
| 157 } | 166 } |
| 158 | 167 |
| 159 void AddInterceptorForURL(const GURL& url, | 168 void AddInterceptorForURL(const GURL& url, |
| 160 std::unique_ptr<net::URLRequestInterceptor> handler) { | 169 std::unique_ptr<net::URLRequestInterceptor> handler) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 162 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(url, | 171 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(url, |
| 163 std::move(handler)); | 172 std::move(handler)); |
| 164 } | 173 } |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 } | 929 } |
| 921 | 930 |
| 922 // Checks that navigation corrections are not loaded when we receive an actual | 931 // Checks that navigation corrections are not loaded when we receive an actual |
| 923 // 404 page. | 932 // 404 page. |
| 924 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 933 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
| 925 NavigateToURLAndWaitForTitle( | 934 NavigateToURLAndWaitForTitle( |
| 926 net::URLRequestMockHTTPJob::GetMockUrl("page404.html"), "SUCCESS", 1); | 935 net::URLRequestMockHTTPJob::GetMockUrl("page404.html"), "SUCCESS", 1); |
| 927 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); | 936 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); |
| 928 } | 937 } |
| 929 | 938 |
| 939 // Checks that navigation corrections are loaded when we get a 404 page with no | |
| 940 // body. | |
| 941 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Empty404) { | |
| 942 // The first navigation should fail and load a blank page, while it fetches | |
| 943 // the Link Doctor response. The second navigation is the Link Doctor. | |
| 944 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
| 945 browser(), | |
| 946 net::URLRequestMockHTTPJob::GetMockUrl("errorpage/empty404.html"), 2); | |
| 947 // This depends on the non-internationalized error ID string in | |
| 948 // localized_error.cc. | |
| 949 ExpectDisplayingNavigationCorrections(browser(), "HTTP ERROR 404"); | |
| 950 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); | |
| 951 } | |
| 952 | |
| 953 // Checks that navigation corrections are loaded when we get a 404 page with no | |
| 954 // body. | |
|
Randy Smith (Not in Mondays)
2016/08/01 18:59:50
Is this comment correct? It seems to be copied fr
mmenke
2016/08/01 20:18:28
Done.
| |
| 955 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Empty500) { | |
| 956 NavigateToFileURL("errorpage/empty500.html"); | |
|
Randy Smith (Not in Mondays)
2016/08/01 18:59:50
I'm not familiar with the underlying logic of the
mmenke
2016/08/01 20:18:28
If there's a two phase navigation, we load a blank
| |
| 957 // This depends on the non-internationalized error ID string in | |
| 958 // localized_error.cc. | |
| 959 ExpectDisplayingLocalErrorPage(browser(), "HTTP ERROR 500"); | |
| 960 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); | |
| 961 } | |
| 962 | |
| 930 // Checks that when an error occurs, the stale cache status of the page | 963 // Checks that when an error occurs, the stale cache status of the page |
| 931 // is correctly transferred, and that stale cached copied can be loaded | 964 // is correctly transferred, and that stale cached copied can be loaded |
| 932 // from the javascript. | 965 // from the javascript. |
| 933 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { | 966 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { |
| 934 ASSERT_TRUE(embedded_test_server()->Start()); | 967 ASSERT_TRUE(embedded_test_server()->Start()); |
| 935 // Load cache with entry with "nocache" set, to create stale | 968 // Load cache with entry with "nocache" set, to create stale |
| 936 // cache. | 969 // cache. |
| 937 GURL test_url(embedded_test_server()->GetURL("/nocache.html")); | 970 GURL test_url(embedded_test_server()->GetURL("/nocache.html")); |
| 938 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); | 971 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); |
| 939 | 972 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1455 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 1488 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
| 1456 // ERR_UNSAFE_PORT will not trigger navigation corrections. | 1489 // ERR_UNSAFE_PORT will not trigger navigation corrections. |
| 1457 ui_test_utils::NavigateToURL( | 1490 ui_test_utils::NavigateToURL( |
| 1458 browser(), | 1491 browser(), |
| 1459 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1492 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
| 1460 kHostname)); | 1493 kHostname)); |
| 1461 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1494 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
| 1462 } | 1495 } |
| 1463 | 1496 |
| 1464 } // namespace | 1497 } // namespace |
| OLD | NEW |