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

Side by Side Diff: chrome/browser/policy/cloud/device_management_service_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (interceptor_) 113 if (interceptor_)
114 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); 114 interceptor_->PushJobCallback(base::Bind(&ResponseJob));
115 } 115 }
116 116
117 void PerformRegistration() { 117 void PerformRegistration() {
118 ExpectRequest(); 118 ExpectRequest();
119 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 119 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
120 .WillOnce( 120 .WillOnce(
121 DoAll(Invoke(this, 121 DoAll(Invoke(this,
122 &DeviceManagementServiceIntegrationTest::RecordToken), 122 &DeviceManagementServiceIntegrationTest::RecordToken),
123 InvokeWithoutArgs(MessageLoop::current(), 123 InvokeWithoutArgs(base::MessageLoop::current(),
124 &MessageLoop::Quit))); 124 &base::MessageLoop::Quit)));
125 scoped_ptr<DeviceManagementRequestJob> job( 125 scoped_ptr<DeviceManagementRequestJob> job(
126 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); 126 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION));
127 job->SetGaiaToken("gaia_auth_token"); 127 job->SetGaiaToken("gaia_auth_token");
128 job->SetOAuthToken("oauth_token"); 128 job->SetOAuthToken("oauth_token");
129 job->SetClientID("testid"); 129 job->SetClientID("testid");
130 job->GetRequest()->mutable_register_request(); 130 job->GetRequest()->mutable_register_request();
131 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 131 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
132 base::Unretained(this))); 132 base::Unretained(this)));
133 MessageLoop::current()->Run(); 133 base::MessageLoop::current()->Run();
134 } 134 }
135 135
136 virtual void SetUpOnMainThread() OVERRIDE { 136 virtual void SetUpOnMainThread() OVERRIDE {
137 std::string service_url((this->*(GetParam()))()); 137 std::string service_url((this->*(GetParam()))());
138 service_.reset(new DeviceManagementService(service_url)); 138 service_.reset(new DeviceManagementService(service_url));
139 service_->ScheduleInitialization(0); 139 service_->ScheduleInitialization(0);
140 } 140 }
141 141
142 virtual void CleanUpOnMainThread() OVERRIDE { 142 virtual void CleanUpOnMainThread() OVERRIDE {
143 service_.reset(); 143 service_.reset();
(...skipping 27 matching lines...) Expand all
171 171
172 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, 172 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest,
173 ApiAuthCodeFetch) { 173 ApiAuthCodeFetch) {
174 PerformRegistration(); 174 PerformRegistration();
175 175
176 ExpectRequest(); 176 ExpectRequest();
177 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 177 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
178 .WillOnce( 178 .WillOnce(
179 DoAll(Invoke(this, 179 DoAll(Invoke(this,
180 &DeviceManagementServiceIntegrationTest::RecordAuthCode), 180 &DeviceManagementServiceIntegrationTest::RecordAuthCode),
181 InvokeWithoutArgs(MessageLoop::current(), 181 InvokeWithoutArgs(base::MessageLoop::current(),
182 &MessageLoop::Quit))); 182 &base::MessageLoop::Quit)));
183 scoped_ptr<DeviceManagementRequestJob> job(service_->CreateJob( 183 scoped_ptr<DeviceManagementRequestJob> job(service_->CreateJob(
184 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH)); 184 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH));
185 job->SetDMToken(token_); 185 job->SetDMToken(token_);
186 job->SetClientID("testid"); 186 job->SetClientID("testid");
187 em::DeviceServiceApiAccessRequest* request = 187 em::DeviceServiceApiAccessRequest* request =
188 job->GetRequest()->mutable_service_api_access_request(); 188 job->GetRequest()->mutable_service_api_access_request();
189 request->add_auth_scope("authScope4Test"); 189 request->add_auth_scope("authScope4Test");
190 request->set_oauth2_client_id("oauth2ClientId4Test"); 190 request->set_oauth2_client_id("oauth2ClientId4Test");
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 ASSERT_EQ("fake_auth_code", robot_auth_code_); 194 ASSERT_EQ("fake_auth_code", robot_auth_code_);
195 } 195 }
196 196
197 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { 197 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) {
198 PerformRegistration(); 198 PerformRegistration();
199 199
200 ExpectRequest(); 200 ExpectRequest();
201 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 201 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
202 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); 202 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
203 &base::MessageLoop::Quit));
203 scoped_ptr<DeviceManagementRequestJob> job( 204 scoped_ptr<DeviceManagementRequestJob> job(
204 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); 205 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH));
205 job->SetDMToken(token_); 206 job->SetDMToken(token_);
206 job->SetUserAffiliation(USER_AFFILIATION_NONE); 207 job->SetUserAffiliation(USER_AFFILIATION_NONE);
207 job->SetClientID("testid"); 208 job->SetClientID("testid");
208 em::DevicePolicyRequest* request = 209 em::DevicePolicyRequest* request =
209 job->GetRequest()->mutable_policy_request(); 210 job->GetRequest()->mutable_policy_request();
210 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType); 211 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType);
211 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 212 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
212 base::Unretained(this))); 213 base::Unretained(this)));
213 MessageLoop::current()->Run(); 214 base::MessageLoop::current()->Run();
214 } 215 }
215 216
216 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) { 217 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) {
217 PerformRegistration(); 218 PerformRegistration();
218 219
219 ExpectRequest(); 220 ExpectRequest();
220 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 221 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
221 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); 222 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
223 &base::MessageLoop::Quit));
222 scoped_ptr<DeviceManagementRequestJob> job( 224 scoped_ptr<DeviceManagementRequestJob> job(
223 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); 225 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION));
224 job->SetDMToken(token_); 226 job->SetDMToken(token_);
225 job->SetClientID("testid"); 227 job->SetClientID("testid");
226 job->GetRequest()->mutable_unregister_request(); 228 job->GetRequest()->mutable_unregister_request();
227 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 229 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
228 base::Unretained(this))); 230 base::Unretained(this)));
229 MessageLoop::current()->Run(); 231 base::MessageLoop::current()->Run();
230 } 232 }
231 233
232 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) { 234 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) {
233 ExpectRequest(); 235 ExpectRequest();
234 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 236 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
235 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); 237 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
238 &base::MessageLoop::Quit));
236 scoped_ptr<DeviceManagementRequestJob> job( 239 scoped_ptr<DeviceManagementRequestJob> job(
237 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT)); 240 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT));
238 job->SetClientID("testid"); 241 job->SetClientID("testid");
239 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0); 242 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0);
240 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1); 243 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1);
241 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 244 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
242 base::Unretained(this))); 245 base::Unretained(this)));
243 MessageLoop::current()->Run(); 246 base::MessageLoop::current()->Run();
244 } 247 }
245 248
246 INSTANTIATE_TEST_CASE_P( 249 INSTANTIATE_TEST_CASE_P(
247 DeviceManagementServiceIntegrationTestInstance, 250 DeviceManagementServiceIntegrationTestInstance,
248 DeviceManagementServiceIntegrationTest, 251 DeviceManagementServiceIntegrationTest,
249 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, 252 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse,
250 &DeviceManagementServiceIntegrationTest::InitTestServer)); 253 &DeviceManagementServiceIntegrationTest::InitTestServer));
251 254
252 } // namespace policy 255 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698