| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #import "ios/chrome/browser/ui/dialogs/nsurl_protection_space_util.h" | 5 #import "ios/chrome/browser/ui/dialogs/nsurl_protection_space_util.h" |
| 6 | 6 |
| 7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Tests showing the dialog for SOCKS proxy server. | 74 // Tests showing the dialog for SOCKS proxy server. |
| 75 TEST(NSURLProtectionSpaceUtilTest, ShowForSocksProxy) { | 75 TEST(NSURLProtectionSpaceUtilTest, ShowForSocksProxy) { |
| 76 NSURLProtectionSpace* protectionSpace = | 76 NSURLProtectionSpace* protectionSpace = |
| 77 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceSOCKSProxy); | 77 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceSOCKSProxy); |
| 78 | 78 |
| 79 ASSERT_TRUE(CanShow(protectionSpace)); | 79 ASSERT_TRUE(CanShow(protectionSpace)); |
| 80 | 80 |
| 81 // Expecting the following text: | 81 // Expecting the following text: |
| 82 // The proxy chromium.org requires a username and password. | 82 // The proxy chromium.org requires a username and password. |
| 83 // Your connection to this site is not private. | 83 // Your connection to this site is not private. |
| 84 NSString* expectedText = | 84 NSString* expectedText = [NSString |
| 85 [NSString stringWithFormat:@"%@ %@", | 85 stringWithFormat:@"%@ %@", |
| 86 l10n_util::GetNSStringF( | 86 l10n_util::GetNSStringF( |
| 87 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, | 87 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, |
| 88 base::SysNSStringToUTF16(kTestHost)), | 88 base::SysNSStringToUTF16(kTestHost)), |
| 89 l10n_util::GetNSString( | 89 l10n_util::GetNSString(IDS_PAGEINFO_NOT_SECURE_SUMMARY)]; |
| 90 IDS_PAGE_INFO_NON_SECURE_TRANSPORT)]; | |
| 91 | 90 |
| 92 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); | 91 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); |
| 93 } | 92 } |
| 94 | 93 |
| 95 // Tests showing the dialog for http proxy server. | 94 // Tests showing the dialog for http proxy server. |
| 96 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpProxy) { | 95 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpProxy) { |
| 97 NSURLProtectionSpace* protectionSpace = | 96 NSURLProtectionSpace* protectionSpace = |
| 98 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPProxy); | 97 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPProxy); |
| 99 | 98 |
| 100 ASSERT_TRUE(CanShow(protectionSpace)); | 99 ASSERT_TRUE(CanShow(protectionSpace)); |
| 101 | 100 |
| 102 // Expecting the following text: | 101 // Expecting the following text: |
| 103 // The proxy http://chromium.org requires a username and password. | 102 // The proxy http://chromium.org requires a username and password. |
| 104 // Your connection to this site is not private. | 103 // Your connection to this site is not private. |
| 105 NSString* expectedText = | 104 NSString* expectedText = [NSString |
| 106 [NSString stringWithFormat:@"%@ %@", | 105 stringWithFormat:@"%@ %@", |
| 107 l10n_util::GetNSStringF( | 106 l10n_util::GetNSStringF( |
| 108 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, | 107 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, |
| 109 base::SysNSStringToUTF16(kTestHttpOrigin)), | 108 base::SysNSStringToUTF16(kTestHttpOrigin)), |
| 110 l10n_util::GetNSString( | 109 l10n_util::GetNSString(IDS_PAGEINFO_NOT_SECURE_SUMMARY)]; |
| 111 IDS_PAGE_INFO_NON_SECURE_TRANSPORT)]; | |
| 112 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); | 110 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Tests showing the dialog for https proxy server. | 113 // Tests showing the dialog for https proxy server. |
| 116 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsProxy) { | 114 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsProxy) { |
| 117 NSURLProtectionSpace* protectionSpace = | 115 NSURLProtectionSpace* protectionSpace = |
| 118 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPSProxy); | 116 GetProtectionSpaceForProxyHost(kTestHost, NSURLProtectionSpaceHTTPSProxy); |
| 119 | 117 |
| 120 ASSERT_TRUE(CanShow(protectionSpace)); | 118 ASSERT_TRUE(CanShow(protectionSpace)); |
| 121 | 119 |
| 122 NSString* expectedText = nil; | 120 NSString* expectedText = nil; |
| 123 // On iOS 10, HTTPS Proxy protection space reports itself as unsecure | 121 // On iOS 10, HTTPS Proxy protection space reports itself as unsecure |
| 124 // (crbug.com/629570). | 122 // (crbug.com/629570). |
| 125 if (base::ios::IsRunningOnIOS10OrLater()) { | 123 if (base::ios::IsRunningOnIOS10OrLater()) { |
| 126 // Expecting the following text: | 124 // Expecting the following text: |
| 127 // The proxy https://chromium.org requires a username and password. | 125 // The proxy https://chromium.org requires a username and password. |
| 128 // Your connection to this site is not private. | 126 // Your connection to this site is not private. |
| 129 expectedText = [NSString | 127 expectedText = [NSString |
| 130 stringWithFormat:@"%@ %@", | 128 stringWithFormat:@"%@ %@", |
| 131 l10n_util::GetNSStringF( | 129 l10n_util::GetNSStringF( |
| 132 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, | 130 IDS_LOGIN_DIALOG_PROXY_AUTHORITY, |
| 133 base::SysNSStringToUTF16(kTestHttpsOrigin)), | 131 base::SysNSStringToUTF16(kTestHttpsOrigin)), |
| 134 l10n_util::GetNSString( | 132 l10n_util::GetNSString( |
| 135 IDS_PAGE_INFO_NON_SECURE_TRANSPORT)]; | 133 IDS_PAGEINFO_NOT_SECURE_SUMMARY)]; |
| 136 } else { | 134 } else { |
| 137 // Expecting the following text: | 135 // Expecting the following text: |
| 138 // The proxy https://chromium.org:80 requires a username and password. | 136 // The proxy https://chromium.org:80 requires a username and password. |
| 139 expectedText = | 137 expectedText = |
| 140 l10n_util::GetNSStringF(IDS_LOGIN_DIALOG_PROXY_AUTHORITY, | 138 l10n_util::GetNSStringF(IDS_LOGIN_DIALOG_PROXY_AUTHORITY, |
| 141 base::SysNSStringToUTF16(kTestHttpsOrigin)); | 139 base::SysNSStringToUTF16(kTestHttpsOrigin)); |
| 142 } | 140 } |
| 143 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); | 141 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); |
| 144 } | 142 } |
| 145 | 143 |
| 146 // Tests showing the dialog for http server. | 144 // Tests showing the dialog for http server. |
| 147 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpServer) { | 145 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpServer) { |
| 148 NSURLProtectionSpace* protectionSpace = | 146 NSURLProtectionSpace* protectionSpace = |
| 149 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTP); | 147 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTP); |
| 150 | 148 |
| 151 ASSERT_TRUE(CanShow(protectionSpace)); | 149 ASSERT_TRUE(CanShow(protectionSpace)); |
| 152 | 150 |
| 153 // Expecting the following text: | 151 // Expecting the following text: |
| 154 // http://chromium.org requires a username and password. | 152 // http://chromium.org requires a username and password. |
| 155 NSString* expectedText = | 153 NSString* expectedText = [NSString |
| 156 [NSString stringWithFormat:@"%@ %@", | 154 stringWithFormat:@"%@ %@", |
| 157 l10n_util::GetNSStringF( | 155 l10n_util::GetNSStringF( |
| 158 IDS_LOGIN_DIALOG_AUTHORITY, | 156 IDS_LOGIN_DIALOG_AUTHORITY, |
| 159 base::SysNSStringToUTF16(kTestHttpOrigin)), | 157 base::SysNSStringToUTF16(kTestHttpOrigin)), |
| 160 l10n_util::GetNSString( | 158 l10n_util::GetNSString(IDS_PAGEINFO_NOT_SECURE_SUMMARY)]; |
| 161 IDS_PAGE_INFO_NON_SECURE_TRANSPORT)]; | |
| 162 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); | 159 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); |
| 163 } | 160 } |
| 164 | 161 |
| 165 // Tests showing the dialog for https server. | 162 // Tests showing the dialog for https server. |
| 166 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsServer) { | 163 TEST(NSURLProtectionSpaceUtilTest, ShowForHttpsServer) { |
| 167 NSURLProtectionSpace* protectionSpace = | 164 NSURLProtectionSpace* protectionSpace = |
| 168 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTPS); | 165 GetProtectionSpaceForHost(kTestHost, NSURLProtectionSpaceHTTPS); |
| 169 | 166 |
| 170 ASSERT_TRUE(CanShow(protectionSpace)); | 167 ASSERT_TRUE(CanShow(protectionSpace)); |
| 171 | 168 |
| 172 // Expecting the following text: | 169 // Expecting the following text: |
| 173 // https://chromium.org:80 requires a username and password. | 170 // https://chromium.org:80 requires a username and password. |
| 174 NSString* expectedText = l10n_util::GetNSStringF( | 171 NSString* expectedText = l10n_util::GetNSStringF( |
| 175 IDS_LOGIN_DIALOG_AUTHORITY, base::SysNSStringToUTF16(kTestHttpsOrigin)); | 172 IDS_LOGIN_DIALOG_AUTHORITY, base::SysNSStringToUTF16(kTestHttpsOrigin)); |
| 176 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); | 173 EXPECT_NSEQ(expectedText, MessageForHTTPAuth(protectionSpace)); |
| 177 } | 174 } |
| OLD | NEW |