Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 24503004: Show IDN in error screens (DNS failure etc.) (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/offline/offline_load_page.cc ('k') | chrome/common/localized_error.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Javascript code that executes plain text search for the page.
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);",
264 value_to_search.c_str());
265 }
266
251 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 267 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
252 class AddressUnreachableProtocolHandler 268 class AddressUnreachableProtocolHandler
253 : public net::URLRequestJobFactory::ProtocolHandler { 269 : public net::URLRequestJobFactory::ProtocolHandler {
254 public: 270 public:
255 AddressUnreachableProtocolHandler() {} 271 AddressUnreachableProtocolHandler() {}
256 virtual ~AddressUnreachableProtocolHandler() {} 272 virtual ~AddressUnreachableProtocolHandler() {}
257 273
258 // net::URLRequestJobFactory::ProtocolHandler: 274 // net::URLRequestJobFactory::ProtocolHandler:
259 virtual net::URLRequestJob* MaybeCreateJob( 275 virtual net::URLRequestJob* MaybeCreateJob(
260 net::URLRequest* request, 276 net::URLRequest* request,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 332 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
317 browser(), 333 browser(),
318 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 334 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
319 2); 335 2);
320 336
321 // Verify that the expected error page is being displayed. Do this by making 337 // 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. 338 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed.
323 bool result = false; 339 bool result = false;
324 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 340 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
325 browser()->tab_strip_model()->GetActiveWebContents(), 341 browser()->tab_strip_model()->GetActiveWebContents(),
326 "var textContent = document.body.textContent;" 342 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"),
327 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" 343 &result));
328 "domAutomationController.send(hasError);", 344 EXPECT_TRUE(result);
345 }
346
347 // A test fixture that simulates failing requests for an IDN domain name.
348 class ErrorPageForIDNTest : public InProcessBrowserTest {
349 public:
350 // InProcessBrowserTest:
351 virtual void SetUpOnMainThread() OVERRIDE {
352 // Clear AcceptLanguages to force punycode decoding.
353 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages,
354 std::string());
355 BrowserThread::PostTask(
356 BrowserThread::IO, FROM_HERE,
357 base::Bind(&ErrorPageForIDNTest::AddFilters));
358 }
359
360 virtual void CleanUpOnMainThread() OVERRIDE {
361 BrowserThread::PostTask(
362 BrowserThread::IO, FROM_HERE,
363 base::Bind(&ErrorPageForIDNTest::RemoveFilters));
364 }
365
366 // Target hostname in different forms.
367 static const char kHostname[];
368 static const char kHostnameJSUnicode[];
mmenke 2013/09/28 16:15:56 nit: Static constants should go before function d
yuusuke 2013/09/28 18:56:56 Done.
369
370 private:
371 static void AddFilters() {
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
373 content::URLRequestFailedJob::AddUrlHandlerForHostname(kHostname);
374 }
375
376 static void RemoveFilters() {
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
378 net::URLRequestFilter::GetInstance()->ClearHandlers();
379 }
380 };
381
382 const char ErrorPageForIDNTest::kHostname[] =
383 "xn--d1abbgf6aiiy.xn--p1ai";
384 const char ErrorPageForIDNTest::kHostnameJSUnicode[] =
385 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442."
386 "\\u0440\\u0444";
387
388 // Make sure error page shows correct unicode for IDN.
389 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
390 // ERR_UNSAFE_PORT will not trigger the link doctor.
391 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
392 browser(),
393 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
394 kHostname),
395 1);
396
397 bool result = false;
398 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
399 browser()->tab_strip_model()->GetActiveWebContents(),
400 GetTextContentContainsStringScript(kHostnameJSUnicode),
329 &result)); 401 &result));
330 EXPECT_TRUE(result); 402 EXPECT_TRUE(result);
331 } 403 }
332 404
333 } // namespace 405 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/offline/offline_load_page.cc ('k') | chrome/common/localized_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698