Chromium Code Reviews| 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 ACTION_P(RegisterSignalCallback, callback_addr) { | |
| 23 *callback_addr = arg2; | |
| 24 arg3.Run("", "", true); | |
|
Peter Beverloo
2017/05/02 13:50:21
It would be good to annotate what the parameters m
Tom (Use chromium acct)
2017/05/02 21:23:16
Done.
| |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 class NotificationPlatformBridgeLinuxTest : public testing::Test { | |
| 30 public: | |
| 31 NotificationPlatformBridgeLinuxTest() {} | |
|
Peter Beverloo
2017/05/02 13:50:21
nit: {} --> = default;
Could just leave out this
Tom (Use chromium acct)
2017/05/02 21:23:16
Done.
| |
| 32 | |
| 33 void SetUp() override { | |
| 34 static const char kFreedesktopNotificationsName[] = | |
| 35 "org.freedesktop.Notifications"; | |
| 36 static const char kFreedesktopNotificationsPath[] = | |
| 37 "/org/freedesktop/Notifications"; | |
|
Peter Beverloo
2017/05/02 13:50:21
nit: usually we just put such constants in the ano
Tom (Use chromium acct)
2017/05/02 21:23:16
Done.
| |
| 38 | |
| 39 mock_bus_ = new dbus::MockBus(dbus::Bus::Options()); | |
| 40 mock_notification_proxy_ = new testing::StrictMock<dbus::MockObjectProxy>( | |
| 41 mock_bus_.get(), kFreedesktopNotificationsName, | |
| 42 dbus::ObjectPath(kFreedesktopNotificationsPath)); | |
| 43 | |
| 44 EXPECT_CALL(*mock_bus_.get(), | |
| 45 GetObjectProxy(kFreedesktopNotificationsName, | |
| 46 dbus::ObjectPath(kFreedesktopNotificationsPath))) | |
| 47 .WillOnce(testing::Return(mock_notification_proxy_.get())); | |
| 48 | |
| 49 EXPECT_CALL(*mock_notification_proxy_.get(), | |
| 50 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", | |
| 51 testing::_, testing::_)) | |
| 52 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); | |
| 53 | |
| 54 EXPECT_CALL(*mock_notification_proxy_.get(), | |
| 55 ConnectToSignal(kFreedesktopNotificationsName, | |
| 56 "NotificationClosed", testing::_, testing::_)) | |
| 57 .WillOnce(RegisterSignalCallback(¬ification_closed_callback_)); | |
| 58 | |
| 59 notification_bridge_linux_.reset( | |
| 60 new NotificationPlatformBridgeLinux(mock_bus_)); | |
| 61 } | |
| 62 | |
| 63 void TearDown() override { | |
| 64 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()); | |
| 65 notification_bridge_linux_->CleanUp(); | |
| 66 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 67 notification_bridge_linux_.reset(); | |
| 68 mock_notification_proxy_ = nullptr; | |
| 69 mock_bus_ = nullptr; | |
| 70 } | |
| 71 | |
| 72 protected: | |
| 73 content::TestBrowserThreadBundle thread_bundle_; | |
| 74 | |
| 75 scoped_refptr<dbus::MockBus> mock_bus_; | |
| 76 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_; | |
| 77 | |
| 78 base::Callback<void(dbus::Signal*)> action_invoked_callback_; | |
| 79 base::Callback<void(dbus::Signal*)> notification_closed_callback_; | |
| 80 | |
| 81 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_; | |
| 82 | |
| 83 private: | |
| 84 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); | |
| 85 }; | |
| 86 | |
| 87 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {} | |
|
Peter Beverloo
2017/05/02 13:50:21
What sort of tests do you have in mind?
Tom (Use chromium acct)
2017/05/02 21:23:16
* Verify format of the "Notify" message
* Verify f
Peter Beverloo
2017/05/03 00:31:26
Perfect :)
| |
| OLD | NEW |