Index: chrome/browser/ui/login/login_handler_unittest.cc |
diff --git a/chrome/browser/ui/login/login_handler_unittest.cc b/chrome/browser/ui/login/login_handler_unittest.cc |
index 3279341e056bb7e86cc3f9aa42f571eb523dee4a..9b22070c9dd2c771b0d876c6593fbf2e19fad96f 100644 |
--- a/chrome/browser/ui/login/login_handler_unittest.cc |
+++ b/chrome/browser/ui/login/login_handler_unittest.cc |
@@ -5,40 +5,138 @@ |
#include <stddef.h> |
#include "base/macros.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/ui/login/login_handler.h" |
#include "net/base/auth.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
-TEST(LoginPromptTest, GetSignonRealm) { |
+namespace { |
+ |
+const char kHttpUrl[] = "http://example.com/foo/bar"; |
+const char kBasicAuthScheme[] = "Basic"; |
+const char kFooRealm[] = "Foo"; |
+const char kInsecureProxy[] = "Your connection to this site is not private."; |
+ |
+enum TargetType { PROXY, SERVER }; |
+ |
+const struct TestCase { |
+ const char* const request_url; |
+ struct { |
+ TargetType target_type; |
+ const char* const scheme; |
+ const char* const realm; |
+ const char* const challenger; |
+ } auth_info; |
+ struct { |
+ const char* const authority; |
+ const char* const explanation; |
+ const char* const signon_realm; |
+ } expected; |
+} kTestCases[]{ |
+ // Insecure proxy |
+ {kHttpUrl, |
+ {PROXY, kBasicAuthScheme, kFooRealm, "http://example.com"}, |
+ {"The proxy http://example.com requires a username and password.", |
+ kInsecureProxy, "example.com:80/Foo"}}, |
+ |
+ // Insecure proxy on non-standard port |
+ {kHttpUrl, |
+ {PROXY, kBasicAuthScheme, kFooRealm, "http://example.com:8009"}, |
+ {"The proxy http://example.com:8009 requires a username and password.", |
+ kInsecureProxy, "example.com:8009/Foo"}}, |
+ |
+ // Secure proxy |
+ {kHttpUrl, |
+ {PROXY, kBasicAuthScheme, kFooRealm, "https://example.com"}, |
+ {"The proxy https://example.com requires a username and password.", "", |
+ "example.com:443/Foo"}}, |
+ |
+ // Secure proxy on non-standard port |
+ {kHttpUrl, |
+ {PROXY, kBasicAuthScheme, kFooRealm, "https://example.com:446"}, |
+ {"The proxy https://example.com:446 requires a username and password.", "", |
+ "example.com:446/Foo"}}, |
+ |
+ // localhost |
+ {kHttpUrl, |
+ {PROXY, kBasicAuthScheme, kFooRealm, "http://localhost:7323"}, |
+ {"The proxy http://localhost:7323 requires a username and password.", "", |
+ "localhost:7323/Foo"}}, |
+ |
+ // Secure server |
+ {"https://www.nowhere.org/dir/index.html", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+ |
+ // URL uses default port. |
+ {"https://www.nowhere.org:443/dir/index.html", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+ |
+ // URL uses non-default port. |
+ {"https://www.nowhere.org:8443/dir/index.html", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org:8443 requires a username and password.", "", |
+ "https://www.nowhere.org:8443/Foo"}}, |
+ |
+ // URL has no trailing slash. |
+ {"https://www.nowhere.org", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+ |
+ // username:password |
+ {"https://foo:bar@www.nowhere.org/dir/index.html", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+ |
+ // query |
+ {"https://www.nowhere.org/dir/index.html?id=965362", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+ |
+ // reference |
+ {"https://www.nowhere.org/dir/index.html#toc", |
+ {SERVER, kBasicAuthScheme, kFooRealm, nullptr}, |
+ {"https://www.nowhere.org requires a username and password.", "", |
+ "https://www.nowhere.org/Foo"}}, |
+}; |
+ |
+} // namespace |
+ |
+TEST(LoginHandlerTest, DialogStringsAndRealm) { |
scoped_refptr<net::AuthChallengeInfo> auth_info = new net::AuthChallengeInfo; |
- auth_info->is_proxy = false; // server auth |
- // auth_info->host is intentionally left empty. |
- auth_info->scheme = "Basic"; |
- auth_info->realm = "WallyWorld"; |
- |
- std::string url[] = { |
- "https://www.nowhere.org/dir/index.html", |
- "https://www.nowhere.org:443/dir/index.html", // default port |
- "https://www.nowhere.org:8443/dir/index.html", // non-default port |
- "https://www.nowhere.org", // no trailing slash |
- "https://foo:bar@www.nowhere.org/dir/index.html", // username:password |
- "https://www.nowhere.org/dir/index.html?id=965362", // query |
- "https://www.nowhere.org/dir/index.html#toc", // reference |
- }; |
- |
- std::string expected[] = { |
- "https://www.nowhere.org/WallyWorld", |
- "https://www.nowhere.org/WallyWorld", |
- "https://www.nowhere.org:8443/WallyWorld", |
- "https://www.nowhere.org/WallyWorld", |
- "https://www.nowhere.org/WallyWorld", |
- "https://www.nowhere.org/WallyWorld", |
- "https://www.nowhere.org/WallyWorld" |
- }; |
- |
- for (size_t i = 0; i < arraysize(url); i++) { |
- std::string key = GetSignonRealm(GURL(url[i]), *auth_info.get()); |
- EXPECT_EQ(expected[i], key); |
+ for (const auto& test_case : kTestCases) { |
+ GURL request_url(test_case.request_url); |
+ auth_info->is_proxy = test_case.auth_info.target_type == PROXY; |
+ auth_info->scheme = test_case.auth_info.scheme; |
+ auth_info->realm = test_case.auth_info.realm; |
+ auth_info->challenger = url::Origin( |
+ test_case.auth_info.challenger ? GURL(test_case.auth_info.challenger) |
+ : request_url); |
+ |
+ SCOPED_TRACE(::testing::Message() |
+ << "request_url:" << test_case.request_url |
+ << " auth_info: { is_proxy:" << auth_info->is_proxy |
+ << " scheme:'" << auth_info->scheme << "' realm:'" |
+ << auth_info->realm << "' challenger:'" |
+ << auth_info->challenger.Serialize() << "' }"); |
+ base::string16 authority; |
+ base::string16 explanation; |
+ |
+ LoginHandler::GetDialogStrings(request_url, *auth_info, &authority, |
+ &explanation); |
+ EXPECT_STREQ(test_case.expected.authority, |
+ base::UTF16ToASCII(authority).c_str()); |
+ EXPECT_STREQ(test_case.expected.explanation, |
+ base::UTF16ToASCII(explanation).c_str()); |
+ |
+ EXPECT_STREQ(test_case.expected.signon_realm, |
+ LoginHandler::GetSignonRealm(request_url, *auth_info).c_str()); |
} |
} |