xref: /aosp_15_r20/external/cronet/components/metrics/machine_id_provider_nonwin_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 The Chromium Authors
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 
TEST(MachineIdProviderNonWinTest,GetId)13 TEST(MachineIdProviderNonWinTest, GetId) {
14   const bool has_machine_name = !base::SysInfo::HardwareModelName().empty();
15 
16 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
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
34