1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "crypto/unexportable_key_metrics.h"
7 #include "base/test/metrics/histogram_tester.h"
8 #include "crypto/scoped_mock_unexportable_key_provider.h"
9 #include "crypto/signature_verifier.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 // Note mock provider only supports ECDSA
15 TEST(UnexportableKeyMetricTest, GatherAllMetrics) {
16 crypto::ScopedMockUnexportableKeyProvider scoped_mock_key_provider;
18 base::HistogramTester histogram_tester;
19 histogram_tester.ExpectTotalCount("Crypto.TPMSupport2", 0);
20 histogram_tester.ExpectTotalCount("Crypto.TPMDuration.NewKeyCreationECDSA",
22 histogram_tester.ExpectTotalCount(
23 "Crypto.TPMDuration.WrappedKeyCreationECDSA", 0);
24 histogram_tester.ExpectTotalCount("Crypto.TPMDuration.MessageSigningECDSA",
26 histogram_tester.ExpectTotalCount("Crypto.TPMOperation.NewKeyCreation", 0);
27 histogram_tester.ExpectTotalCount("Crypto.TPMOperation.WrappedKeyCreation",
29 histogram_tester.ExpectTotalCount("Crypto.TPMOperation.MessageSigning", 0);
30 histogram_tester.ExpectTotalCount("Crypto.TPMOperation.MessageVerify", 0);
32 crypto::internal::MeasureTpmOperationsInternalForTesting();
35 histogram_tester.GetAllSamples("Crypto.TPMSupport2"),
36 BucketsAre(base::Bucket(crypto::internal::TPMSupport::kECDSA, 1)));
37 histogram_tester.ExpectTotalCount("Crypto.TPMDuration.NewKeyCreationECDSA",
39 histogram_tester.ExpectTotalCount(
40 "Crypto.TPMDuration.WrappedKeyCreationECDSA", 1);
41 histogram_tester.ExpectTotalCount("Crypto.TPMDuration.MessageSigningECDSA",
44 histogram_tester.GetAllSamples("Crypto.TPMOperation.NewKeyCreationECDSA"),
45 BucketsAre(base::Bucket(true, 1)));
46 EXPECT_THAT(histogram_tester.GetAllSamples(
47 "Crypto.TPMOperation.WrappedKeyCreationECDSA"),
48 BucketsAre(base::Bucket(true, 1)));
50 histogram_tester.GetAllSamples("Crypto.TPMOperation.MessageSigningECDSA"),
51 BucketsAre(base::Bucket(true, 1)));
53 histogram_tester.GetAllSamples("Crypto.TPMOperation.MessageVerifyECDSA"),
54 BucketsAre(base::Bucket(true, 1)));