Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / ssl / ssl_config_service_unittest.cc
blob42c8ae47b9f5613356c4eec81c8ea8a3afcd416f
1 // Copyright (c) 2012 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_config_service.h"
7 #include <vector>
9 #include "base/basictypes.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace net {
15 namespace {
17 class MockSSLConfigService : public SSLConfigService {
18 public:
19 explicit MockSSLConfigService(const SSLConfig& config) : config_(config) {}
21 // SSLConfigService implementation
22 virtual void GetSSLConfig(SSLConfig* config) OVERRIDE {
23 *config = config_;
26 // Sets the SSLConfig to be returned by GetSSLConfig and processes any
27 // updates.
28 void SetSSLConfig(const SSLConfig& config) {
29 SSLConfig old_config = config_;
30 config_ = config;
31 ProcessConfigUpdate(old_config, config_);
34 private:
35 virtual ~MockSSLConfigService() {}
37 SSLConfig config_;
40 class MockSSLConfigServiceObserver : public SSLConfigService::Observer {
41 public:
42 MockSSLConfigServiceObserver() {}
43 virtual ~MockSSLConfigServiceObserver() {}
45 MOCK_METHOD0(OnSSLConfigChanged, void());
48 } // namespace
50 TEST(SSLConfigServiceTest, NoChangesWontNotifyObservers) {
51 SSLConfig initial_config;
52 initial_config.rev_checking_enabled = true;
53 initial_config.false_start_enabled = false;
54 initial_config.version_min = SSL_PROTOCOL_VERSION_SSL3;
55 initial_config.version_max = SSL_PROTOCOL_VERSION_TLS1_1;
57 scoped_refptr<MockSSLConfigService> mock_service(
58 new MockSSLConfigService(initial_config));
59 MockSSLConfigServiceObserver observer;
60 mock_service->AddObserver(&observer);
62 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(0);
63 mock_service->SetSSLConfig(initial_config);
65 mock_service->RemoveObserver(&observer);
68 TEST(SSLConfigServiceTest, ConfigUpdatesNotifyObservers) {
69 SSLConfig initial_config;
70 initial_config.rev_checking_enabled = true;
71 initial_config.false_start_enabled = false;
72 initial_config.unrestricted_ssl3_fallback_enabled = false;
73 initial_config.version_min = SSL_PROTOCOL_VERSION_SSL3;
74 initial_config.version_max = SSL_PROTOCOL_VERSION_TLS1_1;
76 scoped_refptr<MockSSLConfigService> mock_service(
77 new MockSSLConfigService(initial_config));
78 MockSSLConfigServiceObserver observer;
79 mock_service->AddObserver(&observer);
81 // Test that the basic boolean preferences trigger updates.
82 initial_config.rev_checking_enabled = false;
83 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
84 mock_service->SetSSLConfig(initial_config);
86 initial_config.false_start_enabled = true;
87 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
88 mock_service->SetSSLConfig(initial_config);
90 initial_config.unrestricted_ssl3_fallback_enabled = true;
91 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
92 mock_service->SetSSLConfig(initial_config);
94 // Test that changing the SSL version range triggers updates.
95 initial_config.version_min = SSL_PROTOCOL_VERSION_TLS1;
96 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
97 mock_service->SetSSLConfig(initial_config);
99 initial_config.version_max = SSL_PROTOCOL_VERSION_SSL3;
100 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
101 mock_service->SetSSLConfig(initial_config);
103 // Test that disabling certain cipher suites triggers an update.
104 std::vector<uint16> disabled_ciphers;
105 disabled_ciphers.push_back(0x0004u);
106 disabled_ciphers.push_back(0xBEEFu);
107 disabled_ciphers.push_back(0xDEADu);
108 initial_config.disabled_cipher_suites = disabled_ciphers;
109 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
110 mock_service->SetSSLConfig(initial_config);
112 // Ensure that changing a disabled cipher suite, while still maintaining
113 // sorted order, triggers an update.
114 disabled_ciphers[1] = 0xCAFEu;
115 initial_config.disabled_cipher_suites = disabled_ciphers;
116 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
117 mock_service->SetSSLConfig(initial_config);
119 // Ensure that removing a disabled cipher suite, while still keeping some
120 // cipher suites disabled, triggers an update.
121 disabled_ciphers.pop_back();
122 initial_config.disabled_cipher_suites = disabled_ciphers;
123 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1);
124 mock_service->SetSSLConfig(initial_config);
126 mock_service->RemoveObserver(&observer);
129 } // namespace net