Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1186)

Side by Side Diff: chrome/browser/chromeos/login/hwid_checker_unittest.cc

Issue 2907493002: ChromeOS: Per-user time zone: refactor tests first. (Closed)
Patch Set: Move more code from dependent CL here. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/sys_info.h" 5 #include "base/sys_info.h"
6 #include "base/test/scoped_command_line.h" 6 #include "base/test/scoped_command_line.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/chromeos/login/hwid_checker.h" 8 #include "chrome/browser/chromeos/login/hwid_checker.h"
9 #include "chromeos/system/fake_statistics_provider.h" 9 #include "chromeos/system/fake_statistics_provider.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 EXPECT_FALSE(IsHWIDCorrect("DELL HORIZ0N MAGENTA 8992")); 121 EXPECT_FALSE(IsHWIDCorrect("DELL HORIZ0N MAGENTA 8992"));
122 122
123 EXPECT_TRUE(IsHWIDCorrect("DELL HORIZON MAGENTA DVT 4770")); 123 EXPECT_TRUE(IsHWIDCorrect("DELL HORIZON MAGENTA DVT 4770"));
124 EXPECT_FALSE(IsHWIDCorrect("DELL MAGENTA HORIZON DVT 4770")); 124 EXPECT_FALSE(IsHWIDCorrect("DELL MAGENTA HORIZON DVT 4770"));
125 125
126 EXPECT_TRUE(IsHWIDCorrect("SAMS ALEX GAMMA DVT 9247")); 126 EXPECT_TRUE(IsHWIDCorrect("SAMS ALEX GAMMA DVT 9247"));
127 EXPECT_FALSE(IsHWIDCorrect("SAMS ALPX GAMMA DVT 9247")); 127 EXPECT_FALSE(IsHWIDCorrect("SAMS ALPX GAMMA DVT 9247"));
128 } 128 }
129 129
130 #if defined(GOOGLE_CHROME_BUILD) 130 #if defined(GOOGLE_CHROME_BUILD)
131 const char kLsbRelease[] =
132 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
133 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
131 134
132 // Sets a valid Chrome OS version info so IsRunningOnChromeOS() returns true. 135 // Sets a valid Chrome OS version info so IsRunningOnChromeOS() returns true.
133 void SetRunningOnChromeOS() { 136 class ScopedSetRunningOnChromeOS {
134 const char kLsbRelease[] = 137 public:
135 "CHROMEOS_RELEASE_NAME=Chrome OS\n" 138 ScopedSetRunningOnChromeOS(const std::string& lsb_release,
136 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; 139 const base::Time& lsb_release_time) {
137 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); 140 base::SysInfo::SetChromeOSVersionInfoForTest(lsb_release, lsb_release_time);
138 } 141 }
142 ~ScopedSetRunningOnChromeOS() {
143 base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
144 }
145
146 private:
147 DISALLOW_COPY_AND_ASSIGN(ScopedSetRunningOnChromeOS);
148 };
stevenjb 2017/05/25 21:20:24 Can we go ahead and move this to a separate file s
Alexander Alekseev 2017/05/26 02:18:01 Done.
139 149
140 // Test logic for command line "test-type" switch. 150 // Test logic for command line "test-type" switch.
141 TEST(MachineHWIDCheckerTest, TestSwitch) { 151 TEST(MachineHWIDCheckerTest, TestSwitch) {
142 // GIVEN test switch is active. 152 // GIVEN test switch is active.
143 base::test::ScopedCommandLine scoped_command_line; 153 base::test::ScopedCommandLine scoped_command_line;
144 scoped_command_line.GetProcessCommandLine()->AppendSwitch( 154 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
145 ::switches::kTestType); 155 ::switches::kTestType);
146 156
147 // THEN IsMachineHWIDCorrect() is always true. 157 // THEN IsMachineHWIDCorrect() is always true.
148 EXPECT_TRUE(IsMachineHWIDCorrect()); 158 EXPECT_TRUE(IsMachineHWIDCorrect());
149 SetRunningOnChromeOS(); 159 ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
150 EXPECT_TRUE(IsMachineHWIDCorrect()); 160 EXPECT_TRUE(IsMachineHWIDCorrect());
151 161
152 system::ScopedFakeStatisticsProvider fake_statistics_provider; 162 system::ScopedFakeStatisticsProvider fake_statistics_provider;
153 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 163 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
154 "INVALID_HWID"); 164 "INVALID_HWID");
155 EXPECT_TRUE(IsMachineHWIDCorrect()); 165 EXPECT_TRUE(IsMachineHWIDCorrect());
156 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey); 166 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
157 EXPECT_TRUE(IsMachineHWIDCorrect()); 167 EXPECT_TRUE(IsMachineHWIDCorrect());
158 } 168 }
159 169
160 // Test logic when not running on Chrome OS. 170 // Test logic when not running on Chrome OS.
161 TEST(MachineHWIDCheckerTest, NotOnChromeOS) { 171 TEST(MachineHWIDCheckerTest, NotOnChromeOS) {
162 // GIVEN the OS is not Chrome OS. 172 // GIVEN the OS is not Chrome OS.
163 base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time()); 173 ScopedSetRunningOnChromeOS fake_release("", base::Time());
164 174
165 // THEN IsMachineHWIDCorrect() is always true. 175 // THEN IsMachineHWIDCorrect() is always true.
166 EXPECT_TRUE(IsMachineHWIDCorrect()); 176 EXPECT_TRUE(IsMachineHWIDCorrect());
167 177
168 system::ScopedFakeStatisticsProvider fake_statistics_provider; 178 system::ScopedFakeStatisticsProvider fake_statistics_provider;
169 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 179 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
170 "INVALID_HWID"); 180 "INVALID_HWID");
171 EXPECT_TRUE(IsMachineHWIDCorrect()); 181 EXPECT_TRUE(IsMachineHWIDCorrect());
172 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey); 182 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
173 EXPECT_TRUE(IsMachineHWIDCorrect()); 183 EXPECT_TRUE(IsMachineHWIDCorrect());
174 } 184 }
175 185
176 // Test logic when running on Chrome OS but the HWID is not present. 186 // Test logic when running on Chrome OS but the HWID is not present.
177 TEST(MachineHWIDCheckerTest, OnCrosNoHWID) { 187 TEST(MachineHWIDCheckerTest, OnCrosNoHWID) {
178 // GIVEN the OS is Chrome OS. 188 // GIVEN the OS is Chrome OS.
179 SetRunningOnChromeOS(); 189 ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
180 190
181 // GIVEN the HWID is not present. 191 // GIVEN the HWID is not present.
182 system::ScopedFakeStatisticsProvider fake_statistics_provider; 192 system::ScopedFakeStatisticsProvider fake_statistics_provider;
183 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey); 193 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
184 194
185 // WHEN Chrome OS is running in a VM. 195 // WHEN Chrome OS is running in a VM.
186 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 196 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
187 system::kIsVmValueTrue); 197 system::kIsVmValueTrue);
188 // THEN IsMachineHWIDCorrect() is true. 198 // THEN IsMachineHWIDCorrect() is true.
189 EXPECT_TRUE(IsMachineHWIDCorrect()); 199 EXPECT_TRUE(IsMachineHWIDCorrect());
190 // WHEN Chrome OS is not running in a VM. 200 // WHEN Chrome OS is not running in a VM.
191 fake_statistics_provider.ClearMachineStatistic(system::kIsVmKey); 201 fake_statistics_provider.ClearMachineStatistic(system::kIsVmKey);
192 // THEN IsMachineHWIDCorrect() is always false. 202 // THEN IsMachineHWIDCorrect() is always false.
193 EXPECT_FALSE(IsMachineHWIDCorrect()); 203 EXPECT_FALSE(IsMachineHWIDCorrect());
194 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 204 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
195 system::kIsVmValueFalse); 205 system::kIsVmValueFalse);
196 EXPECT_FALSE(IsMachineHWIDCorrect()); 206 EXPECT_FALSE(IsMachineHWIDCorrect());
197 } 207 }
198 208
199 // Test logic when the HWID is valid. 209 // Test logic when the HWID is valid.
200 TEST(MachineHWIDCheckerTest, ValidHWID) { 210 TEST(MachineHWIDCheckerTest, ValidHWID) {
201 // GIVEN the HWID is valid. 211 // GIVEN the HWID is valid.
202 system::ScopedFakeStatisticsProvider fake_statistics_provider; 212 system::ScopedFakeStatisticsProvider fake_statistics_provider;
203 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 213 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
204 "DELL HORIZON MAGENTA DVT 4770"); 214 "DELL HORIZON MAGENTA DVT 4770");
205 215
206 // THEN IsMachineHWIDCorrect() is always true. 216 // THEN IsMachineHWIDCorrect() is always true.
207 SetRunningOnChromeOS(); 217 ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
208 EXPECT_TRUE(IsMachineHWIDCorrect()); 218 EXPECT_TRUE(IsMachineHWIDCorrect());
209 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 219 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
210 system::kIsVmValueFalse); 220 system::kIsVmValueFalse);
211 EXPECT_TRUE(IsMachineHWIDCorrect()); 221 EXPECT_TRUE(IsMachineHWIDCorrect());
212 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 222 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
213 system::kIsVmValueTrue); 223 system::kIsVmValueTrue);
214 EXPECT_TRUE(IsMachineHWIDCorrect()); 224 EXPECT_TRUE(IsMachineHWIDCorrect());
215 } 225 }
216 226
217 // Test logic when running inside a VM. 227 // Test logic when running inside a VM.
218 TEST(MachineHWIDCheckerTest, InVM) { 228 TEST(MachineHWIDCheckerTest, InVM) {
219 // GIVEN kIsVmKey is kIsVmValueTrue. 229 // GIVEN kIsVmKey is kIsVmValueTrue.
220 system::ScopedFakeStatisticsProvider fake_statistics_provider; 230 system::ScopedFakeStatisticsProvider fake_statistics_provider;
221 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 231 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
222 system::kIsVmValueTrue); 232 system::kIsVmValueTrue);
223 233
224 // GIVEN the OS is Chrome OS. 234 // GIVEN the OS is Chrome OS.
225 SetRunningOnChromeOS(); 235 ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
226 // THEN IsMachineHWIDCorrect() is always true. 236 // THEN IsMachineHWIDCorrect() is always true.
227 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 237 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
228 "INVALID_HWID"); 238 "INVALID_HWID");
229 EXPECT_TRUE(IsMachineHWIDCorrect()); 239 EXPECT_TRUE(IsMachineHWIDCorrect());
230 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, ""); 240 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, "");
231 EXPECT_TRUE(IsMachineHWIDCorrect()); 241 EXPECT_TRUE(IsMachineHWIDCorrect());
232 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 242 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
233 "DELL HORIZON MAGENTA DVT 4770"); 243 "DELL HORIZON MAGENTA DVT 4770");
234 EXPECT_TRUE(IsMachineHWIDCorrect()); 244 EXPECT_TRUE(IsMachineHWIDCorrect());
235 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey); 245 fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
236 EXPECT_TRUE(IsMachineHWIDCorrect()); 246 EXPECT_TRUE(IsMachineHWIDCorrect());
237 } 247 }
238 248
239 // Test logic when HWID is invalid and we're not in a VM. 249 // Test logic when HWID is invalid and we're not in a VM.
240 TEST(MachineHWIDCheckerTest, InvalidHWIDInVMNotTrue) { 250 TEST(MachineHWIDCheckerTest, InvalidHWIDInVMNotTrue) {
241 // GIVEN the OS is Chrome OS. 251 // GIVEN the OS is Chrome OS.
242 SetRunningOnChromeOS(); 252 ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
243 253
244 // GIVEN the HWID is invalid. 254 // GIVEN the HWID is invalid.
245 system::ScopedFakeStatisticsProvider fake_statistics_provider; 255 system::ScopedFakeStatisticsProvider fake_statistics_provider;
246 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, 256 fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
247 "INVALID_HWID"); 257 "INVALID_HWID");
248 258
249 // GIVEN kIsVmKey is anything but kIsVmValueTrue. 259 // GIVEN kIsVmKey is anything but kIsVmValueTrue.
250 // THEN IsMachineHWIDCorrect() is always false. 260 // THEN IsMachineHWIDCorrect() is always false.
251 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, 261 fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
252 system::kIsVmValueFalse); 262 system::kIsVmValueFalse);
(...skipping 14 matching lines...) Expand all
267 // Test non-Google Chromium builds. 277 // Test non-Google Chromium builds.
268 TEST(MachineHWIDCheckerTest, NonGoogleBuild) { 278 TEST(MachineHWIDCheckerTest, NonGoogleBuild) {
269 // GIVEN this is not a Google build. 279 // GIVEN this is not a Google build.
270 // THEN IsMachineHWIDCorrect() is always true. 280 // THEN IsMachineHWIDCorrect() is always true.
271 EXPECT_TRUE(IsMachineHWIDCorrect()); 281 EXPECT_TRUE(IsMachineHWIDCorrect());
272 } 282 }
273 283
274 #endif // defined(GOOGLE_CHROME_BUILD) 284 #endif // defined(GOOGLE_CHROME_BUILD)
275 } // namespace chromeos 285 } // namespace chromeos
276 286
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698