| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/environment.h" | 5 #include "base/environment.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/sys_info.h" | 7 #include "base/sys_info.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 EXPECT_GT(up_time_1, 0); | 64 EXPECT_GT(up_time_1, 0); |
| 65 EXPECT_GT(up_time_2, up_time_1); | 65 EXPECT_GT(up_time_2, up_time_1); |
| 66 } | 66 } |
| 67 | 67 |
| 68 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
| 69 | 69 |
| 70 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { | 70 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { |
| 71 int32 os_major_version = -1; | 71 int32 os_major_version = -1; |
| 72 int32 os_minor_version = -1; | 72 int32 os_minor_version = -1; |
| 73 int32 os_bugfix_version = -1; | 73 int32 os_bugfix_version = -1; |
| 74 const char* kLsbRelease = | 74 const char kLsbRelease[] = |
| 75 "FOO=1234123.34.5\n" | 75 "FOO=1234123.34.5\n" |
| 76 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; | 76 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; |
| 77 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | 77 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
| 78 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 78 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 79 &os_minor_version, | 79 &os_minor_version, |
| 80 &os_bugfix_version); | 80 &os_bugfix_version); |
| 81 EXPECT_EQ(1, os_major_version); | 81 EXPECT_EQ(1, os_major_version); |
| 82 EXPECT_EQ(2, os_minor_version); | 82 EXPECT_EQ(2, os_minor_version); |
| 83 EXPECT_EQ(3, os_bugfix_version); | 83 EXPECT_EQ(3, os_bugfix_version); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { | 86 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { |
| 87 int32 os_major_version = -1; | 87 int32 os_major_version = -1; |
| 88 int32 os_minor_version = -1; | 88 int32 os_minor_version = -1; |
| 89 int32 os_bugfix_version = -1; | 89 int32 os_bugfix_version = -1; |
| 90 const char* kLsbRelease = | 90 const char kLsbRelease[] = |
| 91 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" | 91 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
| 92 "FOO=1234123.34.5\n"; | 92 "FOO=1234123.34.5\n"; |
| 93 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | 93 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
| 94 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 94 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 95 &os_minor_version, | 95 &os_minor_version, |
| 96 &os_bugfix_version); | 96 &os_bugfix_version); |
| 97 EXPECT_EQ(1, os_major_version); | 97 EXPECT_EQ(1, os_major_version); |
| 98 EXPECT_EQ(2, os_minor_version); | 98 EXPECT_EQ(2, os_minor_version); |
| 99 EXPECT_EQ(3, os_bugfix_version); | 99 EXPECT_EQ(3, os_bugfix_version); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { | 102 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { |
| 103 int32 os_major_version = -1; | 103 int32 os_major_version = -1; |
| 104 int32 os_minor_version = -1; | 104 int32 os_minor_version = -1; |
| 105 int32 os_bugfix_version = -1; | 105 int32 os_bugfix_version = -1; |
| 106 const char* kLsbRelease = "FOO=1234123.34.5\n"; | 106 const char kLsbRelease[] = "FOO=1234123.34.5\n"; |
| 107 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | 107 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
| 108 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 108 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 109 &os_minor_version, | 109 &os_minor_version, |
| 110 &os_bugfix_version); | 110 &os_bugfix_version); |
| 111 EXPECT_EQ(0, os_major_version); | 111 EXPECT_EQ(0, os_major_version); |
| 112 EXPECT_EQ(0, os_minor_version); | 112 EXPECT_EQ(0, os_minor_version); |
| 113 EXPECT_EQ(0, os_bugfix_version); | 113 EXPECT_EQ(0, os_bugfix_version); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) { | 116 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) { |
| 117 const char* kLsbRelease = "CHROMEOS_RELEASE_VERSION=1.2.3.4"; | 117 const char kLsbRelease[] = "CHROMEOS_RELEASE_VERSION=1.2.3.4"; |
| 118 // Use a fake time that can be safely displayed as a string. | 118 // Use a fake time that can be safely displayed as a string. |
| 119 const base::Time lsb_release_time(base::Time::FromDoubleT(12345.6)); | 119 const base::Time lsb_release_time(base::Time::FromDoubleT(12345.6)); |
| 120 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time); | 120 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time); |
| 121 base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime(); | 121 base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime(); |
| 122 EXPECT_DOUBLE_EQ(lsb_release_time.ToDoubleT(), | 122 EXPECT_DOUBLE_EQ(lsb_release_time.ToDoubleT(), |
| 123 parsed_lsb_release_time.ToDoubleT()); | 123 parsed_lsb_release_time.ToDoubleT()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(SysInfoTest, IsRunningOnChromeOS) { | 126 TEST_F(SysInfoTest, IsRunningOnChromeOS) { |
| 127 base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time()); | 127 base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time()); |
| 128 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS()); | 128 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS()); |
| 129 | 129 |
| 130 const char* kLsbRelease1 = | 130 const char kLsbRelease1[] = |
| 131 "CHROMEOS_RELEASE_NAME=Non Chrome OS\n" | 131 "CHROMEOS_RELEASE_NAME=Non Chrome OS\n" |
| 132 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; | 132 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; |
| 133 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time()); | 133 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time()); |
| 134 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS()); | 134 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS()); |
| 135 | 135 |
| 136 const char* kLsbRelease2 = | 136 const char kLsbRelease2[] = |
| 137 "CHROMEOS_RELEASE_NAME=Chrome OS\n" | 137 "CHROMEOS_RELEASE_NAME=Chrome OS\n" |
| 138 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; | 138 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; |
| 139 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time()); | 139 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time()); |
| 140 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS()); | 140 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS()); |
| 141 | 141 |
| 142 const char* kLsbRelease3 = | 142 const char kLsbRelease3[] = |
| 143 "CHROMEOS_RELEASE_NAME=Chromium OS\n"; | 143 "CHROMEOS_RELEASE_NAME=Chromium OS\n"; |
| 144 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease3, base::Time()); | 144 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease3, base::Time()); |
| 145 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS()); | 145 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 #endif // OS_CHROMEOS | 148 #endif // OS_CHROMEOS |
| OLD | NEW |