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

Side by Side Diff: google_apis/gaia/fake_gaia.cc

Issue 1141163002: Browser tests for the new way of handling device ID in Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@device_id
Patch Set: Comments addressed. Created 5 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
« no previous file with comments | « google_apis/gaia/fake_gaia.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "google_apis/gaia/fake_gaia.h" 5 #include "google_apis/gaia/fake_gaia.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 : expires_in(3600) {} 129 : expires_in(3600) {}
130 130
131 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {} 131 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {}
132 132
133 FakeGaia::MergeSessionParams::MergeSessionParams() { 133 FakeGaia::MergeSessionParams::MergeSessionParams() {
134 } 134 }
135 135
136 FakeGaia::MergeSessionParams::~MergeSessionParams() { 136 FakeGaia::MergeSessionParams::~MergeSessionParams() {
137 } 137 }
138 138
139 void FakeGaia::MergeSessionParams::Update(const MergeSessionParams& update) {
140 // This lambda uses a pointer to data member to merge attributes.
141 auto maybe_update_field =
142 [this, &update](std::string MergeSessionParams::* field_ptr) {
143 if (!(update.*field_ptr).empty())
144 this->*field_ptr = update.*field_ptr;
145 };
146
147 maybe_update_field(&MergeSessionParams::auth_sid_cookie);
148 maybe_update_field(&MergeSessionParams::auth_lsid_cookie);
149 maybe_update_field(&MergeSessionParams::auth_code);
150 maybe_update_field(&MergeSessionParams::refresh_token);
151 maybe_update_field(&MergeSessionParams::access_token);
152 maybe_update_field(&MergeSessionParams::gaia_uber_token);
153 maybe_update_field(&MergeSessionParams::session_sid_cookie);
154 maybe_update_field(&MergeSessionParams::session_lsid_cookie);
155 maybe_update_field(&MergeSessionParams::email);
156 }
157
139 FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) { 158 FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) {
140 base::FilePath source_root_dir; 159 base::FilePath source_root_dir;
141 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); 160 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir);
142 CHECK(base::ReadFileToString( 161 CHECK(base::ReadFileToString(
143 source_root_dir.Append(base::FilePath(kServiceLogin)), 162 source_root_dir.Append(base::FilePath(kServiceLogin)),
144 &service_login_response_)); 163 &service_login_response_));
145 CHECK(base::ReadFileToString( 164 CHECK(base::ReadFileToString(
146 source_root_dir.Append(base::FilePath(kEmbeddedSetupChromeos)), 165 source_root_dir.Append(base::FilePath(kEmbeddedSetupChromeos)),
147 &embedded_setup_chromeos_response_)); 166 &embedded_setup_chromeos_response_));
148 } 167 }
(...skipping 15 matching lines...) Expand all
164 params.session_lsid_cookie = kTestSessionLSIDCookie; 183 params.session_lsid_cookie = kTestSessionLSIDCookie;
165 params.email = email; 184 params.email = email;
166 SetMergeSessionParams(params); 185 SetMergeSessionParams(params);
167 } 186 }
168 187
169 void FakeGaia::SetMergeSessionParams( 188 void FakeGaia::SetMergeSessionParams(
170 const MergeSessionParams& params) { 189 const MergeSessionParams& params) {
171 merge_session_params_ = params; 190 merge_session_params_ = params;
172 } 191 }
173 192
193 void FakeGaia::UpdateMergeSessionParams(const MergeSessionParams& params) {
194 merge_session_params_.Update(params);
195 }
196
174 void FakeGaia::MapEmailToGaiaId(const std::string& email, 197 void FakeGaia::MapEmailToGaiaId(const std::string& email,
175 const std::string& gaia_id) { 198 const std::string& gaia_id) {
176 DCHECK(!email.empty()); 199 DCHECK(!email.empty());
177 DCHECK(!gaia_id.empty()); 200 DCHECK(!gaia_id.empty());
178 email_to_gaia_id_map_[email] = gaia_id; 201 email_to_gaia_id_map_[email] = gaia_id;
179 } 202 }
180 203
181 std::string FakeGaia::GetGaiaIdOfEmail(const std::string& email) const { 204 std::string FakeGaia::GetGaiaIdOfEmail(const std::string& email) const {
182 DCHECK(!email.empty()); 205 DCHECK(!email.empty());
183 auto it = email_to_gaia_id_map_.find(email); 206 const auto it = email_to_gaia_id_map_.find(email);
184 return it == email_to_gaia_id_map_.end() ? std::string(kDefaultGaiaId) : 207 return it == email_to_gaia_id_map_.end() ? std::string(kDefaultGaiaId) :
185 it->second; 208 it->second;
186 } 209 }
187 210
188 void FakeGaia::AddGoogleAccountsSigninHeader( 211 void FakeGaia::AddGoogleAccountsSigninHeader(
189 net::test_server::BasicHttpResponse* http_response, 212 net::test_server::BasicHttpResponse* http_response,
190 const std::string& email) const { 213 const std::string& email) const {
191 DCHECK(!email.empty()); 214 DCHECK(!email.empty());
192 http_response->AddCustomHeader("google-accounts-signin", 215 http_response->AddCustomHeader("google-accounts-signin",
193 base::StringPrintf( 216 base::StringPrintf(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // static 322 // static
300 bool FakeGaia::GetQueryParameter(const std::string& query, 323 bool FakeGaia::GetQueryParameter(const std::string& query,
301 const std::string& key, 324 const std::string& key,
302 std::string* value) { 325 std::string* value) {
303 // Name and scheme actually don't matter, but are required to get a valid URL 326 // Name and scheme actually don't matter, but are required to get a valid URL
304 // for parsing. 327 // for parsing.
305 GURL query_url("http://localhost?" + query); 328 GURL query_url("http://localhost?" + query);
306 return net::GetValueForKeyInQuery(query_url, key, value); 329 return net::GetValueForKeyInQuery(query_url, key, value);
307 } 330 }
308 331
332 std::string FakeGaia::GetDeviceIdByRefreshToken(
333 const std::string& refresh_token) const {
334 auto it = refresh_token_to_device_id_map_.find(refresh_token);
335 return it != refresh_token_to_device_id_map_.end() ? it->second
336 : std::string();
337 }
338
339 void FakeGaia::SetRefreshTokenToDeviceIdMap(
340 const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map) {
341 refresh_token_to_device_id_map_ = refresh_token_to_device_id_map;
342 }
343
309 void FakeGaia::HandleMergeSession(const HttpRequest& request, 344 void FakeGaia::HandleMergeSession(const HttpRequest& request,
310 BasicHttpResponse* http_response) { 345 BasicHttpResponse* http_response) {
311 http_response->set_code(net::HTTP_UNAUTHORIZED); 346 http_response->set_code(net::HTTP_UNAUTHORIZED);
312 if (merge_session_params_.session_sid_cookie.empty() || 347 if (merge_session_params_.session_sid_cookie.empty() ||
313 merge_session_params_.session_lsid_cookie.empty()) { 348 merge_session_params_.session_lsid_cookie.empty()) {
314 http_response->set_code(net::HTTP_BAD_REQUEST); 349 http_response->set_code(net::HTTP_BAD_REQUEST);
315 return; 350 return;
316 } 351 }
317 352
318 std::string uber_token; 353 std::string uber_token;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 630
596 if (grant_type == "authorization_code") { 631 if (grant_type == "authorization_code") {
597 std::string auth_code; 632 std::string auth_code;
598 if (!GetQueryParameter(request.content, "code", &auth_code) || 633 if (!GetQueryParameter(request.content, "code", &auth_code) ||
599 auth_code != merge_session_params_.auth_code) { 634 auth_code != merge_session_params_.auth_code) {
600 http_response->set_code(net::HTTP_BAD_REQUEST); 635 http_response->set_code(net::HTTP_BAD_REQUEST);
601 LOG(ERROR) << "No 'code' param in /o/oauth2/token"; 636 LOG(ERROR) << "No 'code' param in /o/oauth2/token";
602 return; 637 return;
603 } 638 }
604 639
640 std::string device_id;
641 if (GetQueryParameter(request.content, "device_id", &device_id)) {
642 std::string device_type;
643 if (!GetQueryParameter(request.content, "device_type", &device_type)) {
644 http_response->set_code(net::HTTP_BAD_REQUEST);
645 LOG(ERROR) << "'device_type' should be set if 'device_id' is set.";
646 return;
647 }
648 if (device_type != "chrome") {
649 http_response->set_code(net::HTTP_BAD_REQUEST);
650 LOG(ERROR) << "'device_type' is not 'chrome'.";
651 return;
652 }
653 }
654
605 base::DictionaryValue response_dict; 655 base::DictionaryValue response_dict;
606 response_dict.SetString("refresh_token", 656 response_dict.SetString("refresh_token",
607 merge_session_params_.refresh_token); 657 merge_session_params_.refresh_token);
658 if (!device_id.empty())
659 refresh_token_to_device_id_map_[merge_session_params_.refresh_token] =
660 device_id;
608 response_dict.SetString("access_token", 661 response_dict.SetString("access_token",
609 merge_session_params_.access_token); 662 merge_session_params_.access_token);
610 response_dict.SetInteger("expires_in", 3600); 663 response_dict.SetInteger("expires_in", 3600);
611 FormatJSONResponse(response_dict, http_response); 664 FormatJSONResponse(response_dict, http_response);
612 return; 665 return;
613 } 666 }
614 667
615 std::string scope; 668 std::string scope;
616 GetQueryParameter(request.content, "scope", &scope); 669 GetQueryParameter(request.content, "scope", &scope);
617 670
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 if (token_info) { 765 if (token_info) {
713 base::DictionaryValue response_dict; 766 base::DictionaryValue response_dict;
714 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); 767 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email));
715 response_dict.SetString("email", token_info->email); 768 response_dict.SetString("email", token_info->email);
716 response_dict.SetString("verified_email", token_info->email); 769 response_dict.SetString("verified_email", token_info->email);
717 FormatJSONResponse(response_dict, http_response); 770 FormatJSONResponse(response_dict, http_response);
718 } else { 771 } else {
719 http_response->set_code(net::HTTP_BAD_REQUEST); 772 http_response->set_code(net::HTTP_BAD_REQUEST);
720 } 773 }
721 } 774 }
OLDNEW
« no previous file with comments | « google_apis/gaia/fake_gaia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698