Commit 4c8a62ca authored by David Black's avatar David Black Committed by Commit Bot

Add test coverage for drag-and-drop of download chips.

Bug: 1124581
Change-Id: I6dead04514935b1a6f5a9abc9f6e4398991776f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399455
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805454}
parent 3f4d3cca
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
namespace ash { namespace ash {
// UI constants. // Appearance.
constexpr gfx::Insets kHoldingSpaceContainerPadding(16); constexpr gfx::Insets kHoldingSpaceContainerPadding(16);
constexpr int kHoldingSpaceContainerSeparation = 8; constexpr int kHoldingSpaceContainerSeparation = 8;
constexpr gfx::Insets kHoldingSpaceChipPadding(8); constexpr gfx::Insets kHoldingSpaceChipPadding(8);
...@@ -22,6 +22,10 @@ constexpr int kHoldingSpaceColumnWidth = 160; ...@@ -22,6 +22,10 @@ constexpr int kHoldingSpaceColumnWidth = 160;
constexpr int kHoldingSpaceRowPadding = 8; constexpr int kHoldingSpaceRowPadding = 8;
constexpr gfx::Size kHoldingSpaceScreenshotSize(104, 80); constexpr gfx::Size kHoldingSpaceScreenshotSize(104, 80);
// View IDs.
constexpr int kHoldingSpacePinnedFilesContainerId = 1;
constexpr int kHoldingSpaceRecentFilesContainerId = 2;
} // namespace ash } // namespace ash
#endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONSTANTS_H_ #endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONSTANTS_H_
...@@ -42,6 +42,10 @@ class ASH_EXPORT HoldingSpaceTestApi { ...@@ -42,6 +42,10 @@ class ASH_EXPORT HoldingSpaceTestApi {
// Returns true if holding space UI is showing, false otherwise. // Returns true if holding space UI is showing, false otherwise.
bool IsShowing(); bool IsShowing();
// Returns the collection of download chips in holding space UI.
// If holding space UI is not visible, an empty collection is returned.
std::vector<views::View*> GetDownloadChips();
// Returns the collection of pinned file chips in holding space UI. // Returns the collection of pinned file chips in holding space UI.
// If holding space UI is not visible, an empty collection is returned. // If holding space UI is not visible, an empty collection is returned.
std::vector<views::View*> GetPinnedFileChips(); std::vector<views::View*> GetPinnedFileChips();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/public/cpp/holding_space/holding_space_test_api.h" #include "ash/public/cpp/holding_space/holding_space_test_api.h"
#include "ash/drag_drop/drag_drop_controller.h" #include "ash/drag_drop/drag_drop_controller.h"
#include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/test/shell_test_api.h" #include "ash/public/cpp/test/shell_test_api.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
...@@ -88,18 +89,37 @@ bool HoldingSpaceTestApi::IsShowing() { ...@@ -88,18 +89,37 @@ bool HoldingSpaceTestApi::IsShowing() {
holding_space_tray_->GetBubbleView()->GetVisible(); holding_space_tray_->GetBubbleView()->GetVisible();
} }
std::vector<views::View*> HoldingSpaceTestApi::GetDownloadChips() {
std::vector<views::View*> download_chips;
if (holding_space_tray_->GetBubbleView()) {
FindDescendentsOfClass<HoldingSpaceItemChipView>(
holding_space_tray_->GetBubbleView()->GetViewByID(
kHoldingSpaceRecentFilesContainerId),
&download_chips);
}
return download_chips;
}
std::vector<views::View*> HoldingSpaceTestApi::GetPinnedFileChips() { std::vector<views::View*> HoldingSpaceTestApi::GetPinnedFileChips() {
std::vector<views::View*> chips; std::vector<views::View*> pinned_file_chips;
FindDescendentsOfClass<HoldingSpaceItemChipView>( if (holding_space_tray_->GetBubbleView()) {
holding_space_tray_->GetBubbleView(), &chips); FindDescendentsOfClass<HoldingSpaceItemChipView>(
return chips; holding_space_tray_->GetBubbleView()->GetViewByID(
kHoldingSpacePinnedFilesContainerId),
&pinned_file_chips);
}
return pinned_file_chips;
} }
std::vector<views::View*> HoldingSpaceTestApi::GetScreenshotViews() { std::vector<views::View*> HoldingSpaceTestApi::GetScreenshotViews() {
std::vector<views::View*> screenshots; std::vector<views::View*> screenshot_views;
FindDescendentsOfClass<HoldingSpaceScreenshotView>( if (holding_space_tray_->GetBubbleView()) {
holding_space_tray_->GetBubbleView(), &screenshots); FindDescendentsOfClass<HoldingSpaceScreenshotView>(
return screenshots; holding_space_tray_->GetBubbleView()->GetViewByID(
kHoldingSpaceRecentFilesContainerId),
&screenshot_views);
}
return screenshot_views;
} }
} // namespace ash } // namespace ash
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
namespace ash { namespace ash {
PinnedFilesContainer::PinnedFilesContainer() { PinnedFilesContainer::PinnedFilesContainer() {
SetID(kHoldingSpacePinnedFilesContainerId);
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding)); views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding));
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
namespace ash { namespace ash {
RecentFilesContainer::RecentFilesContainer() { RecentFilesContainer::RecentFilesContainer() {
SetID(kHoldingSpaceRecentFilesContainerId);
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding)); views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding));
auto setup_layered_child = [](views::View* child) { auto setup_layered_child = [](views::View* child) {
......
...@@ -27,6 +27,23 @@ namespace { ...@@ -27,6 +27,23 @@ namespace {
// Helpers --------------------------------------------------------------------- // Helpers ---------------------------------------------------------------------
// Adds and returns a holding space item of the specified `type` backed by the
// file at the specified `file_path`.
HoldingSpaceItem* AddItem(HoldingSpaceItem::Type type,
const base::FilePath& file_path) {
auto item = HoldingSpaceItem::CreateFileBackedItem(
type, file_path,
/*file_system_url=*/GURL(),
/*image=*/
std::make_unique<HoldingSpaceImage>(
/*placeholder=*/gfx::ImageSkia(),
/*async_bitmap_resolver=*/base::DoNothing()));
auto* item_ptr = item.get();
HoldingSpaceController::Get()->model()->AddItem(std::move(item));
return item_ptr;
}
// Returns the path of the downloads mount point for the given `profile`. // Returns the path of the downloads mount point for the given `profile`.
base::FilePath GetDownloadsPath(Profile* profile) { base::FilePath GetDownloadsPath(Profile* profile) {
base::FilePath result; base::FilePath result;
...@@ -102,40 +119,28 @@ bool HoldingSpaceBrowserTestBase::IsShowing() { ...@@ -102,40 +119,28 @@ bool HoldingSpaceBrowserTestBase::IsShowing() {
return test_api_->IsShowing(); return test_api_->IsShowing();
} }
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddPinnedFile() { HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddDownloadFile() {
auto item = HoldingSpaceItem::CreateFileBackedItem( return AddItem(HoldingSpaceItem::Type::kDownload,
HoldingSpaceItem::Type::kPinnedFile, /*file_path=*/CreateTextFile(GetProfile()));
/*file_path=*/CreateTextFile(GetProfile()), }
/*file_system_url=*/GURL(),
/*image=*/
std::make_unique<HoldingSpaceImage>(
/*placeholder=*/gfx::ImageSkia(),
/*async_bitmap_resolver=*/base::DoNothing()));
auto* item_ptr = item.get(); HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddPinnedFile() {
HoldingSpaceController::Get()->model()->AddItem(std::move(item)); return AddItem(HoldingSpaceItem::Type::kPinnedFile,
return item_ptr; /*file_path=*/CreateTextFile(GetProfile()));
} }
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddScreenshotFile() { HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddScreenshotFile() {
auto item = HoldingSpaceItem::CreateFileBackedItem( return AddItem(HoldingSpaceItem::Type::kScreenshot,
HoldingSpaceItem::Type::kScreenshot, /*file_path=*/CreateImageFile(GetProfile()));
/*file_path=*/CreateImageFile(GetProfile()), }
/*file_system_url=*/GURL(),
/*image=*/
std::make_unique<HoldingSpaceImage>(
/*placeholder=*/gfx::ImageSkia(),
/*async_bitmap_resolver=*/base::DoNothing()));
auto* item_ptr = item.get(); std::vector<views::View*> HoldingSpaceBrowserTestBase::GetDownloadChips() {
HoldingSpaceController::Get()->model()->AddItem(std::move(item)); return test_api_->GetDownloadChips();
return item_ptr;
} }
std::vector<views::View*> HoldingSpaceBrowserTestBase::GetPinnedFileChips() { std::vector<views::View*> HoldingSpaceBrowserTestBase::GetPinnedFileChips() {
return test_api_->GetPinnedFileChips(); return test_api_->GetPinnedFileChips();
} }
std::vector<views::View*> HoldingSpaceBrowserTestBase::GetScreenshotViews() { std::vector<views::View*> HoldingSpaceBrowserTestBase::GetScreenshotViews() {
return test_api_->GetScreenshotViews(); return test_api_->GetScreenshotViews();
} }
......
...@@ -47,12 +47,19 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest { ...@@ -47,12 +47,19 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest {
// Returns true if holding space UI is showing, false otherwise. // Returns true if holding space UI is showing, false otherwise.
bool IsShowing(); bool IsShowing();
// Adds and returns an arbitrary download file to the holding space.
HoldingSpaceItem* AddDownloadFile();
// Adds and returns an arbitrary pinned file to the holding space. // Adds and returns an arbitrary pinned file to the holding space.
HoldingSpaceItem* AddPinnedFile(); HoldingSpaceItem* AddPinnedFile();
// Adds and returns an arbitrary screenshot file to the holding space. // Adds and returns an arbitrary screenshot file to the holding space.
HoldingSpaceItem* AddScreenshotFile(); HoldingSpaceItem* AddScreenshotFile();
// Returns the collection of download chips in holding space UI.
// If holding space UI is not visible, an empty collection is returned.
std::vector<views::View*> GetDownloadChips();
// Returns the collection of pinned file chips in holding space UI. // Returns the collection of pinned file chips in holding space UI.
// If holding space UI is not visible, an empty collection is returned. // If holding space UI is not visible, an empty collection is returned.
std::vector<views::View*> GetPinnedFileChips(); std::vector<views::View*> GetPinnedFileChips();
......
...@@ -90,26 +90,33 @@ using HoldingSpaceUiBrowserTest = HoldingSpaceBrowserTestBase; ...@@ -90,26 +90,33 @@ using HoldingSpaceUiBrowserTest = HoldingSpaceBrowserTestBase;
// Verifies that drag-and-drop of holding space items works. // Verifies that drag-and-drop of holding space items works.
IN_PROC_BROWSER_TEST_F(HoldingSpaceUiBrowserTest, DragAndDrop) { IN_PROC_BROWSER_TEST_F(HoldingSpaceUiBrowserTest, DragAndDrop) {
HoldingSpaceItem* const download_file = AddDownloadFile();
HoldingSpaceItem* const pinned_file = AddPinnedFile(); HoldingSpaceItem* const pinned_file = AddPinnedFile();
HoldingSpaceItem* const screenshot_file = AddScreenshotFile(); HoldingSpaceItem* const screenshot_file = AddScreenshotFile();
Show(); Show();
ASSERT_TRUE(IsShowing()); ASSERT_TRUE(IsShowing());
std::vector<views::View*> chips = GetPinnedFileChips(); std::vector<views::View*> download_chips = GetDownloadChips();
ASSERT_EQ(1u, chips.size()); ASSERT_EQ(1u, download_chips.size());
std::vector<views::View*> screenshots = GetScreenshotViews(); std::vector<views::View*> pinned_file_chips = GetPinnedFileChips();
ASSERT_EQ(1u, screenshots.size()); ASSERT_EQ(1u, pinned_file_chips.size());
std::vector<views::View*> screenshot_views = GetScreenshotViews();
ASSERT_EQ(1u, screenshot_views.size());
auto* drop_target_view = DropTargetView::Create(GetRootWindowForNewWindows()); auto* drop_target_view = DropTargetView::Create(GetRootWindowForNewWindows());
drop_target_view->GetWidget()->SetBounds(gfx::Rect(0, 0, 100, 100)); drop_target_view->GetWidget()->SetBounds(gfx::Rect(0, 0, 100, 100));
drop_target_view->GetWidget()->ShowInactive(); drop_target_view->GetWidget()->ShowInactive();
MouseDrag(/*from=*/chips[0], /*to=*/drop_target_view); MouseDrag(/*from=*/download_chips[0], /*to=*/drop_target_view);
EXPECT_EQ(download_file->file_path(), drop_target_view->copied_file_path());
MouseDrag(/*from=*/pinned_file_chips[0], /*to=*/drop_target_view);
EXPECT_EQ(pinned_file->file_path(), drop_target_view->copied_file_path()); EXPECT_EQ(pinned_file->file_path(), drop_target_view->copied_file_path());
MouseDrag(/*from=*/screenshots[0], /*to=*/drop_target_view); MouseDrag(/*from=*/screenshot_views[0], /*to=*/drop_target_view);
EXPECT_EQ(screenshot_file->file_path(), drop_target_view->copied_file_path()); EXPECT_EQ(screenshot_file->file_path(), drop_target_view->copied_file_path());
drop_target_view->GetWidget()->Close(); drop_target_view->GetWidget()->Close();
......
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