| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 10 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 void ExpectRequest() { | 103 void ExpectRequest() { |
| 104 if (interceptor_) | 104 if (interceptor_) |
| 105 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); | 105 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void PerformRegistration() { | 108 void PerformRegistration() { |
| 109 ExpectRequest(); | 109 ExpectRequest(); |
| 110 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) | 110 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)).WillOnce(DoAll( |
| 111 .WillOnce( | 111 Invoke(this, &DeviceManagementServiceIntegrationTest::RecordToken), |
| 112 DoAll(Invoke(this, | 112 InvokeWithoutArgs(base::MessageLoop::current(), |
| 113 &DeviceManagementServiceIntegrationTest::RecordToken), | 113 &base::MessageLoop::Quit))); |
| 114 InvokeWithoutArgs(MessageLoop::current(), | |
| 115 &MessageLoop::Quit))); | |
| 116 scoped_ptr<DeviceManagementRequestJob> job( | 114 scoped_ptr<DeviceManagementRequestJob> job( |
| 117 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); | 115 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); |
| 118 job->SetGaiaToken("gaia_auth_token"); | 116 job->SetGaiaToken("gaia_auth_token"); |
| 119 job->SetOAuthToken("oauth_token"); | 117 job->SetOAuthToken("oauth_token"); |
| 120 job->SetClientID("testid"); | 118 job->SetClientID("testid"); |
| 121 job->GetRequest()->mutable_register_request(); | 119 job->GetRequest()->mutable_register_request(); |
| 122 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, | 120 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, |
| 123 base::Unretained(this))); | 121 base::Unretained(this))); |
| 124 MessageLoop::current()->Run(); | 122 base::MessageLoop::current()->Run(); |
| 125 } | 123 } |
| 126 | 124 |
| 127 virtual void SetUpOnMainThread() OVERRIDE { | 125 virtual void SetUpOnMainThread() OVERRIDE { |
| 128 std::string service_url((this->*(GetParam()))()); | 126 std::string service_url((this->*(GetParam()))()); |
| 129 service_.reset(new DeviceManagementService(service_url)); | 127 service_.reset(new DeviceManagementService(service_url)); |
| 130 service_->ScheduleInitialization(0); | 128 service_->ScheduleInitialization(0); |
| 131 } | 129 } |
| 132 | 130 |
| 133 virtual void CleanUpOnMainThread() OVERRIDE { | 131 virtual void CleanUpOnMainThread() OVERRIDE { |
| 134 service_.reset(); | 132 service_.reset(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 156 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { | 154 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { |
| 157 PerformRegistration(); | 155 PerformRegistration(); |
| 158 EXPECT_FALSE(token_.empty()); | 156 EXPECT_FALSE(token_.empty()); |
| 159 } | 157 } |
| 160 | 158 |
| 161 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { | 159 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { |
| 162 PerformRegistration(); | 160 PerformRegistration(); |
| 163 | 161 |
| 164 ExpectRequest(); | 162 ExpectRequest(); |
| 165 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) | 163 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) |
| 166 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); | 164 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), |
| 165 &base::MessageLoop::Quit)); |
| 167 scoped_ptr<DeviceManagementRequestJob> job( | 166 scoped_ptr<DeviceManagementRequestJob> job( |
| 168 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); | 167 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); |
| 169 job->SetDMToken(token_); | 168 job->SetDMToken(token_); |
| 170 job->SetUserAffiliation(USER_AFFILIATION_NONE); | 169 job->SetUserAffiliation(USER_AFFILIATION_NONE); |
| 171 job->SetClientID("testid"); | 170 job->SetClientID("testid"); |
| 172 em::DevicePolicyRequest* request = | 171 em::DevicePolicyRequest* request = |
| 173 job->GetRequest()->mutable_policy_request(); | 172 job->GetRequest()->mutable_policy_request(); |
| 174 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType); | 173 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType); |
| 175 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, | 174 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, |
| 176 base::Unretained(this))); | 175 base::Unretained(this))); |
| 177 MessageLoop::current()->Run(); | 176 base::MessageLoop::current()->Run(); |
| 178 } | 177 } |
| 179 | 178 |
| 180 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) { | 179 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) { |
| 181 PerformRegistration(); | 180 PerformRegistration(); |
| 182 | 181 |
| 183 ExpectRequest(); | 182 ExpectRequest(); |
| 184 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) | 183 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) |
| 185 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); | 184 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), |
| 185 &base::MessageLoop::Quit)); |
| 186 scoped_ptr<DeviceManagementRequestJob> job( | 186 scoped_ptr<DeviceManagementRequestJob> job( |
| 187 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); | 187 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); |
| 188 job->SetDMToken(token_); | 188 job->SetDMToken(token_); |
| 189 job->SetClientID("testid"); | 189 job->SetClientID("testid"); |
| 190 job->GetRequest()->mutable_unregister_request(); | 190 job->GetRequest()->mutable_unregister_request(); |
| 191 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, | 191 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, |
| 192 base::Unretained(this))); | 192 base::Unretained(this))); |
| 193 MessageLoop::current()->Run(); | 193 base::MessageLoop::current()->Run(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) { | 196 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) { |
| 197 ExpectRequest(); | 197 ExpectRequest(); |
| 198 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) | 198 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) |
| 199 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); | 199 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), |
| 200 &base::MessageLoop::Quit)); |
| 200 scoped_ptr<DeviceManagementRequestJob> job( | 201 scoped_ptr<DeviceManagementRequestJob> job( |
| 201 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT)); | 202 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT)); |
| 202 job->SetClientID("testid"); | 203 job->SetClientID("testid"); |
| 203 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0); | 204 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0); |
| 204 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1); | 205 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1); |
| 205 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, | 206 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, |
| 206 base::Unretained(this))); | 207 base::Unretained(this))); |
| 207 MessageLoop::current()->Run(); | 208 base::MessageLoop::current()->Run(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 INSTANTIATE_TEST_CASE_P( | 211 INSTANTIATE_TEST_CASE_P( |
| 211 DeviceManagementServiceIntegrationTestInstance, | 212 DeviceManagementServiceIntegrationTestInstance, |
| 212 DeviceManagementServiceIntegrationTest, | 213 DeviceManagementServiceIntegrationTest, |
| 213 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, | 214 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, |
| 214 &DeviceManagementServiceIntegrationTest::InitTestServer)); | 215 &DeviceManagementServiceIntegrationTest::InitTestServer)); |
| 215 | 216 |
| 216 } // namespace policy | 217 } // namespace policy |
| OLD | NEW |