| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 std::string BuildGetFamilyProfileResponse( | 42 std::string BuildGetFamilyProfileResponse( |
| 43 const FamilyInfoFetcher::FamilyProfile& family) { | 43 const FamilyInfoFetcher::FamilyProfile& family) { |
| 44 base::DictionaryValue dict; | 44 base::DictionaryValue dict; |
| 45 base::DictionaryValue* family_dict = new base::DictionaryValue; | 45 base::DictionaryValue* family_dict = new base::DictionaryValue; |
| 46 family_dict->SetStringWithoutPathExpansion("familyId", family.id); | 46 family_dict->SetStringWithoutPathExpansion("familyId", family.id); |
| 47 base::DictionaryValue* profile_dict = new base::DictionaryValue; | 47 base::DictionaryValue* profile_dict = new base::DictionaryValue; |
| 48 profile_dict->SetStringWithoutPathExpansion("name", family.name); | 48 profile_dict->SetStringWithoutPathExpansion("name", family.name); |
| 49 family_dict->SetWithoutPathExpansion("profile", profile_dict); | 49 family_dict->SetWithoutPathExpansion("profile", profile_dict); |
| 50 dict.SetWithoutPathExpansion("family", family_dict); | 50 dict.SetWithoutPathExpansion("family", family_dict); |
| 51 std::string result; | 51 std::string result; |
| 52 base::JSONWriter::Write(&dict, &result); | 52 base::JSONWriter::Write(dict, &result); |
| 53 return result; | 53 return result; |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::string BuildEmptyGetFamilyProfileResponse() { | 56 std::string BuildEmptyGetFamilyProfileResponse() { |
| 57 base::DictionaryValue dict; | 57 base::DictionaryValue dict; |
| 58 base::DictionaryValue* family_dict = new base::DictionaryValue; | 58 base::DictionaryValue* family_dict = new base::DictionaryValue; |
| 59 dict.SetWithoutPathExpansion("family", family_dict); | 59 dict.SetWithoutPathExpansion("family", family_dict); |
| 60 std::string result; | 60 std::string result; |
| 61 base::JSONWriter::Write(&dict, &result); | 61 base::JSONWriter::Write(dict, &result); |
| 62 return result; | 62 return result; |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::string BuildGetFamilyMembersResponse( | 65 std::string BuildGetFamilyMembersResponse( |
| 66 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { | 66 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { |
| 67 base::DictionaryValue dict; | 67 base::DictionaryValue dict; |
| 68 base::ListValue* list = new base::ListValue; | 68 base::ListValue* list = new base::ListValue; |
| 69 for (size_t i = 0; i < members.size(); i++) { | 69 for (size_t i = 0; i < members.size(); i++) { |
| 70 const FamilyInfoFetcher::FamilyMember& member = members[i]; | 70 const FamilyInfoFetcher::FamilyMember& member = members[i]; |
| 71 base::DictionaryValue* member_dict = new base::DictionaryValue; | 71 base::DictionaryValue* member_dict = new base::DictionaryValue; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 if (!member.profile_image_url.empty()) | 90 if (!member.profile_image_url.empty()) |
| 91 profile_dict->SetStringWithoutPathExpansion("profileImageUrl", | 91 profile_dict->SetStringWithoutPathExpansion("profileImageUrl", |
| 92 member.profile_image_url); | 92 member.profile_image_url); |
| 93 | 93 |
| 94 member_dict->SetWithoutPathExpansion("profile", profile_dict); | 94 member_dict->SetWithoutPathExpansion("profile", profile_dict); |
| 95 } | 95 } |
| 96 list->Append(member_dict); | 96 list->Append(member_dict); |
| 97 } | 97 } |
| 98 dict.SetWithoutPathExpansion("members", list); | 98 dict.SetWithoutPathExpansion("members", list); |
| 99 std::string result; | 99 std::string result; |
| 100 base::JSONWriter::Write(&dict, &result); | 100 base::JSONWriter::Write(dict, &result); |
| 101 return result; | 101 return result; |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 class FamilyInfoFetcherTest : public testing::Test, | 106 class FamilyInfoFetcherTest : public testing::Test, |
| 107 public FamilyInfoFetcher::Consumer { | 107 public FamilyInfoFetcher::Consumer { |
| 108 public: | 108 public: |
| 109 FamilyInfoFetcherTest() | 109 FamilyInfoFetcherTest() |
| 110 : request_context_(new net::TestURLRequestContextGetter( | 110 : request_context_(new net::TestURLRequestContextGetter( |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 IssueRefreshToken(); | 312 IssueRefreshToken(); |
| 313 | 313 |
| 314 fetcher_.StartGetFamilyProfile(); | 314 fetcher_.StartGetFamilyProfile(); |
| 315 | 315 |
| 316 IssueAccessToken(); | 316 IssueAccessToken(); |
| 317 | 317 |
| 318 // Failed API call should result in a network error. | 318 // Failed API call should result in a network error. |
| 319 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); | 319 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); |
| 320 SendFailedResponse(); | 320 SendFailedResponse(); |
| 321 } | 321 } |
| OLD | NEW |