Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
adamta | 33cf2a4 | 2020-03-06 17:51:16 | [diff] [blame] | 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 "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 | |
| 11 | namespace metrics { |
| 12 | |
| 13 | TEST(MachineIdProviderNonWinTest, GetId) { |
| 14 | const bool has_machine_name = !base::SysInfo::HardwareModelName().empty(); |
| 15 | |
Xiaohan Wang | c6dd848 | 2022-01-14 19:22:09 | [diff] [blame] | 16 | #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE) |
adamta | 33cf2a4 | 2020-03-06 17:51:16 | [diff] [blame] | 17 | 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) { |
| 22 | const std::string id1 = MachineIdProvider::GetMachineId(); |
| 23 | EXPECT_TRUE(MachineIdProvider::HasId()); |
| 24 | EXPECT_NE(std::string(), id1); |
| 25 | |
| 26 | const std::string id2 = MachineIdProvider::GetMachineId(); |
| 27 | EXPECT_EQ(id1, id2); |
| 28 | } else { |
| 29 | EXPECT_FALSE(MachineIdProvider::HasId()); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | } // namespace metrics |