Index: chrome/browser/policy/cloud/cloud_policy_browsertest.cc |
diff --git a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc |
index 46c12435675aff33af7dc187fc383b197f51f8d6..4d25fd9c70897b74b9a6894cefdb8ab78721e9fb 100644 |
--- a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc |
+++ b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc |
@@ -43,10 +43,7 @@ |
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h" |
#include "chromeos/chromeos_paths.h" |
-#include "chromeos/dbus/mock_cryptohome_client.h" |
-#include "chromeos/dbus/mock_dbus_thread_manager.h" |
-#include "chromeos/dbus/mock_session_manager_client.h" |
-#include "chromeos/dbus/mock_update_engine_client.h" |
+#include "chromeos/dbus/cryptohome_client.h" |
#else |
#include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
@@ -66,41 +63,6 @@ namespace policy { |
namespace { |
-#if defined(OS_CHROMEOS) |
- |
-const char kSanitizedUsername[] = "0123456789ABCDEF0123456789ABCDEF01234567"; |
- |
-ACTION(GetSanitizedUsername) { |
- MessageLoop::current()->PostTask( |
- FROM_HERE, |
- base::Bind(arg1, chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername)); |
-} |
- |
-ACTION_P(RetrieveUserPolicy, storage) { |
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg0, *storage)); |
-} |
- |
-ACTION_P2(StoreUserPolicy, storage, user_policy_key_file) { |
- // The session_manager stores a copy of the policy key at |
- // /var/run/user_policy/$hash/policy.pub. Simulate that behavior here, so |
- // that the policy signature can be validated. |
- em::PolicyFetchResponse policy; |
- ASSERT_TRUE(policy.ParseFromString(arg0)); |
- if (policy.has_new_public_key()) { |
- ASSERT_TRUE(file_util::CreateDirectory(user_policy_key_file.DirName())); |
- int result = file_util::WriteFile( |
- user_policy_key_file, |
- policy.new_public_key().data(), |
- policy.new_public_key().size()); |
- ASSERT_EQ(static_cast<int>(policy.new_public_key().size()), result); |
- } |
- |
- *storage = arg0; |
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg1, true)); |
-} |
- |
-#endif |
- |
const char* GetTestUser() { |
#if defined(OS_CHROMEOS) |
return chromeos::UserManager::kStubUser; |
@@ -184,29 +146,6 @@ class CloudPolicyTest : public InProcessBrowserTest { |
CommandLine* command_line = CommandLine::ForCurrentProcess(); |
command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); |
- |
-#if defined(OS_CHROMEOS) |
- ASSERT_TRUE(PathService::Override(chromeos::DIR_USER_POLICY_KEYS, |
- user_policy_key_dir())); |
- |
- mock_dbus_thread_manager_ = new chromeos::MockDBusThreadManager(); |
- chromeos::DBusThreadManager::InitializeForTesting( |
- mock_dbus_thread_manager_); |
- EXPECT_CALL(*mock_dbus_thread_manager_->mock_cryptohome_client(), |
- GetSanitizedUsername(_, _)) |
- .WillRepeatedly(GetSanitizedUsername()); |
- EXPECT_CALL(*mock_dbus_thread_manager_->mock_session_manager_client(), |
- StoreUserPolicy(_, _)) |
- .WillRepeatedly(StoreUserPolicy(&session_manager_user_policy_, |
- user_policy_key_file())); |
- EXPECT_CALL(*mock_dbus_thread_manager_->mock_session_manager_client(), |
- RetrieveUserPolicy(_)) |
- .WillRepeatedly(RetrieveUserPolicy(&session_manager_user_policy_)); |
- EXPECT_CALL(*mock_dbus_thread_manager_->mock_update_engine_client(), |
- GetLastStatus()) |
- .Times(1) |
- .WillOnce(Return(chromeos::MockUpdateEngineClient::Status())); |
-#endif |
} |
virtual void SetUpOnMainThread() OVERRIDE { |
@@ -260,18 +199,18 @@ class CloudPolicyTest : public InProcessBrowserTest { |
Mock::VerifyAndClearExpectations(&observer); |
policy_manager->core()->client()->RemoveObserver(&observer); |
EXPECT_TRUE(policy_manager->core()->client()->is_registered()); |
- } |
#if defined(OS_CHROMEOS) |
- base::FilePath user_policy_key_dir() { |
- return temp_dir_.path().AppendASCII("user_policy"); |
- } |
- |
- base::FilePath user_policy_key_file() { |
- return user_policy_key_dir().AppendASCII(kSanitizedUsername) |
- .AppendASCII("policy.pub"); |
- } |
+ // Get the path to the user policy key file. |
+ base::FilePath user_policy_key_dir; |
+ ASSERT_TRUE( |
+ PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &user_policy_key_dir)); |
+ std::string sanitized_username = |
+ chromeos::CryptohomeClient::GetStubSanitizedUsername(GetTestUser()); |
+ user_policy_key_file_ = user_policy_key_dir.AppendASCII(sanitized_username) |
+ .AppendASCII("policy.pub"); |
#endif |
+ } |
PolicyService* GetPolicyService() { |
ProfilePolicyConnector* profile_connector = |
@@ -291,11 +230,7 @@ class CloudPolicyTest : public InProcessBrowserTest { |
base::ScopedTempDir temp_dir_; |
scoped_ptr<LocalPolicyTestServer> test_server_; |
- |
-#if defined(OS_CHROMEOS) |
- std::string session_manager_user_policy_; |
- chromeos::MockDBusThreadManager* mock_dbus_thread_manager_; |
-#endif |
+ base::FilePath user_policy_key_file_; |
}; |
IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) { |
@@ -337,7 +272,7 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) { |
// Read the initial key. |
std::string initial_key; |
ASSERT_TRUE( |
- file_util::ReadFileToString(user_policy_key_file(), &initial_key)); |
+ file_util::ReadFileToString(user_policy_key_file_, &initial_key)); |
PolicyMap empty; |
EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( |
@@ -359,7 +294,7 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) { |
// Verify that the key was rotated. |
std::string rotated_key; |
ASSERT_TRUE( |
- file_util::ReadFileToString(user_policy_key_file(), &rotated_key)); |
+ file_util::ReadFileToString(user_policy_key_file_, &rotated_key)); |
EXPECT_NE(rotated_key, initial_key); |
// Another refresh using the same key won't rotate it again. |
@@ -372,7 +307,7 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) { |
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
std::string current_key; |
ASSERT_TRUE( |
- file_util::ReadFileToString(user_policy_key_file(), ¤t_key)); |
+ file_util::ReadFileToString(user_policy_key_file_, ¤t_key)); |
EXPECT_EQ(rotated_key, current_key); |
} |
#endif |