blob: c701a7d528233f5e3bdd5b09978b3cdba472528d [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) {
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