Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef NET_CERT_INTERNAL_TRUST_STORE_TEST_HELPERS_H_ | |
| 6 #define NET_CERT_INTERNAL_TRUST_STORE_TEST_HELPERS_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "net/cert/internal/trust_store.h" | |
| 11 #include "net/cert/internal/trust_store_in_memory.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 // Deletes the Request owned by |*req_owner|, then calls done_callback. Intended | |
| 16 // to be passed as the TrustAnchorCallback to FindTrustAnchorsForCert to test | |
| 17 // deleting the Request during the request callback. | |
| 18 void TrustStoreRequestDeleter(std::unique_ptr<TrustStore::Request>* req_owner, | |
| 19 base::Closure done_callback, | |
|
eroman
2016/08/23 18:30:10
should this be a const-reference?
mattm
2016/08/26 02:24:43
Done.
| |
| 20 std::unique_ptr<TrustAnchors> anchors); | |
| 21 | |
| 22 // Helper to record async results from a FindTrustAnchorsForCert call. | |
| 23 class TrustAnchorResultRecorder { | |
| 24 public: | |
| 25 TrustAnchorResultRecorder(); | |
| 26 ~TrustAnchorResultRecorder(); | |
| 27 | |
| 28 TrustStore::TrustAnchorCallback Callback(); | |
| 29 | |
| 30 void Run() { run_loop_.Run(); } | |
| 31 | |
| 32 const TrustAnchors& matches() const { return *anchors_; } | |
| 33 | |
| 34 private: | |
| 35 void OnGotAnchors(std::unique_ptr<TrustAnchors> anchors); | |
| 36 | |
| 37 base::RunLoop run_loop_; | |
| 38 std::unique_ptr<TrustAnchors> anchors_; | |
| 39 }; | |
| 40 | |
| 41 // In-memory TrustStore that can return results synchronously, asynchronously, | |
| 42 // or both. | |
| 43 class TrustStoreInMemoryAsync : public TrustStore { | |
| 44 public: | |
| 45 TrustStoreInMemoryAsync(); | |
| 46 ~TrustStoreInMemoryAsync() override; | |
| 47 | |
| 48 // Adds |anchor| to the set of results that will be returned synchronously. | |
| 49 void AddSyncTrustAnchor(scoped_refptr<TrustAnchor> anchor); | |
| 50 | |
| 51 // Adds |anchor| to the set of results that will be returned asynchronously. | |
| 52 void AddAsyncTrustAnchor(scoped_refptr<TrustAnchor> anchor); | |
| 53 | |
| 54 // TrustStore implementation: | |
| 55 void FindTrustAnchorsForCert( | |
| 56 const ParsedCertificate* cert, | |
| 57 const TrustAnchorCallback& callback, | |
| 58 TrustAnchors* out_matches, | |
| 59 std::unique_ptr<Request>* out_req) const override; | |
| 60 | |
| 61 private: | |
| 62 TrustStoreInMemory sync_store_; | |
| 63 TrustStoreInMemory async_store_; | |
| 64 }; | |
| 65 | |
| 66 } // namespace net | |
| 67 | |
| 68 #endif // NET_CERT_INTERNAL_TRUST_STORE_TEST_HELPERS_H_ | |
| OLD | NEW |