blob: b92d353fb1da5e904ce08544ce7e547e93089b08 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/metrics/machine_id_provider.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace metrics {
TEST(MachineIdProviderNonWinTest, GetId) {
const bool has_machine_name = !base::SysInfo::HardwareModelName().empty();
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_IOS)
DCHECK(has_machine_name);
#endif
// Should only return a machine ID if the hardware model name is available.
if (has_machine_name) {
const std::string id1 = MachineIdProvider::GetMachineId();
EXPECT_TRUE(MachineIdProvider::HasId());
EXPECT_NE(std::string(), id1);
const std::string id2 = MachineIdProvider::GetMachineId();
EXPECT_EQ(id1, id2);
} else {
EXPECT_FALSE(MachineIdProvider::HasId());
}
}
} // namespace metrics