| 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/default_origin_bound_cert_store.h" | 5 #include "net/base/default_origin_bound_cert_store.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 class MockPersistentStore | 19 class MockPersistentStore |
| 19 : public DefaultOriginBoundCertStore::PersistentStore { | 20 : public DefaultOriginBoundCertStore::PersistentStore { |
| 20 public: | 21 public: |
| 21 MockPersistentStore(); | 22 MockPersistentStore(); |
| 22 virtual ~MockPersistentStore(); | 23 virtual ~MockPersistentStore(); |
| 23 | 24 |
| 24 // DefaultOriginBoundCertStore::PersistentStore implementation. | 25 // DefaultOriginBoundCertStore::PersistentStore implementation. |
| 25 virtual bool Load( | 26 virtual bool Load( |
| 26 std::vector<DefaultOriginBoundCertStore::OriginBoundCert*>* certs) | 27 std::vector<DefaultOriginBoundCertStore::OriginBoundCert*>* certs) |
| 27 OVERRIDE; | 28 OVERRIDE; |
| 28 virtual void AddOriginBoundCert( | 29 virtual void AddOriginBoundCert( |
| 29 const DefaultOriginBoundCertStore::OriginBoundCert& cert) OVERRIDE; | 30 const DefaultOriginBoundCertStore::OriginBoundCert& cert) OVERRIDE; |
| 30 virtual void DeleteOriginBoundCert( | 31 virtual void DeleteOriginBoundCert( |
| 31 const DefaultOriginBoundCertStore::OriginBoundCert& cert) OVERRIDE; | 32 const DefaultOriginBoundCertStore::OriginBoundCert& cert) OVERRIDE; |
| 32 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; | 33 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; |
| 33 virtual void Flush(Task* completion_task) OVERRIDE; | 34 virtual void Flush(const base::Closure& completion_task) OVERRIDE; |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 typedef std::map<std::string, DefaultOriginBoundCertStore::OriginBoundCert> | 37 typedef std::map<std::string, DefaultOriginBoundCertStore::OriginBoundCert> |
| 37 OriginBoundCertMap; | 38 OriginBoundCertMap; |
| 38 | 39 |
| 39 OriginBoundCertMap origin_certs_; | 40 OriginBoundCertMap origin_certs_; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 MockPersistentStore::MockPersistentStore() {} | 43 MockPersistentStore::MockPersistentStore() {} |
| 43 | 44 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 60 origin_certs_[cert.origin()] = cert; | 61 origin_certs_[cert.origin()] = cert; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void MockPersistentStore::DeleteOriginBoundCert( | 64 void MockPersistentStore::DeleteOriginBoundCert( |
| 64 const DefaultOriginBoundCertStore::OriginBoundCert& cert) { | 65 const DefaultOriginBoundCertStore::OriginBoundCert& cert) { |
| 65 origin_certs_.erase(cert.origin()); | 66 origin_certs_.erase(cert.origin()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void MockPersistentStore::SetClearLocalStateOnExit(bool clear_local_state) {} | 69 void MockPersistentStore::SetClearLocalStateOnExit(bool clear_local_state) {} |
| 69 | 70 |
| 70 void MockPersistentStore::Flush(Task* completion_task) { | 71 void MockPersistentStore::Flush(const base::Closure& completion_task) { |
| 71 NOTREACHED(); | 72 NOTREACHED(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 TEST(DefaultOriginBoundCertStoreTest, TestLoading) { | 75 TEST(DefaultOriginBoundCertStoreTest, TestLoading) { |
| 75 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 76 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
| 76 | 77 |
| 77 persistent_store->AddOriginBoundCert( | 78 persistent_store->AddOriginBoundCert( |
| 78 DefaultOriginBoundCertStore::OriginBoundCert( | 79 DefaultOriginBoundCertStore::OriginBoundCert( |
| 79 "https://encrypted.google.com/", "a", "b")); | 80 "https://encrypted.google.com/", "a", "b")); |
| 80 persistent_store->AddOriginBoundCert( | 81 persistent_store->AddOriginBoundCert( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); | 174 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); |
| 174 store.SetOriginBoundCert("https://www.mit.com/", "g", "h"); | 175 store.SetOriginBoundCert("https://www.mit.com/", "g", "h"); |
| 175 | 176 |
| 176 EXPECT_EQ(4, store.GetCertCount()); | 177 EXPECT_EQ(4, store.GetCertCount()); |
| 177 std::vector<OriginBoundCertStore::OriginBoundCertInfo> certs; | 178 std::vector<OriginBoundCertStore::OriginBoundCertInfo> certs; |
| 178 store.GetAllOriginBoundCerts(&certs); | 179 store.GetAllOriginBoundCerts(&certs); |
| 179 EXPECT_EQ(4u, certs.size()); | 180 EXPECT_EQ(4u, certs.size()); |
| 180 } | 181 } |
| 181 | 182 |
| 182 } // namespace net | 183 } // namespace net |
| OLD | NEW |