Commit 9e5083e7 authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Show recent NearbyShared files in holding space tray

As nearby shared files are added to the model, show the item chips in
the holding space tray.
The recently nearby shared files will show on the Downloads section and
will be treated as regular downloads.

Bug: 1130625
Change-Id: I082f46945138e487bb926c019a404af31b6871a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514774Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823824}
parent 74fd7644
......@@ -856,6 +856,170 @@ TEST_F(HoldingSpaceTrayTest, PinnedFilesContainerWithFinalizedItemsOnly) {
items.pop_front();
pinned_files.pop_back();
}
test_api()->Close();
}
// Tests that as nearby shared files are added to the model, they show on the
// downloads container.
TEST_F(HoldingSpaceTrayTest, DownloadsContainerWithNearbySharedFiles) {
StartSession();
test_api()->Show();
EXPECT_TRUE(test_api()->PinnedFilesContainerShown());
EXPECT_FALSE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
ASSERT_TRUE(test_api()->GetDownloadChips().empty());
// Add a nearby share item and verify recent file container gets shown.
HoldingSpaceItem* item_1 = AddItem(HoldingSpaceItem::Type::kNearbyShare,
base::FilePath("/tmp/fake_1"));
ASSERT_TRUE(item_1->IsFinalized());
EXPECT_TRUE(test_api()->PinnedFilesContainerShown());
EXPECT_TRUE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
ASSERT_EQ(1u, test_api()->GetDownloadChips().size());
// Add a download item, and verify it's also shown in the UI in the order they
// were added.
HoldingSpaceItem* item_2 =
AddItem(HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake_2"));
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
std::vector<views::View*> download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_1->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
// Remove the first item, and verify the container gets updated.
model()->RemoveItem(item_1->id());
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(1u, download_chips.size());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
test_api()->Close();
}
// Tests that a partially initialized nearby share item does not get shown if a
// full download item gets removed from the holding space.
TEST_F(HoldingSpaceTrayTest, PartialNearbyShareItemWithExistingDownloadItems) {
StartSession();
test_api()->Show();
EXPECT_FALSE(test_api()->RecentFilesContainerShown());
ASSERT_TRUE(test_api()->GetDownloadChips().empty());
// Add partially initialized nearby share item - verify it doesn't get shown
// in the UI yet.
HoldingSpaceItem* item_1 = AddPartiallyInitializedItem(
HoldingSpaceItem::Type::kNearbyShare, base::FilePath("/tmp/fake_1"));
EXPECT_FALSE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetDownloadChips().empty());
// Add two download items.
HoldingSpaceItem* item_2 =
AddItem(HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake_2"));
HoldingSpaceItem* item_3 =
AddItem(HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake_3"));
EXPECT_TRUE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
std::vector<views::View*> download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
// Finalize the nearby share item and verify it is not shown.
model()->FinalizeOrRemoveItem(item_1->id(), GURL("filesystem:fake_1"));
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
// Remove one of the fully initialized items, and verify the partially
// initialized item is not shown.
model()->RemoveItem(item_2->id());
download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_1->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
test_api()->Close();
}
// Tests that a partially initialized download item does not get shown if a
// full download item gets removed from the holding space.
TEST_F(HoldingSpaceTrayTest, PartialDownloadItemWithExistingNearbyShareItems) {
StartSession();
test_api()->Show();
EXPECT_FALSE(test_api()->RecentFilesContainerShown());
ASSERT_TRUE(test_api()->GetDownloadChips().empty());
// Add partially initialized download item - verify it doesn't get shown
// in the UI yet.
HoldingSpaceItem* item_1 = AddPartiallyInitializedItem(
HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake_1"));
EXPECT_FALSE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetDownloadChips().empty());
// Add two nearby share items.
HoldingSpaceItem* item_2 = AddItem(HoldingSpaceItem::Type::kNearbyShare,
base::FilePath("/tmp/fake_2"));
HoldingSpaceItem* item_3 = AddItem(HoldingSpaceItem::Type::kNearbyShare,
base::FilePath("/tmp/fake_3"));
EXPECT_TRUE(test_api()->RecentFilesContainerShown());
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
std::vector<views::View*> download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
// Finalize the download item and verify it is not shown.
model()->FinalizeOrRemoveItem(item_1->id(), GURL("filesystem:fake_1"));
EXPECT_TRUE(test_api()->GetPinnedFileChips().empty());
EXPECT_TRUE(test_api()->GetScreenCaptureViews().empty());
download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_2->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
// Remove one of the fully initialized items, and verify the partially
// initialized item is not shown.
model()->RemoveItem(item_2->id());
download_chips = test_api()->GetDownloadChips();
ASSERT_EQ(2u, download_chips.size());
EXPECT_EQ(item_3->id(),
HoldingSpaceItemView::Cast(download_chips[0])->item()->id());
EXPECT_EQ(item_1->id(),
HoldingSpaceItemView::Cast(download_chips[1])->item()->id());
test_api()->Close();
}
......
......@@ -46,6 +46,18 @@ void SetupLabel(views::Label* label) {
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
}
bool BelongsToDownloadsSection(HoldingSpaceItem::Type type) {
return type == HoldingSpaceItem::Type::kDownload ||
type == HoldingSpaceItem::Type::kNearbyShare;
}
bool ItemsBelongsToSameSection(HoldingSpaceItem::Type candidate_type,
HoldingSpaceItem::Type item_type) {
return candidate_type == item_type ||
(BelongsToDownloadsSection(candidate_type) &&
BelongsToDownloadsSection(candidate_type));
}
// DownloadsHeader--------------------------------------------------------------
class DownloadsHeader : public views::Button {
......@@ -151,7 +163,7 @@ void RecentFilesContainer::AddHoldingSpaceItemView(const HoldingSpaceItem* item,
DCHECK(item->IsFinalized());
if (item->type() != HoldingSpaceItem::Type::kScreenshot &&
item->type() != HoldingSpaceItem::Type::kDownload) {
!BelongsToDownloadsSection(item->type())) {
return;
}
......@@ -163,14 +175,16 @@ void RecentFilesContainer::AddHoldingSpaceItemView(const HoldingSpaceItem* item,
base::Reversed(HoldingSpaceController::Get()->model()->items())) {
if (candidate->id() == item->id())
break;
if (candidate->IsFinalized() && candidate->type() == item->type())
if (candidate->IsFinalized() &&
ItemsBelongsToSameSection(candidate->type(), item->type())) {
++index;
}
}
}
if (item->type() == HoldingSpaceItem::Type::kScreenshot)
AddHoldingSpaceScreenCaptureView(item, index);
else if (item->type() == HoldingSpaceItem::Type::kDownload)
else if (BelongsToDownloadsSection(item->type()))
AddHoldingSpaceDownloadView(item, index);
}
......@@ -184,7 +198,7 @@ void RecentFilesContainer::RemoveHoldingSpaceItemView(
const HoldingSpaceItem* item) {
if (item->type() == HoldingSpaceItem::Type::kScreenshot)
RemoveHoldingSpaceScreenCaptureView(item);
else if (item->type() == HoldingSpaceItem::Type::kDownload)
else if (BelongsToDownloadsSection(item->type()))
RemoveHoldingSpaceDownloadView(item);
}
......@@ -247,7 +261,7 @@ void RecentFilesContainer::RemoveHoldingSpaceScreenCaptureView(
void RecentFilesContainer::AddHoldingSpaceDownloadView(
const HoldingSpaceItem* item,
size_t index) {
DCHECK_EQ(item->type(), HoldingSpaceItem::Type::kDownload);
DCHECK(BelongsToDownloadsSection(item->type()));
DCHECK(!base::Contains(views_by_item_id_, item->id()));
if (index >= kMaxDownloads)
......@@ -268,7 +282,7 @@ void RecentFilesContainer::AddHoldingSpaceDownloadView(
void RecentFilesContainer::RemoveHoldingSpaceDownloadView(
const HoldingSpaceItem* item) {
DCHECK_EQ(item->type(), HoldingSpaceItem::Type::kDownload);
DCHECK(BelongsToDownloadsSection(item->type()));
auto it = views_by_item_id_.find(item->id());
if (it == views_by_item_id_.end())
......@@ -286,8 +300,7 @@ void RecentFilesContainer::RemoveHoldingSpaceDownloadView(
// back in order to maintain sort by recency.
for (const auto& candidate :
base::Reversed(HoldingSpaceController::Get()->model()->items())) {
if (candidate->IsFinalized() &&
candidate->type() == HoldingSpaceItem::Type::kDownload &&
if (candidate->IsFinalized() && BelongsToDownloadsSection(item->type()) &&
!base::Contains(views_by_item_id_, candidate->id())) {
views_by_item_id_[candidate->id()] = downloads_container_->AddChildView(
std::make_unique<HoldingSpaceItemChipView>(delegate_,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment