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

Unified Diff: chrome/browser/chromeos/login/hwid_checker_unittest.cc

Issue 2218703006: Clean up handling of invalid HWID when running ChromeOS in VMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: kSystemVendorKey no longer exists Created 4 years, 4 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 9de664b2607d67d585756d2ab9e3e182ec8c3045..e3b1b64da0c63d432d19e452f9c0c212c726a873 100644
--- a/chrome/browser/chromeos/login/hwid_checker_unittest.cc
+++ b/chrome/browser/chromeos/login/hwid_checker_unittest.cc
@@ -2,8 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/sys_info.h"
+#include "base/test/scoped_command_line.h"
+#include "base/time/time.h"
#include "chrome/browser/chromeos/login/hwid_checker.h"
-
+#include "chromeos/system/fake_statistics_provider.h"
+#include "content/public/common/content_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -123,5 +127,128 @@ TEST(HWIDCheckerTest, KnownHWIDs) {
EXPECT_FALSE(IsHWIDCorrect("SAMS ALPX GAMMA DVT 9247"));
}
-} // namespace chromeos
+#if defined(GOOGLE_CHROME_BUILD)
+
+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());
+}
+
+TEST(MachineHWIDCheckerTest, TestSwitch) {
achuithb 2016/08/11 18:40:16 I think adding a comment describing each test woul
norvez 2016/08/12 10:18:29 Done.
+ // GIVEN test switch is active.
+ base::test::ScopedCommandLine scoped_command_line;
+ scoped_command_line.GetProcessCommandLine()->AppendSwitch(
+ ::switches::kTestType);
achuithb 2016/08/11 18:40:15 Isn't this always true for unittests? Apparently n
+ // THEN IsMachineHWIDCorrect() is always true.
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ SetRunningOnChromeOS();
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "INVALID_HWID");
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+}
+
+TEST(MachineHWIDCheckerTest, NotOnChromeOS) {
+ // GIVEN The OS is not Chrome OS.
+ base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
+ // THEN IsMachineHWIDCorrect() is always true.
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "INVALID_HWID");
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+}
+
+
+TEST(MachineHWIDCheckerTest, OnCrosNoHWID) {
+ // GIVEN The OS is Chrome OS.
+ SetRunningOnChromeOS();
+ // GIVEN The HWID is not present.
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.ClearMachineStatistic(system::kHardwareClassKey);
+ // THEN IsMachineHWIDCorrect() is always false.
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueFalse);
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueTrue);
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+}
+
+TEST(MachineHWIDCheckerTest, ValidHWID) {
+ // GIVEN The HWID is valid
achuithb 2016/08/11 18:40:16 nit: period
norvez 2016/08/12 10:18:29 Done.
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "DELL HORIZON MAGENTA DVT 4770");
+ // THEN IsMachineHWIDCorrect() is always true.
+ SetRunningOnChromeOS();
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueFalse);
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueTrue);
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+}
+
+TEST(MachineHWIDCheckerTest, InVM) {
+ // GIVEN kIsVmKey is kIsVmValueTrue.
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueTrue);
+
+ // GIVEN Any HWID is present.
+ // THEN IsMachineHWIDCorrect() is always true.
+ SetRunningOnChromeOS();
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "INVALID_HWID");
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey, "");
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "DELL HORIZON MAGENTA DVT 4770");
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+}
+
+TEST(MachineHWIDCheckerTest, InvalidHWIDInVMNotTrue) {
+ // GIVEN The OS is Chrome OS.
+ SetRunningOnChromeOS();
+ // GIVEN The HWID is invalid.
+ system::ScopedFakeStatisticsProvider fake_statistics_provider;
+ fake_statistics_provider.SetMachineStatistic(system::kHardwareClassKey,
+ "INVALID_HWID");
+ // GIVEN kIsVmKey is anything but kIsVmValueTrue.
+ // THEN IsMachineHWIDCorrect() is always false.
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ system::kIsVmValueFalse);
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey,
+ "INVALID_VM_KEY");
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, "(error)");
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.SetMachineStatistic(system::kIsVmKey, "");
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+ fake_statistics_provider.ClearMachineStatistic(system::kIsVmKey);
+ EXPECT_FALSE(IsMachineHWIDCorrect());
+}
+
+#else // defined(GOOGLE_CHROME_BUILD)
+
+TEST(MachineHWIDCheckerTest, NonGoogleBuild) {
+ // GIVEN This is not a Google build.
+ // THEN IsMachineHWIDCorrect() is always true.
+ EXPECT_TRUE(IsMachineHWIDCorrect());
+}
+
+#endif // defined(GOOGLE_CHROME_BUILD)
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698