Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / ssl / ssl_cipher_suite_names_unittest.cc
blob042ca82a5d3b1473a8f7f53b57e52acdb4d13961
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.
5 #include "net/ssl/ssl_cipher_suite_names.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
12 namespace {
14 TEST(CipherSuiteNamesTest, Basic) {
15 const char *key_exchange, *cipher, *mac;
16 bool is_aead;
18 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xc001);
19 EXPECT_STREQ("ECDH_ECDSA", key_exchange);
20 EXPECT_STREQ("NULL", cipher);
21 EXPECT_STREQ("SHA1", mac);
22 EXPECT_FALSE(is_aead);
24 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x009f);
25 EXPECT_STREQ("DHE_RSA", key_exchange);
26 EXPECT_STREQ("AES_256_GCM", cipher);
27 EXPECT_TRUE(is_aead);
28 EXPECT_EQ(NULL, mac);
30 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xff31);
31 EXPECT_STREQ("???", key_exchange);
32 EXPECT_STREQ("???", cipher);
33 EXPECT_STREQ("???", mac);
34 EXPECT_FALSE(is_aead);
37 TEST(CipherSuiteNamesTest, ParseSSLCipherString) {
38 uint16 cipher_suite = 0;
39 EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite));
40 EXPECT_EQ(0x00004u, cipher_suite);
42 EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite));
43 EXPECT_EQ(0xBEEFu, cipher_suite);
46 TEST(CipherSuiteNamesTest, ParseSSLCipherStringFails) {
47 const char* const cipher_strings[] = {
48 "0004",
49 "0x004",
50 "0xBEEFY",
53 for (size_t i = 0; i < arraysize(cipher_strings); ++i) {
54 uint16 cipher_suite = 0;
55 EXPECT_FALSE(ParseSSLCipherString(cipher_strings[i], &cipher_suite));
59 TEST(CipherSuiteNamesTest, SecureCipherSuites) {
60 // Picked some random cipher suites.
61 EXPECT_FALSE(IsSecureTLSCipherSuite(0x0));
62 EXPECT_FALSE(IsSecureTLSCipherSuite(0x39));
63 EXPECT_FALSE(IsSecureTLSCipherSuite(0xc5));
64 EXPECT_FALSE(IsSecureTLSCipherSuite(0xc00f));
65 EXPECT_FALSE(IsSecureTLSCipherSuite(0xc083));
67 // Non-existent cipher suite.
68 EXPECT_FALSE(IsSecureTLSCipherSuite(0xffff)) << "Doesn't exist!";
70 // Secure ones.
71 EXPECT_TRUE(IsSecureTLSCipherSuite(0xcc13));
72 EXPECT_TRUE(IsSecureTLSCipherSuite(0xcc14));
75 } // anonymous namespace
77 } // namespace net