machine_id_provider_nonwin_unittest.cc 984 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/metrics/machine_id_provider.h"
  5. #include "base/system/sys_info.h"
  6. #include "build/build_config.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace metrics {
  9. TEST(MachineIdProviderNonWinTest, GetId) {
  10. const bool has_machine_name = !base::SysInfo::HardwareModelName().empty();
  11. #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
  12. DCHECK(has_machine_name);
  13. #endif
  14. // Should only return a machine ID if the hardware model name is available.
  15. if (has_machine_name) {
  16. const std::string id1 = MachineIdProvider::GetMachineId();
  17. EXPECT_TRUE(MachineIdProvider::HasId());
  18. EXPECT_NE(std::string(), id1);
  19. const std::string id2 = MachineIdProvider::GetMachineId();
  20. EXPECT_EQ(id1, id2);
  21. } else {
  22. EXPECT_FALSE(MachineIdProvider::HasId());
  23. }
  24. }
  25. } // namespace metrics