Commit 29c369fb authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Linux native notifications: Add suppress-sound hint when notification is silent

BUG=676220
R=peter@chromium.org
CC=thestig@chromium.org

Change-Id: I20a4a246b89f8be56bfdffcbfb7b7c38be203eaa
Reviewed-on: https://chromium-review.googlesource.com/687887
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505165}
parent 86d4006b
......@@ -620,6 +620,14 @@ class NotificationPlatformBridgeLinuxImpl
NotificationPriorityToFdoUrgency(notification->priority()));
hints_writer.CloseContainer(&urgency_writer);
if (notification->silent()) {
dbus::MessageWriter suppress_sound_writer(nullptr);
hints_writer.OpenDictEntry(&suppress_sound_writer);
suppress_sound_writer.AppendString("suppress-sound");
suppress_sound_writer.AppendVariantOfBool(true);
hints_writer.CloseContainer(&suppress_sound_writer);
}
std::unique_ptr<base::Environment> env = base::Environment::Create();
base::FilePath desktop_file(
shell_integration_linux::GetDesktopName(env.get()));
......
......@@ -84,6 +84,11 @@ class NotificationBuilder {
return *this;
}
NotificationBuilder& SetSilent(bool silent) {
notification_.set_silent(silent);
return *this;
}
NotificationBuilder& SetTitle(const base::string16& title) {
notification_.set_title(title);
return *this;
......@@ -102,6 +107,7 @@ struct NotificationRequest {
std::string summary;
std::string body;
int32_t expire_timeout = 0;
bool silent = false;
};
const SkBitmap CreateBitmap(int width, int height) {
......@@ -147,7 +153,13 @@ NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
EXPECT_TRUE(hints_reader.PopDictEntry(&dict_entry_reader));
EXPECT_TRUE(dict_entry_reader.PopString(&str));
dbus::MessageReader variant_reader(nullptr);
if (str == "suppress-sound") {
bool suppress_sound;
EXPECT_TRUE(dict_entry_reader.PopVariantOfBool(&suppress_sound));
request.silent = suppress_sound;
} else {
EXPECT_TRUE(dict_entry_reader.PopVariant(&variant_reader));
}
EXPECT_FALSE(dict_entry_reader.HasMoreData());
}
}
......@@ -485,3 +497,26 @@ TEST_F(NotificationPlatformBridgeLinuxTest, EscapeHtml) {
.GetResult(),
nullptr);
}
TEST_F(NotificationPlatformBridgeLinuxTest, Silent) {
EXPECT_CALL(*mock_notification_proxy_.get(),
CallMethodAndBlock(Calls("Notify"), _))
.WillOnce(OnNotify(
[=](const NotificationRequest& request) {
EXPECT_FALSE(request.silent);
},
1))
.WillOnce(OnNotify(
[=](const NotificationRequest& request) {
EXPECT_TRUE(request.silent);
},
2));
CreateNotificationBridgeLinux();
notification_bridge_linux_->Display(
NotificationCommon::PERSISTENT, "", "", false,
NotificationBuilder("1").SetSilent(false).GetResult(), nullptr);
notification_bridge_linux_->Display(
NotificationCommon::PERSISTENT, "", "", false,
NotificationBuilder("2").SetSilent(true).GetResult(), nullptr);
}
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