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