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 24c4a3761b9f737f0f14f7475f65c1d28d3d0e8a..53a301f2942be47e4ad3c209222e23cff5e5d3a5 100644 |
| --- a/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc |
| +++ b/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| #include "base/callback.h" |
| +#include "base/i18n/number_formatting.h" |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/ref_counted.h" |
| @@ -30,43 +31,59 @@ namespace { |
| const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications"; |
| const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications"; |
| -ACTION_P(RegisterSignalCallback, callback_addr) { |
| - *callback_addr = arg2; |
| - arg3.Run("" /* interface_name */, "" /* signal_name */, true /* success */); |
| -} |
| +class NotificationBuilder { |
| + public: |
| + explicit NotificationBuilder(const std::string& id) |
| + : notification_(message_center::NOTIFICATION_TYPE_SIMPLE, |
| + base::string16(), |
| + base::string16(), |
| + gfx::Image(), |
| + message_center::NotifierId(GURL()), |
| + base::string16(), |
| + GURL(), |
| + id, |
| + message_center::RichNotificationData(), |
| + new MockNotificationDelegate(id)) {} |
| -ACTION_P(OnGetCapabilities, capabilities) { |
| - // MockObjectProxy::CallMethodAndBlock will wrap the return value in |
| - // a unique_ptr. |
| - dbus::Response* response = dbus::Response::CreateEmpty().release(); |
| - dbus::MessageWriter writer(response); |
| - writer.AppendArrayOfStrings(capabilities); |
| - return response; |
| -} |
| + Notification GetResult() { return notification_; } |
| -ACTION_P(OnGetServerInformation, spec_version) { |
| - dbus::Response* response = dbus::Response::CreateEmpty().release(); |
| - dbus::MessageWriter writer(response); |
| - writer.AppendString(""); // name |
| - writer.AppendString(""); // vendor |
| - writer.AppendString(""); // version |
| - writer.AppendString(spec_version); |
| - return response; |
| -} |
| + NotificationBuilder& SetProgress(int progress) { |
| + notification_.set_progress(progress); |
| + return *this; |
| + } |
| -ACTION_P(OnNotify, id) { |
| + NotificationBuilder& SetTitle(const base::string16& title) { |
| + notification_.set_title(title); |
| + return *this; |
| + } |
| + |
| + NotificationBuilder& SetType(message_center::NotificationType type) { |
| + notification_.set_type(type); |
| + return *this; |
| + } |
| + |
| + private: |
| + Notification notification_; |
| +}; |
| + |
| +struct NotificationRequest { |
|
Lei Zhang
2017/05/10 20:45:28
Is this going to have more members later?
Tom (Use chromium acct)
2017/05/10 21:05:44
Yes:
https://codereview.chromium.org/2875443002/
|
| + std::string summary; |
| +}; |
| + |
| +NotificationRequest ParseRequest(dbus::MethodCall* method_call) { |
| // The "Notify" message must have type (susssasa{sv}i). |
| // https://developer.gnome.org/notification-spec/#command-notify |
| - dbus::MethodCall* method_call = arg0; |
| + NotificationRequest request; |
| + |
| dbus::MessageReader reader(method_call); |
| std::string str; |
| uint32_t uint32; |
| int32_t int32; |
| - EXPECT_TRUE(reader.PopString(&str)); |
| - EXPECT_TRUE(reader.PopUint32(&uint32)); |
| - EXPECT_TRUE(reader.PopString(&str)); |
| - EXPECT_TRUE(reader.PopString(&str)); |
| - EXPECT_TRUE(reader.PopString(&str)); |
| + 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 |
| { |
| dbus::MessageReader actions_reader(nullptr); |
| @@ -91,15 +108,48 @@ ACTION_P(OnNotify, id) { |
| } |
| } |
| - EXPECT_TRUE(reader.PopInt32(&int32)); |
| + EXPECT_TRUE(reader.PopInt32(&int32)); // expire_timeout |
| EXPECT_FALSE(reader.HasMoreData()); |
| + return request; |
| +} |
| + |
| +dbus::Response* GetIdResponse(uint32_t id) { |
| dbus::Response* response = dbus::Response::CreateEmpty().release(); |
| dbus::MessageWriter writer(response); |
| writer.AppendUint32(id); |
| return response; |
| } |
| +ACTION_P(RegisterSignalCallback, callback_addr) { |
| + *callback_addr = arg2; |
| + arg3.Run("" /* interface_name */, "" /* signal_name */, true /* success */); |
| +} |
| + |
| +ACTION_P(OnGetCapabilities, capabilities) { |
| + // MockObjectProxy::CallMethodAndBlock will wrap the return value in |
| + // a unique_ptr. |
| + dbus::Response* response = dbus::Response::CreateEmpty().release(); |
| + dbus::MessageWriter writer(response); |
| + writer.AppendArrayOfStrings(capabilities); |
| + return response; |
| +} |
| + |
| +ACTION_P(OnGetServerInformation, spec_version) { |
| + dbus::Response* response = dbus::Response::CreateEmpty().release(); |
| + dbus::MessageWriter writer(response); |
| + writer.AppendString(""); // name |
| + writer.AppendString(""); // vendor |
| + writer.AppendString(""); // version |
| + writer.AppendString(spec_version); |
| + return response; |
| +} |
| + |
| +ACTION_P(OnNotify, id) { |
| + ParseRequest(arg0); |
| + return GetIdResponse(id); |
| +} |
| + |
| ACTION(OnCloseNotification) { |
| // The "CloseNotification" message must have type (u). |
| // https://developer.gnome.org/notification-spec/#command-close-notification |
| @@ -117,19 +167,6 @@ MATCHER_P(Calls, member, "") { |
| return arg->GetMember() == member; |
| } |
| -Notification CreateNotification(const char* id, |
| - const char* title, |
| - const char* body, |
| - const char* origin) { |
| - message_center::RichNotificationData optional_fields; |
| - GURL url = GURL(origin); |
| - return Notification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| - base::UTF8ToUTF16(title), base::UTF8ToUTF16(body), |
| - gfx::Image(), message_center::NotifierId(url), |
| - base::UTF8ToUTF16("Notifier's Name"), url, id, |
| - optional_fields, new MockNotificationDelegate(id)); |
| -} |
| - |
| } // namespace |
| class NotificationPlatformBridgeLinuxTest : public testing::Test { |
| @@ -211,6 +248,28 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) { |
| CreateNotificationBridgeLinux(); |
| notification_bridge_linux_->Display(NotificationCommon::PERSISTENT, "", "", |
| false, |
| - CreateNotification("id1", "", "", "")); |
| + NotificationBuilder("").GetResult()); |
| 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)); |
| + |
| + CreateNotificationBridgeLinux(); |
| + notification_bridge_linux_->Display( |
| + NotificationCommon::PERSISTENT, "", "", false, |
| + NotificationBuilder("") |
| + .SetType(message_center::NOTIFICATION_TYPE_PROGRESS) |
| + .SetProgress(42) |
| + .SetTitle(base::UTF8ToUTF16("The Title")) |
| + .GetResult()); |
| +} |