blob: d54e36b5630c4c6d064e7eebd7dec2fabc65b3c1 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2020 The Chromium Authors
adamta33cf2a42020-03-06 17:51:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/metrics/machine_id_provider.h"
6
7#include "base/system/sys_info.h"
8#include "build/build_config.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace metrics {
12
13TEST(MachineIdProviderNonWinTest, GetId) {
14 const bool has_machine_name = !base::SysInfo::HardwareModelName().empty();
15
Xiaohan Wangc6dd8482022-01-14 19:22:0916#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
adamta33cf2a42020-03-06 17:51:1617 DCHECK(has_machine_name);
18#endif
19
20 // Should only return a machine ID if the hardware model name is available.
21 if (has_machine_name) {
Nicolas Dossou-Gbeteb3b8a172025-05-20 08:21:3622 const std::string id1 = MachineIdProvider().GetMachineId();
23 EXPECT_TRUE(MachineIdProvider().HasId());
adamta33cf2a42020-03-06 17:51:1624 EXPECT_NE(std::string(), id1);
25
Nicolas Dossou-Gbeteb3b8a172025-05-20 08:21:3626 const std::string id2 = MachineIdProvider().GetMachineId();
adamta33cf2a42020-03-06 17:51:1627 EXPECT_EQ(id1, id2);
28 } else {
Nicolas Dossou-Gbeteb3b8a172025-05-20 08:21:3629 EXPECT_FALSE(MachineIdProvider().HasId());
adamta33cf2a42020-03-06 17:51:1630 }
31}
32
33} // namespace metrics