• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "crypto/unexportable_key_metrics.h"
6 
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"
11 
12 namespace {
13 
14 // Note mock provider only supports ECDSA
TEST(UnexportableKeyMetricTest,GatherAllMetrics)15 TEST(UnexportableKeyMetricTest, GatherAllMetrics) {
16   crypto::ScopedMockUnexportableKeyProvider scoped_mock_key_provider;
17 
18   base::HistogramTester histogram_tester;
19   histogram_tester.ExpectTotalCount("Crypto.TPMSupport2", 0);
20   histogram_tester.ExpectTotalCount("Crypto.TPMDuration.NewKeyCreationECDSA",
21                                     0);
22   histogram_tester.ExpectTotalCount(
23       "Crypto.TPMDuration.WrappedKeyCreationECDSA", 0);
24   histogram_tester.ExpectTotalCount("Crypto.TPMDuration.MessageSigningECDSA",
25                                     0);
26   histogram_tester.ExpectTotalCount("Crypto.TPMOperation.NewKeyCreation", 0);
27   histogram_tester.ExpectTotalCount("Crypto.TPMOperation.WrappedKeyCreation",
28                                     0);
29   histogram_tester.ExpectTotalCount("Crypto.TPMOperation.MessageSigning", 0);
30   histogram_tester.ExpectTotalCount("Crypto.TPMOperation.MessageVerify", 0);
31 
32   crypto::internal::MeasureTpmOperationsInternalForTesting();
33 
34   EXPECT_THAT(
35       histogram_tester.GetAllSamples("Crypto.TPMSupport2"),
36       BucketsAre(base::Bucket(crypto::internal::TPMSupport::kECDSA, 1)));
37   histogram_tester.ExpectTotalCount("Crypto.TPMDuration.NewKeyCreationECDSA",
38                                     1);
39   histogram_tester.ExpectTotalCount(
40       "Crypto.TPMDuration.WrappedKeyCreationECDSA", 1);
41   histogram_tester.ExpectTotalCount("Crypto.TPMDuration.MessageSigningECDSA",
42                                     1);
43   EXPECT_THAT(
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)));
49   EXPECT_THAT(
50       histogram_tester.GetAllSamples("Crypto.TPMOperation.MessageSigningECDSA"),
51       BucketsAre(base::Bucket(true, 1)));
52   EXPECT_THAT(
53       histogram_tester.GetAllSamples("Crypto.TPMOperation.MessageVerifyECDSA"),
54       BucketsAre(base::Bucket(true, 1)));
55 }
56 
57 }  // namespace
58