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

Unified Diff: chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc

Issue 265013002: Revert of Enable Enterprise enrollment on desktop builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/policy/enterprise_install_attributes_unittest.cc
diff --git a/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc b/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
index 565f22a0ca74f6a09607972305b65bfc301566e1..338735ab51266654ad219b1234a46cdfba1090f0 100644
--- a/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
+++ b/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
@@ -5,18 +5,14 @@
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
-#include "base/path_service.h"
#include "base/run_loop.h"
-#include "base/threading/worker_pool.h"
#include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h"
-#include "chromeos/chromeos_paths.h"
#include "chromeos/cryptohome/cryptohome_util.h"
-#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/fake_cryptohome_client.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -42,15 +38,15 @@
class EnterpriseInstallAttributesTest : public testing::Test {
protected:
- EnterpriseInstallAttributesTest() {}
+ EnterpriseInstallAttributesTest()
+ : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
+ install_attributes_(fake_cryptohome_client_.get()) {
+ fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
+ }
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
- chromeos::FILE_INSTALL_ATTRIBUTES, GetTempPath(), true, false));
chromeos::DBusThreadManager::InitializeWithStub();
- install_attributes_.reset(new EnterpriseInstallAttributes(
- chromeos::DBusThreadManager::Get()->GetCryptohomeClient()));
}
virtual void TearDown() OVERRIDE {
@@ -58,8 +54,7 @@
}
base::FilePath GetTempPath() const {
- base::FilePath temp_path = base::MakeAbsoluteFilePath(temp_dir_.path());
- return temp_path.Append("install_attrs_test");
+ return temp_dir_.path().Append("install_attrs_test");
}
void SetAttribute(
@@ -74,7 +69,8 @@
base::MessageLoopForUI message_loop_;
base::ScopedTempDir temp_dir_;
- scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
+ scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
+ EnterpriseInstallAttributes install_attributes_;
EnterpriseInstallAttributes::LockResult LockDeviceAndWaitForResult(
const std::string& user,
@@ -82,11 +78,8 @@
const std::string& device_id) {
base::RunLoop loop;
EnterpriseInstallAttributes::LockResult result;
- install_attributes_->LockDevice(
- user,
- device_mode,
- device_id,
- base::Bind(&CopyLockResult, &loop, &result));
+ install_attributes_.LockDevice(user, device_mode, device_id,
+ base::Bind(&CopyLockResult, &loop, &result));
loop.Run();
return result;
}
@@ -125,81 +118,81 @@
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_EQ(gaia::CanonicalizeEmail(kTestUserCanonicalize),
- install_attributes_->GetRegistrationUser());
+ install_attributes_.GetRegistrationUser());
}
TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_FALSE(install_attributes_->IsEnterpriseDevice());
- ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
- LockDeviceAndWaitForResult(
- kTestUser,
- DEVICE_MODE_ENTERPRISE,
- kTestDeviceId));
- EXPECT_TRUE(install_attributes_->IsEnterpriseDevice());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_FALSE(install_attributes_.IsEnterpriseDevice());
+ ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
+ LockDeviceAndWaitForResult(
+ kTestUser,
+ DEVICE_MODE_ENTERPRISE,
+ kTestDeviceId));
+ EXPECT_TRUE(install_attributes_.IsEnterpriseDevice());
}
TEST_F(EnterpriseInstallAttributesTest, GetDomain) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(std::string(), install_attributes_->GetDomain());
- ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
- LockDeviceAndWaitForResult(
- kTestUser,
- DEVICE_MODE_ENTERPRISE,
- kTestDeviceId));
- EXPECT_EQ(kTestDomain, install_attributes_->GetDomain());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(std::string(), install_attributes_.GetDomain());
+ ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
+ LockDeviceAndWaitForResult(
+ kTestUser,
+ DEVICE_MODE_ENTERPRISE,
+ kTestDeviceId));
+ EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
}
TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(std::string(), install_attributes_->GetRegistrationUser());
- ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
- LockDeviceAndWaitForResult(
- kTestUser,
- DEVICE_MODE_ENTERPRISE,
- kTestDeviceId));
- EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser());
+ ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
+ LockDeviceAndWaitForResult(
+ kTestUser,
+ DEVICE_MODE_ENTERPRISE,
+ kTestDeviceId));
+ EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
}
TEST_F(EnterpriseInstallAttributesTest, GetDeviceId) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(std::string(), install_attributes_->GetDeviceId());
- ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
- LockDeviceAndWaitForResult(
- kTestUser,
- DEVICE_MODE_ENTERPRISE,
- kTestDeviceId));
- EXPECT_EQ(kTestDeviceId, install_attributes_->GetDeviceId());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(std::string(), install_attributes_.GetDeviceId());
+ ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
+ LockDeviceAndWaitForResult(
+ kTestUser,
+ DEVICE_MODE_ENTERPRISE,
+ kTestDeviceId));
+ EXPECT_EQ(kTestDeviceId, install_attributes_.GetDeviceId());
}
TEST_F(EnterpriseInstallAttributesTest, GetMode) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
LockDeviceAndWaitForResult(
kTestUser,
DEVICE_MODE_RETAIL_KIOSK,
kTestDeviceId));
EXPECT_EQ(DEVICE_MODE_RETAIL_KIOSK,
- install_attributes_->GetMode());
+ install_attributes_.GetMode());
}
TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
// Lock the attributes empty.
ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
base::RunLoop loop;
- install_attributes_->ReadImmutableAttributes(loop.QuitClosure());
+ install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
loop.Run();
ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
- EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_->GetMode());
+ EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_.GetMode());
}
TEST_F(EnterpriseInstallAttributesTest, ConsumerKioskDevice) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
// Lock the attributes for consumer kiosk.
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
LockDeviceAndWaitForResult(
@@ -209,13 +202,13 @@
ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH,
- install_attributes_->GetMode());
- ASSERT_TRUE(install_attributes_->IsConsumerKioskDeviceWithAutoLaunch());
+ install_attributes_.GetMode());
+ ASSERT_TRUE(install_attributes_.IsConsumerKioskDeviceWithAutoLaunch());
}
TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) {
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
// Lock the attributes as if it was done from older Chrome version.
ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"));
@@ -223,14 +216,14 @@
EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser));
ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
base::RunLoop loop;
- install_attributes_->ReadImmutableAttributes(loop.QuitClosure());
+ install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
loop.Run();
ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
- EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode());
- EXPECT_EQ(kTestDomain, install_attributes_->GetDomain());
- EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser());
- EXPECT_EQ("", install_attributes_->GetDeviceId());
+ EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_.GetMode());
+ EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
+ EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
+ EXPECT_EQ("", install_attributes_.GetDeviceId());
}
TEST_F(EnterpriseInstallAttributesTest, ReadCacheFile) {
@@ -242,11 +235,11 @@
const std::string blob(install_attrs_proto.SerializeAsString());
ASSERT_EQ(static_cast<int>(blob.size()),
base::WriteFile(GetTempPath(), blob.c_str(), blob.size()));
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode());
- EXPECT_EQ(kTestDomain, install_attributes_->GetDomain());
- EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser());
- EXPECT_EQ("", install_attributes_->GetDeviceId());
+ install_attributes_.ReadCacheFile(GetTempPath());
+ EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_.GetMode());
+ EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
+ EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
+ EXPECT_EQ("", install_attributes_.GetDeviceId());
}
TEST_F(EnterpriseInstallAttributesTest, ReadCacheFileForConsumerKiosk) {
@@ -256,38 +249,12 @@
const std::string blob(install_attrs_proto.SerializeAsString());
ASSERT_EQ(static_cast<int>(blob.size()),
base::WriteFile(GetTempPath(), blob.c_str(), blob.size()));
- install_attributes_->ReadCacheFile(GetTempPath());
+ install_attributes_.ReadCacheFile(GetTempPath());
EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH,
- install_attributes_->GetMode());
- EXPECT_EQ("", install_attributes_->GetDomain());
- EXPECT_EQ("", install_attributes_->GetRegistrationUser());
- EXPECT_EQ("", install_attributes_->GetDeviceId());
-}
-
-TEST_F(EnterpriseInstallAttributesTest, VerifyFakeInstallAttributesCache) {
- // This test verifies that FakeCryptohomeClient::InstallAttributesFinalize
- // writes a cache that EnterpriseInstallAttributes::ReadCacheFile accepts.
-
- // Verify that no attributes are initially set.
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ("", install_attributes_->GetRegistrationUser());
-
- // Write test values.
- ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
- EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"));
- ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
- EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser));
- ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
- // Wait for the async write.
- base::RunLoop loop;
- base::WorkerPool::PostTaskAndReply(
- FROM_HERE, base::Bind(&base::DoNothing), loop.QuitClosure(), false);
- loop.Run();
-
- // Verify that EnterpriseInstallAttributes correctly decodes the stub
- // cache file.
- install_attributes_->ReadCacheFile(GetTempPath());
- EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser());
+ install_attributes_.GetMode());
+ EXPECT_EQ("", install_attributes_.GetDomain());
+ EXPECT_EQ("", install_attributes_.GetRegistrationUser());
+ EXPECT_EQ("", install_attributes_.GetDeviceId());
}
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698