Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: components/ssl_config/ssl_config_service_manager_pref_unittest.cc

Issue 1320533007: Componentize ssl_config_service_manager_pref.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve -Wnewline-eof mac_chromium bot failure Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ssl_config/ssl_config_service_manager_pref_unittest.cc
diff --git a/chrome/browser/net/ssl_config_service_manager_pref_unittest.cc b/components/ssl_config/ssl_config_service_manager_pref_unittest.cc
similarity index 54%
rename from chrome/browser/net/ssl_config_service_manager_pref_unittest.cc
rename to components/ssl_config/ssl_config_service_manager_pref_unittest.cc
index 321663252847e1d53f681cf4ddd29e66c55277ef..85cbc20a4c31e66bee47566f42e0e8f0c6144f3a 100644
--- a/chrome/browser/net/ssl_config_service_manager_pref_unittest.cc
+++ b/components/ssl_config/ssl_config_service_manager_pref_unittest.cc
@@ -2,43 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/net/ssl_config_service_manager.h"
+#include "components/ssl_config/ssl_config_service_manager.h"
-#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
-#include "base/prefs/pref_registry_simple.h"
-#include "base/prefs/testing_pref_store.h"
+#include "base/prefs/testing_pref_service.h"
+#include "base/thread_task_runner_handle.h"
#include "base/values.h"
-#include "chrome/browser/prefs/command_line_pref_store.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_profile.h"
-#include "components/content_settings/core/browser/host_content_settings_map.h"
-#include "components/content_settings/core/common/content_settings.h"
-#include "components/syncable_prefs/pref_service_mock_factory.h"
-#include "components/syncable_prefs/testing_pref_service_syncable.h"
-#include "content/public/test/test_browser_thread.h"
+#include "components/ssl_config/ssl_config_prefs.h"
+#include "components/ssl_config/ssl_config_switches.h"
#include "net/ssl/ssl_config.h"
#include "net/ssl/ssl_config_service.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ListValue;
-using base::Value;
-using content::BrowserThread;
using net::SSLConfig;
using net::SSLConfigService;
+using ssl_config::SSLConfigServiceManager;
class SSLConfigServiceManagerPrefTest : public testing::Test {
public:
- SSLConfigServiceManagerPrefTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- io_thread_(BrowserThread::IO, &message_loop_) {}
+ SSLConfigServiceManagerPrefTest() {}
protected:
base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
};
// Test channel id with no user prefs.
@@ -47,7 +34,8 @@ TEST_F(SSLConfigServiceManagerPrefTest, ChannelIDWithoutUserPrefs) {
SSLConfigServiceManager::RegisterPrefs(local_state.registry());
scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(&local_state));
+ SSLConfigServiceManager::CreateDefaultManager(
+ &local_state, base::ThreadTaskRunnerHandle::Get()));
ASSERT_TRUE(config_manager.get());
scoped_refptr<SSLConfigService> config_service(config_manager->Get());
ASSERT_TRUE(config_service.get());
@@ -64,7 +52,8 @@ TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) {
SSLConfigServiceManager::RegisterPrefs(local_state.registry());
scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(&local_state));
+ SSLConfigServiceManager::CreateDefaultManager(
+ &local_state, base::ThreadTaskRunnerHandle::Get()));
ASSERT_TRUE(config_manager.get());
scoped_refptr<SSLConfigService> config_service(config_manager->Get());
ASSERT_TRUE(config_service.get());
@@ -76,7 +65,7 @@ TEST_F(SSLConfigServiceManagerPrefTest, GoodDisabledCipherSuites) {
base::ListValue* list_value = new base::ListValue();
list_value->Append(new base::StringValue("0x0004"));
list_value->Append(new base::StringValue("0x0005"));
- local_state.SetUserPref(prefs::kCipherSuiteBlacklist, list_value);
+ local_state.SetUserPref(ssl_config::prefs::kCipherSuiteBlacklist, list_value);
// Pump the message loop to notify the SSLConfigServiceManagerPref that the
// preferences changed.
@@ -99,7 +88,8 @@ TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) {
SSLConfigServiceManager::RegisterPrefs(local_state.registry());
scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(&local_state));
+ SSLConfigServiceManager::CreateDefaultManager(
+ &local_state, base::ThreadTaskRunnerHandle::Get()));
ASSERT_TRUE(config_manager.get());
scoped_refptr<SSLConfigService> config_service(config_manager->Get());
ASSERT_TRUE(config_service.get());
@@ -113,7 +103,7 @@ TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) {
list_value->Append(new base::StringValue("TLS_NOT_WITH_A_CIPHER_SUITE"));
list_value->Append(new base::StringValue("0x0005"));
list_value->Append(new base::StringValue("0xBEEFY"));
- local_state.SetUserPref(prefs::kCipherSuiteBlacklist, list_value);
+ local_state.SetUserPref(ssl_config::prefs::kCipherSuiteBlacklist, list_value);
// Pump the message loop to notify the SSLConfigServiceManagerPref that the
// preferences changed.
@@ -132,16 +122,12 @@ TEST_F(SSLConfigServiceManagerPrefTest, BadDisabledCipherSuites) {
// TLS versions from 1.0 up to 1.1 or 1.2 are enabled.
TEST_F(SSLConfigServiceManagerPrefTest, NoCommandLinePrefs) {
scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore());
-
- syncable_prefs::PrefServiceMockFactory factory;
- factory.set_user_prefs(local_state_store);
- scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple;
- scoped_ptr<PrefService> local_state(factory.Create(registry.get()));
-
- SSLConfigServiceManager::RegisterPrefs(registry.get());
+ TestingPrefServiceSimple local_state;
+ SSLConfigServiceManager::RegisterPrefs(local_state.registry());
scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(local_state.get()));
+ SSLConfigServiceManager::CreateDefaultManager(
+ &local_state, base::ThreadTaskRunnerHandle::Get()));
ASSERT_TRUE(config_manager.get());
scoped_refptr<SSLConfigService> config_service(config_manager->Get());
ASSERT_TRUE(config_service.get());
@@ -154,61 +140,15 @@ TEST_F(SSLConfigServiceManagerPrefTest, NoCommandLinePrefs) {
EXPECT_EQ(net::kDefaultSSLVersionMax, ssl_config.version_max);
// The settings should not be added to the local_state.
- EXPECT_FALSE(local_state->HasPrefPath(prefs::kSSLVersionMin));
- EXPECT_FALSE(local_state->HasPrefPath(prefs::kSSLVersionMax));
-
- // Explicitly double-check the settings are not in the preference store.
- std::string version_min_str;
- std::string version_max_str;
- EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMin,
- &version_min_str));
- EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMax,
- &version_max_str));
-}
-
-// Test that command-line settings for minimum and maximum SSL versions are
-// respected and that they do not persist to the preferences files.
-TEST_F(SSLConfigServiceManagerPrefTest, CommandLinePrefs) {
- scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore());
-
- base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
- command_line.AppendSwitchASCII(switches::kSSLVersionMin, "tls1.1");
- command_line.AppendSwitchASCII(switches::kSSLVersionMax, "tls1");
-
- syncable_prefs::PrefServiceMockFactory factory;
- factory.set_user_prefs(local_state_store);
- factory.set_command_line_prefs(new CommandLinePrefStore(&command_line));
- scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple;
- scoped_ptr<PrefService> local_state(factory.Create(registry.get()));
-
- SSLConfigServiceManager::RegisterPrefs(registry.get());
-
- scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(local_state.get()));
- ASSERT_TRUE(config_manager.get());
- scoped_refptr<SSLConfigService> config_service(config_manager->Get());
- ASSERT_TRUE(config_service.get());
-
- SSLConfig ssl_config;
- config_service->GetSSLConfig(&ssl_config);
- // Command-line flags should be respected.
- EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1_1, ssl_config.version_min);
- EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1, ssl_config.version_max);
+ EXPECT_FALSE(local_state.HasPrefPath(ssl_config::prefs::kSSLVersionMin));
+ EXPECT_FALSE(local_state.HasPrefPath(ssl_config::prefs::kSSLVersionMax));
// Explicitly double-check the settings are not in the preference store.
- const PrefService::Preference* version_min_pref =
- local_state->FindPreference(prefs::kSSLVersionMin);
- EXPECT_FALSE(version_min_pref->IsUserModifiable());
-
- const PrefService::Preference* version_max_pref =
- local_state->FindPreference(prefs::kSSLVersionMax);
- EXPECT_FALSE(version_max_pref->IsUserModifiable());
-
std::string version_min_str;
std::string version_max_str;
- EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMin,
+ EXPECT_FALSE(local_state_store->GetString(ssl_config::prefs::kSSLVersionMin,
&version_min_str));
- EXPECT_FALSE(local_state_store->GetString(prefs::kSSLVersionMax,
+ EXPECT_FALSE(local_state_store->GetString(ssl_config::prefs::kSSLVersionMax,
&version_max_str));
}
@@ -216,19 +156,14 @@ TEST_F(SSLConfigServiceManagerPrefTest, CommandLinePrefs) {
TEST_F(SSLConfigServiceManagerPrefTest, NoSSL3) {
scoped_refptr<TestingPrefStore> local_state_store(new TestingPrefStore());
- base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
- command_line.AppendSwitchASCII(switches::kSSLVersionMin, "ssl3");
-
- syncable_prefs::PrefServiceMockFactory factory;
- factory.set_user_prefs(local_state_store);
- factory.set_command_line_prefs(new CommandLinePrefStore(&command_line));
- scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple;
- scoped_ptr<PrefService> local_state(factory.Create(registry.get()));
-
- SSLConfigServiceManager::RegisterPrefs(registry.get());
+ TestingPrefServiceSimple local_state;
+ local_state.SetUserPref(ssl_config::prefs::kSSLVersionMin,
+ new base::StringValue("ssl3"));
+ SSLConfigServiceManager::RegisterPrefs(local_state.registry());
scoped_ptr<SSLConfigServiceManager> config_manager(
- SSLConfigServiceManager::CreateDefaultManager(local_state.get()));
+ SSLConfigServiceManager::CreateDefaultManager(
+ &local_state, base::ThreadTaskRunnerHandle::Get()));
ASSERT_TRUE(config_manager.get());
scoped_refptr<SSLConfigService> config_service(config_manager->Get());
ASSERT_TRUE(config_service.get());
« no previous file with comments | « components/ssl_config/ssl_config_service_manager_pref.cc ('k') | components/ssl_config/ssl_config_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698