src/net/cert/multi_threaded_cert_verifier_unittest.cc
TEST_F(MultiThreadedCertVerifierTest, CancelRequestThenQuit) {
  base::FilePath certs_dir = GetTestCertsDirectory();
  scoped_refptr<X509Certificate> test_cert(
      ImportCertFromFile(certs_dir, "ok_cert.pem"));
  ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());

  int error;
  CertVerifyResult verify_result;
  TestCompletionCallback callback;
  std::unique_ptr<CertVerifier::Request> request;

  {
    // Because shutdown intentionally doesn't join worker threads, memory may
    // be leaked if the main thread shuts down before the worker thread
    // completes. In particular MultiThreadedCertVerifier calls
    // base::WorkerPool::PostTaskAndReply(), which leaks its "relay" when it
    // can't post the reply back to the origin thread. See
    // https://crbug.com/522514
    ANNOTATE_SCOPED_MEMORY_LEAK;
    error = verifier_->Verify(
        CertVerifier::RequestParams(test_cert, "www.example.com", 0,
                                    /*ocsp_response=*/std::string(),
                                    /*sct_list=*/std::string()),
        &verify_result, callback.callback(), &request, NetLogWithSource());
  }
  ASSERT_THAT(error, IsError(ERR_IO_PENDING));
  EXPECT_TRUE(request);
  request.reset();
  // Destroy |verifier_| by going out of scope.
}
// Tests that a canceled request is not leaked.
Tests that a canceled request is not leaked.
Tests that a canceled request is not leaked .
TEST_F(MultiThreadedCertVerifierTest, CancelRequestThenQuit) {
  base::FilePath certs_dir = GetTestCertsDirectory();
  scoped_refptr<X509Certificate> test_cert(
      ImportCertFromFile(certs_dir, "ok_cert.pem"));
  ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());
  int error;
  CertVerifyResult verify_result;
  TestCompletionCallback callback;
  std::unique_ptr<CertVerifier::Request> request;
  {
    ANNOTATE_SCOPED_MEMORY_LEAK;
    error = verifier_->Verify(
        CertVerifier::RequestParams(test_cert, "www.example.com", 0,
                                    std::string(),
                                    std::string()),
        &verify_result, callback.callback(), &request, NetLogWithSource());
  }
  ASSERT_THAT(error, IsError(ERR_IO_PENDING));
  EXPECT_TRUE(request);
  request.reset();
}
TEST_F ( MultiThreadedCertVerifierTest , CancelRequestThenQuit ) { base :: FilePath certs_dir = GetTestCertsDirectory ( ) ; scoped_refptr < X509Certificate > test_cert ( ImportCertFromFile ( certs_dir , " " ) ) ; ASSERT_NE ( static_cast < X509Certificate * > ( nullptr ) , test_cert . get ( ) ) ; int error ; CertVerifyResult verify_result ; TestCompletionCallback callback ; std :: unique_ptr < CertVerifier :: Request > request ; { ANNOTATE_SCOPED_MEMORY_LEAK ; error = verifier_ -> Verify ( CertVerifier :: RequestParams ( test_cert , " " , 0 , std :: string ( ) , std :: string ( ) ) , & verify_result , callback . callback ( ) , & request , NetLogWithSource ( ) ) ; } ASSERT_THAT ( error , IsError ( ERR_IO_PENDING ) ) ; EXPECT_TRUE ( request ) ; request . reset ( ) ; }
Tests that a canceled request is not leaked.
Tests that a canceled request is not leaked .
// Because shutdown intentionally doesn't join worker threads, memory may // be leaked if the main thread shuts down before the worker thread // completes. In particular MultiThreadedCertVerifier calls // base::WorkerPool::PostTaskAndReply(), which leaks its "relay" when it // can't post the reply back to the origin thread. See // https://crbug.com/522514 /*ocsp_response=*/ /*sct_list=*/ // Destroy |verifier_| by going out of scope.