Index: chrome/browser/chromeos/contacts/contact_test_util.cc |
diff --git a/chrome/browser/chromeos/contacts/contact_test_util.cc b/chrome/browser/chromeos/contacts/contact_test_util.cc |
index 70b3a88c43ed7d07dd173d3f57a62a9502662123..9053b3657ed34401de692602c38dcf35bbffc2dd 100644 |
--- a/chrome/browser/chromeos/contacts/contact_test_util.cc |
+++ b/chrome/browser/chromeos/contacts/contact_test_util.cc |
@@ -13,6 +13,7 @@ |
#include "base/string_util.h" |
#include "base/time.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/gfx/codec/png_codec.h" |
#include "ui/gfx/size.h" |
namespace contacts { |
@@ -24,73 +25,83 @@ namespace { |
// and then sorts the resulting strings and joins them using |join_char|. |
template<class T> |
std::string StringifyField( |
- const std::vector<T>& items, |
+ const ::google::protobuf::RepeatedPtrField<T>& items, |
base::Callback<std::string(const T&)> stringify_callback, |
const std::string& prefix, |
char join_char) { |
std::vector<std::string> strings; |
- for (size_t i = 0; i < items.size(); ++i) |
- strings.push_back(prefix + stringify_callback.Run(items[i])); |
+ for (int i = 0; i < items.size(); ++i) |
+ strings.push_back(prefix + stringify_callback.Run(items.Get(i))); |
std::sort(strings.begin(), strings.end()); |
return JoinString(strings, join_char); |
} |
-std::string EmailAddressToString(const Contact::EmailAddress& email) { |
- return email.address + "," + |
- base::IntToString(email.type.relation) + "," + |
- email.type.label + "," + |
- base::IntToString(email.primary); |
+std::string EmailAddressToString(const Contact_EmailAddress& email) { |
+ return email.address() + "," + |
+ base::IntToString(email.type().relation()) + "," + |
+ email.type().label() + "," + |
+ base::IntToString(email.primary()); |
} |
-std::string PhoneNumberToString(const Contact::PhoneNumber& phone) { |
- return phone.number + "," + |
- base::IntToString(phone.type.relation) + "," + |
- phone.type.label + "," + |
- base::IntToString(phone.primary); |
+std::string PhoneNumberToString(const Contact_PhoneNumber& phone) { |
+ return phone.number() + "," + |
+ base::IntToString(phone.type().relation()) + "," + |
+ phone.type().label() + "," + |
+ base::IntToString(phone.primary()); |
} |
-std::string PostalAddressToString(const Contact::PostalAddress& postal) { |
- return postal.address + "," + |
- base::IntToString(postal.type.relation) + "," + |
- postal.type.label + "," + |
- base::IntToString(postal.primary); |
+std::string PostalAddressToString(const Contact_PostalAddress& postal) { |
+ return postal.address() + "," + |
+ base::IntToString(postal.type().relation()) + "," + |
+ postal.type().label() + "," + |
+ base::IntToString(postal.primary()); |
} |
std::string InstantMessagingAddressToString( |
- const Contact::InstantMessagingAddress& im) { |
- return im.address + "," + |
- base::IntToString(im.protocol) + "," + |
- base::IntToString(im.type.relation) + "," + |
- im.type.label + "," + |
- base::IntToString(im.primary); |
+ const Contact_InstantMessagingAddress& im) { |
+ return im.address() + "," + |
+ base::IntToString(im.protocol()) + "," + |
+ base::IntToString(im.type().relation()) + "," + |
+ im.type().label() + "," + |
+ base::IntToString(im.primary()); |
} |
} // namespace |
std::string ContactToString(const Contact& contact) { |
std::string result = |
- contact.provider_id + "," + |
- base::Int64ToString(contact.update_time.ToInternalValue()) + "," + |
- base::IntToString(contact.deleted) + "," + |
- contact.full_name + "," + |
- contact.given_name + "," + |
- contact.additional_name + "," + |
- contact.family_name + "," + |
- contact.name_prefix + "," + |
- contact.name_suffix + "," + |
- base::IntToString(contact.photo.width()) + "x" + |
- base::IntToString(contact.photo.height()); |
- |
- result += " " + StringifyField(contact.email_addresses, |
+ contact.provider_id() + "," + |
+ base::Int64ToString(contact.update_time()) + "," + |
+ base::IntToString(contact.deleted()) + "," + |
+ contact.full_name() + "," + |
+ contact.given_name() + "," + |
+ contact.additional_name() + "," + |
+ contact.family_name() + "," + |
+ contact.name_prefix() + "," + |
+ contact.name_suffix(); |
+ |
+ SkBitmap bitmap; |
+ if (contact.has_raw_untrusted_photo()) { |
+ // Testing code just uses PNG for now. If that changes, use ImageDecoder |
+ // here instead. |
+ CHECK(gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>( |
+ contact.raw_untrusted_photo().data()), |
+ contact.raw_untrusted_photo().size(), |
+ &bitmap)); |
+ } |
+ result += "," + base::IntToString(bitmap.width()) + "x" + |
+ base::IntToString(bitmap.height()); |
+ |
+ result += " " + StringifyField(contact.email_addresses(), |
base::Bind(EmailAddressToString), |
"email=", ' '); |
- result += " " + StringifyField(contact.phone_numbers, |
+ result += " " + StringifyField(contact.phone_numbers(), |
base::Bind(PhoneNumberToString), |
"phone=", ' '); |
- result += " " + StringifyField(contact.postal_addresses, |
+ result += " " + StringifyField(contact.postal_addresses(), |
base::Bind(PostalAddressToString), |
"postal=", ' '); |
- result += " " + StringifyField(contact.instant_messaging_addresses, |
+ result += " " + StringifyField(contact.instant_messaging_addresses(), |
base::Bind(InstantMessagingAddressToString), |
"im=", ' '); |
@@ -122,30 +133,13 @@ std::string VarContactsToString(int num_contacts, ...) { |
return ContactsToString(contacts); |
} |
-void CopyContact(const Contact& source, Contact* dest) { |
- dest->provider_id = source.provider_id; |
- dest->update_time = source.update_time; |
- dest->deleted = source.deleted; |
- dest->full_name = source.full_name; |
- dest->given_name = source.given_name; |
- dest->additional_name = source.additional_name; |
- dest->family_name = source.family_name; |
- dest->name_prefix = source.name_prefix; |
- dest->name_suffix = source.name_suffix; |
- dest->photo = source.photo; |
- dest->email_addresses = source.email_addresses; |
- dest->phone_numbers = source.phone_numbers; |
- dest->postal_addresses = source.postal_addresses; |
- dest->instant_messaging_addresses = source.instant_messaging_addresses; |
-} |
- |
void CopyContacts(const ContactPointers& source, |
ScopedVector<Contact>* dest) { |
DCHECK(dest); |
dest->clear(); |
for (size_t i = 0; i < source.size(); ++i) { |
Contact* contact = new Contact; |
- CopyContact(*source[i], contact); |
+ *contact = *source[i]; |
dest->push_back(contact); |
} |
} |
@@ -163,86 +157,86 @@ void InitContact(const std::string& provider_id, |
bool deleted, |
Contact* contact) { |
DCHECK(contact); |
- contact->provider_id = provider_id; |
- contact->update_time = base::Time::Now(); |
- contact->deleted = deleted; |
- contact->full_name = "full_name_" + name_suffix; |
- contact->given_name = "given_name_" + name_suffix; |
- contact->additional_name = "additional_name_" + name_suffix; |
- contact->family_name = "family_name_" + name_suffix; |
- contact->name_prefix = "name_prefix_" + name_suffix; |
- contact->name_suffix = "name_suffix_" + name_suffix; |
- contact->photo = SkBitmap(); |
- contact->email_addresses.clear(); |
- contact->phone_numbers.clear(); |
- contact->postal_addresses.clear(); |
- contact->instant_messaging_addresses.clear(); |
+ contact->Clear(); |
+ contact->set_provider_id(provider_id); |
+ contact->set_update_time(base::Time::Now().ToInternalValue()); |
+ contact->set_deleted(deleted); |
+ contact->set_full_name("full_name_" + name_suffix); |
+ contact->set_given_name("given_name_" + name_suffix); |
+ contact->set_additional_name("additional_name_" + name_suffix); |
+ contact->set_family_name("family_name_" + name_suffix); |
+ contact->set_name_prefix("name_prefix_" + name_suffix); |
+ contact->set_name_suffix("name_suffix_" + name_suffix); |
} |
void AddEmailAddress(const std::string& address, |
- Contact::AddressType::Relation relation, |
+ Contact_AddressType_Relation relation, |
const std::string& label, |
bool primary, |
Contact* contact) { |
DCHECK(contact); |
- Contact::EmailAddress email; |
- email.address = address; |
- email.type.relation = relation; |
- email.type.label = label; |
- email.primary = primary; |
- contact->email_addresses.push_back(email); |
+ Contact::EmailAddress* email = contact->add_email_addresses(); |
+ email->set_address(address); |
+ email->mutable_type()->set_relation(relation); |
+ email->mutable_type()->set_label(label); |
+ email->set_primary(primary); |
} |
void AddPhoneNumber(const std::string& number, |
- Contact::AddressType::Relation relation, |
+ Contact_AddressType_Relation relation, |
const std::string& label, |
bool primary, |
Contact* contact) { |
DCHECK(contact); |
- Contact::PhoneNumber phone; |
- phone.number = number; |
- phone.type.relation = relation; |
- phone.type.label = label; |
- phone.primary = primary; |
- contact->phone_numbers.push_back(phone); |
+ Contact::PhoneNumber* phone = contact->add_phone_numbers(); |
+ phone->set_number(number); |
+ phone->mutable_type()->set_relation(relation); |
+ phone->mutable_type()->set_label(label); |
+ phone->set_primary(primary); |
} |
void AddPostalAddress(const std::string& address, |
- Contact::AddressType::Relation relation, |
+ Contact_AddressType_Relation relation, |
const std::string& label, |
bool primary, |
Contact* contact) { |
DCHECK(contact); |
- Contact::PostalAddress postal; |
- postal.address = address; |
- postal.type.relation = relation; |
- postal.type.label = label; |
- postal.primary = primary; |
- contact->postal_addresses.push_back(postal); |
+ Contact::PostalAddress* postal = contact->add_postal_addresses(); |
+ postal->set_address(address); |
+ postal->mutable_type()->set_relation(relation); |
+ postal->mutable_type()->set_label(label); |
+ postal->set_primary(primary); |
} |
void AddInstantMessagingAddress( |
const std::string& address, |
- Contact::InstantMessagingAddress::Protocol protocol, |
- Contact::AddressType::Relation relation, |
+ Contact_InstantMessagingAddress_Protocol protocol, |
+ Contact_AddressType_Relation relation, |
const std::string& label, |
bool primary, |
Contact* contact) { |
DCHECK(contact); |
- Contact::InstantMessagingAddress im; |
- im.address = address; |
- im.protocol = protocol; |
- im.type.relation = relation; |
- im.type.label = label; |
- im.primary = primary; |
- contact->instant_messaging_addresses.push_back(im); |
+ Contact::InstantMessagingAddress* im = |
+ contact->add_instant_messaging_addresses(); |
+ im->set_address(address); |
+ im->set_protocol(protocol); |
+ im->mutable_type()->set_relation(relation); |
+ im->mutable_type()->set_label(label); |
+ im->set_primary(primary); |
} |
void SetPhoto(const gfx::Size& size, Contact* contact) { |
DCHECK(contact); |
- contact->photo.setConfig( |
- SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
- contact->photo.allocPixels(); |
+ if (size.IsEmpty()) { |
+ contact->clear_raw_untrusted_photo(); |
+ return; |
+ } |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
+ bitmap.allocPixels(); |
+ std::vector<unsigned char> png_photo; |
+ CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_photo)); |
+ contact->set_raw_untrusted_photo(&png_photo[0], png_photo.size()); |
} |
} // namespace test |