| Index: chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc
|
| diff --git a/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc b/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc
|
| index 53a301f2942be47e4ad3c209222e23cff5e5d3a5..6eb1ad1037a5181360803993b2a01e046d0560bf 100644
|
| --- a/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc
|
| +++ b/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc
|
| @@ -47,6 +47,27 @@ class NotificationBuilder {
|
|
|
| Notification GetResult() { return notification_; }
|
|
|
| + NotificationBuilder& SetItems(
|
| + const std::vector<message_center::NotificationItem>& items) {
|
| + notification_.set_items(items);
|
| + return *this;
|
| + }
|
| +
|
| + NotificationBuilder& SetMessage(const base::string16& message) {
|
| + notification_.set_message(message);
|
| + return *this;
|
| + }
|
| +
|
| + NotificationBuilder& SetNeverTimeout(bool never_timeout) {
|
| + notification_.set_never_timeout(never_timeout);
|
| + return *this;
|
| + }
|
| +
|
| + NotificationBuilder& SetOriginUrl(const GURL& origin_url) {
|
| + notification_.set_origin_url(origin_url);
|
| + return *this;
|
| + }
|
| +
|
| NotificationBuilder& SetProgress(int progress) {
|
| notification_.set_progress(progress);
|
| return *this;
|
| @@ -68,6 +89,8 @@ class NotificationBuilder {
|
|
|
| struct NotificationRequest {
|
| std::string summary;
|
| + std::string body;
|
| + int32_t expire_timeout = 0;
|
| };
|
|
|
| NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
|
| @@ -78,12 +101,11 @@ NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
|
| dbus::MessageReader reader(method_call);
|
| std::string str;
|
| uint32_t uint32;
|
| - int32_t int32;
|
| EXPECT_TRUE(reader.PopString(&str)); // app_name
|
| EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id
|
| EXPECT_TRUE(reader.PopString(&str)); // app_icon
|
| EXPECT_TRUE(reader.PopString(&request.summary)); // summary
|
| - EXPECT_TRUE(reader.PopString(&str)); // body
|
| + EXPECT_TRUE(reader.PopString(&request.body)); // body
|
|
|
| {
|
| dbus::MessageReader actions_reader(nullptr);
|
| @@ -108,7 +130,7 @@ NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
|
| }
|
| }
|
|
|
| - EXPECT_TRUE(reader.PopInt32(&int32)); // expire_timeout
|
| + EXPECT_TRUE(reader.PopInt32(&request.expire_timeout));
|
| EXPECT_FALSE(reader.HasMoreData());
|
|
|
| return request;
|
| @@ -145,8 +167,8 @@ ACTION_P(OnGetServerInformation, spec_version) {
|
| return response;
|
| }
|
|
|
| -ACTION_P(OnNotify, id) {
|
| - ParseRequest(arg0);
|
| +ACTION_P2(OnNotify, verifier, id) {
|
| + verifier(ParseRequest(arg0));
|
| return GetIdResponse(id);
|
| }
|
|
|
| @@ -187,7 +209,7 @@ class NotificationPlatformBridgeLinuxTest : public testing::Test {
|
|
|
| EXPECT_CALL(*mock_notification_proxy_.get(),
|
| MockCallMethodAndBlock(Calls("GetCapabilities"), _))
|
| - .WillOnce(OnGetCapabilities(std::vector<std::string>()));
|
| + .WillOnce(OnGetCapabilities(std::vector<std::string>{"body"}));
|
|
|
| EXPECT_CALL(*mock_notification_proxy_.get(),
|
| MockCallMethodAndBlock(Calls("GetServerInformation"), _))
|
| @@ -240,7 +262,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {
|
| TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) {
|
| EXPECT_CALL(*mock_notification_proxy_.get(),
|
| MockCallMethodAndBlock(Calls("Notify"), _))
|
| - .WillOnce(OnNotify(1));
|
| + .WillOnce(OnNotify([](const NotificationRequest&) {}, 1));
|
| EXPECT_CALL(*mock_notification_proxy_.get(),
|
| MockCallMethodAndBlock(Calls("CloseNotification"), _))
|
| .WillOnce(OnCloseNotification());
|
| @@ -252,17 +274,16 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) {
|
| notification_bridge_linux_->Close("", "");
|
| }
|
|
|
| -ACTION_P2(VerifySummary, summary, id) {
|
| - NotificationRequest request = ParseRequest(arg0);
|
| - EXPECT_EQ(summary, request.summary);
|
| - return GetIdResponse(id);
|
| -}
|
| -
|
| TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
|
| EXPECT_CALL(*mock_notification_proxy_.get(),
|
| MockCallMethodAndBlock(Calls("Notify"), _))
|
| - .WillOnce(VerifySummary(
|
| - base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title", 1));
|
| + .WillOnce(OnNotify(
|
| + [](const NotificationRequest& request) {
|
| + EXPECT_EQ(
|
| + base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title",
|
| + request.summary);
|
| + },
|
| + 1));
|
|
|
| CreateNotificationBridgeLinux();
|
| notification_bridge_linux_->Display(
|
| @@ -273,3 +294,66 @@ TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
|
| .SetTitle(base::UTF8ToUTF16("The Title"))
|
| .GetResult());
|
| }
|
| +
|
| +TEST_F(NotificationPlatformBridgeLinuxTest, NotificationListItemsInBody) {
|
| + EXPECT_CALL(*mock_notification_proxy_.get(),
|
| + MockCallMethodAndBlock(Calls("Notify"), _))
|
| + .WillOnce(OnNotify(
|
| + [](const NotificationRequest& request) {
|
| + EXPECT_EQ("abc - 123\ndef - 456", request.body);
|
| + },
|
| + 1));
|
| +
|
| + CreateNotificationBridgeLinux();
|
| + notification_bridge_linux_->Display(
|
| + NotificationCommon::PERSISTENT, "", "", false,
|
| + NotificationBuilder("")
|
| + .SetType(message_center::NOTIFICATION_TYPE_MULTIPLE)
|
| + .SetItems(std::vector<message_center::NotificationItem>{
|
| + {base::UTF8ToUTF16("abc"), base::UTF8ToUTF16("123")},
|
| + {base::UTF8ToUTF16("def"), base::UTF8ToUTF16("456")}})
|
| + .GetResult());
|
| +}
|
| +
|
| +TEST_F(NotificationPlatformBridgeLinuxTest, NotificationTimeouts) {
|
| + const int32_t kExpireTimeoutDefault = -1;
|
| + const int32_t kExpireTimeoutNever = 0;
|
| + EXPECT_CALL(*mock_notification_proxy_.get(),
|
| + MockCallMethodAndBlock(Calls("Notify"), _))
|
| + .WillOnce(OnNotify(
|
| + [=](const NotificationRequest& request) {
|
| + EXPECT_EQ(kExpireTimeoutDefault, request.expire_timeout);
|
| + },
|
| + 1))
|
| + .WillOnce(OnNotify(
|
| + [=](const NotificationRequest& request) {
|
| + EXPECT_EQ(kExpireTimeoutNever, request.expire_timeout);
|
| + },
|
| + 2));
|
| +
|
| + CreateNotificationBridgeLinux();
|
| + notification_bridge_linux_->Display(
|
| + NotificationCommon::PERSISTENT, "", "", false,
|
| + NotificationBuilder("1").SetNeverTimeout(false).GetResult());
|
| + notification_bridge_linux_->Display(
|
| + NotificationCommon::PERSISTENT, "", "", false,
|
| + NotificationBuilder("2").SetNeverTimeout(true).GetResult());
|
| +}
|
| +
|
| +TEST_F(NotificationPlatformBridgeLinuxTest, NotificationAttribution) {
|
| + EXPECT_CALL(*mock_notification_proxy_.get(),
|
| + MockCallMethodAndBlock(Calls("Notify"), _))
|
| + .WillOnce(OnNotify(
|
| + [](const NotificationRequest& request) {
|
| + EXPECT_EQ("Body text\ngoogle.com", request.body);
|
| + },
|
| + 1));
|
| +
|
| + CreateNotificationBridgeLinux();
|
| + notification_bridge_linux_->Display(
|
| + NotificationCommon::PERSISTENT, "", "", false,
|
| + NotificationBuilder("")
|
| + .SetMessage(base::UTF8ToUTF16("Body text"))
|
| + .SetOriginUrl(GURL("https://google.com/"))
|
| + .GetResult());
|
| +}
|
|
|