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

Side by Side Diff: ios/chrome/browser/ui/dialogs/nsurl_protection_space_util_unittest.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: Cancel overlays on queue deallocation Created 3 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 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/chrome/browser/ui/dialogs/nsurl_protection_space_util.h"
6
7 #include "base/ios/ios_util.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "components/strings/grit/components_strings.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/gtest_mac.h"
12 #include "testing/platform_test.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/l10n/l10n_util_mac.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 using namespace ios_internal::nsurlprotectionspace_util;
21
22 namespace {
23
24 // Test hostnames and URL origins.
25 NSString* const kTestHost = @"chromium.org";
26 NSString* const kTestHttpOrigin = @"http://chromium.org";
27 NSString* const kTestHttpsOrigin = @"https://chromium.org:80";
28
29 // Returns protection space for the given |host|, |protocol| and |port|.
30 NSURLProtectionSpace* GetProtectionSpaceForHost(NSString* host,
31 NSString* protocol,
32 NSInteger port) {
33 return [[NSURLProtectionSpace alloc] initWithHost:host
34 port:port
35 protocol:protocol
36 realm:nil
37 authenticationMethod:nil];
38 }
39
40 // Returns protection space for the given |host| and |protocol| and port 80.
41 NSURLProtectionSpace* GetProtectionSpaceForHost(NSString* host,
42 NSString* protocol) {
43 return GetProtectionSpaceForHost(host, protocol, 80);
44 }
45
46 // Returns protection space for the given proxy |host| and |protocol|.
47 NSURLProtectionSpace* GetProtectionSpaceForProxyHost(NSString* host,
48 NSString* type) {
49 return [[NSURLProtectionSpace alloc] initWithProxyHost:host
50 port:80
51 type:type
52 realm:nil
53 authenticationMethod:nil];
54 }
55
56 } // namespace
57
58 // Tests that dialog can not be shown without valid host.
59 TEST(NSURLProtectionSpaceUtilTest, CantShowWithoutValidHost) {
60 NSURLProtectionSpace* protectionSpace =
61 GetProtectionSpaceForHost(@"", NSURLProtectionSpaceHTTPS);
62
63 EXPECT_FALSE(CanShow(protectionSpace));
64 }
65
66 // Tests that dialog can not be shown with invalid port.
67 TEST(NSURLProtectionSpaceUtilTest, CantShowWithoutValidPort) {
68 NSURLProtectionSpace* protectionSpace =
69 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTPS, INT_MAX);
70
71 EXPECT_FALSE(CanShow(protectionSpace));
72 }
73
74 // Tests showing the dialog for SOCKS proxy server.
75 TEST(NSURLProtectionSpaceUtilTest, ShowForSocksProxy) {
76 NSURLProtectionSpace* protectionSpace =
77 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceSOCKSProxy);
78
79 ASSERT_TRUE(CanShow(protectionSpace));
80
81 // Expecting the following text:
82 // The proxy chromium.org requires a username and password.
83 // Your connection to this site is not private.
84 NSString* expectedText =
85 [NSString stringWithFormat:@"%@ %@",
86 l10n_util::GetNSStringF(
87 IDS_LOGIN_DIALOG_PROXY_AUTHORITY,
88 base::SysNSStringToUTF16(kTestHost)),
89 l10n_util::GetNSString(
90 IDS_PAGE_INFO_NOT_SECURE_SUMMARY)];
91
92 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace));
93 }
94
95 // Tests showing the dialog for http proxy server.
96 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpProxy) {
97 NSURLProtectionSpace* protectionSpace =
98 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPProxy);
99
100 ASSERT_TRUE(CanShow(protectionSpace));
101
102 // Expecting the following text:
103 // The proxy http://chromium.org requires a username and password.
104 // Your connection to this site is not private.
105 NSString* expectedText =
106 [NSString stringWithFormat:@"%@ %@",
107 l10n_util::GetNSStringF(
108 IDS_LOGIN_DIALOG_PROXY_AUTHORITY,
109 base::SysNSStringToUTF16(kTestHttpOrigin)),
110 l10n_util::GetNSString(
111 IDS_PAGE_INFO_NOT_SECURE_SUMMARY)];
112 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace));
113 }
114
115 // Tests showing the dialog for https proxy server.
116 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsProxy) {
117 NSURLProtectionSpace* protectionSpace =
118 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPSProxy);
119
120 ASSERT_TRUE(CanShow(protectionSpace));
121
122 NSString* expectedText = nil;
123 // On iOS 10, HTTPS Proxy protection space reports itself as unsecure
124 // (crbug.com/629570).
125 if (base::ios::IsRunningOnIOS10OrLater()) {
126 // Expecting the following text:
127 // The proxy https://chromium.org requires a username and password.
128 // Your connection to this site is not private.
129 expectedText = [NSString
130 stringWithFormat:@"%@ %@",
131 l10n_util::GetNSStringF(
132 IDS_LOGIN_DIALOG_PROXY_AUTHORITY,
133 base::SysNSStringToUTF16(kTestHttpsOrigin)),
134 l10n_util::GetNSString(
135 IDS_PAGE_INFO_NOT_SECURE_SUMMARY)];
136 } else {
137 // Expecting the following text:
138 // The proxy https://chromium.org:80 requires a username and password.
139 expectedText =
140 l10n_util::GetNSStringF(IDS_LOGIN_DIALOG_PROXY_AUTHORITY,
141 base::SysNSStringToUTF16(kTestHttpsOrigin));
142 }
143 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace));
144 }
145
146 // Tests showing the dialog for http server.
147 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpServer) {
148 NSURLProtectionSpace* protectionSpace =
149 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTP);
150
151 ASSERT_TRUE(CanShow(protectionSpace));
152
153 // Expecting the following text:
154 // http://chromium.org requires a username and password.
155 NSString* expectedText =
156 [NSString stringWithFormat:@"%@ %@",
157 l10n_util::GetNSStringF(
158 IDS_LOGIN_DIALOG_AUTHORITY,
159 base::SysNSStringToUTF16(kTestHttpOrigin)),
160 l10n_util::GetNSString(
161 IDS_PAGE_INFO_NOT_SECURE_SUMMARY)];
162 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace));
163 }
164
165 // Tests showing the dialog for https server.
166 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsServer) {
167 NSURLProtectionSpace* protectionSpace =
168 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTPS);
169
170 ASSERT_TRUE(CanShow(protectionSpace));
171
172 // Expecting the following text:
173 // https://chromium.org:80 requires a username and password.
174 NSString* expectedText = l10n_util::GetNSStringF(
175 IDS_LOGIN_DIALOG_AUTHORITY, base::SysNSStringToUTF16(kTestHttpsOrigin));
176 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace));
177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698