0

[SysUi download integration] Add the download resume button

In this CL, DisplayManager attaches the resume button metadata to
the display metadata if the download is able to be resumed.

This CL also implements the entry point to resume download from
holding space chips.

This CL adds a string for the download resume command text. Its
screenshot is attached to the issue.

Bug: b/307353486
Change-Id: Ie187dea3bc56a59597528c05dae5ec79fe0e928a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5116522
Reviewed-by: David Black <dmblack@google.com>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1237300}
This commit is contained in:
andrewxu
2023-12-14 00:55:12 +00:00
committed by Chromium LUCI CQ
parent b4351a8574
commit 4a5c576b6d
6 changed files with 69 additions and 8 deletions

@ -7389,6 +7389,9 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_DOWNLOAD_COMMAND_TEXT_PAUSE" desc="Text of the command to pause a download.">
Pause
</message>
<message name="IDS_ASH_DOWNLOAD_COMMAND_TEXT_RESUME" desc="Text of the command to resume a paused download.">
Resume
</message>
</messages>
</release>
</grit>

@ -0,0 +1 @@
17005fb71be33977cdefba9e05ce74e100aab28c

@ -150,6 +150,15 @@ DisplayMetadata DisplayManager::CalculateDisplayMetadata(
/*callback=*/base::DoNothing()),
&kPauseIcon, IDS_ASH_DOWNLOAD_COMMAND_TEXT_PAUSE, CommandType::kPause);
}
if (download_status.resumable.value_or(false)) {
command_infos.emplace_back(
base::BindRepeating(&crosapi::DownloadStatusUpdaterAsh::Resume,
base::Unretained(download_status_updater_),
download_status.guid,
/*callback=*/base::DoNothing()),
&kResumeIcon, IDS_ASH_DOWNLOAD_COMMAND_TEXT_RESUME,
CommandType::kResume);
}
display_metadata.command_infos = std::move(command_infos);
display_metadata.file_path = *download_status.full_path;

@ -25,6 +25,7 @@ namespace ash::download_status {
enum class CommandType {
kCancel,
kPause,
kResume,
};
// The metadata to display a download command.

@ -30,6 +30,8 @@ HoldingSpaceCommandId ConvertCommandTypeToId(CommandType type) {
return HoldingSpaceCommandId::kCancelItem;
case CommandType::kPause:
return HoldingSpaceCommandId::kPauseItem;
case CommandType::kResume:
return HoldingSpaceCommandId::kResumeItem;
}
}

@ -420,7 +420,7 @@ IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest,
}
IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest,
PauseDownloadViaContextMenu) {
PauseAndResumeDownloadViaContextMenu) {
crosapi::mojom::DownloadStatusPtr download = CreateInProgressDownloadStatus(
ProfileManager::GetActiveUserProfile(), /*received_bytes=*/0,
/*target_bytes=*/1024);
@ -440,22 +440,44 @@ IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest,
// Press ENTER to execute the "Pause" command and then check that the download
// is paused.
base::RunLoop run_loop;
auto run_loop = std::make_unique<base::RunLoop>();
EXPECT_CALL(download_status_updater_client(), Pause(download->guid, _))
.WillOnce([&](const std::string& guid,
crosapi::MockDownloadStatusUpdaterClient::PauseCallback
callback) {
download->pausable = false;
download->resumable = true;
Update(download->Clone());
std::move(callback).Run(/*handled=*/true);
run_loop.Quit();
run_loop->Quit();
});
PressAndReleaseKey(ui::VKEY_RETURN);
run_loop.Run();
run_loop->Run();
// Right click the download chip. Because the underlying download is paused,
// the context menu should contain a "Resume" command.
RightClick(download_chips[0]);
EXPECT_TRUE(SelectMenuItemWithCommandId(HoldingSpaceCommandId::kResumeItem));
// Press ENTER to execute the "Resume" command and then check that the
// download is resumed.
run_loop = std::make_unique<base::RunLoop>();
EXPECT_CALL(download_status_updater_client(), Resume(download->guid, _))
.WillOnce([&](const std::string& guid,
crosapi::MockDownloadStatusUpdaterClient::ResumeCallback
callback) {
download->pausable = true;
download->resumable = false;
Update(download->Clone());
std::move(callback).Run(/*handled=*/true);
run_loop->Quit();
});
PressAndReleaseKey(ui::VKEY_RETURN);
run_loop->Run();
}
IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest,
PauseDownloadViaSecondaryAction) {
PauseAndResumeDownloadViaSecondaryAction) {
crosapi::mojom::DownloadStatusPtr download = CreateInProgressDownloadStatus(
ProfileManager::GetActiveUserProfile(), /*received_bytes=*/0,
/*target_bytes=*/1024);
@ -480,18 +502,41 @@ IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest,
ViewDrawnWaiter().Wait(pause_button);
// Press `pause_button` and then check that the download is paused.
base::RunLoop run_loop;
auto run_loop = std::make_unique<base::RunLoop>();
EXPECT_CALL(download_status_updater_client(), Pause(download->guid, _))
.WillOnce([&](const std::string& guid,
crosapi::MockDownloadStatusUpdaterClient::PauseCallback
callback) {
download->pausable = false;
download->resumable = true;
Update(download->Clone());
std::move(callback).Run(/*handled=*/true);
run_loop.Quit();
run_loop->Quit();
});
test::Click(pause_button);
run_loop.Run();
run_loop->Run();
// Move mouse to `download_chip` and wait until `resume_button` shows.
test::MoveMouseTo(download_chip, /*count=*/10);
auto* const resume_button =
secondary_action_container->GetViewByID(kHoldingSpaceItemResumeButtonId);
ASSERT_TRUE(resume_button);
ViewDrawnWaiter().Wait(resume_button);
// Press `resume_button` and then check that the download is resumed.
run_loop = std::make_unique<base::RunLoop>();
EXPECT_CALL(download_status_updater_client(), Resume(download->guid, _))
.WillOnce([&](const std::string& guid,
crosapi::MockDownloadStatusUpdaterClient::ResumeCallback
callback) {
download->pausable = true;
download->resumable = false;
Update(download->Clone());
std::move(callback).Run(/*handled=*/true);
run_loop->Quit();
});
test::Click(resume_button);
run_loop->Run();
}
IN_PROC_BROWSER_TEST_F(HoldingSpaceDisplayClientBrowserTest, SecondaryLabel) {