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

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

Issue 1395103003: Don't use base::MessageLoop::{Quit,QuitClosure} in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 protected: 119 protected:
120 void ExpectRequest() { 120 void ExpectRequest() {
121 if (interceptor_) 121 if (interceptor_)
122 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); 122 interceptor_->PushJobCallback(base::Bind(&ResponseJob));
123 } 123 }
124 124
125 void PerformRegistration() { 125 void PerformRegistration() {
126 ExpectRequest(); 126 ExpectRequest();
127 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 127 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
128 .WillOnce( 128 .WillOnce(DoAll(
129 DoAll(Invoke(this, 129 Invoke(this, &DeviceManagementServiceIntegrationTest::RecordToken),
130 &DeviceManagementServiceIntegrationTest::RecordToken), 130 InvokeWithoutArgs(base::MessageLoop::current(),
131 InvokeWithoutArgs(base::MessageLoop::current(), 131 &base::MessageLoop::QuitWhenIdle)));
132 &base::MessageLoop::Quit)));
133 scoped_ptr<DeviceManagementRequestJob> job( 132 scoped_ptr<DeviceManagementRequestJob> job(
134 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION, 133 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION,
135 g_browser_process->system_request_context())); 134 g_browser_process->system_request_context()));
136 job->SetGaiaToken("gaia_auth_token"); 135 job->SetGaiaToken("gaia_auth_token");
137 job->SetOAuthToken("oauth_token"); 136 job->SetOAuthToken("oauth_token");
138 job->SetClientID("testid"); 137 job->SetClientID("testid");
139 job->GetRequest()->mutable_register_request(); 138 job->GetRequest()->mutable_register_request();
140 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 139 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
141 base::Unretained(this))); 140 base::Unretained(this)));
142 base::MessageLoop::current()->Run(); 141 base::MessageLoop::current()->Run();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 PerformRegistration(); 178 PerformRegistration();
180 EXPECT_FALSE(token_.empty()); 179 EXPECT_FALSE(token_.empty());
181 } 180 }
182 181
183 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, 182 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest,
184 ApiAuthCodeFetch) { 183 ApiAuthCodeFetch) {
185 PerformRegistration(); 184 PerformRegistration();
186 185
187 ExpectRequest(); 186 ExpectRequest();
188 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 187 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
189 .WillOnce( 188 .WillOnce(DoAll(
190 DoAll(Invoke(this, 189 Invoke(this, &DeviceManagementServiceIntegrationTest::RecordAuthCode),
191 &DeviceManagementServiceIntegrationTest::RecordAuthCode), 190 InvokeWithoutArgs(base::MessageLoop::current(),
192 InvokeWithoutArgs(base::MessageLoop::current(), 191 &base::MessageLoop::QuitWhenIdle)));
193 &base::MessageLoop::Quit)));
194 scoped_ptr<DeviceManagementRequestJob> job(service_->CreateJob( 192 scoped_ptr<DeviceManagementRequestJob> job(service_->CreateJob(
195 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH, 193 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH,
196 g_browser_process->system_request_context())); 194 g_browser_process->system_request_context()));
197 job->SetDMToken(token_); 195 job->SetDMToken(token_);
198 job->SetClientID("testid"); 196 job->SetClientID("testid");
199 em::DeviceServiceApiAccessRequest* request = 197 em::DeviceServiceApiAccessRequest* request =
200 job->GetRequest()->mutable_service_api_access_request(); 198 job->GetRequest()->mutable_service_api_access_request();
201 request->add_auth_scope("authScope4Test"); 199 request->add_auth_scope("authScope4Test");
202 request->set_oauth2_client_id("oauth2ClientId4Test"); 200 request->set_oauth2_client_id("oauth2ClientId4Test");
203 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 201 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
204 base::Unretained(this))); 202 base::Unretained(this)));
205 base::MessageLoop::current()->Run(); 203 base::MessageLoop::current()->Run();
206 ASSERT_EQ("fake_auth_code", robot_auth_code_); 204 ASSERT_EQ("fake_auth_code", robot_auth_code_);
207 } 205 }
208 206
209 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { 207 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) {
210 PerformRegistration(); 208 PerformRegistration();
211 209
212 ExpectRequest(); 210 ExpectRequest();
213 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 211 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
214 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), 212 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
215 &base::MessageLoop::Quit)); 213 &base::MessageLoop::QuitWhenIdle));
216 scoped_ptr<DeviceManagementRequestJob> job( 214 scoped_ptr<DeviceManagementRequestJob> job(
217 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, 215 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH,
218 g_browser_process->system_request_context())); 216 g_browser_process->system_request_context()));
219 job->SetDMToken(token_); 217 job->SetDMToken(token_);
220 job->SetClientID("testid"); 218 job->SetClientID("testid");
221 em::DevicePolicyRequest* request = 219 em::DevicePolicyRequest* request =
222 job->GetRequest()->mutable_policy_request(); 220 job->GetRequest()->mutable_policy_request();
223 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType); 221 request->add_request()->set_policy_type(dm_protocol::kChromeUserPolicyType);
224 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 222 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
225 base::Unretained(this))); 223 base::Unretained(this)));
226 base::MessageLoop::current()->Run(); 224 base::MessageLoop::current()->Run();
227 } 225 }
228 226
229 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) { 227 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Unregistration) {
230 PerformRegistration(); 228 PerformRegistration();
231 229
232 ExpectRequest(); 230 ExpectRequest();
233 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 231 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
234 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), 232 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
235 &base::MessageLoop::Quit)); 233 &base::MessageLoop::QuitWhenIdle));
236 scoped_ptr<DeviceManagementRequestJob> job( 234 scoped_ptr<DeviceManagementRequestJob> job(
237 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, 235 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION,
238 g_browser_process->system_request_context())); 236 g_browser_process->system_request_context()));
239 job->SetDMToken(token_); 237 job->SetDMToken(token_);
240 job->SetClientID("testid"); 238 job->SetClientID("testid");
241 job->GetRequest()->mutable_unregister_request(); 239 job->GetRequest()->mutable_unregister_request();
242 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 240 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
243 base::Unretained(this))); 241 base::Unretained(this)));
244 base::MessageLoop::current()->Run(); 242 base::MessageLoop::current()->Run();
245 } 243 }
246 244
247 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) { 245 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, AutoEnrollment) {
248 ExpectRequest(); 246 ExpectRequest();
249 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _)) 247 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _, _))
250 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(), 248 .WillOnce(InvokeWithoutArgs(base::MessageLoop::current(),
251 &base::MessageLoop::Quit)); 249 &base::MessageLoop::QuitWhenIdle));
252 scoped_ptr<DeviceManagementRequestJob> job( 250 scoped_ptr<DeviceManagementRequestJob> job(
253 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, 251 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT,
254 g_browser_process->system_request_context())); 252 g_browser_process->system_request_context()));
255 job->SetClientID("testid"); 253 job->SetClientID("testid");
256 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0); 254 job->GetRequest()->mutable_auto_enrollment_request()->set_remainder(0);
257 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1); 255 job->GetRequest()->mutable_auto_enrollment_request()->set_modulus(1);
258 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone, 256 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
259 base::Unretained(this))); 257 base::Unretained(this)));
260 base::MessageLoop::current()->Run(); 258 base::MessageLoop::current()->Run();
261 } 259 }
262 260
263 INSTANTIATE_TEST_CASE_P( 261 INSTANTIATE_TEST_CASE_P(
264 DeviceManagementServiceIntegrationTestInstance, 262 DeviceManagementServiceIntegrationTestInstance,
265 DeviceManagementServiceIntegrationTest, 263 DeviceManagementServiceIntegrationTest,
266 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, 264 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse,
267 &DeviceManagementServiceIntegrationTest::InitTestServer)); 265 &DeviceManagementServiceIntegrationTest::InitTestServer));
268 266
269 } // namespace policy 267 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_win_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698