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

Side by Side Diff: chrome/browser/supervised_user/child_accounts/family_info_fetcher_unittest.cc

Issue 2845113002: Remove raw base::DictionaryValue::SetWithoutPathExpansion in //chrome (Closed)
Patch Set: Address comments Created 3 years, 7 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 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>
(...skipping 30 matching lines...) Expand all
41 account1.email == account2.email && 41 account1.email == account2.email &&
42 account1.profile_url == account2.profile_url && 42 account1.profile_url == account2.profile_url &&
43 account1.profile_image_url == account2.profile_image_url; 43 account1.profile_image_url == account2.profile_image_url;
44 } 44 }
45 45
46 namespace { 46 namespace {
47 47
48 std::string BuildGetFamilyProfileResponse( 48 std::string BuildGetFamilyProfileResponse(
49 const FamilyInfoFetcher::FamilyProfile& family) { 49 const FamilyInfoFetcher::FamilyProfile& family) {
50 base::DictionaryValue dict; 50 base::DictionaryValue dict;
51 base::DictionaryValue* family_dict = new base::DictionaryValue; 51 auto family_dict = base::MakeUnique<base::DictionaryValue>();
52 family_dict->SetStringWithoutPathExpansion("familyId", family.id); 52 family_dict->SetStringWithoutPathExpansion("familyId", family.id);
53 std::unique_ptr<base::DictionaryValue> profile_dict = 53 std::unique_ptr<base::DictionaryValue> profile_dict =
54 base::MakeUnique<base::DictionaryValue>(); 54 base::MakeUnique<base::DictionaryValue>();
55 profile_dict->SetStringWithoutPathExpansion("name", family.name); 55 profile_dict->SetStringWithoutPathExpansion("name", family.name);
56 family_dict->SetWithoutPathExpansion("profile", std::move(profile_dict)); 56 family_dict->SetWithoutPathExpansion("profile", std::move(profile_dict));
57 dict.SetWithoutPathExpansion("family", family_dict); 57 dict.SetWithoutPathExpansion("family", std::move(family_dict));
58 std::string result; 58 std::string result;
59 base::JSONWriter::Write(dict, &result); 59 base::JSONWriter::Write(dict, &result);
60 return result; 60 return result;
61 } 61 }
62 62
63 std::string BuildEmptyGetFamilyProfileResponse() { 63 std::string BuildEmptyGetFamilyProfileResponse() {
64 base::DictionaryValue dict; 64 base::DictionaryValue dict;
65 base::DictionaryValue* family_dict = new base::DictionaryValue; 65 dict.SetWithoutPathExpansion("family",
66 dict.SetWithoutPathExpansion("family", family_dict); 66 base::MakeUnique<base::DictionaryValue>());
67 std::string result; 67 std::string result;
68 base::JSONWriter::Write(dict, &result); 68 base::JSONWriter::Write(dict, &result);
69 return result; 69 return result;
70 } 70 }
71 71
72 std::string BuildGetFamilyMembersResponse( 72 std::string BuildGetFamilyMembersResponse(
73 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { 73 const std::vector<FamilyInfoFetcher::FamilyMember>& members) {
74 base::DictionaryValue dict; 74 base::DictionaryValue dict;
75 base::ListValue* list = new base::ListValue; 75 auto list = base::MakeUnique<base::ListValue>();
76 for (size_t i = 0; i < members.size(); i++) { 76 for (size_t i = 0; i < members.size(); i++) {
77 const FamilyInfoFetcher::FamilyMember& member = members[i]; 77 const FamilyInfoFetcher::FamilyMember& member = members[i];
78 std::unique_ptr<base::DictionaryValue> member_dict( 78 std::unique_ptr<base::DictionaryValue> member_dict(
79 new base::DictionaryValue); 79 new base::DictionaryValue);
80 member_dict->SetStringWithoutPathExpansion("userId", 80 member_dict->SetStringWithoutPathExpansion("userId",
81 member.obfuscated_gaia_id); 81 member.obfuscated_gaia_id);
82 member_dict->SetStringWithoutPathExpansion( 82 member_dict->SetStringWithoutPathExpansion(
83 "role", FamilyInfoFetcher::RoleToString(member.role)); 83 "role", FamilyInfoFetcher::RoleToString(member.role));
84 if (!member.display_name.empty() || 84 if (!member.display_name.empty() ||
85 !member.email.empty() || 85 !member.email.empty() ||
86 !member.profile_url.empty() || 86 !member.profile_url.empty() ||
87 !member.profile_image_url.empty()) { 87 !member.profile_image_url.empty()) {
88 base::DictionaryValue* profile_dict = new base::DictionaryValue; 88 auto profile_dict = base::MakeUnique<base::DictionaryValue>();
89 if (!member.display_name.empty()) 89 if (!member.display_name.empty())
90 profile_dict->SetStringWithoutPathExpansion("displayName", 90 profile_dict->SetStringWithoutPathExpansion("displayName",
91 member.display_name); 91 member.display_name);
92 if (!member.email.empty()) 92 if (!member.email.empty())
93 profile_dict->SetStringWithoutPathExpansion("email", 93 profile_dict->SetStringWithoutPathExpansion("email",
94 member.email); 94 member.email);
95 if (!member.profile_url.empty()) 95 if (!member.profile_url.empty())
96 profile_dict->SetStringWithoutPathExpansion("profileUrl", 96 profile_dict->SetStringWithoutPathExpansion("profileUrl",
97 member.profile_url); 97 member.profile_url);
98 if (!member.profile_image_url.empty()) 98 if (!member.profile_image_url.empty())
99 profile_dict->SetStringWithoutPathExpansion("profileImageUrl", 99 profile_dict->SetStringWithoutPathExpansion("profileImageUrl",
100 member.profile_image_url); 100 member.profile_image_url);
101 101
102 member_dict->SetWithoutPathExpansion("profile", profile_dict); 102 member_dict->SetWithoutPathExpansion("profile", std::move(profile_dict));
103 } 103 }
104 list->Append(std::move(member_dict)); 104 list->Append(std::move(member_dict));
105 } 105 }
106 dict.SetWithoutPathExpansion("members", list); 106 dict.SetWithoutPathExpansion("members", std::move(list));
107 std::string result; 107 std::string result;
108 base::JSONWriter::Write(dict, &result); 108 base::JSONWriter::Write(dict, &result);
109 return result; 109 return result;
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 class FamilyInfoFetcherTest : public testing::Test, 114 class FamilyInfoFetcherTest : public testing::Test,
115 public FamilyInfoFetcher::Consumer { 115 public FamilyInfoFetcher::Consumer {
116 public: 116 public:
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 IssueRefreshToken(); 316 IssueRefreshToken();
317 317
318 fetcher_.StartGetFamilyProfile(); 318 fetcher_.StartGetFamilyProfile();
319 319
320 IssueAccessToken(); 320 IssueAccessToken();
321 321
322 // Failed API call should result in a network error. 322 // Failed API call should result in a network error.
323 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); 323 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR));
324 SendFailedResponse(); 324 SendFailedResponse();
325 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698