Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 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 #include "chrome/browser/ui/login/login_prompt.h"
      6 #include "net/base/auth.h"
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 #include "url/gurl.h"
      9 
     10 TEST(LoginPromptTest, GetSignonRealm) {
     11   scoped_refptr<net::AuthChallengeInfo> auth_info = new net::AuthChallengeInfo;
     12   auth_info->is_proxy = false;  // server auth
     13   // auth_info->host is intentionally left empty.
     14   auth_info->scheme = "Basic";
     15   auth_info->realm = "WallyWorld";
     16 
     17   std::string url[] = {
     18     "https://www.nowhere.org/dir/index.html",
     19     "https://www.nowhere.org:443/dir/index.html",  // default port
     20     "https://www.nowhere.org:8443/dir/index.html",  // non-default port
     21     "https://www.nowhere.org",  // no trailing slash
     22     "https://foo:bar@www.nowhere.org/dir/index.html",  // username:password
     23     "https://www.nowhere.org/dir/index.html?id=965362",  // query
     24     "https://www.nowhere.org/dir/index.html#toc",  // reference
     25   };
     26 
     27   std::string expected[] = {
     28     "https://www.nowhere.org/WallyWorld",
     29     "https://www.nowhere.org/WallyWorld",
     30     "https://www.nowhere.org:8443/WallyWorld",
     31     "https://www.nowhere.org/WallyWorld",
     32     "https://www.nowhere.org/WallyWorld",
     33     "https://www.nowhere.org/WallyWorld",
     34     "https://www.nowhere.org/WallyWorld"
     35   };
     36 
     37   for (size_t i = 0; i < arraysize(url); i++) {
     38     std::string key = GetSignonRealm(GURL(url[i]), *auth_info.get());
     39     EXPECT_EQ(expected[i], key);
     40   }
     41 }
     42