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

Side by Side Diff: ios/web/web_state/error_translation_util_unittest.mm

Issue 2096973002: [ios] Do not show SSL interstitial if cert is absent or cannot be parsed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittest Created 4 years, 5 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 | « ios/web/web_state/error_translation_util.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/web/web_state/error_translation_util.h"
6
7 #import <Foundation/Foundation.h>
8
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "net/base/net_errors.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gtest_mac.h"
14 #include "testing/platform_test.h"
15
16 // Test fixture for error translation testing.
17 typedef PlatformTest ErrorTranslationUtilTest;
18
19 namespace {
20 // Returns net error domain.
21 NSString* GetNetErrorDomain() {
22 return base::SysUTF8ToNSString(net::kErrorDomain);
23 }
24 } // namespcae
25
26 // Tests translation of an error with empty domain and no underlying error.
27 TEST_F(ErrorTranslationUtilTest, MalformedError) {
28 base::scoped_nsobject<NSError> error(
29 [[NSError alloc] initWithDomain:@"" code:0 userInfo:nil]);
30 NSError* net_error = web::NetErrorFromError(error);
31
32 // Top level error should be the same as the original error.
33 EXPECT_TRUE(net_error);
34 EXPECT_NSEQ([error domain], [net_error domain]);
35 EXPECT_EQ([error code], [net_error code]);
36
37 // Underlying error should have net error doamin and code.
38 NSError* net_underlying_error = [net_error userInfo][NSUnderlyingErrorKey];
39 EXPECT_TRUE(net_underlying_error);
40 EXPECT_NSEQ(GetNetErrorDomain(), [net_underlying_error domain]);
41 EXPECT_EQ(net::ERR_FAILED, [net_underlying_error code]);
42 }
43
44 // Tests translation of unknown CFNetwork error, which does not have an
45 // underlying error.
46 TEST_F(ErrorTranslationUtilTest, UnknownCFNetworkError) {
47 base::scoped_nsobject<NSError> error([[NSError alloc]
48 initWithDomain:static_cast<NSString*>(kCFErrorDomainCFNetwork)
49 code:kCFURLErrorUnknown
50 userInfo:nil]);
51 NSError* net_error = web::NetErrorFromError(error);
52
53 // Top level error should be the same as the original error.
54 EXPECT_TRUE(net_error);
55 EXPECT_NSEQ([error domain], [net_error domain]);
56 EXPECT_EQ([error code], [net_error code]);
57
58 // Underlying error should have net error domain and code.
59 NSError* net_underlying_error = [net_error userInfo][NSUnderlyingErrorKey];
60 EXPECT_TRUE(net_underlying_error);
61 EXPECT_NSEQ(GetNetErrorDomain(), [net_underlying_error domain]);
62 EXPECT_EQ(net::ERR_FAILED, [net_underlying_error code]);
63 }
64
65 // Tests translation of kCFURLErrorCannotFindHost CFNetwork error, which has an
66 // underlying error with NSURLError domain.
67 TEST_F(ErrorTranslationUtilTest, CanNotFindHostError) {
68 base::scoped_nsobject<NSError> underlying_error([[NSError alloc]
69 initWithDomain:NSURLErrorDomain
70 code:kCFURLErrorCannotFindHost
71 userInfo:nil]);
72
73 NSError* error =
74 [[NSError alloc] initWithDomain:NSURLErrorDomain
75 code:NSURLErrorCannotFindHost
76 userInfo:@{
77 NSUnderlyingErrorKey : underlying_error,
78 }];
79 NSError* net_error = web::NetErrorFromError(error);
80
81 // Top level error should be the same as the original error.
82 EXPECT_TRUE(net_error);
83 EXPECT_NSEQ([error domain], [net_error domain]);
84 EXPECT_EQ([error code], [net_error code]);
85
86 // First underlying error should be the same as the original underlying error.
87 NSError* net_underlying_error = [net_error userInfo][NSUnderlyingErrorKey];
88 EXPECT_TRUE(underlying_error);
89 EXPECT_NSEQ([underlying_error domain], [net_underlying_error domain]);
90 EXPECT_EQ([underlying_error code], [net_underlying_error code]);
91
92 // Final underlying error should have net error domain and code.
93 NSError* final_net_underlying_error =
94 [net_underlying_error userInfo][NSUnderlyingErrorKey];
95 EXPECT_TRUE(final_net_underlying_error);
96 EXPECT_NSEQ(GetNetErrorDomain(), [final_net_underlying_error domain]);
97 EXPECT_EQ(net::ERR_NAME_NOT_RESOLVED, [final_net_underlying_error code]);
98 }
99
100 // Tests translation of kCFURLErrorSecureConnectionFailed CFNetwork error, by
101 // specifying different net error code.
102 TEST_F(ErrorTranslationUtilTest, CertError) {
103 base::scoped_nsobject<NSError> underlying_error([[NSError alloc]
104 initWithDomain:NSURLErrorDomain
105 code:kCFURLErrorSecureConnectionFailed
106 userInfo:nil]);
107
108 NSError* error =
109 [[NSError alloc] initWithDomain:NSURLErrorDomain
110 code:kCFURLErrorSecureConnectionFailed
111 userInfo:@{
112 NSUnderlyingErrorKey : underlying_error,
113 }];
114 NSError* net_error = web::NetErrorFromError(error, net::ERR_CONNECTION_RESET);
115
116 // Top level error should be the same as the original error.
117 EXPECT_TRUE(net_error);
118 EXPECT_NSEQ([error domain], [net_error domain]);
119 EXPECT_EQ([error code], [net_error code]);
120
121 // First underlying error should be the same as the original underlying error.
122 NSError* net_underlying_error = [net_error userInfo][NSUnderlyingErrorKey];
123 EXPECT_TRUE(underlying_error);
124 EXPECT_NSEQ([underlying_error domain], [net_underlying_error domain]);
125 EXPECT_EQ([underlying_error code], [net_underlying_error code]);
126
127 // Final underlying error should have net error domain and specified code.
128 NSError* final_net_underlying_error =
129 [net_underlying_error userInfo][NSUnderlyingErrorKey];
130 EXPECT_TRUE(final_net_underlying_error);
131 EXPECT_NSEQ(GetNetErrorDomain(), [final_net_underlying_error domain]);
132 EXPECT_EQ(net::ERR_CONNECTION_RESET, [final_net_underlying_error code]);
133 }
OLDNEW
« no previous file with comments | « ios/web/web_state/error_translation_util.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698