OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/ssl_config_service.h" | 5 #include "net/base/ssl_config_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 bool IsFalseStartIncompatible(const std::string& hostname) { | |
18 return SSLConfigService::IsKnownFalseStartIncompatibleServer( | |
19 hostname); | |
20 } | |
21 | |
22 class MockSSLConfigService : public SSLConfigService { | 17 class MockSSLConfigService : public SSLConfigService { |
23 public: | 18 public: |
24 explicit MockSSLConfigService(const SSLConfig& config) : config_(config) {} | 19 explicit MockSSLConfigService(const SSLConfig& config) : config_(config) {} |
25 | 20 |
26 // SSLConfigService implementation | 21 // SSLConfigService implementation |
27 virtual void GetSSLConfig(SSLConfig* config) { | 22 virtual void GetSSLConfig(SSLConfig* config) { |
28 *config = config_; | 23 *config = config_; |
29 } | 24 } |
30 | 25 |
31 // Sets the SSLConfig to be returned by GetSSLConfig and processes any | 26 // Sets the SSLConfig to be returned by GetSSLConfig and processes any |
(...skipping 13 matching lines...) Expand all Loading... |
45 class MockSSLConfigServiceObserver : public SSLConfigService::Observer { | 40 class MockSSLConfigServiceObserver : public SSLConfigService::Observer { |
46 public: | 41 public: |
47 MockSSLConfigServiceObserver() {} | 42 MockSSLConfigServiceObserver() {} |
48 virtual ~MockSSLConfigServiceObserver() {} | 43 virtual ~MockSSLConfigServiceObserver() {} |
49 | 44 |
50 MOCK_METHOD0(OnSSLConfigChanged, void()); | 45 MOCK_METHOD0(OnSSLConfigChanged, void()); |
51 }; | 46 }; |
52 | 47 |
53 } // namespace | 48 } // namespace |
54 | 49 |
55 TEST(SSLConfigServiceTest, FalseStartDisabledHosts) { | |
56 EXPECT_TRUE(IsFalseStartIncompatible("www.picnik.com")); | |
57 EXPECT_FALSE(IsFalseStartIncompatible("picnikfoo.com")); | |
58 EXPECT_FALSE(IsFalseStartIncompatible("foopicnik.com")); | |
59 } | |
60 | |
61 TEST(SSLConfigServiceTest, FalseStartDisabledDomains) { | |
62 EXPECT_TRUE(IsFalseStartIncompatible("yodlee.com")); | |
63 EXPECT_TRUE(IsFalseStartIncompatible("a.yodlee.com")); | |
64 EXPECT_TRUE(IsFalseStartIncompatible("b.a.yodlee.com")); | |
65 EXPECT_FALSE(IsFalseStartIncompatible("ayodlee.com")); | |
66 EXPECT_FALSE(IsFalseStartIncompatible("yodleea.com")); | |
67 EXPECT_FALSE(IsFalseStartIncompatible("yodlee.org")); | |
68 } | |
69 | |
70 TEST(SSLConfigServiceTest, NoChangesWontNotifyObservers) { | 50 TEST(SSLConfigServiceTest, NoChangesWontNotifyObservers) { |
71 SSLConfig initial_config; | 51 SSLConfig initial_config; |
72 initial_config.rev_checking_enabled = true; | 52 initial_config.rev_checking_enabled = true; |
73 initial_config.ssl3_enabled = true; | 53 initial_config.ssl3_enabled = true; |
74 initial_config.tls1_enabled = true; | 54 initial_config.tls1_enabled = true; |
75 | 55 |
76 scoped_refptr<MockSSLConfigService> mock_service( | 56 scoped_refptr<MockSSLConfigService> mock_service( |
77 new MockSSLConfigService(initial_config)); | 57 new MockSSLConfigService(initial_config)); |
78 MockSSLConfigServiceObserver observer; | 58 MockSSLConfigServiceObserver observer; |
79 mock_service->AddObserver(&observer); | 59 mock_service->AddObserver(&observer); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // cipher suites disabled, triggers an update. | 108 // cipher suites disabled, triggers an update. |
129 disabled_ciphers.pop_back(); | 109 disabled_ciphers.pop_back(); |
130 initial_config.disabled_cipher_suites = disabled_ciphers; | 110 initial_config.disabled_cipher_suites = disabled_ciphers; |
131 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | 111 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); |
132 mock_service->SetSSLConfig(initial_config); | 112 mock_service->SetSSLConfig(initial_config); |
133 | 113 |
134 mock_service->RemoveObserver(&observer); | 114 mock_service->RemoveObserver(&observer); |
135 } | 115 } |
136 | 116 |
137 } // namespace net | 117 } // namespace net |
OLD | NEW |