Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: net/cert/internal/cert_issuer_source_aia_unittest.cc

Issue 2595723002: Allow CertNetFetcher to be shutdown from the network thread (Closed)
Patch Set: fix AIA tests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/cert/internal/cert_issuer_source_aia_unittest.cc
diff --git a/net/cert/internal/cert_issuer_source_aia_unittest.cc b/net/cert/internal/cert_issuer_source_aia_unittest.cc
index 87a5795a0bd744a36d1b9c4c3da38b25db062e60..fbf1c2a4779d3d0c00ee7a2542c08b45976029ca 100644
--- a/net/cert/internal/cert_issuer_source_aia_unittest.cc
+++ b/net/cert/internal/cert_issuer_source_aia_unittest.cc
@@ -63,6 +63,8 @@ std::vector<uint8_t> CertDataVector(const ParsedCertificate* cert) {
// MockCertNetFetcher is an implementation of CertNetFetcher for testing.
class MockCertNetFetcher : public CertNetFetcher {
public:
+ MockCertNetFetcher() {}
+ MOCK_METHOD0(Shutdown, void());
MOCK_METHOD3(FetchCaIssuers,
std::unique_ptr<Request>(const GURL& url,
int timeout_milliseconds,
@@ -76,6 +78,9 @@ class MockCertNetFetcher : public CertNetFetcher {
std::unique_ptr<Request>(const GURL& url,
int timeout_milliseconds,
int max_response_bytes));
+
+ protected:
+ ~MockCertNetFetcher() override {}
};
// MockCertNetFetcherRequest gives back the indicated error and bytes.
@@ -116,8 +121,9 @@ TEST(CertIssuerSourceAiaTest, NoSyncResults) {
ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
// No methods on |mock_fetcher| should be called.
- StrictMock<MockCertNetFetcher> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
eroman 2017/01/11 01:56:59 nit: make_scoped_refptr() ?
estark 2017/01/12 01:06:30 Done.
+ new StrictMock<MockCertNetFetcher>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
ParsedCertificateList issuers;
aia_source.SyncGetIssuersOf(cert.get(), &issuers);
EXPECT_EQ(0U, issuers.size());
@@ -130,8 +136,9 @@ TEST(CertIssuerSourceAiaTest, NoAia) {
ASSERT_TRUE(ReadTestCert("target_no_aia.pem", &cert));
// No methods on |mock_fetcher| should be called.
- StrictMock<MockCertNetFetcher> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
+ new StrictMock<MockCertNetFetcher>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> request;
aia_source.AsyncGetIssuersOf(cert.get(), &request);
EXPECT_EQ(nullptr, request);
@@ -146,11 +153,13 @@ TEST(CertIssuerSourceAiaTest, FileAia) {
scoped_refptr<ParsedCertificate> cert;
ASSERT_TRUE(ReadTestCert("target_file_aia.pem", &cert));
- StrictMock<MockCertNetFetcher> mock_fetcher;
- EXPECT_CALL(mock_fetcher, FetchCaIssuers(GURL("file:///dev/null"), _, _))
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
+ new StrictMock<MockCertNetFetcher>());
+ EXPECT_CALL(*mock_fetcher.get(),
eroman 2017/01/11 01:56:59 nit: I don't believe the .get() is needed here --
estark 2017/01/12 01:06:30 Done.
+ FetchCaIssuers(GURL("file:///dev/null"), _, _))
.WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME))));
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
ASSERT_NE(nullptr, cert_source_request);
@@ -167,8 +176,9 @@ TEST(CertIssuerSourceAiaTest, OneInvalidURL) {
scoped_refptr<ParsedCertificate> cert;
ASSERT_TRUE(ReadTestCert("target_invalid_url_aia.pem", &cert));
- StrictMock<MockCertNetFetcher> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
+ new StrictMock<MockCertNetFetcher>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> request;
aia_source.AsyncGetIssuersOf(cert.get(), &request);
EXPECT_EQ(nullptr, request);
@@ -181,14 +191,15 @@ TEST(CertIssuerSourceAiaTest, OneAia) {
scoped_refptr<ParsedCertificate> intermediate_cert;
ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
- StrictMock<MockCertNetFetcher> mock_fetcher;
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
+ new StrictMock<MockCertNetFetcher>());
- EXPECT_CALL(mock_fetcher,
+ EXPECT_CALL(*mock_fetcher.get(),
FetchCaIssuers(GURL("http://url-for-aia/I.cer"), _, _))
.WillOnce(Return(
ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get())))));
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
ASSERT_NE(nullptr, cert_source_request);
@@ -213,17 +224,19 @@ TEST(CertIssuerSourceAiaTest, OneFileOneHttpAia) {
scoped_refptr<ParsedCertificate> intermediate_cert;
ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert));
- StrictMock<MockCertNetFetcher> mock_fetcher;
+ scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
+ new StrictMock<MockCertNetFetcher>());
- EXPECT_CALL(mock_fetcher, FetchCaIssuers(GURL("file:///dev/null"), _, _))
+ EXPECT_CALL(*mock_fetcher.get(),
+ FetchCaIssuers(GURL("file:///dev/null"), _, _))
.WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME))));
- EXPECT_CALL(mock_fetcher,
+ EXPECT_CALL(*mock_fetcher.get(),
FetchCaIssuers(GURL("http://url-for-aia2/I2.foo"), _, _))
.WillOnce(Return(
ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get())))));
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
ASSERT_NE(nullptr, cert_source_request);
@@ -247,8 +260,9 @@ TEST(CertIssuerSourceAiaTest, OneInvalidOneHttpAia) {
ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -292,8 +306,9 @@ TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeries) {
ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -368,8 +383,9 @@ TEST(CertIssuerSourceAiaTest, TwoAiaCompletedBeforeGetNext) {
ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -440,8 +456,9 @@ TEST(CertIssuerSourceAiaTest, AiaRequestCompletesDuringGetNextSequence) {
ASSERT_TRUE(ReadTestCert("i3.pem", &intermediate_cert3));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -516,8 +533,9 @@ TEST(CertIssuerSourceAiaTest, OneAiaHttpError) {
ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -550,8 +568,9 @@ TEST(CertIssuerSourceAiaTest, OneAiaParseError) {
ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -585,8 +604,9 @@ TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesFirstFails) {
ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -639,8 +659,9 @@ TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesSecondFails) {
ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -697,8 +718,9 @@ TEST(CertIssuerSourceAiaTest, CertSourceRequestCancelled) {
ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -733,8 +755,9 @@ TEST(CertIssuerSourceAiaTest, TwoAiaOneCompletedThenRequestCancelled) {
ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,
@@ -784,8 +807,9 @@ TEST(CertIssuerSourceAiaTest, MaxFetchesPerCert) {
ASSERT_TRUE(ReadTestCert("target_six_aia.pem", &cert));
StrictMock<MockIssuerCallback> mock_callback;
- StrictMock<MockCertNetFetcherImpl> mock_fetcher;
- CertIssuerSourceAia aia_source(&mock_fetcher);
+ scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
+ new StrictMock<MockCertNetFetcherImpl>());
+ CertIssuerSourceAia aia_source(mock_fetcher);
std::unique_ptr<CertIssuerSource::Request> cert_source_request;
aia_source.AsyncGetIssuersOf(cert.get(),
base::Bind(&MockIssuerCallback::Callback,

Powered by Google App Engine
This is Rietveld 408576698