OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/chromeos/policy/user_policy_test_helper.h" | 5 #include "chrome/browser/chromeos/policy/user_policy_test_helper.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 17 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h" |
18 #include "chrome/browser/policy/profile_policy_connector.h" | 18 #include "chrome/browser/policy/profile_policy_connector.h" |
19 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 19 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
20 #include "chrome/browser/policy/test/local_policy_test_server.h" | 20 #include "chrome/browser/policy/test/local_policy_test_server.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "components/policy/core/browser/browser_policy_connector.h" | 22 #include "components/policy/core/browser/browser_policy_connector.h" |
23 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 23 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
25 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 25 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
26 #include "components/policy/core/common/policy_service.h" | 26 #include "components/policy/core/common/policy_service.h" |
27 #include "components/policy/core/common/policy_switches.h" | 27 #include "components/policy/core/common/policy_switches.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | 84 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, |
85 test_server_->GetServiceURL().spec()); | 85 test_server_->GetServiceURL().spec()); |
86 } | 86 } |
87 | 87 |
88 void UserPolicyTestHelper::WaitForInitialPolicy(Profile* profile) { | 88 void UserPolicyTestHelper::WaitForInitialPolicy(Profile* profile) { |
89 BrowserPolicyConnector* const connector = | 89 BrowserPolicyConnector* const connector = |
90 g_browser_process->browser_policy_connector(); | 90 g_browser_process->browser_policy_connector(); |
91 connector->ScheduleServiceInitialization(0); | 91 connector->ScheduleServiceInitialization(0); |
92 | 92 |
93 UserCloudPolicyManagerChromeOS* const policy_manager = | 93 UserCloudPolicyManagerChromeOS* const policy_manager = |
94 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | 94 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManagerForProfile( |
| 95 profile); |
95 | 96 |
96 // Give a bogus OAuth token to the |policy_manager|. This should make its | 97 // Give a bogus OAuth token to the |policy_manager|. This should make its |
97 // CloudPolicyClient fetch the DMToken. | 98 // CloudPolicyClient fetch the DMToken. |
98 ASSERT_FALSE(policy_manager->core()->client()->is_registered()); | 99 ASSERT_FALSE(policy_manager->core()->client()->is_registered()); |
99 const enterprise_management::DeviceRegisterRequest::Type registration_type = | 100 const enterprise_management::DeviceRegisterRequest::Type registration_type = |
100 enterprise_management::DeviceRegisterRequest::USER; | 101 enterprise_management::DeviceRegisterRequest::USER; |
101 policy_manager->core()->client()->Register( | 102 policy_manager->core()->client()->Register( |
102 registration_type, | 103 registration_type, |
103 enterprise_management::DeviceRegisterRequest::FLAVOR_USER_REGISTRATION, | 104 enterprise_management::DeviceRegisterRequest::FLAVOR_USER_REGISTRATION, |
104 "bogus", std::string(), std::string(), std::string()); | 105 "bogus", std::string(), std::string(), std::string()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const int bytes_written = | 142 const int bytes_written = |
142 base::WriteFile(PolicyFilePath(), policy.data(), policy.size()); | 143 base::WriteFile(PolicyFilePath(), policy.data(), policy.size()); |
143 ASSERT_EQ(static_cast<int>(policy.size()), bytes_written); | 144 ASSERT_EQ(static_cast<int>(policy.size()), bytes_written); |
144 } | 145 } |
145 | 146 |
146 base::FilePath UserPolicyTestHelper::PolicyFilePath() const { | 147 base::FilePath UserPolicyTestHelper::PolicyFilePath() const { |
147 return temp_dir_.GetPath().AppendASCII("policy.json"); | 148 return temp_dir_.GetPath().AppendASCII("policy.json"); |
148 } | 149 } |
149 | 150 |
150 } // namespace policy | 151 } // namespace policy |
OLD | NEW |