1 // Copyright 2022 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 <fidl/fuchsia.buildinfo/cpp/fidl.h> 6 7 #include "base/fuchsia/system_info.h" 8 #include "base/test/gtest_util.h" 9 10 namespace base { 11 12 // Ensures that when FetchAndCacheSystemInfo() has not been called in the 13 // process that a DCHECK fires to alert the developer. TEST(BuildInfoDeathTest,GetCachedBuildInfo_DcheckIfNotAlreadyFetched)14TEST(BuildInfoDeathTest, GetCachedBuildInfo_DcheckIfNotAlreadyFetched) { 15 // Clear the cached build info to force an error condition. 16 ClearCachedSystemInfoForTesting(); 17 18 EXPECT_DCHECK_DEATH_WITH( 19 { GetCachedBuildInfo(); }, 20 "FetchAndCacheSystemInfo\\(\\) has not been called in this process"); 21 22 // All test processes have BuildInfo cached before tests are run. Re-fetch and 23 // cache the BuildInfo to restore that state for any tests that are 24 // subsequently run in the same process as this one. 25 EXPECT_TRUE(FetchAndCacheSystemInfo()); 26 } 27 TEST(BuildInfoTest,GetCachedBuildInfo_CheckExpectedValues)28TEST(BuildInfoTest, GetCachedBuildInfo_CheckExpectedValues) { 29 // Ensure the cached BuildInfo is in a known state. 30 ClearCachedSystemInfoForTesting(); 31 ASSERT_TRUE(FetchAndCacheSystemInfo()); 32 33 // TODO(crbug.com/1326674): Check for specific values once Fuchsia 34 // completes the requested changes to the data returned from the fake. 35 EXPECT_TRUE(GetCachedBuildInfo().product_config().has_value()); 36 EXPECT_TRUE(GetCachedBuildInfo().board_config().has_value()); 37 EXPECT_TRUE(GetCachedBuildInfo().version().has_value()); 38 EXPECT_TRUE(GetCachedBuildInfo().latest_commit_date().has_value()); 39 } 40 41 } // namespace base 42