| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" | 5 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 18 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
| 20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 base::JSONWriter::Write(dict, &result); | 66 base::JSONWriter::Write(dict, &result); |
| 66 return result; | 67 return result; |
| 67 } | 68 } |
| 68 | 69 |
| 69 std::string BuildGetFamilyMembersResponse( | 70 std::string BuildGetFamilyMembersResponse( |
| 70 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { | 71 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { |
| 71 base::DictionaryValue dict; | 72 base::DictionaryValue dict; |
| 72 base::ListValue* list = new base::ListValue; | 73 base::ListValue* list = new base::ListValue; |
| 73 for (size_t i = 0; i < members.size(); i++) { | 74 for (size_t i = 0; i < members.size(); i++) { |
| 74 const FamilyInfoFetcher::FamilyMember& member = members[i]; | 75 const FamilyInfoFetcher::FamilyMember& member = members[i]; |
| 75 base::DictionaryValue* member_dict = new base::DictionaryValue; | 76 std::unique_ptr<base::DictionaryValue> member_dict( |
| 77 new base::DictionaryValue); |
| 76 member_dict->SetStringWithoutPathExpansion("userId", | 78 member_dict->SetStringWithoutPathExpansion("userId", |
| 77 member.obfuscated_gaia_id); | 79 member.obfuscated_gaia_id); |
| 78 member_dict->SetStringWithoutPathExpansion( | 80 member_dict->SetStringWithoutPathExpansion( |
| 79 "role", FamilyInfoFetcher::RoleToString(member.role)); | 81 "role", FamilyInfoFetcher::RoleToString(member.role)); |
| 80 if (!member.display_name.empty() || | 82 if (!member.display_name.empty() || |
| 81 !member.email.empty() || | 83 !member.email.empty() || |
| 82 !member.profile_url.empty() || | 84 !member.profile_url.empty() || |
| 83 !member.profile_image_url.empty()) { | 85 !member.profile_image_url.empty()) { |
| 84 base::DictionaryValue* profile_dict = new base::DictionaryValue; | 86 base::DictionaryValue* profile_dict = new base::DictionaryValue; |
| 85 if (!member.display_name.empty()) | 87 if (!member.display_name.empty()) |
| 86 profile_dict->SetStringWithoutPathExpansion("displayName", | 88 profile_dict->SetStringWithoutPathExpansion("displayName", |
| 87 member.display_name); | 89 member.display_name); |
| 88 if (!member.email.empty()) | 90 if (!member.email.empty()) |
| 89 profile_dict->SetStringWithoutPathExpansion("email", | 91 profile_dict->SetStringWithoutPathExpansion("email", |
| 90 member.email); | 92 member.email); |
| 91 if (!member.profile_url.empty()) | 93 if (!member.profile_url.empty()) |
| 92 profile_dict->SetStringWithoutPathExpansion("profileUrl", | 94 profile_dict->SetStringWithoutPathExpansion("profileUrl", |
| 93 member.profile_url); | 95 member.profile_url); |
| 94 if (!member.profile_image_url.empty()) | 96 if (!member.profile_image_url.empty()) |
| 95 profile_dict->SetStringWithoutPathExpansion("profileImageUrl", | 97 profile_dict->SetStringWithoutPathExpansion("profileImageUrl", |
| 96 member.profile_image_url); | 98 member.profile_image_url); |
| 97 | 99 |
| 98 member_dict->SetWithoutPathExpansion("profile", profile_dict); | 100 member_dict->SetWithoutPathExpansion("profile", profile_dict); |
| 99 } | 101 } |
| 100 list->Append(member_dict); | 102 list->Append(std::move(member_dict)); |
| 101 } | 103 } |
| 102 dict.SetWithoutPathExpansion("members", list); | 104 dict.SetWithoutPathExpansion("members", list); |
| 103 std::string result; | 105 std::string result; |
| 104 base::JSONWriter::Write(dict, &result); | 106 base::JSONWriter::Write(dict, &result); |
| 105 return result; | 107 return result; |
| 106 } | 108 } |
| 107 | 109 |
| 108 } // namespace | 110 } // namespace |
| 109 | 111 |
| 110 class FamilyInfoFetcherTest : public testing::Test, | 112 class FamilyInfoFetcherTest : public testing::Test, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 IssueRefreshToken(); | 314 IssueRefreshToken(); |
| 313 | 315 |
| 314 fetcher_.StartGetFamilyProfile(); | 316 fetcher_.StartGetFamilyProfile(); |
| 315 | 317 |
| 316 IssueAccessToken(); | 318 IssueAccessToken(); |
| 317 | 319 |
| 318 // Failed API call should result in a network error. | 320 // Failed API call should result in a network error. |
| 319 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); | 321 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); |
| 320 SendFailedResponse(); | 322 SendFailedResponse(); |
| 321 } | 323 } |
| OLD | NEW |