chromium/components/metrics/structured/key_data_prefs_delegate_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/metrics/structured/key_data_prefs_delegate.h"

#include <memory>
#include <string_view>

#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/metrics/structured/histogram_util.h"
#include "components/metrics/structured/lib/histogram_util.h"
#include "components/metrics/structured/lib/key_data.h"
#include "components/metrics/structured/lib/key_util.h"
#include "components/metrics/structured/lib/proto/key.pb.h"
#include "components/metrics/structured/structured_metrics_validator.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace metrics::structured {

namespace {
constexpr char kTestPrefName[] =;

// 32 byte long test key, matching the size of a real key.
constexpr char kKey[] =;

// These project, event, and metric names are used for testing.
// - project: TestProjectOne
//   - event: TestEventOne
//     - metric: TestMetricOne
//     - metric: TestMetricTwo
// - project: TestProjectTwo

// The name hash of "TestProjectOne".
constexpr uint64_t kProjectOneHash =;
// The name hash of "TestProjectTwo".
constexpr uint64_t kProjectTwoHash =;

// The name hash of "TestMetricOne".
constexpr uint64_t kMetricOneHash =;
// The name hash of "TestMetricTwo".
constexpr uint64_t kMetricTwoHash =;

// The hex-encoded frst 8 bytes of SHA256(kKey), ie. the user ID for key kKey.
constexpr char kUserId[] =;

// Test values and their hashes. Hashes are the first 8 bytes of:
// HMAC_SHA256(concat(hex(kMetricNHash), kValueN), kKey)
constexpr char kValueOne[] =;
constexpr char kValueTwo[] =;
constexpr char kValueOneHash[] =;
constexpr char kValueTwoHash[] =;

constexpr base::TimeDelta kKeyRotationPeriod =;

std::string HashToHex(const uint64_t hash) {}
}  // namespace

class KeyDataPrefsDelegateTest : public testing::Test {};

// If there is no key store file present, check that new keys are generated for
// each project, and those keys are of the right length and different from each
// other.
TEST_F(KeyDataPrefsDelegateTest, GeneratesKeysForProjects) {}

// If there is an existing key store file, check that its keys are not replaced.
TEST_F(KeyDataPrefsDelegateTest, ReuseExistingKeys) {}

// Check that different events have different hashes for the same metric and
// value.
TEST_F(KeyDataPrefsDelegateTest, DifferentEventsDifferentHashes) {}

// Check that an event has different hashes for different metrics with the same
// value.
TEST_F(KeyDataPrefsDelegateTest, DifferentMetricsDifferentHashes) {}

// Check that an event has different hashes for different values of the same
// metric.
TEST_F(KeyDataPrefsDelegateTest, DifferentValuesDifferentHashes) {}

// Ensure that KeyDataFileDelegate::UserId is the expected value of SHA256(key).
TEST_F(KeyDataPrefsDelegateTest, CheckUserIDs) {}

// Ensure that KeyDataFileDelegate::Hash returns expected values for a known
// key / and value.
TEST_F(KeyDataPrefsDelegateTest, CheckHashes) {}

//// Check that keys for a event are correctly rotated after a given rotation
//// period.
TEST_F(KeyDataPrefsDelegateTest, KeysRotated) {}

//// Check that keys with updated rotations are correctly rotated.
TEST_F(KeyDataPrefsDelegateTest, KeysWithUpdatedRotations) {}

TEST_F(KeyDataPrefsDelegateTest, Purge) {}

}  // namespace metrics::structured