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

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

Issue 12538009: Public Sessions: fetch device robot api token during enterprise enrollment. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: updated tests Created 7 years, 8 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.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 24 matching lines...) Expand all
35 // DeviceManagementResponse to |response_data|. 35 // DeviceManagementResponse to |response_data|.
36 void ConstructResponse(const char* request_data, 36 void ConstructResponse(const char* request_data,
37 uint64 request_data_length, 37 uint64 request_data_length,
38 std::string* response_data) { 38 std::string* response_data) {
39 em::DeviceManagementRequest request; 39 em::DeviceManagementRequest request;
40 ASSERT_TRUE(request.ParseFromArray(request_data, request_data_length)); 40 ASSERT_TRUE(request.ParseFromArray(request_data, request_data_length));
41 em::DeviceManagementResponse response; 41 em::DeviceManagementResponse response;
42 if (request.has_register_request()) { 42 if (request.has_register_request()) {
43 response.mutable_register_response()->set_device_management_token( 43 response.mutable_register_response()->set_device_management_token(
44 "fake_token"); 44 "fake_token");
45 } else if (request.has_service_api_access_request()) {
46 response.mutable_service_api_access_response();
45 } else if (request.has_unregister_request()) { 47 } else if (request.has_unregister_request()) {
46 response.mutable_unregister_response(); 48 response.mutable_unregister_response();
47 } else if (request.has_policy_request()) { 49 } else if (request.has_policy_request()) {
48 response.mutable_policy_response()->add_response(); 50 response.mutable_policy_response()->add_response();
49 } else if (request.has_auto_enrollment_request()) { 51 } else if (request.has_auto_enrollment_request()) {
50 response.mutable_auto_enrollment_response(); 52 response.mutable_auto_enrollment_response();
51 } else { 53 } else {
52 FAIL() << "Failed to parse request."; 54 FAIL() << "Failed to parse request.";
53 } 55 }
54 ASSERT_TRUE(response.SerializeToString(response_data)); 56 ASSERT_TRUE(response.SerializeToString(response_data));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 scoped_ptr<DeviceManagementService> service_; 153 scoped_ptr<DeviceManagementService> service_;
152 scoped_ptr<LocalPolicyTestServer> test_server_; 154 scoped_ptr<LocalPolicyTestServer> test_server_;
153 scoped_ptr<TestRequestInterceptor> interceptor_; 155 scoped_ptr<TestRequestInterceptor> interceptor_;
154 }; 156 };
155 157
156 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { 158 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) {
157 PerformRegistration(); 159 PerformRegistration();
158 EXPECT_FALSE(token_.empty()); 160 EXPECT_FALSE(token_.empty());
159 } 161 }
160 162
163 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest,
164 ApiAuthCodeFetch) {
165 PerformRegistration();
166
167 ExpectRequest();
168 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _))
169 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit));
170 scoped_ptr<DeviceManagementRequestJob> job(service_->CreateJob(
171 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH));
172 job->SetDMToken(token_);
173 job->SetClientID("testid");
174 em::DeviceServiceApiAccessRequest* request =
175 job->GetRequest()->mutable_service_api_access_request();
176 request->add_auth_scope("authScope4Test");
177 request->set_oauth2_client_id("oauth2ClientId4Test");
178 job->Start(base::Bind(&DeviceManagementServiceIntegrationTest::OnJobDone,
179 base::Unretained(this)));
180 MessageLoop::current()->Run();
181 }
182
161 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { 183 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) {
162 PerformRegistration(); 184 PerformRegistration();
163 185
164 ExpectRequest(); 186 ExpectRequest();
165 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) 187 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _))
166 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit)); 188 .WillOnce(InvokeWithoutArgs(MessageLoop::current(), &MessageLoop::Quit));
167 scoped_ptr<DeviceManagementRequestJob> job( 189 scoped_ptr<DeviceManagementRequestJob> job(
168 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); 190 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH));
169 job->SetDMToken(token_); 191 job->SetDMToken(token_);
170 job->SetUserAffiliation(USER_AFFILIATION_NONE); 192 job->SetUserAffiliation(USER_AFFILIATION_NONE);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 MessageLoop::current()->Run(); 229 MessageLoop::current()->Run();
208 } 230 }
209 231
210 INSTANTIATE_TEST_CASE_P( 232 INSTANTIATE_TEST_CASE_P(
211 DeviceManagementServiceIntegrationTestInstance, 233 DeviceManagementServiceIntegrationTestInstance,
212 DeviceManagementServiceIntegrationTest, 234 DeviceManagementServiceIntegrationTest,
213 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, 235 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse,
214 &DeviceManagementServiceIntegrationTest::InitTestServer)); 236 &DeviceManagementServiceIntegrationTest::InitTestServer));
215 237
216 } // namespace policy 238 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698