diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/base/system | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/system')
-rw-r--r-- | chromium/base/system/sys_info.h | 4 | ||||
-rw-r--r-- | chromium/base/system/sys_info_chromeos.cc | 17 | ||||
-rw-r--r-- | chromium/base/system/sys_info_linux.cc | 1 | ||||
-rw-r--r-- | chromium/base/system/sys_info_unittest.cc | 29 |
4 files changed, 51 insertions, 0 deletions
diff --git a/chromium/base/system/sys_info.h b/chromium/base/system/sys_info.h index 057b0dc45e8..ae3fef01811 100644 --- a/chromium/base/system/sys_info.h +++ b/chromium/base/system/sys_info.h @@ -160,6 +160,10 @@ class BASE_EXPORT SysInfo { // Returns the kernel version of the host operating system. static std::string KernelVersion(); + + // Crashes if running on Chrome OS non-test image. Use only for really + // sensitive and risky use cases. + static void CrashIfChromeOSNonTestImage(); #endif // defined(OS_CHROMEOS) #if defined(OS_ANDROID) diff --git a/chromium/base/system/sys_info_chromeos.cc b/chromium/base/system/sys_info_chromeos.cc index 1d688f13491..6be670fb0d3 100644 --- a/chromium/base/system/sys_info_chromeos.cc +++ b/chromium/base/system/sys_info_chromeos.cc @@ -223,4 +223,21 @@ void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release, g_chrome_os_version_info.Get().Parse(); } +// static +void SysInfo::CrashIfChromeOSNonTestImage() { + if (!IsRunningOnChromeOS()) + return; + + // On the test images etc/lsb-release has a line: + // CHROMEOS_RELEASE_TRACK=testimage-channel. + const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; + const char kTestImageRelease[] = "testimage-channel"; + + std::string track; + CHECK(SysInfo::GetLsbReleaseValue(kChromeOSReleaseTrack, &track)); + + // Crash if can't find test-image marker in the release track. + CHECK_NE(track.find(kTestImageRelease), std::string::npos); +} + } // namespace base diff --git a/chromium/base/system/sys_info_linux.cc b/chromium/base/system/sys_info_linux.cc index d9bfa496fde..f69569fb51c 100644 --- a/chromium/base/system/sys_info_linux.cc +++ b/chromium/base/system/sys_info_linux.cc @@ -8,6 +8,7 @@ #include <stdint.h> #include <limits> +#include <sstream> #include "base/check.h" #include "base/files/file_util.h" diff --git a/chromium/base/system/sys_info_unittest.cc b/chromium/base/system/sys_info_unittest.cc index 68add20e022..6c9c226a92e 100644 --- a/chromium/base/system/sys_info_unittest.cc +++ b/chromium/base/system/sys_info_unittest.cc @@ -21,6 +21,7 @@ #include "base/threading/platform_thread.h" #include "base/time/time.h" #include "build/build_config.h" +#include "testing/gtest/include/gtest/gtest-death-test.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -268,6 +269,34 @@ TEST_F(SysInfoTest, IsRunningOnChromeOS) { EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); } +TEST_F(SysInfoTest, CrashOnBaseImage) { + const char kLsbRelease2[] = + "CHROMEOS_RELEASE_NAME=Chrome OS\n" + "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" + "CHROMEOS_RELEASE_TRACK=stable-channel\n"; + SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); + EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); + EXPECT_DEATH_IF_SUPPORTED({ SysInfo::CrashIfChromeOSNonTestImage(); }, ""); +} + +TEST_F(SysInfoTest, NoCrashOnTestImage) { + const char kLsbRelease2[] = + "CHROMEOS_RELEASE_NAME=Chrome OS\n" + "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" + "CHROMEOS_RELEASE_TRACK=testimage-channel\n"; + SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); + EXPECT_TRUE(SysInfo::IsRunningOnChromeOS()); + // Should not crash. + SysInfo::CrashIfChromeOSNonTestImage(); +} + +TEST_F(SysInfoTest, NoCrashOnLinuxBuild) { + SysInfo::SetChromeOSVersionInfoForTest("", Time()); + EXPECT_FALSE(SysInfo::IsRunningOnChromeOS()); + // Should not crash. + SysInfo::CrashIfChromeOSNonTestImage(); +} + #endif // OS_CHROMEOS } // namespace base |