Reland "Birch: Add and propagate file id to BirchAttachmentItem"
This reverts commit45f6ae81c4
. Reason for revert: Fix some Birch unittests which were landed and broke with this CL originally Original change's description: > Revert "Birch: Add and propagate file id to BirchAttachmentItem" > > This reverts commit9f9d18e2ba
. > > Reason for revert: cause failure: https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20ChromiumOS%20MSan%20Builder/68924/overview > > Original change's description: > > Birch: Add and propagate file id to BirchAttachmentItem > > > > Add fileId to the calendar attachment API query. Add a file_id member to > > the BirchAttachmentItem and propagate the file id from calendar API to > > the BirchAttachmentItem. This is in preparation for using the > > BirchItemRemover to remove attachment items by their file id. > > > > Bug: b/305094537 > > Change-Id: Ie0edb305a8220608e7baff070547d75c7638c17d > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5378872 > > Reviewed-by: Alex Ilin <alexilin@chromium.org> > > Reviewed-by: James Cook <jamescook@chromium.org> > > Reviewed-by: Jiaming Cheng <jiamingc@chromium.org> > > Commit-Queue: Matthew Mourgos <mmourgos@chromium.org> > > Cr-Commit-Position: refs/heads/main@{#1276896} > > Bug: b/305094537 > Change-Id: I5510afa33cdd980f521599fa4db6c771f7e60c1b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5386686 > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Fabian Sommer <fabiansommer@chromium.org> > Reviewed-by: Fabian Sommer <fabiansommer@chromium.org> > Owners-Override: Fabian Sommer <fabiansommer@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1276908} Bug: b/305094537 Change-Id: I39dcf64522485bc681324da9e291e0c7452c7481 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5386822 Reviewed-by: Jiaming Cheng <jiamingc@chromium.org> Reviewed-by: Alex Ilin <alexilin@chromium.org> Reviewed-by: James Cook <jamescook@chromium.org> Commit-Queue: Matthew Mourgos <mmourgos@chromium.org> Cr-Commit-Position: refs/heads/main@{#1277709}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
fa8db56f3b
commit
9ba5d8f55b
ash/birch
chrome/browser/ui/ash/birch
google_apis
@ -169,12 +169,14 @@ BirchAttachmentItem::BirchAttachmentItem(const std::u16string& title,
|
||||
const GURL& file_url,
|
||||
const GURL& icon_url,
|
||||
const base::Time& start_time,
|
||||
const base::Time& end_time)
|
||||
const base::Time& end_time,
|
||||
const std::string& file_id)
|
||||
: BirchItem(title, GetSubtitle()),
|
||||
file_url_(file_url),
|
||||
icon_url_(icon_url),
|
||||
start_time_(start_time),
|
||||
end_time_(end_time) {}
|
||||
end_time_(end_time),
|
||||
file_id_(file_id) {}
|
||||
|
||||
BirchAttachmentItem::BirchAttachmentItem(BirchAttachmentItem&&) = default;
|
||||
|
||||
@ -201,7 +203,7 @@ std::string BirchAttachmentItem::ToString() const {
|
||||
<< ", start: "
|
||||
<< UTF16ToUTF8(base::TimeFormatShortDateAndTime(start_time_))
|
||||
<< ", end: " << UTF16ToUTF8(base::TimeFormatShortDateAndTime(end_time_))
|
||||
<< "}";
|
||||
<< ", file_id: " << file_id_ << "}";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,8 @@ class ASH_EXPORT BirchAttachmentItem : public BirchItem {
|
||||
const GURL& file_url,
|
||||
const GURL& icon_url,
|
||||
const base::Time& start_time,
|
||||
const base::Time& end_time);
|
||||
const base::Time& end_time,
|
||||
const std::string& file_id);
|
||||
BirchAttachmentItem(BirchAttachmentItem&&);
|
||||
BirchAttachmentItem& operator=(BirchAttachmentItem&&);
|
||||
BirchAttachmentItem(const BirchAttachmentItem&);
|
||||
@ -157,6 +158,7 @@ class ASH_EXPORT BirchAttachmentItem : public BirchItem {
|
||||
const GURL& icon_url() const { return icon_url_; }
|
||||
const base::Time& start_time() const { return start_time_; }
|
||||
const base::Time& end_time() const { return end_time_; }
|
||||
const std::string& file_id() const { return file_id_; }
|
||||
|
||||
private:
|
||||
static std::u16string GetSubtitle();
|
||||
@ -165,6 +167,7 @@ class ASH_EXPORT BirchAttachmentItem : public BirchItem {
|
||||
GURL icon_url_; // Link to the file's icon's art asset.
|
||||
base::Time start_time_; // Start time of the event (used for ranking).
|
||||
base::Time end_time_; // End time of the event (used for ranking).
|
||||
std::string file_id_; // ID of the file.
|
||||
};
|
||||
|
||||
// A birch item which contains file path and time information.
|
||||
|
@ -123,7 +123,8 @@ TEST_F(BirchItemTest, Attachment_PerformAction_ValidUrl) {
|
||||
/*file_url=*/GURL("http://file.com/"),
|
||||
/*icon_url=*/GURL("http://attachment.icon"),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
item.PerformAction();
|
||||
EXPECT_EQ(new_window_delegate_->last_opened_url_, GURL("http://file.com/"));
|
||||
}
|
||||
@ -134,7 +135,8 @@ TEST_F(BirchItemTest, Attachment_PerformAction_Histograms) {
|
||||
/*file_url=*/GURL("http://file.com/"),
|
||||
/*icon_url=*/GURL("http://attachment.icon"),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
item.PerformAction();
|
||||
histograms.ExpectBucketCount("Ash.Birch.Bar.Activate", true, 1);
|
||||
histograms.ExpectBucketCount("Ash.Birch.Chip.Activate",
|
||||
@ -146,7 +148,8 @@ TEST_F(BirchItemTest, Attachment_PerformAction_EmptyUrl) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL("http://attachment.icon"),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
item.PerformAction();
|
||||
EXPECT_EQ(new_window_delegate_->last_opened_url_, GURL());
|
||||
}
|
||||
@ -259,7 +262,8 @@ TEST_F(BirchItemIconTest, Attachment_LoadIcon) {
|
||||
/*file_url=*/GURL("http://file.com/"),
|
||||
/*icon_url=*/GURL("http://attachment.icon"),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
|
||||
item.LoadIcon(base::BindOnce(
|
||||
[](const ui::ImageModel& icon) { EXPECT_FALSE(icon.IsEmpty()); }));
|
||||
@ -270,7 +274,8 @@ TEST_F(BirchItemIconTest, Attachment_LoadIcon_InvalidUrl) {
|
||||
/*file_url=*/GURL("http://file.com/"),
|
||||
/*icon_url=*/GURL("invalid-url"),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
|
||||
item.LoadIcon(base::BindOnce(
|
||||
[](const ui::ImageModel& icon) { EXPECT_TRUE(icon.IsEmpty()); }));
|
||||
|
@ -56,6 +56,20 @@ std::vector<BirchCalendarItem> MakeCalendarItemList(int event_count) {
|
||||
return calendar_item_list;
|
||||
}
|
||||
|
||||
std::vector<BirchAttachmentItem> MakeAttachmentItemList(int item_count) {
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
for (int i = 0; i < item_count; i++) {
|
||||
attachment_item_list.emplace_back(
|
||||
u"Attachment " + base::NumberToString16(i),
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time(),
|
||||
/*file_id=*/"");
|
||||
}
|
||||
return attachment_item_list;
|
||||
}
|
||||
|
||||
// A data provider that does nothing.
|
||||
class StubBirchDataProvider : public BirchDataProvider {
|
||||
public:
|
||||
@ -348,12 +362,7 @@ TEST_F(BirchModelTest, DisablingPrefsClearsModel) {
|
||||
|
||||
// Populate the model with every data type.
|
||||
model->SetCalendarItems(MakeCalendarItemList(/*event_count=*/1));
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
model->SetAttachmentItems(MakeAttachmentItemList(/*item_count=*/1));
|
||||
model->SetFileSuggestItems(MakeFileItemList(/*item_count=*/1));
|
||||
std::vector<BirchTabItem> tab_item_list;
|
||||
tab_item_list.emplace_back(u"tab", GURL("foo.bar"), base::Time(),
|
||||
@ -672,12 +681,7 @@ TEST_F(BirchModelTest, ResponseAfterFirstTimeout) {
|
||||
BirchTabItem::DeviceFormFactor::kDesktop);
|
||||
model->SetRecentTabItems(std::move(tab_item_list));
|
||||
model->SetCalendarItems(MakeCalendarItemList(/*event_count=*/1));
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
model->SetAttachmentItems(MakeAttachmentItemList(/*item_count=*/1));
|
||||
std::vector<BirchReleaseNotesItem> release_notes_item_list;
|
||||
release_notes_item_list.emplace_back(u"note", u"explore", GURL("foo.bar"),
|
||||
base::Time());
|
||||
@ -721,12 +725,7 @@ TEST_F(BirchModelTest, GetAllItems) {
|
||||
base::Time());
|
||||
model->SetReleaseNotesItems(std::move(release_notes_item_list));
|
||||
model->SetCalendarItems(MakeCalendarItemList(/*event_count=*/1));
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
model->SetAttachmentItems(MakeAttachmentItemList(/*item_count=*/1));
|
||||
std::vector<BirchTabItem> tab_item_list;
|
||||
tab_item_list.emplace_back(u"tab", GURL("foo.bar"), base::Time(),
|
||||
GURL("favicon"), "session",
|
||||
@ -752,12 +751,7 @@ TEST_F(BirchModelTest, SetItemListRecordsHistogram) {
|
||||
|
||||
// Insert one item of each type.
|
||||
model->SetCalendarItems(MakeCalendarItemList(/*event_count=*/1));
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
model->SetAttachmentItems(MakeAttachmentItemList(/*item_count=*/1));
|
||||
std::vector<BirchTabItem> tab_item_list;
|
||||
tab_item_list.emplace_back(u"tab", GURL("foo.bar"), base::Time(),
|
||||
GURL("favicon"), "session",
|
||||
@ -794,11 +788,8 @@ TEST_F(BirchModelTest, GetItemsForDisplay_EnoughTypes) {
|
||||
model->SetCalendarItems(std::move(calendar_item_list));
|
||||
|
||||
// Insert one item for other types.
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
std::vector<BirchAttachmentItem> attachment_item_list =
|
||||
MakeAttachmentItemList(/*item_count=*/1);
|
||||
|
||||
attachment_item_list.back().set_ranking(3.f);
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
@ -842,11 +833,8 @@ TEST_F(BirchModelTest, GetItemsForDisplay_IncludesDuplicateTypes) {
|
||||
model->SetCalendarItems(std::move(calendar_item_list));
|
||||
|
||||
// Then insert 3 other items with lower priority.
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
std::vector<BirchAttachmentItem> attachment_item_list =
|
||||
MakeAttachmentItemList(/*item_count=*/1);
|
||||
attachment_item_list.back().set_ranking(3.f);
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
|
||||
@ -888,16 +876,9 @@ TEST_F(BirchModelTest, GetItemsForDisplay_TwoDuplicateTypes) {
|
||||
model->SetCalendarItems(std::move(calendar_item_list));
|
||||
|
||||
// Insert 2 more items of a different type.
|
||||
std::vector<BirchAttachmentItem> attachment_item_list;
|
||||
attachment_item_list.emplace_back(u"Attachment 1", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
attachment_item_list.back().set_ranking(3.f);
|
||||
attachment_item_list.emplace_back(u"Attachment 2", /*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/base::Time(),
|
||||
/*end_time=*/base::Time());
|
||||
std::vector<BirchAttachmentItem> attachment_item_list =
|
||||
MakeAttachmentItemList(/*item_count=*/2);
|
||||
attachment_item_list.front().set_ranking(3.f);
|
||||
attachment_item_list.back().set_ranking(4.f);
|
||||
model->SetAttachmentItems(std::move(attachment_item_list));
|
||||
|
||||
|
@ -190,7 +190,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Morning) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 08:00 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 10:00 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 10:00 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Create an attachment for an upcoming event (9:15 to 9:45).
|
||||
BirchAttachmentItem item1(
|
||||
@ -198,7 +199,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Morning) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 09:15 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 09:45 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 09:45 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Create an attachment for another event later in the day (1 PM).
|
||||
BirchAttachmentItem item2(
|
||||
@ -206,7 +208,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Morning) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 13:00 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 13:30 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 13:30 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Put the items in the vector in reverse order to validate that they are
|
||||
// still handled in the correct order (by time) inside the ranker.
|
||||
@ -240,7 +243,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Evening) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 17:00 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 19:00 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 19:00 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Create an attachment for an upcoming event (6:15 PM).
|
||||
BirchAttachmentItem item1(
|
||||
@ -248,7 +252,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Evening) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 18:15 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 18:45 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 18:45 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Create an attachment for another event later in the evening (8 PM).
|
||||
BirchAttachmentItem item2(
|
||||
@ -256,7 +261,8 @@ TEST(BirchRankerTest, RankAttachmentItems_Evening) {
|
||||
/*file_url=*/GURL(),
|
||||
/*icon_url=*/GURL(),
|
||||
/*start_time=*/TimeFromString("22 Feb 2024 20:00 UTC"),
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 20:30 UTC"));
|
||||
/*end_time=*/TimeFromString("22 Feb 2024 20:30 UTC"),
|
||||
/*file_id=*/"");
|
||||
|
||||
// Put the items in the vector in reverse order to validate that they are
|
||||
// still handled in the correct order (by time) inside the ranker.
|
||||
|
@ -93,7 +93,7 @@ void BirchCalendarProvider::OnEventsFetched(
|
||||
BirchAttachmentItem birch_attachment(
|
||||
base::UTF8ToUTF16(attachment.title()), attachment.file_url(),
|
||||
attachment.icon_link(), item->start_time().date_time(),
|
||||
item->end_time().date_time());
|
||||
item->end_time().date_time(), attachment.file_id());
|
||||
attachment_items.push_back(std::move(birch_attachment));
|
||||
}
|
||||
}
|
||||
|
@ -125,10 +125,12 @@ TEST_F(BirchCalendarProviderTest, GetCalendarEvents_WithAttachments) {
|
||||
attachment0.set_title("attachment0");
|
||||
attachment0.set_file_url(GURL("http://file0.com/"));
|
||||
attachment0.set_icon_link(GURL("http://icon0.com/"));
|
||||
attachment0.set_file_id("file_id_0");
|
||||
google_apis::calendar::Attachment attachment1;
|
||||
attachment1.set_title("attachment1");
|
||||
attachment1.set_file_url(GURL("http://file1.com/"));
|
||||
attachment1.set_icon_link(GURL("http://icon1.com/"));
|
||||
attachment1.set_file_id("file_id_1");
|
||||
event->set_attachments({attachment0, attachment1});
|
||||
events->InjectItemForTesting(std::move(event));
|
||||
fetcher->events_ = std::move(events);
|
||||
@ -151,9 +153,11 @@ TEST_F(BirchCalendarProviderTest, GetCalendarEvents_WithAttachments) {
|
||||
EXPECT_EQ(attachments[0].title(), u"attachment0");
|
||||
EXPECT_EQ(attachments[0].file_url().spec(), "http://file0.com/");
|
||||
EXPECT_EQ(attachments[0].icon_url().spec(), "http://icon0.com/");
|
||||
EXPECT_EQ(attachments[0].file_id(), "file_id_0");
|
||||
EXPECT_EQ(attachments[1].title(), u"attachment1");
|
||||
EXPECT_EQ(attachments[1].file_url().spec(), "http://file1.com/");
|
||||
EXPECT_EQ(attachments[1].icon_url().spec(), "http://icon1.com/");
|
||||
EXPECT_EQ(attachments[1].file_id(), "file_id_1");
|
||||
}
|
||||
|
||||
TEST_F(BirchCalendarProviderTest, GetCalendarEvents_HttpError) {
|
||||
|
@ -69,7 +69,8 @@ std::string GetCalendarEventListFields(bool include_attachments) {
|
||||
"attendees(responseStatus,self),attendeesOmitted,"
|
||||
"conferenceData(conferenceId,entryPoints(entryPointType,uri)),"
|
||||
"creator(self)",
|
||||
include_attachments ? ",attachments(title,fileUrl,iconLink)" : "", ")"});
|
||||
include_attachments ? ",attachments(title,fileUrl,iconLink,fileId)" : "",
|
||||
")"});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -268,7 +268,7 @@ TEST_F(CalendarApiRequestsTest, GetEventListRequestWithAttachments) {
|
||||
"%2ChtmlLink%2Cattendees(responseStatus%2Cself)%2CattendeesOmitted"
|
||||
"%2CconferenceData(conferenceId%2CentryPoints(entryPointType%2Curi))"
|
||||
"%2Ccreator(self)"
|
||||
"%2Cattachments(title%2CfileUrl%2CiconLink))",
|
||||
"%2Cattachments(title%2CfileUrl%2CiconLink%2CfileId))",
|
||||
http_request_.relative_url);
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ constexpr char kAttachments[] = "attachments";
|
||||
constexpr char kAttachmentTitle[] = "title";
|
||||
constexpr char kAttachmentFileUrl[] = "fileUrl";
|
||||
constexpr char kAttachmentIconLink[] = "iconLink";
|
||||
constexpr char kAttachmentFileId[] = "fileId";
|
||||
|
||||
constexpr auto kEventStatuses =
|
||||
base::MakeFixedFlatMap<std::string_view, CalendarEvent::EventStatus>(
|
||||
@ -245,6 +246,11 @@ std::vector<Attachment> GetAttachments(const base::Value::Dict& dict) {
|
||||
attachment.set_icon_link(icon_link.is_valid() ? icon_link : GURL());
|
||||
}
|
||||
|
||||
const std::string* file_id = attachment_dict->FindString(kAttachmentFileId);
|
||||
if (title) {
|
||||
attachment.set_file_id(*file_id);
|
||||
}
|
||||
|
||||
result.push_back(std::move(attachment));
|
||||
}
|
||||
|
||||
|
@ -153,10 +153,15 @@ class Attachment {
|
||||
const GURL& icon_link() const { return icon_link_; }
|
||||
void set_icon_link(const GURL& icon_link) { icon_link_ = icon_link; }
|
||||
|
||||
// The file ID of the attachment.
|
||||
const std::string& file_id() const { return file_id_; }
|
||||
void set_file_id(const std::string& file_id) { file_id_ = file_id; }
|
||||
|
||||
private:
|
||||
std::string title_;
|
||||
GURL file_url_;
|
||||
GURL icon_link_;
|
||||
std::string file_id_;
|
||||
};
|
||||
|
||||
// Parses the event item from the response. Not every field is parsed. If you
|
||||
|
@ -244,6 +244,8 @@ TEST(CalendarAPIResponseTypesTest, ParseAttachments) {
|
||||
"https://www.gstatic.com/images/branding/product/1x/"
|
||||
"docs_2020q4_48dp.png");
|
||||
EXPECT_EQ(attachments[0].title(), "Google Docs Attachment");
|
||||
EXPECT_EQ(attachments[0].file_id(),
|
||||
"1yeRZ9Je4i9XvbnnOygitkXgJQpLvR98_TrfWRec84Bw");
|
||||
|
||||
EXPECT_EQ(attachments[1].file_url(),
|
||||
"https://docs.google.com/presentation/d/"
|
||||
@ -252,6 +254,8 @@ TEST(CalendarAPIResponseTypesTest, ParseAttachments) {
|
||||
"https://www.gstatic.com/images/branding/product/1x/"
|
||||
"slides_2020q4_48dp.png");
|
||||
EXPECT_EQ(attachments[1].title(), "Google Slides Attachment");
|
||||
EXPECT_EQ(attachments[1].file_id(),
|
||||
"17tkfUouD4CjwnW7cFWww4lk5__7parQy_eJBAwPIC-Q");
|
||||
}
|
||||
|
||||
TEST(CalendarAPIResponseTypesTest, ParseInvalidAttachments) {
|
||||
|
@ -106,12 +106,14 @@
|
||||
{
|
||||
"fileUrl": "https://docs.google.com/document/d/1yeRZ9Je4i9XvbnnOygitkXgJQpLvR98_TrfWRec84Bw/edit?tab=t.0&resourcekey=0-yNQRr67lHMYKNFyrXmvwBw",
|
||||
"title": "Google Docs Attachment",
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/docs_2020q4_48dp.png"
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/docs_2020q4_48dp.png",
|
||||
"fileId": "1yeRZ9Je4i9XvbnnOygitkXgJQpLvR98_TrfWRec84Bw"
|
||||
},
|
||||
{
|
||||
"fileUrl": "https://docs.google.com/presentation/d/17tkfUouD4CjwnW7cFWww4lk5__7parQy_eJBAwPIC-Q/edit#slide=id.p",
|
||||
"title": "Google Slides Attachment",
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/slides_2020q4_48dp.png"
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/slides_2020q4_48dp.png",
|
||||
"fileId": "17tkfUouD4CjwnW7cFWww4lk5__7parQy_eJBAwPIC-Q"
|
||||
}
|
||||
],
|
||||
"eventType": "default"
|
||||
|
@ -106,12 +106,14 @@
|
||||
{
|
||||
"fileUrl": "http:://docs.google.com/document/d/1yeRZ9Je4i9XvbnnOygitkXgJQpLvR98_TrfWRec84Bw/edit?tab=t.0&resourcekey=0-yNQRr67lHMYKNFyrXmvwBw",
|
||||
"title": "Google Docs Attachment",
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/docs_2020q4_48dp.png"
|
||||
"iconLink": "https://www.gstatic.com/images/branding/product/1x/docs_2020q4_48dp.png",
|
||||
"fileId": "1yeRZ9Je4i9XvbnnOygitkXgJQpLvR98_TrfWRec84Bw"
|
||||
},
|
||||
{
|
||||
"fileUrl": "https://docs.google.com/presentation/d/17tkfUouD4CjwnW7cFWww4lk5__7parQy_eJBAwPIC-Q/edit#slide=id.p",
|
||||
"title": "Google Slides Attachment",
|
||||
"iconLink": "www.gstatic.com/images/branding/product/1x/slides_2020q4_48dp.png"
|
||||
"iconLink": "www.gstatic.com/images/branding/product/1x/slides_2020q4_48dp.png",
|
||||
"fileId": "17tkfUouD4CjwnW7cFWww4lk5__7parQy_eJBAwPIC-Q"
|
||||
}
|
||||
],
|
||||
"eventType": "default"
|
||||
|
Reference in New Issue
Block a user