Index: net/cert/internal/cert_issuer_source_test_helpers.h |
diff --git a/net/cert/internal/cert_issuer_source_test_helpers.h b/net/cert/internal/cert_issuer_source_test_helpers.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ce2011d88a4734ce0337d19e5432389f8908fc0 |
--- /dev/null |
+++ b/net/cert/internal/cert_issuer_source_test_helpers.h |
@@ -0,0 +1,91 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_TEST_HELPERS_H_ |
+#define NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_TEST_HELPERS_H_ |
+ |
+#include "base/cancelable_callback.h" |
+#include "base/location.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "net/cert/internal/cert_issuer_source_static.h" |
+#include "net/cert/internal/parsed_certificate.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+ |
+namespace net { |
+ |
+// AsyncCertIssuerSourceStatic always returns its certs asynchronously, in a |
+// single batch. |
+class AsyncCertIssuerSourceStatic : public CertIssuerSource { |
+ public: |
+ AsyncCertIssuerSourceStatic(); |
+ ~AsyncCertIssuerSourceStatic() override; |
+ |
+ void AddCert(scoped_refptr<ParsedCertificate> cert); |
+ int num_async_gets() const { return num_async_gets_; } |
+ |
+ // CertIssuerSource implementation: |
+ void SyncGetIssuersOf(const ParsedCertificate* cert, |
+ ParsedCertificateList* issuers) override {} |
+ void AsyncGetIssuersOf(scoped_refptr<ParsedCertificate> cert, |
+ const IssuerCallback& issuers_callback, |
+ std::unique_ptr<Request>* out_req) override; |
+ |
+ private: |
+ CertIssuerSourceStatic static_cert_issuer_source_; |
+ |
+ int num_async_gets_ = 0; |
+}; |
+ |
+// Mocks of CertIssuerSource::Request and CertIssuerSource that allow testing |
+// more complicated sequences of results. |
+class MockCertIssuerSourceRequest : public CertIssuerSource::Request { |
+ public: |
+ MockCertIssuerSourceRequest(); |
+ ~MockCertIssuerSourceRequest() override; |
+ |
+ MOCK_METHOD1(GetNext, CompletionStatus(scoped_refptr<ParsedCertificate>*)); |
+}; |
+ |
+class MockCertIssuerSource : public CertIssuerSource { |
+ public: |
+ MockCertIssuerSource(); |
+ ~MockCertIssuerSource() override; |
+ |
+ MOCK_METHOD2(SyncGetIssuersOf, |
+ void(const ParsedCertificate*, ParsedCertificateList*)); |
+ MOCK_METHOD3(AsyncGetIssuersOf, |
+ void(scoped_refptr<ParsedCertificate>, |
+ const IssuerCallback&, |
+ std::unique_ptr<Request>*)); |
+}; |
+ |
+// Helper class to pass the Request to the PathBuilder when it calls |
+// AsyncGetIssuersOf. (GoogleMock has a ByMove helper, but it apparently can |
+// only be used with Return, not SetArgPointee.) |
+class CertIssuerSourceRequestMover { |
+ public: |
+ CertIssuerSourceRequestMover(std::unique_ptr<CertIssuerSource::Request> req); |
+ ~CertIssuerSourceRequestMover(); |
+ |
+ void MoveIt(scoped_refptr<ParsedCertificate> cert, |
+ const CertIssuerSource::IssuerCallback& issuers_callback, |
+ std::unique_ptr<CertIssuerSource::Request>* out_req) { |
+ *out_req = std::move(request_); |
+ } |
+ |
+ private: |
+ std::unique_ptr<CertIssuerSource::Request> request_; |
+}; |
+ |
+class MockIssuerCallback { |
+ public: |
+ MockIssuerCallback(); |
+ ~MockIssuerCallback(); |
+ |
+ MOCK_METHOD1(Callback, void(CertIssuerSource::Request*)); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_TEST_HELPERS_H_ |