Replace RTCCertificateGeneratorCallback interface with an AnyInvocable
follow up of the https://webrtc-review.googlesource.com/c/src/+/272402
Bug: None
Change-Id: Ie47aff9fccdb4037c1f560801c780dd549b373ae
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272553
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37870}
diff --git a/rtc_base/rtc_certificate_generator_unittest.cc b/rtc_base/rtc_certificate_generator_unittest.cc
index 3d9df58..fb7ec91 100644
--- a/rtc_base/rtc_certificate_generator_unittest.cc
+++ b/rtc_base/rtc_certificate_generator_unittest.cc
@@ -21,7 +21,7 @@
namespace rtc {
-class RTCCertificateGeneratorFixture : public RTCCertificateGeneratorCallback {
+class RTCCertificateGeneratorFixture {
public:
RTCCertificateGeneratorFixture()
: signaling_thread_(Thread::Current()),
@@ -32,21 +32,16 @@
generator_.reset(
new RTCCertificateGenerator(signaling_thread_, worker_thread_.get()));
}
- ~RTCCertificateGeneratorFixture() override {}
RTCCertificateGenerator* generator() const { return generator_.get(); }
RTCCertificate* certificate() const { return certificate_.get(); }
- void OnSuccess(const scoped_refptr<RTCCertificate>& certificate) override {
- RTC_CHECK(signaling_thread_->IsCurrent());
- RTC_CHECK(certificate);
- certificate_ = certificate;
- generate_async_completed_ = true;
- }
- void OnFailure() override {
- RTC_CHECK(signaling_thread_->IsCurrent());
- certificate_ = nullptr;
- generate_async_completed_ = true;
+ RTCCertificateGeneratorInterface::Callback OnGenerated() {
+ return [this](scoped_refptr<RTCCertificate> certificate) mutable {
+ RTC_CHECK(signaling_thread_->IsCurrent());
+ certificate_ = std::move(certificate);
+ generate_async_completed_ = true;
+ };
}
bool GenerateAsyncCompleted() {
@@ -69,14 +64,11 @@
class RTCCertificateGeneratorTest : public ::testing::Test {
public:
- RTCCertificateGeneratorTest()
- : fixture_(make_ref_counted<RTCCertificateGeneratorFixture>()) {}
-
protected:
static constexpr int kGenerationTimeoutMs = 10000;
rtc::AutoThread main_thread_;
- scoped_refptr<RTCCertificateGeneratorFixture> fixture_;
+ RTCCertificateGeneratorFixture fixture_;
};
TEST_F(RTCCertificateGeneratorTest, GenerateECDSA) {
@@ -90,16 +82,16 @@
}
TEST_F(RTCCertificateGeneratorTest, GenerateAsyncECDSA) {
- EXPECT_FALSE(fixture_->certificate());
- fixture_->generator()->GenerateCertificateAsync(KeyParams::ECDSA(),
- absl::nullopt, fixture_);
+ EXPECT_FALSE(fixture_.certificate());
+ fixture_.generator()->GenerateCertificateAsync(
+ KeyParams::ECDSA(), absl::nullopt, fixture_.OnGenerated());
// Until generation has completed, the certificate is null. Since this is an
// async call, generation must not have completed until we process messages
// posted to this thread (which is done by `EXPECT_TRUE_WAIT`).
- EXPECT_FALSE(fixture_->GenerateAsyncCompleted());
- EXPECT_FALSE(fixture_->certificate());
- EXPECT_TRUE_WAIT(fixture_->GenerateAsyncCompleted(), kGenerationTimeoutMs);
- EXPECT_TRUE(fixture_->certificate());
+ EXPECT_FALSE(fixture_.GenerateAsyncCompleted());
+ EXPECT_FALSE(fixture_.certificate());
+ EXPECT_TRUE_WAIT(fixture_.GenerateAsyncCompleted(), kGenerationTimeoutMs);
+ EXPECT_TRUE(fixture_.certificate());
}
TEST_F(RTCCertificateGeneratorTest, GenerateWithExpires) {
@@ -136,10 +128,10 @@
EXPECT_FALSE(RTCCertificateGenerator::GenerateCertificate(invalid_params,
absl::nullopt));
- fixture_->generator()->GenerateCertificateAsync(invalid_params, absl::nullopt,
- fixture_);
- EXPECT_TRUE_WAIT(fixture_->GenerateAsyncCompleted(), kGenerationTimeoutMs);
- EXPECT_FALSE(fixture_->certificate());
+ fixture_.generator()->GenerateCertificateAsync(invalid_params, absl::nullopt,
+ fixture_.OnGenerated());
+ EXPECT_TRUE_WAIT(fixture_.GenerateAsyncCompleted(), kGenerationTimeoutMs);
+ EXPECT_FALSE(fixture_.certificate());
}
} // namespace rtc