Add details (where missing) for histograms and remove a few that are not worth provid...
[chromium-blink-merge.git] / net / quic / crypto / crypto_utils_test.cc
blob17eb19250eeb76eac53e0f394911aec61722d4e2
1 // Copyright (c) 2013 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.
5 #include "net/quic/crypto/crypto_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace net {
10 namespace test {
11 namespace {
13 TEST(CryptoUtilsTest, IsValidSNI) {
14 // IP as SNI.
15 EXPECT_FALSE(CryptoUtils::IsValidSNI("192.168.0.1"));
16 // SNI without any dot.
17 EXPECT_FALSE(CryptoUtils::IsValidSNI("somedomain"));
18 // Invalid RFC2396 hostname
19 // TODO(rtenneti): Support RFC2396 hostname.
20 // EXPECT_FALSE(CryptoUtils::IsValidSNI("some_domain.com"));
21 // An empty string must be invalid otherwise the QUIC client will try sending
22 // it.
23 EXPECT_FALSE(CryptoUtils::IsValidSNI(""));
25 // Valid SNI
26 EXPECT_TRUE(CryptoUtils::IsValidSNI("test.google.com"));
29 TEST(CryptoUtilsTest, NormalizeHostname) {
30 struct {
31 const char *input, *expected;
32 } tests[] = {
33 { "www.google.com", "www.google.com", },
34 { "WWW.GOOGLE.COM", "www.google.com", },
35 { "www.google.com.", "www.google.com", },
36 { "www.google.COM.", "www.google.com", },
37 { "www.google.com..", "www.google.com", },
38 { "www.google.com........", "www.google.com", },
41 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
42 EXPECT_EQ(std::string(tests[i].expected),
43 CryptoUtils::NormalizeHostname(tests[i].input));
47 } // namespace
48 } // namespace test
49 } // namespace net