Commit 017286f2 authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Introduce screen recordings files to holding space

Add screen recordings video files type to holding space.

Screen recordings are video captures of the contents of the user
display. These files will be added in to the screen captures area of the
holding space tray and will be treated in the same way as screenshots.

Bug: 1144927
Change-Id: I0f47d1670b1bcd0e43d514325962ef3669a84901
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518411Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825529}
parent a140f2d7
......@@ -37,6 +37,8 @@ std::string TypeToString(HoldingSpaceItem::Type type) {
return "screenshot";
case HoldingSpaceItem::Type::kNearbyShare:
return "nearby_share";
case HoldingSpaceItem::Type::kScreenRecording:
return "screen_recording";
}
}
......
......@@ -35,7 +35,8 @@ class ASH_PUBLIC_EXPORT HoldingSpaceItem {
kScreenshot = 1,
kDownload = 2,
kNearbyShare = 3,
kMaxValue = kNearbyShare,
kScreenRecording = 4,
kMaxValue = kScreenRecording,
};
HoldingSpaceItem(const HoldingSpaceItem&) = delete;
......
......@@ -52,6 +52,8 @@ std::string ItemTypeToString(HoldingSpaceItem::Type type) {
return "Screenshot";
case HoldingSpaceItem::Type::kNearbyShare:
return "NearbyShare";
case HoldingSpaceItem::Type::kScreenRecording:
return "ScreenRecording";
}
NOTREACHED();
return std::string();
......
......@@ -171,6 +171,11 @@ HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddScreenshotFile() {
/*file_path=*/CreateImageFile(GetProfile()));
}
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddScreenRecordingFile() {
return AddItem(GetProfile(), HoldingSpaceItem::Type::kScreenRecording,
/*file_path=*/CreateImageFile(GetProfile()));
}
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddItem(
Profile* profile,
HoldingSpaceItem::Type type,
......
......@@ -64,6 +64,9 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest {
// Adds and returns an arbitrary screenshot file to the holding space.
HoldingSpaceItem* AddScreenshotFile();
// Adds and returns an arbitrary screen recording file to the holding space.
HoldingSpaceItem* AddScreenRecordingFile();
// Adds and returns a holding space item of the specified `type` backed by the
// file at the specified `file_path`.
HoldingSpaceItem* AddItem(Profile* profile,
......
......@@ -198,6 +198,21 @@ void HoldingSpaceKeyedService::AddNearbyShare(
nearby_share_path)));
}
void HoldingSpaceKeyedService::AddScreenRecording(
const base::FilePath& screen_recording_file) {
GURL file_system_url =
holding_space_util::ResolveFileSystemUrl(profile_, screen_recording_file);
if (file_system_url.is_empty())
return;
AddItem(HoldingSpaceItem::CreateFileBackedItem(
HoldingSpaceItem::Type::kScreenRecording, screen_recording_file,
file_system_url,
holding_space_util::ResolveImage(&thumbnail_loader_,
HoldingSpaceItem::Type::kScreenRecording,
screen_recording_file)));
}
void HoldingSpaceKeyedService::AddItem(std::unique_ptr<HoldingSpaceItem> item) {
holding_space_model_.AddItem(std::move(item));
}
......
......@@ -77,6 +77,9 @@ class HoldingSpaceKeyedService : public KeyedService,
// Adds a nearby share item backed by the provided absolute file path.
void AddNearbyShare(const base::FilePath& nearby_share_path);
// Adds a screen recording item backed by the provided absolute file path.
void AddScreenRecording(const base::FilePath& screen_recording_path);
// Adds the specified `item` to the holding space model.
void AddItem(std::unique_ptr<HoldingSpaceItem> item);
......
......@@ -1351,4 +1351,88 @@ TEST_F(HoldingSpaceKeyedServiceNearbySharingTest, AddNearbyShareItem) {
EXPECT_EQ(base::ASCIIToUTF16("File 2.png"), item_2->text());
}
TEST_F(HoldingSpaceKeyedServiceTest, AddScreenRecordingItem) {
// Create a test downloads mount point.
std::unique_ptr<ScopedTestMountPoint> downloads_mount =
ScopedTestMountPoint::CreateAndMountDownloads(GetProfile());
ASSERT_TRUE(downloads_mount->IsValid());
// Wait for the holding space model.
HoldingSpaceModelAttachedWaiter(GetProfile()).Wait();
// Verify that the holding space model gets set even if the holding space
// keyed service is not explicitly created.
HoldingSpaceModel* const initial_model =
HoldingSpaceController::Get()->model();
EXPECT_TRUE(initial_model);
HoldingSpaceKeyedService* const holding_space_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(GetProfile());
const base::FilePath item_1_virtual_path("Screen Recording 1.mpg");
// Create some fake screen recording file on the local file system - later
// parts of the test will try to resolve the file's file system URL, which
// fails if the file does not exist.
const base::FilePath item_1_full_path =
downloads_mount->CreateFile(item_1_virtual_path, "recording 1");
ASSERT_FALSE(item_1_full_path.empty());
holding_space_service->AddScreenRecording(item_1_full_path);
const base::FilePath item_2_virtual_path =
base::FilePath("Alt/Screen Recording 2.mpg");
const base::FilePath item_2_full_path =
downloads_mount->CreateFile(item_2_virtual_path, "recording 2");
ASSERT_FALSE(item_2_full_path.empty());
holding_space_service->AddScreenRecording(item_2_full_path);
EXPECT_EQ(initial_model, HoldingSpaceController::Get()->model());
EXPECT_EQ(HoldingSpaceController::Get()->model(),
holding_space_service->model_for_testing());
HoldingSpaceModel* const model = HoldingSpaceController::Get()->model();
ASSERT_EQ(2u, model->items().size());
const HoldingSpaceItem* item_1 = model->items()[0].get();
EXPECT_EQ(item_1_full_path, item_1->file_path());
EXPECT_TRUE(gfx::BitmapsAreEqual(
*holding_space_util::ResolveImage(
holding_space_service->thumbnail_loader_for_testing(),
HoldingSpaceItem::Type::kScreenRecording, item_1_full_path)
->image_skia()
.bitmap(),
*item_1->image().image_skia().bitmap()));
// Verify the item file system URL resolves to the correct file in the file
// manager's context.
EXPECT_EQ(item_1_virtual_path,
GetVirtualPathFromUrl(item_1->file_system_url(),
downloads_mount->name()));
EXPECT_EQ(base::ASCIIToUTF16("Screen Recording 1.mpg"), item_1->text());
const HoldingSpaceItem* item_2 = model->items()[1].get();
EXPECT_EQ(item_2_full_path, item_2->file_path());
EXPECT_TRUE(gfx::BitmapsAreEqual(
*holding_space_util::ResolveImage(
holding_space_service->thumbnail_loader_for_testing(),
HoldingSpaceItem::Type::kScreenRecording, item_2_full_path)
->image_skia()
.bitmap(),
*item_2->image().image_skia().bitmap()));
// Verify the item file system URL resolves to the correct file in the file
// manager's context.
EXPECT_EQ(item_2_virtual_path,
GetVirtualPathFromUrl(item_2->file_system_url(),
downloads_mount->name()));
EXPECT_EQ(base::ASCIIToUTF16("Screen Recording 2.mpg"), item_2->text());
// Attempt to add an item with an empty file. Verify nothing gets added to the
// model.
const base::FilePath item_3_virtual_path = base::FilePath("");
const base::FilePath item_3_full_path =
downloads_mount->CreateFile(item_3_virtual_path, "");
ASSERT_TRUE(item_3_full_path.empty());
holding_space_service->AddScreenRecording(item_3_full_path);
ASSERT_EQ(2u, model->items().size());
}
} // namespace ash
......@@ -36,6 +36,7 @@ gfx::ImageSkia GetPlaceholderImage(HoldingSpaceItem::Type type,
case HoldingSpaceItem::Type::kPinnedFile:
size = gfx::Size(kHoldingSpaceChipIconSize, kHoldingSpaceChipIconSize);
break;
case HoldingSpaceItem::Type::kScreenRecording:
case HoldingSpaceItem::Type::kScreenshot:
size = kHoldingSpaceScreenCaptureSize;
break;
......
......@@ -36239,6 +36239,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="1" label="kScreenshot"/>
<int value="2" label="kDownload"/>
<int value="3" label="kNearbyShare"/>
<int value="4" label="kScreenRecording"/>
</enum>
<enum name="HoldingSpacePodAction">
......@@ -115,6 +115,8 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<suffix name="Download" label="Items backed by a download file."/>
<suffix name="NearbyShare" label="Items backed by a nearby shared file."/>
<suffix name="PinnedFile" label="Items pinned explicitly by the user."/>
<suffix name="ScreenRecording"
label="Items backed by a screen recording file."/>
<suffix name="Screenshot" label="Items backed by a screenshot file."/>
<affected-histogram name="HoldingSpace.Item.Count"/>
</histogram_suffixes>
......
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