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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/compiler_specific.h" |
| 7 #include "base/path_service.h" |
6 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
7 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/net/url_request_mock_util.h" | 12 #include "chrome/browser/net/url_request_mock_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
22 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_navigation_observer.h" | 26 #include "content/public/test/test_navigation_observer.h" |
24 #include "content/test/net/url_request_failed_job.h" | 27 #include "content/test/net/url_request_failed_job.h" |
25 #include "content/test/net/url_request_mock_http_job.h" | 28 #include "content/test/net/url_request_mock_http_job.h" |
26 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
27 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
28 #include "net/url_request/url_request_filter.h" | 31 #include "net/url_request/url_request_filter.h" |
29 #include "net/url_request/url_request_job_factory.h" | 32 #include "net/url_request/url_request_job_factory.h" |
30 | 33 |
31 using content::BrowserThread; | 34 using content::BrowserThread; |
32 using content::NavigationController; | 35 using content::NavigationController; |
33 using content::URLRequestFailedJob; | 36 using content::URLRequestFailedJob; |
34 | 37 |
35 namespace { | 38 namespace { |
36 | 39 |
| 40 // Returns true if |text| is displayed on the page |browser| is currently |
| 41 // displaying. Uses "innerText", so will miss hidden text, and whitespace |
| 42 // space handling may be weird. |
| 43 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser, |
| 44 const std::string& text) { |
| 45 std::string command = base::StringPrintf( |
| 46 "var textContent = document.body.innerText;" |
| 47 "var hasText = textContent.indexOf('%s') >= 0;" |
| 48 "domAutomationController.send(hasText);", |
| 49 text.c_str()); |
| 50 bool result = false; |
| 51 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 52 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); |
| 53 return result; |
| 54 } |
| 55 |
| 56 // Expands the more box on the currently displayed error page. |
| 57 void ToggleHelpBox(Browser* browser) { |
| 58 EXPECT_TRUE(content::ExecuteScript( |
| 59 browser->tab_strip_model()->GetActiveWebContents(), |
| 60 "document.getElementById('more-less-button').click();")); |
| 61 } |
| 62 |
| 63 // Returns true if |browser| is displaying the text representation of |
| 64 // |error_code| on the current page. |
| 65 bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser, |
| 66 net::Error error_code) { |
| 67 // Get the error as a string, and remove the leading "net::", which is not |
| 68 // included on error pages. |
| 69 std::string error_string = net::ErrorToString(error_code); |
| 70 base::RemoveChars(error_string, "net:", &error_string); |
| 71 |
| 72 return IsDisplayingText(browser, error_string); |
| 73 } |
| 74 |
| 75 // Checks that the local error page is being displayed, without remotely |
| 76 // retrieved Link Doctor information, and with the specified error code. |
| 77 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) { |
| 78 // Expand the help box so innerText will include text below the fold. |
| 79 ToggleHelpBox(browser); |
| 80 |
| 81 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); |
| 82 |
| 83 // Locally generated error pages should not have Link Doctor suggestions. |
| 84 EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/")); |
| 85 EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/")); |
| 86 |
| 87 // Locally generated error pages should not have a populated search box. |
| 88 bool search_box_populated = false; |
| 89 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 90 browser->tab_strip_model()->GetActiveWebContents(), |
| 91 "var searchText = document.getElementById('search-box').value;" |
| 92 "domAutomationController.send(searchText == 'search query');", |
| 93 &search_box_populated)); |
| 94 EXPECT_FALSE(search_box_populated); |
| 95 } |
| 96 |
| 97 // Checks that an error page with information retrieved from the Link Doctor |
| 98 // is being displayed, with the specified specified error code. |
| 99 void ExpectDisplayingLinkDoctor(Browser* browser, net::Error error_code) { |
| 100 // Expand the help box so innerText will include text below the fold. |
| 101 ToggleHelpBox(browser); |
| 102 |
| 103 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); |
| 104 |
| 105 // Check that suggestions from the mock Link Doctor results are displayed. |
| 106 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/")); |
| 107 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/")); |
| 108 |
| 109 // Check that the search box is populated correctly. |
| 110 bool search_box_populated = false; |
| 111 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 112 browser->tab_strip_model()->GetActiveWebContents(), |
| 113 "var searchText = document.getElementById('search-box').value;" |
| 114 "domAutomationController.send(searchText == 'search query');", |
| 115 &search_box_populated)); |
| 116 EXPECT_TRUE(search_box_populated); |
| 117 } |
| 118 |
37 class ErrorPageTest : public InProcessBrowserTest { | 119 class ErrorPageTest : public InProcessBrowserTest { |
38 public: | 120 public: |
39 enum HistoryNavigationDirection { | 121 enum HistoryNavigationDirection { |
40 HISTORY_NAVIGATE_BACK, | 122 HISTORY_NAVIGATE_BACK, |
41 HISTORY_NAVIGATE_FORWARD, | 123 HISTORY_NAVIGATE_FORWARD, |
42 }; | 124 }; |
43 | 125 |
44 // Navigates the active tab to a mock url created for the file at |file_path|. | 126 // Navigates the active tab to a mock url created for the file at |file_path|. |
45 void NavigateToFileURL(const base::FilePath::StringType& file_path) { | 127 void NavigateToFileURL(const base::FilePath::StringType& file_path) { |
46 ui_test_utils::NavigateToURL( | 128 ui_test_utils::NavigateToURL( |
(...skipping 28 matching lines...) Expand all Loading... |
75 | 157 |
76 // Navigates forward in the history and waits for |num_navigations| to occur, | 158 // Navigates forward in the history and waits for |num_navigations| to occur, |
77 // and the title to change to |expected_title|. | 159 // and the title to change to |expected_title|. |
78 void GoForwardAndWaitForTitle(const std::string& expected_title, | 160 void GoForwardAndWaitForTitle(const std::string& expected_title, |
79 int num_navigations) { | 161 int num_navigations) { |
80 NavigateHistoryAndWaitForTitle(expected_title, | 162 NavigateHistoryAndWaitForTitle(expected_title, |
81 num_navigations, | 163 num_navigations, |
82 HISTORY_NAVIGATE_FORWARD); | 164 HISTORY_NAVIGATE_FORWARD); |
83 } | 165 } |
84 | 166 |
| 167 void GoBackAndWaitForNavigations(int num_navigations) { |
| 168 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK); |
| 169 } |
| 170 |
| 171 void GoForwardAndWaitForNavigations(int num_navigations) { |
| 172 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); |
| 173 } |
| 174 |
85 protected: | 175 protected: |
| 176 static void EnableMocks(const GURL& search_url) { |
| 177 chrome_browser_net::SetUrlRequestMocksEnabled(true); |
| 178 |
| 179 // Add a mock for the search engine the error page will use. |
| 180 base::FilePath root_http; |
| 181 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
| 182 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( |
| 183 search_url.host(), root_http.AppendASCII("title3.html")); |
| 184 } |
| 185 |
86 virtual void SetUpOnMainThread() OVERRIDE { | 186 virtual void SetUpOnMainThread() OVERRIDE { |
87 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
88 BrowserThread::IO, FROM_HERE, | 188 BrowserThread::IO, FROM_HERE, |
89 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 189 base::Bind(&ErrorPageTest::EnableMocks, |
| 190 google_util::GetGoogleSearchURL(browser()->profile()))); |
90 } | 191 } |
91 | 192 |
92 // Returns a GURL that results in a DNS error. | 193 // Returns a GURL that results in a DNS error. |
93 GURL GetDnsErrorURL() const { | 194 GURL GetDnsErrorURL() const { |
94 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | 195 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
95 } | 196 } |
96 | 197 |
97 private: | 198 private: |
98 // Navigates the browser the indicated direction in the history and waits for | 199 // Navigates the browser the indicated direction in the history and waits for |
99 // |num_navigations| to occur and the title to change to |expected_title|. | 200 // |num_navigations| to occur and the title to change to |expected_title|. |
100 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, | 201 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, |
101 int num_navigations, | 202 int num_navigations, |
102 HistoryNavigationDirection direction) { | 203 HistoryNavigationDirection direction) { |
103 content::TitleWatcher title_watcher( | 204 content::TitleWatcher title_watcher( |
104 browser()->tab_strip_model()->GetActiveWebContents(), | 205 browser()->tab_strip_model()->GetActiveWebContents(), |
105 base::ASCIIToUTF16(expected_title)); | 206 base::ASCIIToUTF16(expected_title)); |
106 | 207 |
| 208 NavigateHistory(num_navigations, direction); |
| 209 |
| 210 EXPECT_EQ(title_watcher.WaitAndGetTitle(), |
| 211 base::ASCIIToUTF16(expected_title)); |
| 212 } |
| 213 |
| 214 void NavigateHistory(int num_navigations, |
| 215 HistoryNavigationDirection direction) { |
107 content::TestNavigationObserver test_navigation_observer( | 216 content::TestNavigationObserver test_navigation_observer( |
108 browser()->tab_strip_model()->GetActiveWebContents(), | 217 browser()->tab_strip_model()->GetActiveWebContents(), |
109 num_navigations); | 218 num_navigations); |
110 if (direction == HISTORY_NAVIGATE_BACK) { | 219 if (direction == HISTORY_NAVIGATE_BACK) { |
111 chrome::GoBack(browser(), CURRENT_TAB); | 220 chrome::GoBack(browser(), CURRENT_TAB); |
112 } else if (direction == HISTORY_NAVIGATE_FORWARD) { | 221 } else if (direction == HISTORY_NAVIGATE_FORWARD) { |
113 chrome::GoForward(browser(), CURRENT_TAB); | 222 chrome::GoForward(browser(), CURRENT_TAB); |
114 } else { | 223 } else { |
115 FAIL(); | 224 FAIL(); |
116 } | 225 } |
117 test_navigation_observer.Wait(); | 226 test_navigation_observer.Wait(); |
118 | |
119 EXPECT_EQ(title_watcher.WaitAndGetTitle(), | |
120 base::ASCIIToUTF16(expected_title)); | |
121 } | 227 } |
122 }; | 228 }; |
123 | 229 |
124 | 230 |
125 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { | 231 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { |
126 public: | 232 public: |
127 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) | 233 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) |
128 : content::WebContentsObserver(contents) {} | 234 : content::WebContentsObserver(contents) {} |
129 virtual ~TestFailProvisionalLoadObserver() {} | 235 virtual ~TestFailProvisionalLoadObserver() {} |
130 | 236 |
(...skipping 20 matching lines...) Expand all Loading... |
151 // See crbug.com/109669 | 257 // See crbug.com/109669 |
152 #if defined(USE_AURA) || defined(OS_WIN) | 258 #if defined(USE_AURA) || defined(OS_WIN) |
153 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic | 259 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic |
154 #else | 260 #else |
155 #define MAYBE_DNSError_Basic DNSError_Basic | 261 #define MAYBE_DNSError_Basic DNSError_Basic |
156 #endif | 262 #endif |
157 // Test that a DNS error occuring in the main frame redirects to an error page. | 263 // Test that a DNS error occuring in the main frame redirects to an error page. |
158 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { | 264 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { |
159 // The first navigation should fail, and the second one should be the error | 265 // The first navigation should fail, and the second one should be the error |
160 // page. | 266 // page. |
161 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 267 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 268 browser(), GetDnsErrorURL(), 2); |
| 269 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
162 } | 270 } |
163 | 271 |
164 // See crbug.com/109669 | 272 // See crbug.com/109669 |
165 #if defined(USE_AURA) | 273 #if defined(USE_AURA) |
166 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 | 274 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 |
167 #else | 275 #else |
168 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 | 276 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 |
169 #endif | 277 #endif |
170 | 278 |
171 // Test that a DNS error occuring in the main frame does not result in an | 279 // Test that a DNS error occuring in the main frame does not result in an |
172 // additional session history entry. | 280 // additional session history entry. |
173 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { | 281 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { |
174 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 282 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
175 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 283 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 284 browser(), GetDnsErrorURL(), 2); |
| 285 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
176 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 286 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
177 } | 287 } |
178 | 288 |
179 // See crbug.com/109669 | 289 // See crbug.com/109669 |
180 #if defined(USE_AURA) | 290 #if defined(USE_AURA) |
181 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 | 291 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 |
182 #else | 292 #else |
183 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 | 293 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 |
184 #endif | 294 #endif |
185 // Test that a DNS error occuring in the main frame does not result in an | 295 // Test that a DNS error occuring in the main frame does not result in an |
186 // additional session history entry. | 296 // additional session history entry. |
187 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { | 297 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { |
188 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 298 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
189 | 299 |
190 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 300 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 301 browser(), GetDnsErrorURL(), 2); |
| 302 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 303 |
191 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 304 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
192 | 305 |
193 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 306 GoBackAndWaitForNavigations(2); |
| 307 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 308 |
194 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 309 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
195 } | 310 } |
196 | 311 |
197 // See crbug.com/109669 | 312 // See crbug.com/109669 |
198 #if defined(USE_AURA) | 313 #if defined(USE_AURA) |
199 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward | 314 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward |
200 #else | 315 #else |
201 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward | 316 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward |
202 #endif | 317 #endif |
203 // Test that a DNS error occuring in the main frame does not result in an | 318 // Test that a DNS error occuring in the main frame does not result in an |
204 // additional session history entry. | 319 // additional session history entry. |
205 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { | 320 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { |
206 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 321 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
207 | 322 |
208 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 323 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 324 browser(), GetDnsErrorURL(), 2); |
| 325 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 326 |
209 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 327 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
210 | 328 |
211 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 329 GoBackAndWaitForNavigations(2); |
| 330 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 331 |
212 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 332 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
213 | 333 |
214 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 334 GoForwardAndWaitForNavigations(2); |
| 335 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
215 } | 336 } |
216 | 337 |
217 // See crbug.com/109669 | 338 // See crbug.com/109669 |
218 #if defined(USE_AURA) | 339 #if defined(USE_AURA) |
219 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 | 340 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 |
220 #else | 341 #else |
221 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 | 342 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 |
222 #endif | 343 #endif |
223 // Test that a DNS error occuring in the main frame does not result in an | 344 // Test that a DNS error occuring in the main frame does not result in an |
224 // additional session history entry. | 345 // additional session history entry. |
225 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { | 346 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { |
226 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 347 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
227 | 348 |
228 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 349 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 350 browser(), GetDnsErrorURL(), 2); |
| 351 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 352 |
229 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 353 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
230 | 354 |
231 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 355 GoBackAndWaitForNavigations(2); |
| 356 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 357 |
232 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); | 358 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); |
233 | 359 |
234 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 360 GoForwardAndWaitForNavigations(2); |
| 361 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 362 |
235 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 363 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
236 } | 364 } |
237 | 365 |
238 // Test that a DNS error occuring in an iframe. | 366 // See crbug.com/109669 |
| 367 #if defined(USE_AURA) |
| 368 #define MAYBE_DNSError_DoSearch DISABLED_DNSError_DoSearch |
| 369 #else |
| 370 #define MAYBE_DNSError_DoSearch DNSError_DoSearch |
| 371 #endif |
| 372 // Test that the search button on a DNS error page works. |
| 373 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) { |
| 374 // The first navigation should fail, and the second one should be the error |
| 375 // page. |
| 376 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 377 browser(), GetDnsErrorURL(), 2); |
| 378 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 379 |
| 380 // Do a search and make sure the browser ends up at the right page. |
| 381 content::TestNavigationObserver nav_observer( |
| 382 browser()->tab_strip_model()->GetActiveWebContents(), |
| 383 1); |
| 384 content::TitleWatcher title_watcher( |
| 385 browser()->tab_strip_model()->GetActiveWebContents(), |
| 386 base::ASCIIToUTF16("Title Of More Awesomeness")); |
| 387 ASSERT_TRUE(content::ExecuteScript( |
| 388 browser()->tab_strip_model()->GetActiveWebContents(), |
| 389 "document.getElementById('search-button').click();")); |
| 390 nav_observer.Wait(); |
| 391 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), |
| 392 title_watcher.WaitAndGetTitle()); |
| 393 |
| 394 // Check the path and query string. |
| 395 std::string url; |
| 396 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 397 browser()->tab_strip_model()->GetActiveWebContents(), |
| 398 "domAutomationController.send(window.location.href);", |
| 399 &url)); |
| 400 EXPECT_EQ("/search", GURL(url).path()); |
| 401 EXPECT_EQ("q=search+query", GURL(url).query()); |
| 402 |
| 403 // Go back to the error page, to make sure the history is correct. |
| 404 GoBackAndWaitForNavigations(2); |
| 405 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 406 } |
| 407 |
| 408 // Test that a DNS error occuring in an iframe does not result in showing the |
| 409 // Link Doctor. |
239 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 410 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
240 NavigateToURLAndWaitForTitle( | 411 NavigateToURLAndWaitForTitle( |
241 content::URLRequestMockHTTPJob::GetMockUrl( | 412 content::URLRequestMockHTTPJob::GetMockUrl( |
242 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 413 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
243 "Blah", | 414 "Blah", |
244 1); | 415 1); |
245 // We expect to have two history entries, since we started off with navigation | 416 // We expect to have two history entries, since we started off with navigation |
246 // to "about:blank" and then navigated to "iframe_dns_error.html". | 417 // to "about:blank" and then navigated to "iframe_dns_error.html". |
247 EXPECT_EQ(2, | 418 EXPECT_EQ(2, |
248 browser()->tab_strip_model()->GetActiveWebContents()-> | 419 browser()->tab_strip_model()->GetActiveWebContents()-> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 520 |
350 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 521 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
351 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 522 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
352 NavigateToURLAndWaitForTitle( | 523 NavigateToURLAndWaitForTitle( |
353 content::URLRequestMockHTTPJob::GetMockUrl( | 524 content::URLRequestMockHTTPJob::GetMockUrl( |
354 base::FilePath(FILE_PATH_LITERAL("page404.html"))), | 525 base::FilePath(FILE_PATH_LITERAL("page404.html"))), |
355 "SUCCESS", | 526 "SUCCESS", |
356 1); | 527 1); |
357 } | 528 } |
358 | 529 |
359 // Returns Javascript code that executes plain text search for the page. | |
360 // Pass into content::ExecuteScriptAndExtractBool as |script| parameter. | |
361 std::string GetTextContentContainsStringScript( | |
362 const std::string& value_to_search) { | |
363 return base::StringPrintf( | |
364 "var textContent = document.body.textContent;" | |
365 "var hasError = textContent.indexOf('%s') >= 0;" | |
366 "domAutomationController.send(hasError);", | |
367 value_to_search.c_str()); | |
368 } | |
369 | |
370 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 530 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
371 class AddressUnreachableProtocolHandler | 531 class AddressUnreachableProtocolHandler |
372 : public net::URLRequestJobFactory::ProtocolHandler { | 532 : public net::URLRequestJobFactory::ProtocolHandler { |
373 public: | 533 public: |
374 AddressUnreachableProtocolHandler() {} | 534 AddressUnreachableProtocolHandler() {} |
375 virtual ~AddressUnreachableProtocolHandler() {} | 535 virtual ~AddressUnreachableProtocolHandler() {} |
376 | 536 |
377 // net::URLRequestJobFactory::ProtocolHandler: | 537 // net::URLRequestJobFactory::ProtocolHandler: |
378 virtual net::URLRequestJob* MaybeCreateJob( | 538 virtual net::URLRequestJob* MaybeCreateJob( |
379 net::URLRequest* request, | 539 net::URLRequest* request, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 }; | 590 }; |
431 | 591 |
432 // Make sure that when the Link Doctor fails to load, the network error page is | 592 // Make sure that when the Link Doctor fails to load, the network error page is |
433 // successfully loaded. | 593 // successfully loaded. |
434 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { | 594 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { |
435 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 595 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
436 browser(), | 596 browser(), |
437 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), | 597 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), |
438 2); | 598 2); |
439 | 599 |
440 // Verify that the expected error page is being displayed. Do this by making | 600 // Verify that the expected error page is being displayed. |
441 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. | 601 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED); |
442 bool result = false; | |
443 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
444 browser()->tab_strip_model()->GetActiveWebContents(), | |
445 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"), | |
446 &result)); | |
447 EXPECT_TRUE(result); | |
448 } | 602 } |
449 | 603 |
450 // A test fixture that simulates failing requests for an IDN domain name. | 604 // A test fixture that simulates failing requests for an IDN domain name. |
451 class ErrorPageForIDNTest : public InProcessBrowserTest { | 605 class ErrorPageForIDNTest : public InProcessBrowserTest { |
452 public: | 606 public: |
453 // Target hostname in different forms. | 607 // Target hostname in different forms. |
454 static const char kHostname[]; | 608 static const char kHostname[]; |
455 static const char kHostnameJSUnicode[]; | 609 static const char kHostnameJSUnicode[]; |
456 | 610 |
457 // InProcessBrowserTest: | 611 // InProcessBrowserTest: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 644 |
491 // Make sure error page shows correct unicode for IDN. | 645 // Make sure error page shows correct unicode for IDN. |
492 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 646 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
493 // ERR_UNSAFE_PORT will not trigger the link doctor. | 647 // ERR_UNSAFE_PORT will not trigger the link doctor. |
494 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 648 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
495 browser(), | 649 browser(), |
496 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 650 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
497 kHostname), | 651 kHostname), |
498 1); | 652 1); |
499 | 653 |
500 bool result = false; | 654 ToggleHelpBox(browser()); |
501 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 655 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
502 browser()->tab_strip_model()->GetActiveWebContents(), | |
503 GetTextContentContainsStringScript(kHostnameJSUnicode), | |
504 &result)); | |
505 EXPECT_TRUE(result); | |
506 } | 656 } |
507 | 657 |
508 } // namespace | 658 } // namespace |
OLD | NEW |