Commit 6b47612a authored by tby's avatar tby Committed by Commit Bot

[Structured metrics] Add unit test to check IDs shared within project

When two event definitions are grouped under a project, their recorded
events should share an user event ID. This adds a test to make sure
that's the case.

Bug: 1016655
Change-Id: I32476ece7dd80c7366230a456d5e9d8210355115
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119457Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754770}
parent 4a24da2e
...@@ -58,6 +58,8 @@ constexpr char kKeyData[] = R"({ ...@@ -58,6 +58,8 @@ constexpr char kKeyData[] = R"({
constexpr uint64_t kEventOneHash = UINT64_C(15619026293081468407); constexpr uint64_t kEventOneHash = UINT64_C(15619026293081468407);
// The name hash of "TestEventTwo". // The name hash of "TestEventTwo".
constexpr uint64_t kEventTwoHash = UINT64_C(15791833939776536363); constexpr uint64_t kEventTwoHash = UINT64_C(15791833939776536363);
// The name hash of "TestEventThree".
constexpr uint64_t kEventThreeHash = UINT64_C(16464330721839207086);
// The name hash of "TestMetricOne". // The name hash of "TestMetricOne".
constexpr uint64_t kMetricOneHash = UINT64_C(637929385654885975); constexpr uint64_t kMetricOneHash = UINT64_C(637929385654885975);
...@@ -287,6 +289,36 @@ TEST_F(StructuredMetricsProviderTest, EventsReportedCorrectly) { ...@@ -287,6 +289,36 @@ TEST_F(StructuredMetricsProviderTest, EventsReportedCorrectly) {
histogram_tester_.ExpectTotalCount("UMA.StructuredMetrics.PrefReadError", 0); histogram_tester_.ExpectTotalCount("UMA.StructuredMetrics.PrefReadError", 0);
} }
TEST_F(StructuredMetricsProviderTest, EventsWithinProjectReportedWithSameID) {
WriteTestingKeys();
Init();
events::TestEventOne().Record();
events::TestEventTwo().Record();
events::TestEventThree().Record();
const auto uma = GetProvidedEvents();
ASSERT_EQ(uma.structured_event_size(), 3);
const auto& event_one = uma.structured_event(0);
const auto& event_two = uma.structured_event(1);
const auto& event_three = uma.structured_event(2);
// Check events are in the right order.
EXPECT_EQ(event_one.event_name_hash(), kEventOneHash);
EXPECT_EQ(event_two.event_name_hash(), kEventTwoHash);
EXPECT_EQ(event_three.event_name_hash(), kEventThreeHash);
// Events two and three share a project, so should have the same ID. Event
// one should have its own ID.
EXPECT_EQ(HashToHex(event_one.profile_event_id()), kKeyOneId);
EXPECT_EQ(HashToHex(event_two.profile_event_id()), kKeyTwoId);
EXPECT_EQ(HashToHex(event_three.profile_event_id()), kKeyTwoId);
histogram_tester_.ExpectTotalCount("UMA.StructuredMetrics.InternalError", 0);
histogram_tester_.ExpectTotalCount("UMA.StructuredMetrics.PrefReadError", 0);
}
// Test that a call to ProvideCurrentSessionData clears the provided events from // Test that a call to ProvideCurrentSessionData clears the provided events from
// the cache, and a subsequent call does not return those events again. // the cache, and a subsequent call does not return those events again.
TEST_F(StructuredMetricsProviderTest, EventsClearedAfterReport) { TEST_F(StructuredMetricsProviderTest, EventsClearedAfterReport) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment