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/run_loop.h" |
| 9 #include "net/cert/internal/trust_store_static.h" |
| 10 |
| 11 namespace net { |
| 12 |
| 13 class AsyncTrustStoreStatic : public TrustStore { |
| 14 public: |
| 15 AsyncTrustStoreStatic() = default; |
| 16 ~AsyncTrustStoreStatic() override = default; |
| 17 |
| 18 // Adds a trusted certificate to the store. |
| 19 void AddTrustedCertificate(scoped_refptr<ParsedCertificate> anchor) { |
| 20 trust_store_static_.AddTrustedCertificate(std::move(anchor)); |
| 21 } |
| 22 |
| 23 // TrustStore implementation: |
| 24 void IsTrustedCertificate( |
| 25 scoped_refptr<ParsedCertificate> cert, |
| 26 const TrustCallback& callback, |
| 27 bool* out_trusted, |
| 28 std::unique_ptr<TrustStore::Request>* out_req) const override; |
| 29 |
| 30 // CertIssuerSource implementation: |
| 31 void SyncGetIssuersOf(const ParsedCertificate* cert, |
| 32 ParsedCertificateList* issuers) override; |
| 33 void AsyncGetIssuersOf( |
| 34 scoped_refptr<ParsedCertificate> cert, |
| 35 const IssuerCallback& callback, |
| 36 std::unique_ptr<CertIssuerSource::Request>* out_req) override; |
| 37 |
| 38 private: |
| 39 TrustStoreStatic trust_store_static_; |
| 40 }; |
| 41 |
| 42 class TrustResultRecorder { |
| 43 public: |
| 44 TrustResultRecorder(); |
| 45 ~TrustResultRecorder(); |
| 46 |
| 47 void HandleResult(bool trust) { |
| 48 results_.push_back(trust); |
| 49 run_loop_.Quit(); |
| 50 } |
| 51 |
| 52 const std::vector<bool>& results() { return results_; } |
| 53 |
| 54 void Run() { run_loop_.Run(); } |
| 55 |
| 56 TrustStore::TrustCallback Callback(); |
| 57 |
| 58 private: |
| 59 std::vector<bool> results_; |
| 60 base::RunLoop run_loop_; |
| 61 }; |
| 62 |
| 63 // Deletes the Request owned by |*req_owner|, then calls done_callback. Intended |
| 64 // to be passed as the IssuerCallback to IsTrustedCertificate. |
| 65 void TrustRequestDeleter(std::unique_ptr<TrustStore::Request>* req_owner, |
| 66 base::Closure done_callback, |
| 67 bool trusted); |
| 68 |
| 69 } // namespace net |
| 70 |
| 71 #endif // NET_CERT_INTERNAL_TRUST_STORE_TEST_HELPERS_H_ |
OLD | NEW |