OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/sequenced_task_runner.h" | |
12 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
15 #include "dbus/mock_bus.h" | 16 #include "dbus/mock_bus.h" |
16 #include "dbus/mock_object_proxy.h" | 17 #include "dbus/mock_object_proxy.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications"; | 23 const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications"; |
23 const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications"; | 24 const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications"; |
24 | 25 |
25 ACTION_P(RegisterSignalCallback, callback_addr) { | 26 ACTION_P(RegisterSignalCallback, callback_addr) { |
26 *callback_addr = arg2; | 27 *callback_addr = arg2; |
27 arg3.Run("" /* interface_name */, "" /* signal_name */, true /* success */); | 28 arg3.Run("" /* interface_name */, "" /* signal_name */, true /* success */); |
28 } | 29 } |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 class NotificationPlatformBridgeLinuxTest : public testing::Test { | 33 class NotificationPlatformBridgeLinuxTest : public testing::Test { |
33 public: | 34 public: |
34 NotificationPlatformBridgeLinuxTest() = default; | 35 NotificationPlatformBridgeLinuxTest() = default; |
| 36 ~NotificationPlatformBridgeLinuxTest() override = default; |
35 | 37 |
36 void SetUp() override { | 38 void SetUp() override { |
37 mock_bus_ = new dbus::MockBus(dbus::Bus::Options()); | 39 mock_bus_ = new dbus::MockBus(dbus::Bus::Options()); |
38 mock_notification_proxy_ = new testing::StrictMock<dbus::MockObjectProxy>( | 40 mock_notification_proxy_ = new testing::StrictMock<dbus::MockObjectProxy>( |
39 mock_bus_.get(), kFreedesktopNotificationsName, | 41 mock_bus_.get(), kFreedesktopNotificationsName, |
40 dbus::ObjectPath(kFreedesktopNotificationsPath)); | 42 dbus::ObjectPath(kFreedesktopNotificationsPath)); |
41 | 43 |
42 EXPECT_CALL(*mock_bus_.get(), | 44 EXPECT_CALL(*mock_bus_.get(), |
43 GetObjectProxy(kFreedesktopNotificationsName, | 45 GetObjectProxy(kFreedesktopNotificationsName, |
44 dbus::ObjectPath(kFreedesktopNotificationsPath))) | 46 dbus::ObjectPath(kFreedesktopNotificationsPath))) |
45 .WillOnce(testing::Return(mock_notification_proxy_.get())); | 47 .WillOnce(testing::Return(mock_notification_proxy_.get())); |
46 | 48 |
47 EXPECT_CALL(*mock_notification_proxy_.get(), | 49 EXPECT_CALL(*mock_notification_proxy_.get(), |
48 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", | 50 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", |
49 testing::_, testing::_)) | 51 testing::_, testing::_)) |
50 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); | 52 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); |
51 | 53 |
52 EXPECT_CALL(*mock_notification_proxy_.get(), | 54 EXPECT_CALL(*mock_notification_proxy_.get(), |
53 ConnectToSignal(kFreedesktopNotificationsName, | 55 ConnectToSignal(kFreedesktopNotificationsName, |
54 "NotificationClosed", testing::_, testing::_)) | 56 "NotificationClosed", testing::_, testing::_)) |
55 .WillOnce(RegisterSignalCallback(¬ification_closed_callback_)); | 57 .WillOnce(RegisterSignalCallback(¬ification_closed_callback_)); |
56 | 58 |
57 notification_bridge_linux_.reset( | 59 notification_bridge_linux_ = |
58 new NotificationPlatformBridgeLinux(mock_bus_)); | 60 base::WrapUnique(new NotificationPlatformBridgeLinux(mock_bus_)); |
59 } | 61 } |
60 | 62 |
61 void TearDown() override { | 63 void TearDown() override { |
62 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()); | 64 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()); |
63 notification_bridge_linux_->CleanUp(); | 65 notification_bridge_linux_->CleanUp(); |
64 content::RunAllBlockingPoolTasksUntilIdle(); | 66 content::RunAllBlockingPoolTasksUntilIdle(); |
65 notification_bridge_linux_.reset(); | 67 notification_bridge_linux_.reset(); |
66 mock_notification_proxy_ = nullptr; | 68 mock_notification_proxy_ = nullptr; |
67 mock_bus_ = nullptr; | 69 mock_bus_ = nullptr; |
68 } | 70 } |
69 | 71 |
70 protected: | 72 protected: |
71 content::TestBrowserThreadBundle thread_bundle_; | 73 content::TestBrowserThreadBundle thread_bundle_; |
72 | 74 |
73 scoped_refptr<dbus::MockBus> mock_bus_; | 75 scoped_refptr<dbus::MockBus> mock_bus_; |
74 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_; | 76 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_; |
75 | 77 |
76 base::Callback<void(dbus::Signal*)> action_invoked_callback_; | 78 base::Callback<void(dbus::Signal*)> action_invoked_callback_; |
77 base::Callback<void(dbus::Signal*)> notification_closed_callback_; | 79 base::Callback<void(dbus::Signal*)> notification_closed_callback_; |
78 | 80 |
79 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_; | 81 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_; |
80 | 82 |
81 private: | 83 private: |
82 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); | 84 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); |
83 }; | 85 }; |
84 | 86 |
85 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {} | 87 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {} |
OLD | NEW |