1 // Copyright 2012 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 <stdint.h>
6
7 #include <utility>
8 #include <vector>
9
10 #include "base/environment.h"
11 #include "base/files/file_util.h"
12 #include "base/functional/bind.h"
13 #include "base/numerics/safe_conversions.h"
14 #include "base/process/process_metrics.h"
15 #include "base/run_loop.h"
16 #include "base/strings/pattern.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_split.h"
19 #include "base/strings/string_util.h"
20 #include "base/strings/sys_string_conversions.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/system/sys_info.h"
23 #include "base/test/scoped_chromeos_version_info.h"
24 #include "base/test/scoped_running_on_chromeos.h"
25 #include "base/test/task_environment.h"
26 #include "base/threading/platform_thread.h"
27 #include "base/threading/scoped_blocking_call.h"
28 #include "base/time/time.h"
29 #include "build/build_config.h"
30 #include "testing/gtest/include/gtest/gtest-death-test.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "testing/platform_test.h"
33 #include "third_party/abseil-cpp/absl/types/optional.h"
34
35 #if BUILDFLAG(IS_WIN)
36 #include "base/win/com_init_util.h"
37 #include "base/win/scoped_bstr.h"
38 #include "base/win/scoped_com_initializer.h"
39 #include "base/win/scoped_variant.h"
40 #include "base/win/wmi.h"
41 #endif // BUILDFLAG(IS_WIN)
42
43 #if BUILDFLAG(IS_MAC)
44 #include "base/system/sys_info_internal.h"
45 #include "base/test/scoped_feature_list.h"
46 #endif // BUILDFLAG(IS_MAC)
47
48 namespace base {
49
50 #if BUILDFLAG(IS_ANDROID)
51 // Some Android (Cast) test devices have a large portion of physical memory
52 // reserved. During investigation, around 115-150 MB were seen reserved, so we
53 // track this here with a factory of safety of 2.
54 static constexpr int kReservedPhysicalMemory = 300 * 1024; // In _K_bytes.
55 #endif // BUILDFLAG(IS_ANDROID)
56
57 using SysInfoTest = PlatformTest;
58
TEST_F(SysInfoTest,NumProcs)59 TEST_F(SysInfoTest, NumProcs) {
60 // We aren't actually testing that it's correct, just that it's sane.
61 EXPECT_GE(SysInfo::NumberOfProcessors(), 1);
62
63 EXPECT_GE(SysInfo::NumberOfEfficientProcessors(), 0);
64 EXPECT_LT(SysInfo::NumberOfEfficientProcessors(),
65 SysInfo::NumberOfProcessors());
66 }
67
68 #if BUILDFLAG(IS_MAC)
TEST_F(SysInfoTest,NumProcsWithSecurityMitigationEnabled)69 TEST_F(SysInfoTest, NumProcsWithSecurityMitigationEnabled) {
70 // Reset state so that the call to SetCpuSecurityMitigationsEnabled() below
71 // succeeds even if SysInfo::NumberOfProcessors() was previously called.
72 SysInfo::ResetCpuSecurityMitigationsEnabledForTesting();
73
74 // Verify that the number of number of available processors available when CPU
75 // security mitigation is enabled is the number of available "physical"
76 // processors.
77 test::ScopedFeatureList feature_list_;
78 feature_list_.InitAndEnableFeature(kNumberOfCoresWithCpuSecurityMitigation);
79 SysInfo::SetCpuSecurityMitigationsEnabled();
80 EXPECT_EQ(SysInfo::NumberOfProcessors(),
81 internal::NumberOfPhysicalProcessors());
82
83 // Reset state set by this test.
84 SysInfo::ResetCpuSecurityMitigationsEnabledForTesting();
85 }
86 #endif // BUILDFLAG(IS_MAC)
87
TEST_F(SysInfoTest,AmountOfMem)88 TEST_F(SysInfoTest, AmountOfMem) {
89 // We aren't actually testing that it's correct, just that it's sane.
90 EXPECT_GT(SysInfo::AmountOfPhysicalMemory(), 0u);
91 EXPECT_GT(SysInfo::AmountOfPhysicalMemoryMB(), 0);
92 // The maxmimal amount of virtual memory can be zero which means unlimited.
93 EXPECT_GE(SysInfo::AmountOfVirtualMemory(), 0u);
94 }
95
96 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
97 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
98 #define MAYBE_AmountOfAvailablePhysicalMemory \
99 DISABLED_AmountOfAvailablePhysicalMemory
100 #else
101 #define MAYBE_AmountOfAvailablePhysicalMemory AmountOfAvailablePhysicalMemory
102 #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
TEST_F(SysInfoTest,MAYBE_AmountOfAvailablePhysicalMemory)103 TEST_F(SysInfoTest, MAYBE_AmountOfAvailablePhysicalMemory) {
104 // Note: info is in _K_bytes.
105 SystemMemoryInfoKB info;
106 ASSERT_TRUE(GetSystemMemoryInfo(&info));
107 EXPECT_GT(info.free, 0);
108 if (info.available != 0) {
109 // If there is MemAvailable from kernel.
110 EXPECT_LT(info.available, info.total);
111 const uint64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info);
112 // We aren't actually testing that it's correct, just that it's sane.
113 // Available memory is |free - reserved + reclaimable (inactive, non-free)|.
114 // On some android platforms, reserved is a substantial portion.
115 const int available =
116 #if BUILDFLAG(IS_ANDROID)
117 std::max(info.free - kReservedPhysicalMemory, 0);
118 #else
119 info.free;
120 #endif // BUILDFLAG(IS_ANDROID)
121 EXPECT_GT(amount, checked_cast<uint64_t>(available) * 1024);
122 EXPECT_LT(amount / 1024, checked_cast<uint64_t>(info.available));
123 // Simulate as if there is no MemAvailable.
124 info.available = 0;
125 }
126
127 // There is no MemAvailable. Check the fallback logic.
128 const uint64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info);
129 // We aren't actually testing that it's correct, just that it's sane.
130 EXPECT_GT(amount, checked_cast<uint64_t>(info.free) * 1024);
131 EXPECT_LT(amount / 1024, checked_cast<uint64_t>(info.total));
132 }
133 #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
134 // BUILDFLAG(IS_ANDROID)
135
TEST_F(SysInfoTest,AmountOfFreeDiskSpace)136 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
137 // We aren't actually testing that it's correct, just that it's sane.
138 FilePath tmp_path;
139 ASSERT_TRUE(GetTempDir(&tmp_path));
140 EXPECT_GE(SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) << tmp_path;
141 }
142
TEST_F(SysInfoTest,AmountOfTotalDiskSpace)143 TEST_F(SysInfoTest, AmountOfTotalDiskSpace) {
144 // We aren't actually testing that it's correct, just that it's sane.
145 FilePath tmp_path;
146 ASSERT_TRUE(GetTempDir(&tmp_path));
147 EXPECT_GT(SysInfo::AmountOfTotalDiskSpace(tmp_path), 0) << tmp_path;
148 }
149
150 #if BUILDFLAG(IS_FUCHSIA)
151 // Verify that specifying total disk space for nested directories matches
152 // the deepest-nested.
TEST_F(SysInfoTest,NestedVolumesAmountOfTotalDiskSpace)153 TEST_F(SysInfoTest, NestedVolumesAmountOfTotalDiskSpace) {
154 constexpr int64_t kOuterVolumeQuota = 1024;
155 constexpr int64_t kInnerVolumeQuota = kOuterVolumeQuota / 2;
156
157 FilePath tmp_path;
158 ASSERT_TRUE(GetTempDir(&tmp_path));
159 SysInfo::SetAmountOfTotalDiskSpace(tmp_path, kOuterVolumeQuota);
160 const FilePath subdirectory_path = tmp_path.Append("subdirectory");
161 SysInfo::SetAmountOfTotalDiskSpace(subdirectory_path, kInnerVolumeQuota);
162
163 EXPECT_EQ(SysInfo::AmountOfTotalDiskSpace(tmp_path), kOuterVolumeQuota);
164 EXPECT_EQ(SysInfo::AmountOfTotalDiskSpace(subdirectory_path),
165 kInnerVolumeQuota);
166
167 // Remove the inner directory quota setting and check again.
168 SysInfo::SetAmountOfTotalDiskSpace(subdirectory_path, -1);
169 EXPECT_EQ(SysInfo::AmountOfTotalDiskSpace(subdirectory_path),
170 kOuterVolumeQuota);
171 }
172 #endif // BUILDFLAG(IS_FUCHSIA)
173
174 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
175 BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
176
TEST_F(SysInfoTest,OperatingSystemVersion)177 TEST_F(SysInfoTest, OperatingSystemVersion) {
178 std::string version = SysInfo::OperatingSystemVersion();
179 EXPECT_FALSE(version.empty());
180 }
181
TEST_F(SysInfoTest,OperatingSystemVersionNumbers)182 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
183 int32_t os_major_version = -1;
184 int32_t os_minor_version = -1;
185 int32_t os_bugfix_version = -1;
186 SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version,
187 &os_bugfix_version);
188 EXPECT_GT(os_major_version, -1);
189 EXPECT_GT(os_minor_version, -1);
190 EXPECT_GT(os_bugfix_version, -1);
191 }
192 #endif
193
194 #if BUILDFLAG(IS_IOS)
TEST_F(SysInfoTest,GetIOSBuildNumber)195 TEST_F(SysInfoTest, GetIOSBuildNumber) {
196 std::string build_number(SysInfo::GetIOSBuildNumber());
197 EXPECT_GT(build_number.length(), 0U);
198 }
199 #endif // BUILDFLAG(IS_IOS)
200
TEST_F(SysInfoTest,Uptime)201 TEST_F(SysInfoTest, Uptime) {
202 TimeDelta up_time_1 = SysInfo::Uptime();
203 // UpTime() is implemented internally using TimeTicks::Now(), which documents
204 // system resolution as being 1-15ms. Sleep a little longer than that.
205 PlatformThread::Sleep(Milliseconds(20));
206 TimeDelta up_time_2 = SysInfo::Uptime();
207 EXPECT_GT(up_time_1.InMicroseconds(), 0);
208 EXPECT_GT(up_time_2.InMicroseconds(), up_time_1.InMicroseconds());
209 }
210
211 #if BUILDFLAG(IS_APPLE)
TEST_F(SysInfoTest,HardwareModelNameFormatMacAndiOS)212 TEST_F(SysInfoTest, HardwareModelNameFormatMacAndiOS) {
213 std::string hardware_model = SysInfo::HardwareModelName();
214 ASSERT_FALSE(hardware_model.empty());
215
216 // Check that the model is of the expected format, which is different on iOS
217 // simulators and real iOS / MacOS devices.
218 #if BUILDFLAG(IS_IOS) && TARGET_OS_SIMULATOR
219 // On iOS simulators, the device model looks like "iOS Simulator (Foo[,Bar])"
220 // where Foo is either "Unknown", "iPhone" or "iPad", and Bar, if present, is
221 // a number.
222 EXPECT_TRUE(base::MatchPattern(hardware_model, "iOS Simulator (*)"))
223 << hardware_model;
224 std::vector<StringPiece> mainPieces =
225 SplitStringPiece(hardware_model, "()", KEEP_WHITESPACE, SPLIT_WANT_ALL);
226 ASSERT_EQ(3u, mainPieces.size()) << hardware_model;
227 std::vector<StringPiece> modelPieces =
228 SplitStringPiece(mainPieces[1], ",", KEEP_WHITESPACE, SPLIT_WANT_ALL);
229 ASSERT_GE(modelPieces.size(), 1u) << hardware_model;
230 if (modelPieces.size() == 1u) {
231 EXPECT_TRUE(modelPieces[0] == "Unknown" || modelPieces[0] == "iPhone" ||
232 modelPieces[0] == "iPad")
233 << hardware_model;
234 } else {
235 int value;
236 EXPECT_TRUE(StringToInt(modelPieces[1], &value)) << hardware_model;
237 }
238 #else
239 // The expected format is "Foo,Bar" where Foo is "iPhone" or "iPad" and Bar is
240 // a number.
241 std::vector<StringPiece> pieces =
242 SplitStringPiece(hardware_model, ",", KEEP_WHITESPACE, SPLIT_WANT_ALL);
243 ASSERT_EQ(2u, pieces.size()) << hardware_model;
244 int value;
245 EXPECT_TRUE(StringToInt(pieces[1], &value)) << hardware_model;
246 #endif // BUILDFLAG(IS_IOS) && TARGET_OS_SIMULATOR
247 }
248 #endif // BUILDFLAG(IS_APPLE)
249
TEST_F(SysInfoTest,GetHardwareInfo)250 TEST_F(SysInfoTest, GetHardwareInfo) {
251 test::TaskEnvironment task_environment;
252 absl::optional<SysInfo::HardwareInfo> hardware_info;
253
254 auto callback = base::BindOnce(
255 [](absl::optional<SysInfo::HardwareInfo>* target_info,
256 SysInfo::HardwareInfo info) { *target_info = std::move(info); },
257 &hardware_info);
258 SysInfo::GetHardwareInfo(std::move(callback));
259 task_environment.RunUntilIdle();
260
261 ASSERT_TRUE(hardware_info.has_value());
262 EXPECT_TRUE(IsStringUTF8(hardware_info->manufacturer));
263 EXPECT_TRUE(IsStringUTF8(hardware_info->model));
264 bool empty_result_expected =
265 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_WIN) || \
266 BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
267 false;
268 #else
269 true;
270 #endif
271 EXPECT_EQ(hardware_info->manufacturer.empty(), empty_result_expected);
272 EXPECT_EQ(hardware_info->model.empty(), empty_result_expected);
273 }
274
275 #if BUILDFLAG(IS_WIN)
TEST_F(SysInfoTest,GetHardwareInfoWMIMatchRegistry)276 TEST_F(SysInfoTest, GetHardwareInfoWMIMatchRegistry) {
277 base::win::ScopedCOMInitializer com_initializer;
278 test::TaskEnvironment task_environment;
279 absl::optional<SysInfo::HardwareInfo> hardware_info;
280
281 auto callback = base::BindOnce(
282 [](absl::optional<SysInfo::HardwareInfo>* target_info,
283 SysInfo::HardwareInfo info) { *target_info = std::move(info); },
284 &hardware_info);
285 SysInfo::GetHardwareInfo(std::move(callback));
286 task_environment.RunUntilIdle();
287
288 ASSERT_TRUE(hardware_info.has_value());
289
290 Microsoft::WRL::ComPtr<IWbemServices> wmi_services;
291 EXPECT_TRUE(base::win::CreateLocalWmiConnection(true, &wmi_services));
292
293 static constexpr wchar_t query_computer_system[] =
294 L"SELECT Manufacturer,Model FROM Win32_ComputerSystem";
295
296 Microsoft::WRL::ComPtr<IEnumWbemClassObject> enumerator_computer_system;
297 HRESULT hr = wmi_services->ExecQuery(
298 base::win::ScopedBstr(L"WQL").Get(),
299 base::win::ScopedBstr(query_computer_system).Get(),
300 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr,
301 &enumerator_computer_system);
302 EXPECT_FALSE(FAILED(hr) || !enumerator_computer_system.Get());
303
304 Microsoft::WRL::ComPtr<IWbemClassObject> class_object;
305 ULONG items_returned = 0;
306 hr = enumerator_computer_system->Next(WBEM_INFINITE, 1, &class_object,
307 &items_returned);
308 EXPECT_FALSE(FAILED(hr) || !items_returned);
309
310 base::win::ScopedVariant manufacturerVar;
311 std::wstring manufacturer;
312 hr = class_object->Get(L"Manufacturer", 0, manufacturerVar.Receive(), nullptr,
313 nullptr);
314 if (SUCCEEDED(hr) && manufacturerVar.type() == VT_BSTR) {
315 manufacturer.assign(V_BSTR(manufacturerVar.ptr()),
316 ::SysStringLen(V_BSTR(manufacturerVar.ptr())));
317 }
318 base::win::ScopedVariant modelVar;
319 std::wstring model;
320 hr = class_object->Get(L"Model", 0, modelVar.Receive(), nullptr, nullptr);
321 if (SUCCEEDED(hr) && modelVar.type() == VT_BSTR) {
322 model.assign(V_BSTR(modelVar.ptr()),
323 ::SysStringLen(V_BSTR(modelVar.ptr())));
324 }
325
326 EXPECT_TRUE(hardware_info->manufacturer == base::SysWideToUTF8(manufacturer));
327 EXPECT_TRUE(hardware_info->model == base::SysWideToUTF8(model));
328 }
329 #endif
330
331 #if BUILDFLAG(IS_CHROMEOS)
332
TEST_F(SysInfoTest,GoogleChromeOSVersionNumbers)333 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
334 int32_t os_major_version = -1;
335 int32_t os_minor_version = -1;
336 int32_t os_bugfix_version = -1;
337 const char kLsbRelease[] =
338 "FOO=1234123.34.5\n"
339 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
340 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
341 SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version,
342 &os_bugfix_version);
343 EXPECT_EQ(1, os_major_version);
344 EXPECT_EQ(2, os_minor_version);
345 EXPECT_EQ(3, os_bugfix_version);
346 }
347
TEST_F(SysInfoTest,GoogleChromeOSVersionNumbersFirst)348 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
349 int32_t os_major_version = -1;
350 int32_t os_minor_version = -1;
351 int32_t os_bugfix_version = -1;
352 const char kLsbRelease[] =
353 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
354 "FOO=1234123.34.5\n";
355 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
356 SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version,
357 &os_bugfix_version);
358 EXPECT_EQ(1, os_major_version);
359 EXPECT_EQ(2, os_minor_version);
360 EXPECT_EQ(3, os_bugfix_version);
361 }
362
TEST_F(SysInfoTest,GoogleChromeOSNoVersionNumbers)363 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
364 int32_t os_major_version = -1;
365 int32_t os_minor_version = -1;
366 int32_t os_bugfix_version = -1;
367 const char kLsbRelease[] = "FOO=1234123.34.5\n";
368 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
369 SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version,
370 &os_bugfix_version);
371 EXPECT_EQ(0, os_major_version);
372 EXPECT_EQ(0, os_minor_version);
373 EXPECT_EQ(0, os_bugfix_version);
374 }
375
TEST_F(SysInfoTest,GoogleChromeOSLsbReleaseTime)376 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) {
377 const char kLsbRelease[] = "CHROMEOS_RELEASE_VERSION=1.2.3.4";
378 // Use a fake time that can be safely displayed as a string.
379 const Time lsb_release_time(Time::FromSecondsSinceUnixEpoch(12345.6));
380 test::ScopedChromeOSVersionInfo version(kLsbRelease, lsb_release_time);
381 Time parsed_lsb_release_time = SysInfo::GetLsbReleaseTime();
382 EXPECT_DOUBLE_EQ(lsb_release_time.InSecondsFSinceUnixEpoch(),
383 parsed_lsb_release_time.InSecondsFSinceUnixEpoch());
384 }
385
TEST_F(SysInfoTest,IsRunningOnChromeOS)386 TEST_F(SysInfoTest, IsRunningOnChromeOS) {
387 {
388 const char kLsbRelease1[] =
389 "CHROMEOS_RELEASE_NAME=Non Chrome OS\n"
390 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
391 test::ScopedChromeOSVersionInfo version(kLsbRelease1, Time());
392 EXPECT_FALSE(SysInfo::IsRunningOnChromeOS());
393 }
394 {
395 const char kLsbRelease2[] =
396 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
397 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
398 test::ScopedChromeOSVersionInfo version(kLsbRelease2, Time());
399 EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
400 }
401 {
402 const char kLsbRelease3[] = "CHROMEOS_RELEASE_NAME=Chromium OS\n";
403 test::ScopedChromeOSVersionInfo version(kLsbRelease3, Time());
404 EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
405 }
406 }
407
408 // Regression test for https://crbug.com/1148904.
TEST_F(SysInfoTest,ScopedChromeOSVersionInfoDoesNotChangeEnvironment)409 TEST_F(SysInfoTest, ScopedChromeOSVersionInfoDoesNotChangeEnvironment) {
410 std::unique_ptr<Environment> environment = Environment::Create();
411 ASSERT_FALSE(environment->HasVar("LSB_RELEASE"));
412 {
413 const char kLsbRelease[] =
414 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
415 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
416 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
417 }
418 EXPECT_FALSE(environment->HasVar("LSB_RELEASE"));
419 }
420
TEST_F(SysInfoTest,CrashOnBaseImage)421 TEST_F(SysInfoTest, CrashOnBaseImage) {
422 const char kLsbRelease[] =
423 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
424 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
425 "CHROMEOS_RELEASE_TRACK=stable-channel\n";
426 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
427 EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
428 EXPECT_DEATH_IF_SUPPORTED({ SysInfo::CrashIfChromeOSNonTestImage(); }, "");
429 }
430
TEST_F(SysInfoTest,NoCrashOnTestImage)431 TEST_F(SysInfoTest, NoCrashOnTestImage) {
432 const char kLsbRelease[] =
433 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
434 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
435 "CHROMEOS_RELEASE_TRACK=testimage-channel\n";
436 test::ScopedChromeOSVersionInfo version(kLsbRelease, Time());
437 EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
438 // Should not crash.
439 SysInfo::CrashIfChromeOSNonTestImage();
440 }
441
TEST_F(SysInfoTest,NoCrashOnLinuxBuild)442 TEST_F(SysInfoTest, NoCrashOnLinuxBuild) {
443 test::ScopedChromeOSVersionInfo version("", Time());
444 EXPECT_FALSE(SysInfo::IsRunningOnChromeOS());
445 // Should not crash.
446 SysInfo::CrashIfChromeOSNonTestImage();
447 }
448
TEST_F(SysInfoTest,ScopedRunningOnChromeOS)449 TEST_F(SysInfoTest, ScopedRunningOnChromeOS) {
450 // base_unittests run both on linux-chromeos and actual devices, so the
451 // initial state of IsRunningOnChromeOS may vary.
452 bool was_running = SysInfo::IsRunningOnChromeOS();
453 {
454 test::ScopedRunningOnChromeOS running_on_chromeos;
455 EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
456 }
457 // Previous value restored.
458 EXPECT_EQ(was_running, SysInfo::IsRunningOnChromeOS());
459 }
460
461 #endif // BUILDFLAG(IS_CHROMEOS)
462
463 } // namespace base
464