Commit 6737891c authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Support indeterminate progress in native Windows notifications

This adds support for indeterminate progress in native Windows
notifications. Progress values outside the [0-100] range will now show a
spinner instead of a bar set to 0.

Bug: 1064584
Change-Id: I70c483bdd37d717393486cc7c9519aab8787f8b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120493Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753291}
parent dc7658f8
...@@ -57,6 +57,7 @@ const char kHintCrop[] = "hint-crop"; ...@@ -57,6 +57,7 @@ const char kHintCrop[] = "hint-crop";
const char kHintCropNone[] = "none"; const char kHintCropNone[] = "none";
const char kImageElement[] = "image"; const char kImageElement[] = "image";
const char kImageUri[] = "imageUri"; const char kImageUri[] = "imageUri";
const char kIndeterminate[] = "indeterminate";
const char kInputElement[] = "input"; const char kInputElement[] = "input";
const char kInputId[] = "id"; const char kInputId[] = "id";
const char kInputType[] = "type"; const char kInputType[] = "type";
...@@ -224,8 +225,15 @@ void WriteProgressElement(XmlWriter* xml_writer, ...@@ -224,8 +225,15 @@ void WriteProgressElement(XmlWriter* xml_writer,
xml_writer->StartElement(kProgress); xml_writer->StartElement(kProgress);
// Status is mandatory, without it the progress bar is not shown. // Status is mandatory, without it the progress bar is not shown.
xml_writer->AddAttribute(kStatus, std::string()); xml_writer->AddAttribute(kStatus, std::string());
xml_writer->AddAttribute(
kValue, base::StringPrintf("%3.2f", 1.0 * notification.progress() / 100)); // Show indeterminate spinner for values outside the [0-100] range.
if (notification.progress() < 0 || notification.progress() > 100) {
xml_writer->AddAttribute(kValue, kIndeterminate);
} else {
double value = 1.0 * notification.progress() / 100;
xml_writer->AddAttribute(kValue, base::StringPrintf("%3.2f", value));
}
xml_writer->EndElement(); xml_writer->EndElement();
} }
......
...@@ -478,6 +478,33 @@ TEST_F(NotificationTemplateBuilderTest, ProgressBar) { ...@@ -478,6 +478,33 @@ TEST_F(NotificationTemplateBuilderTest, ProgressBar) {
ASSERT_NO_FATAL_FAILURE(VerifyXml(notification, kExpectedXml)); ASSERT_NO_FATAL_FAILURE(VerifyXml(notification, kExpectedXml));
} }
TEST_F(NotificationTemplateBuilderTest, ProgressBar_Indeterminate) {
message_center::Notification notification = BuildNotification();
notification.set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
// Setting the progress outside the [0-100] range should result in an
// indeterminate progress notification.
notification.set_progress(-1);
const wchar_t kExpectedXml[] =
LR"(<toast launch="0|0|Default|0|https://example.com/|notification_id" displayTimestamp="1998-09-04T01:02:03Z">
<visual>
<binding template="ToastGeneric">
<text>My Title</text>
<text>My Message</text>
<text placement="attribution">example.com</text>
<progress status="" value="indeterminate"/>
</binding>
</visual>
<actions>
<action content="settings" placement="contextMenu" activationType="foreground" arguments="2|0|Default|0|https://example.com/|notification_id"/>
</actions>
</toast>
)";
ASSERT_NO_FATAL_FAILURE(VerifyXml(notification, kExpectedXml));
}
TEST_F(NotificationTemplateBuilderTest, ListEntries) { TEST_F(NotificationTemplateBuilderTest, ListEntries) {
message_center::Notification notification = BuildNotification(); message_center::Notification notification = BuildNotification();
......
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