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 "dbus/mock_bus.h" | |
14 #include "dbus/mock_object_proxy.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 namespace { | |
19 | |
20 class FakeTaskRunner : public base::SequencedTaskRunner { | |
Lei Zhang
2017/04/29 01:35:05
Do you want to use TestBrowserThreadBundle, so you
Tom (Use chromium acct)
2017/05/01 18:25:29
Done. I should have just waited for you to reply
| |
21 public: | |
22 bool PostDelayedTask(const tracked_objects::Location& from_here, | |
23 base::OnceClosure task, | |
24 base::TimeDelta delay) override { | |
25 std::move(task).Run(); | |
26 return true; | |
27 } | |
28 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | |
29 base::OnceClosure task, | |
30 base::TimeDelta delay) override { | |
31 NOTREACHED(); | |
32 return false; | |
33 } | |
34 bool RunsTasksOnCurrentThread() const override { return true; } | |
35 | |
36 protected: | |
37 ~FakeTaskRunner() override {} | |
38 }; | |
39 | |
40 ACTION_P(RegisterSignalCallback, callback_addr) { | |
41 *callback_addr = arg2; | |
42 arg3.Run("", "", true); | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 class NotificationPlatformBridgeLinuxTest : public testing::Test { | |
48 public: | |
49 NotificationPlatformBridgeLinuxTest() {} | |
50 | |
51 void SetUp() override { | |
52 static const char kFreedesktopNotificationsName[] = | |
53 "org.freedesktop.Notifications"; | |
54 static const char kFreedesktopNotificationsPath[] = | |
55 "/org/freedesktop/Notifications"; | |
56 | |
57 mock_bus_ = new dbus::MockBus(dbus::Bus::Options()); | |
58 mock_notification_proxy_ = new testing::StrictMock<dbus::MockObjectProxy>( | |
59 mock_bus_.get(), kFreedesktopNotificationsName, | |
60 dbus::ObjectPath(kFreedesktopNotificationsPath)); | |
61 | |
62 EXPECT_CALL(*mock_bus_.get(), | |
63 GetObjectProxy(kFreedesktopNotificationsName, | |
64 dbus::ObjectPath(kFreedesktopNotificationsPath))) | |
65 .WillOnce(testing::Return(mock_notification_proxy_.get())); | |
66 | |
67 EXPECT_CALL(*mock_notification_proxy_.get(), | |
68 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", | |
69 testing::_, testing::_)) | |
70 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); | |
71 | |
72 EXPECT_CALL(*mock_notification_proxy_.get(), | |
73 ConnectToSignal(kFreedesktopNotificationsName, | |
74 "NotificationClosed", testing::_, testing::_)) | |
75 .WillOnce(RegisterSignalCallback(¬ification_closed_callback_)); | |
76 | |
77 notification_bridge_linux_.reset(new NotificationPlatformBridgeLinux( | |
78 new FakeTaskRunner(), new FakeTaskRunner(), mock_bus_)); | |
79 | |
80 testing::Mock::VerifyAndClearExpectations(mock_bus_.get()); | |
81 } | |
82 | |
83 void TearDown() override { | |
84 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()); | |
85 notification_bridge_linux_->CleanUp(); | |
86 notification_bridge_linux_.reset(); | |
87 mock_notification_proxy_ = nullptr; | |
88 mock_bus_ = nullptr; | |
89 } | |
90 | |
91 protected: | |
92 scoped_refptr<dbus::MockBus> mock_bus_; | |
93 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_; | |
94 | |
95 base::Callback<void(dbus::Signal*)> action_invoked_callback_; | |
96 base::Callback<void(dbus::Signal*)> notification_closed_callback_; | |
97 | |
98 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_; | |
99 | |
100 private: | |
101 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); | |
102 }; | |
103 | |
104 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {} | |
OLD | NEW |