Chromium Code Reviews| 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..f18b203bc61dbd4a98da3e6c37a9dd460c6f06a6 100644 |
| --- a/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc |
| +++ b/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc |
| @@ -47,6 +47,17 @@ class NotificationBuilder { |
| Notification GetResult() { return notification_; } |
| + NotificationBuilder& SetItems( |
| + const std::vector<message_center::NotificationItem>& items) { |
| + notification_.set_items(items); |
| + return *this; |
| + } |
| + |
| + NotificationBuilder& SetNeverTimeout(bool never_timeout) { |
| + notification_.set_never_timeout(never_timeout); |
| + return *this; |
| + } |
| + |
| NotificationBuilder& SetProgress(int progress) { |
| notification_.set_progress(progress); |
| return *this; |
| @@ -68,6 +79,8 @@ class NotificationBuilder { |
| struct NotificationRequest { |
| std::string summary; |
| + std::string body; |
| + int32_t expire_timeout = 0; |
| }; |
| NotificationRequest ParseRequest(dbus::MethodCall* method_call) { |
| @@ -78,12 +91,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 +120,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 +157,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 +199,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 +252,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 +264,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 +284,48 @@ 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()); |
| +} |
|
Peter Beverloo
2017/05/15 16:16:00
Should there be a test for big image here?
Tom (Use chromium acct)
2017/05/15 19:18:39
Done.
|