Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2006-2008 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 "net/base/ssl_config_service_win.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 using base::TimeDelta;
      9 using base::TimeTicks;
     10 
     11 namespace {
     12 
     13 class SSLConfigServiceWinTest : public testing::Test {
     14 };
     15 
     16 }  // namespace
     17 
     18 TEST(SSLConfigServiceWinTest, GetNowTest) {
     19   // Verify that the constructor sets the correct default values.
     20   net::SSLConfig config;
     21   EXPECT_EQ(true, config.rev_checking_enabled);
     22   EXPECT_EQ(false, config.ssl2_enabled);
     23   EXPECT_EQ(true, config.ssl3_enabled);
     24   EXPECT_EQ(true, config.tls1_enabled);
     25 
     26   bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
     27   EXPECT_TRUE(rv);
     28 }
     29 
     30 TEST(SSLConfigServiceWinTest, SetTest) {
     31   // Save the current settings so we can restore them after the tests.
     32   net::SSLConfig config_save;
     33   bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config_save);
     34   EXPECT_TRUE(rv);
     35 
     36   net::SSLConfig config;
     37 
     38   // Test SetRevCheckingEnabled.
     39   net::SSLConfigServiceWin::SetRevCheckingEnabled(true);
     40   rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
     41   EXPECT_TRUE(rv);
     42   EXPECT_TRUE(config.rev_checking_enabled);
     43 
     44   net::SSLConfigServiceWin::SetRevCheckingEnabled(false);
     45   rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
     46   EXPECT_TRUE(rv);
     47   EXPECT_FALSE(config.rev_checking_enabled);
     48 
     49   net::SSLConfigServiceWin::SetRevCheckingEnabled(
     50       config_save.rev_checking_enabled);
     51 
     52   // Test SetSSL2Enabled.
     53   net::SSLConfigServiceWin::SetSSL2Enabled(true);
     54   rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
     55   EXPECT_TRUE(rv);
     56   EXPECT_TRUE(config.ssl2_enabled);
     57 
     58   net::SSLConfigServiceWin::SetSSL2Enabled(false);
     59   rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
     60   EXPECT_TRUE(rv);
     61   EXPECT_FALSE(config.ssl2_enabled);
     62 
     63   net::SSLConfigServiceWin::SetSSL2Enabled(config_save.ssl2_enabled);
     64 }
     65 
     66 TEST(SSLConfigServiceWinTest, GetTest) {
     67   TimeTicks now = TimeTicks::Now();
     68   TimeTicks now_1 = now + TimeDelta::FromSeconds(1);
     69   TimeTicks now_11 = now + TimeDelta::FromSeconds(11);
     70 
     71   net::SSLConfig config, config_1, config_11;
     72   scoped_refptr<net::SSLConfigServiceWin> config_service(
     73       new net::SSLConfigServiceWin(now));
     74   config_service->GetSSLConfigAt(&config, now);
     75 
     76   // Flip rev_checking_enabled.
     77   net::SSLConfigServiceWin::SetRevCheckingEnabled(
     78       !config.rev_checking_enabled);
     79 
     80   config_service->GetSSLConfigAt(&config_1, now_1);
     81   EXPECT_EQ(config.rev_checking_enabled, config_1.rev_checking_enabled);
     82 
     83   config_service->GetSSLConfigAt(&config_11, now_11);
     84   EXPECT_EQ(!config.rev_checking_enabled, config_11.rev_checking_enabled);
     85 
     86   // Restore the original value.
     87   net::SSLConfigServiceWin::SetRevCheckingEnabled(
     88       config.rev_checking_enabled);
     89 }
     90