chromium/components/metrics/structured/lib/key_data_file_delegate_unittest.cc

// Copyright 2019 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/lib/key_data_file_delegate.h"

#include <memory>
#include <string>
#include <utility>

#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.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 "base/values.h"
#include "components/metrics/structured/lib/histogram_util.h"
#include "components/metrics/structured/lib/proto/key.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace metrics::structured {

namespace {

// 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 =16881314472396226433);
// The name hash of "TestProjectTwo".
constexpr uint64_t kProjectTwoHash =5876808001962504629);

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

// 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 KeyDataFileDelegateTest : 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(KeyDataFileDelegateTest, GeneratesKeysForProjects) {}

// When repeatedly initialized with no key store file present, ensure the keys
// generated each time are distinct.
TEST_F(KeyDataFileDelegateTest, GeneratesDistinctKeys) {}

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

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

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

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

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

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

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

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

}  // namespace metrics::structured