1 // Copyright 2024 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 "base/test/metrics/histogram_variants_reader.h"
6
7 #include <optional>
8
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace base {
13
TEST(HistogramVariantsReaderTest,SanityChecks)14 TEST(HistogramVariantsReaderTest, SanityChecks) {
15 // NOTE: This results in a dependency on a histogram.xml file, but to
16 // otherwise inject content would circumvent a lot of the logic of the
17 // method and add additional complexity.
18 //
19 // The test file with the "TestToken" variant can be found at:
20 // `//tools/metrics/histograms/test_data/histograms.xml`
21 std::optional<HistogramVariantsEntryMap> results =
22 ReadVariantsFromHistogramsXml("TestToken", "test_data",
23 /*from_metadata=*/false);
24 ASSERT_TRUE(results);
25 EXPECT_THAT(*results, testing::UnorderedElementsAre(
26 std::make_pair("Variant1", "Label1"),
27 std::make_pair("Variant2", "Label2")));
28
29 results = ReadVariantsFromHistogramsXml("TheWorstNameForVariants",
30 "test_data", /*from_metadata=*/false);
31 ASSERT_FALSE(results);
32 }
33
34 } // namespace base
35