<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/base/ssl_config_service_win.h"
#include "testing/gtest/include/gtest/gtest.h"

using base::TimeDelta;
using base::TimeTicks;

namespace {

// SSLClientConfig service caches settings for 10 seconds for performance.
// So we use synthetic time values along with the 'GetSSLConfigAt' method
// to ensure that the current settings are re-read.  By incrementing the time
// value by 11 seconds, we ensure fresh config settings.
const int kSSLConfigNextTimeInternal = 11;

class SSLConfigServiceWinObserver : public net::SSLConfigService::Observer {
 public:
  SSLConfigServiceWinObserver() : change_was_observed_(false) {
  }
  bool change_was_observed() const {
    return change_was_observed_;
  }
 protected:
  virtual void OnSSLConfigChanged() {
    change_was_observed_ = true;
  }
  bool change_was_observed_;
};

class SSLConfigServiceWinTest : public testing::Test {
};

}  // namespace

TEST(SSLConfigServiceWinTest, GetNowTest) {
  // Verify that the constructor sets the correct default values.
  net::SSLConfig config;
  EXPECT_EQ(true, config.rev_checking_enabled);
  EXPECT_EQ(true, config.ssl3_enabled);
  EXPECT_EQ(true, config.tls1_enabled);

  bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
}

TEST(SSLConfigServiceWinTest, SetTest) {
  // Save the current settings so we can restore them after the tests.
  net::SSLConfig config_save;
  bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config_save);
  EXPECT_TRUE(rv);

  net::SSLConfig config;

  // Test SetRevCheckingEnabled.
  net::SSLConfigServiceWin::SetRevCheckingEnabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.rev_checking_enabled);

  net::SSLConfigServiceWin::SetRevCheckingEnabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.rev_checking_enabled);

  net::SSLConfigServiceWin::SetRevCheckingEnabled(
      config_save.rev_checking_enabled);

  // Test SetSSL3Enabled.
  net::SSLConfigServiceWin::SetSSL3Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(config_save.ssl3_enabled);

  // Test SetTLS1Enabled.
  net::SSLConfigServiceWin::SetTLS1Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(config_save.tls1_enabled);

  // Test SetSSL3Enabled.
  net::SSLConfigServiceWin::SetSSL3Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(config_save.ssl3_enabled);

  // Test SetTLS1Enabled.
  net::SSLConfigServiceWin::SetTLS1Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(config_save.tls1_enabled);
}

TEST(SSLConfigServiceWinTest, GetTest) {
  TimeTicks now = TimeTicks::Now();
  TimeTicks now_1 = now + TimeDelta::FromSeconds(1);
  TimeTicks later = now + TimeDelta::FromSeconds(kSSLConfigNextTimeInternal);

  net::SSLConfig config, config_1, config_later;
  scoped_refptr<net::SSLConfigServiceWin> config_service(
      new net::SSLConfigServiceWin(now));<commit_msg>Remove duplicate SetSSL3Enabled and SetTLS1Enabled tests inside SSLConfigServiceWinTest.SetTest, likely the result of a merging error.<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/base/ssl_config_service_win.h"
#include "testing/gtest/include/gtest/gtest.h"

using base::TimeDelta;
using base::TimeTicks;

namespace {

// SSLClientConfig service caches settings for 10 seconds for performance.
// So we use synthetic time values along with the 'GetSSLConfigAt' method
// to ensure that the current settings are re-read.  By incrementing the time
// value by 11 seconds, we ensure fresh config settings.
const int kSSLConfigNextTimeInternal = 11;

class SSLConfigServiceWinObserver : public net::SSLConfigService::Observer {
 public:
  SSLConfigServiceWinObserver() : change_was_observed_(false) {
  }
  bool change_was_observed() const {
    return change_was_observed_;
  }
 protected:
  virtual void OnSSLConfigChanged() {
    change_was_observed_ = true;
  }
  bool change_was_observed_;
};

class SSLConfigServiceWinTest : public testing::Test {
};

}  // namespace

TEST(SSLConfigServiceWinTest, GetNowTest) {
  // Verify that the constructor sets the correct default values.
  net::SSLConfig config;
  EXPECT_EQ(true, config.rev_checking_enabled);
  EXPECT_EQ(true, config.ssl3_enabled);
  EXPECT_EQ(true, config.tls1_enabled);

  bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
}

TEST(SSLConfigServiceWinTest, SetTest) {
  // Save the current settings so we can restore them after the tests.
  net::SSLConfig config_save;
  bool rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config_save);
  EXPECT_TRUE(rv);

  net::SSLConfig config;

  // Test SetRevCheckingEnabled.
  net::SSLConfigServiceWin::SetRevCheckingEnabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.rev_checking_enabled);

  net::SSLConfigServiceWin::SetRevCheckingEnabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.rev_checking_enabled);

  net::SSLConfigServiceWin::SetRevCheckingEnabled(
      config_save.rev_checking_enabled);

  // Test SetSSL3Enabled.
  net::SSLConfigServiceWin::SetSSL3Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.ssl3_enabled);

  net::SSLConfigServiceWin::SetSSL3Enabled(config_save.ssl3_enabled);

  // Test SetTLS1Enabled.
  net::SSLConfigServiceWin::SetTLS1Enabled(true);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_TRUE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(false);
  rv = net::SSLConfigServiceWin::GetSSLConfigNow(&config);
  EXPECT_TRUE(rv);
  EXPECT_FALSE(config.tls1_enabled);

  net::SSLConfigServiceWin::SetTLS1Enabled(config_save.tls1_enabled);
}

TEST(SSLConfigServiceWinTest, GetTest) {
  TimeTicks now = TimeTicks::Now();
  TimeTicks now_1 = now + TimeDelta::FromSeconds(1);
  TimeTicks later = now + TimeDelta::FromSeconds(kSSLConfigNextTimeInternal);

  net::SSLConfig config, config_1, config_later;
  scoped_refptr<net::SSLConfigServiceWin> config_service(
      new net::SSLConfigServiceWin(now));
{'fraction_non_alphanumeric': 0.10874855898552581, 'fraction_numerical': 0.009478672985781991, 'mean_word_length': 6.415004748338082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550439', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2456, 'n_words': 467}