15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/login/login_prompt.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h"
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(LoginPromptTest, GetSignonRealm) {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<net::AuthChallengeInfo> auth_info = new net::AuthChallengeInfo;
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  auth_info->is_proxy = false;  // server auth
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // auth_info->host is intentionally left empty.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  auth_info->scheme = "Basic";
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  auth_info->realm = "WallyWorld";
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string url[] = {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/dir/index.html",
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org:443/dir/index.html",  // default port
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org:8443/dir/index.html",  // non-default port
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org",  // no trailing slash
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://foo:bar@www.nowhere.org/dir/index.html",  // username:password
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/dir/index.html?id=965362",  // query
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/dir/index.html#toc",  // reference
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string expected[] = {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld",
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld",
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org:8443/WallyWorld",
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld",
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld",
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld",
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "https://www.nowhere.org/WallyWorld"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < arraysize(url); i++) {
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    std::string key = GetSignonRealm(GURL(url[i]), *auth_info.get());
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(expected[i], key);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
42