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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/hwid_checker_unittest.cc
diff --git a/chrome/browser/chromeos/login/hwid_checker_unittest.cc b/chrome/browser/chromeos/login/hwid_checker_unittest.cc
index 6badad83bc89429acd35b4758db576c6e0cdae63..582665e3c609233ff8e40d6c81e4da140ee02566 100644
--- a/chrome/browser/chromeos/login/hwid_checker_unittest.cc
+++ b/chrome/browser/chromeos/login/hwid_checker_unittest.cc
@@ -128,14 +128,24 @@ TEST(HWIDCheckerTest, KnownHWIDs) {
}
#if defined(GOOGLE_CHROME_BUILD)
+const char kLsbRelease[] =
+ "CHROMEOS_RELEASE_NAME=Chrome OS\n"
+ "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
// Sets a valid Chrome OS version info so IsRunningOnChromeOS() returns true.
-void SetRunningOnChromeOS() {
- const char kLsbRelease[] =
- "CHROMEOS_RELEASE_NAME=Chrome OS\n"
- "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
-}
+class ScopedSetRunningOnChromeOS {
+ public:
+ ScopedSetRunningOnChromeOS(const std::string& lsb_release,
+ const base::Time& lsb_release_time) {
+ base::SysInfo::SetChromeOSVersionInfoForTest(lsb_release, lsb_release_time);
+ }
+ ~ScopedSetRunningOnChromeOS() {
+ base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedSetRunningOnChromeOS);
+};
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.
// Test logic for command line "test-type" switch.
TEST(MachineHWIDCheckerTest, TestSwitch) {
@@ -146,7 +156,7 @@ TEST(MachineHWIDCheckerTest, TestSwitch) {
// THEN IsMachineHWIDCorrect() is always true.
EXPECT_TRUE(IsMachineHWIDCorrect());
- SetRunningOnChromeOS();
+ ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
EXPECT_TRUE(IsMachineHWIDCorrect());
system::ScopedFakeStatisticsProvider fake_statistics_provider;
@@ -160,7 +170,7 @@ TEST(MachineHWIDCheckerTest, TestSwitch) {
// Test logic when not running on Chrome OS.
TEST(MachineHWIDCheckerTest, NotOnChromeOS) {
// GIVEN the OS is not Chrome OS.
- base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
+ ScopedSetRunningOnChromeOS fake_release("", base::Time());
// THEN IsMachineHWIDCorrect() is always true.
EXPECT_TRUE(IsMachineHWIDCorrect());
@@ -176,7 +186,7 @@ TEST(MachineHWIDCheckerTest, NotOnChromeOS) {
// Test logic when running on Chrome OS but the HWID is not present.
TEST(MachineHWIDCheckerTest, OnCrosNoHWID) {
// GIVEN the OS is Chrome OS.
- SetRunningOnChromeOS();
+ ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
// GIVEN the HWID is not present.
system::ScopedFakeStatisticsProvider fake_statistics_provider;
@@ -204,7 +214,7 @@ TEST(MachineHWIDCheckerTest, ValidHWID) {
"DELL HORIZON MAGENTA DVT 4770");
// THEN IsMachineHWIDCorrect() is always true.
- SetRunningOnChromeOS();
+ ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
EXPECT_TRUE(IsMachineHWIDCorrect());
fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
system::kIsVmValueFalse);
@@ -222,7 +232,7 @@ TEST(MachineHWIDCheckerTest, InVM) {
system::kIsVmValueTrue);
// GIVEN the OS is Chrome OS.
- SetRunningOnChromeOS();
+ ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
// THEN IsMachineHWIDCorrect() is always true.
fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
"INVALID_HWID");
@@ -239,7 +249,7 @@ TEST(MachineHWIDCheckerTest, InVM) {
// Test logic when HWID is invalid and we're not in a VM.
TEST(MachineHWIDCheckerTest, InvalidHWIDInVMNotTrue) {
// GIVEN the OS is Chrome OS.
- SetRunningOnChromeOS();
+ ScopedSetRunningOnChromeOS fake_release(kLsbRelease, base::Time());
// GIVEN the HWID is invalid.
system::ScopedFakeStatisticsProvider fake_statistics_provider;

Powered by Google App Engine
This is Rietveld 408576698