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