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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/prefs/pref_service.h" | |
| 7 #include "base/strings/stringprintf.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
| 8 #include "chrome/browser/net/url_request_mock_util.h" | 10 #include "chrome/browser/net/url_request_mock_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/pref_names.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/test_navigation_observer.h" | 20 #include "content/public/test/test_navigation_observer.h" |
| 17 #include "content/test/net/url_request_failed_job.h" | 21 #include "content/test/net/url_request_failed_job.h" |
| 18 #include "content/test/net/url_request_mock_http_job.h" | 22 #include "content/test/net/url_request_mock_http_job.h" |
| 19 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_util.h" | |
| 20 #include "net/url_request/url_request_filter.h" | 25 #include "net/url_request/url_request_filter.h" |
| 21 #include "net/url_request/url_request_job_factory.h" | 26 #include "net/url_request/url_request_job_factory.h" |
| 22 | 27 |
| 23 using content::BrowserThread; | 28 using content::BrowserThread; |
| 24 using content::NavigationController; | 29 using content::NavigationController; |
| 25 using content::URLRequestFailedJob; | 30 using content::URLRequestFailedJob; |
| 26 | 31 |
| 27 namespace { | 32 namespace { |
| 28 | 33 |
| 29 class ErrorPageTest : public InProcessBrowserTest { | 34 class ErrorPageTest : public InProcessBrowserTest { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 246 |
| 242 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 247 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
| 243 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 248 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
| 244 NavigateToURLAndWaitForTitle( | 249 NavigateToURLAndWaitForTitle( |
| 245 content::URLRequestMockHTTPJob::GetMockUrl( | 250 content::URLRequestMockHTTPJob::GetMockUrl( |
| 246 base::FilePath(FILE_PATH_LITERAL("page404.html"))), | 251 base::FilePath(FILE_PATH_LITERAL("page404.html"))), |
| 247 "SUCCESS", | 252 "SUCCESS", |
| 248 1); | 253 1); |
| 249 } | 254 } |
| 250 | 255 |
| 256 // Returns JavaScrips code that executes plain text search for the page. | |
|
mmenke
2013/09/27 14:44:05
nit: Javascript
yuusuke
2013/09/28 10:42:50
Done.
| |
| 257 // Pass into content::ExecuteScriptAndExtractBool as |script| parameter. | |
| 258 std::string GetTextContentContainsStringScript( | |
| 259 const std::string& value_to_search) { | |
| 260 return base::StringPrintf( | |
| 261 "var textContent = document.body.textContent;" | |
| 262 "var hasError = textContent.indexOf('%s') >= 0;" | |
| 263 "domAutomationController.send(hasError);", value_to_search.c_str()); | |
|
mmenke
2013/09/27 14:44:05
nit: To make the second parameter stand out a bit
yuusuke
2013/09/28 10:42:50
Done.
| |
| 264 } | |
| 265 | |
| 251 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 266 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
| 252 class AddressUnreachableProtocolHandler | 267 class AddressUnreachableProtocolHandler |
| 253 : public net::URLRequestJobFactory::ProtocolHandler { | 268 : public net::URLRequestJobFactory::ProtocolHandler { |
| 254 public: | 269 public: |
| 255 AddressUnreachableProtocolHandler() {} | 270 AddressUnreachableProtocolHandler() {} |
| 256 virtual ~AddressUnreachableProtocolHandler() {} | 271 virtual ~AddressUnreachableProtocolHandler() {} |
| 257 | 272 |
| 258 // net::URLRequestJobFactory::ProtocolHandler: | 273 // net::URLRequestJobFactory::ProtocolHandler: |
| 259 virtual net::URLRequestJob* MaybeCreateJob( | 274 virtual net::URLRequestJob* MaybeCreateJob( |
| 260 net::URLRequest* request, | 275 net::URLRequest* request, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 331 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 317 browser(), | 332 browser(), |
| 318 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), | 333 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), |
| 319 2); | 334 2); |
| 320 | 335 |
| 321 // Verify that the expected error page is being displayed. Do this by making | 336 // Verify that the expected error page is being displayed. Do this by making |
| 322 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. | 337 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. |
| 323 bool result = false; | 338 bool result = false; |
| 324 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 339 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 325 browser()->tab_strip_model()->GetActiveWebContents(), | 340 browser()->tab_strip_model()->GetActiveWebContents(), |
| 326 "var textContent = document.body.textContent;" | 341 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"), |
| 327 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" | 342 &result)); |
| 328 "domAutomationController.send(hasError);", | 343 EXPECT_TRUE(result); |
| 344 } | |
| 345 | |
| 346 // A test fixture that substitutes kMockHostname with IDN. | |
|
mmenke
2013/09/27 14:44:05
nit: Think it's ambiguous what "kMockHostname" is
yuusuke
2013/09/28 10:42:50
Done.
| |
| 347 class ErrorPageForIDNTest : public InProcessBrowserTest { | |
| 348 public: | |
| 349 // InProcessBrowserTest: | |
| 350 virtual void SetUpOnMainThread() OVERRIDE { | |
| 351 // Clear AcceptLanguages to force punycode decoding. | |
| 352 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, | |
| 353 std::string()); | |
| 354 BrowserThread::PostTask( | |
| 355 BrowserThread::IO, FROM_HERE, | |
| 356 base::Bind(&ErrorPageForIDNTest::AddFilters)); | |
| 357 } | |
| 358 | |
| 359 virtual void CleanUpOnMainThread() OVERRIDE { | |
| 360 BrowserThread::PostTask( | |
| 361 BrowserThread::IO, FROM_HERE, | |
| 362 base::Bind(&ErrorPageForIDNTest::RemoveFilters)); | |
| 363 } | |
| 364 | |
| 365 // Target hostname in ASCII (punycode). | |
| 366 static std::string GetHostname() { | |
| 367 return "xn--d1abbgf6aiiy.xn--p1ai"; | |
| 368 } | |
| 369 | |
| 370 static std::string GetHostnameAsJSUnicode() { | |
| 371 return "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d" | |
| 372 "\\u0442.\\u0440\\u0444"; | |
| 373 } | |
|
mmenke
2013/09/27 14:44:05
optional nit: Suggest just making these consts, i
yuusuke
2013/09/28 10:42:50
Done.
| |
| 374 | |
| 375 private: | |
| 376 static void AddFilters() { | |
| 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 378 content::URLRequestFailedJob::AddUrlHandler(GetHostname()); | |
| 379 } | |
| 380 | |
| 381 static void RemoveFilters() { | |
| 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 383 net::URLRequestFilter::GetInstance()->ClearHandlers(); | |
| 384 } | |
| 385 }; | |
| 386 | |
| 387 // Make sure error page shows correct unicode for IDN. | |
| 388 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | |
| 389 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
|
mmenke
2013/09/27 14:44:05
Think it's worth a comment that ERR_UNSAFE_PORT wi
yuusuke
2013/09/28 10:42:50
Done.
| |
| 390 browser(), | |
| 391 URLRequestFailedJob::GetMockHttpUrl(net::ERR_UNSAFE_PORT, | |
| 392 GetHostname()), | |
| 393 1); | |
| 394 | |
| 395 bool result = false; | |
| 396 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 397 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 398 GetTextContentContainsStringScript(GetHostnameAsJSUnicode()), | |
| 329 &result)); | 399 &result)); |
| 330 EXPECT_TRUE(result); | 400 EXPECT_TRUE(result); |
| 331 } | 401 } |
| 332 | 402 |
| 333 } // namespace | 403 } // namespace |
| OLD | NEW |