Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Unified Diff: chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc

Issue 2849003002: Linux native notifications: Add initial unit test (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..46e94fabcca95cc01675c594cd5cf26831427867
--- /dev/null
+++ b/chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc
@@ -0,0 +1,104 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/notification_platform_bridge_linux.h"
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner.h"
+#include "chrome/browser/notifications/notification.h"
+#include "dbus/mock_bus.h"
+#include "dbus/mock_object_proxy.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+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
+ public:
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ std::move(task).Run();
+ return true;
+ }
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ NOTREACHED();
+ return false;
+ }
+ bool RunsTasksOnCurrentThread() const override { return true; }
+
+ protected:
+ ~FakeTaskRunner() override {}
+};
+
+ACTION_P(RegisterSignalCallback, callback_addr) {
+ *callback_addr = arg2;
+ arg3.Run("", "", true);
+}
+
+} // namespace
+
+class NotificationPlatformBridgeLinuxTest : public testing::Test {
+ public:
+ NotificationPlatformBridgeLinuxTest() {}
+
+ void SetUp() override {
+ static const char kFreedesktopNotificationsName[] =
+ "org.freedesktop.Notifications";
+ static const char kFreedesktopNotificationsPath[] =
+ "/org/freedesktop/Notifications";
+
+ mock_bus_ = new dbus::MockBus(dbus::Bus::Options());
+ mock_notification_proxy_ = new testing::StrictMock<dbus::MockObjectProxy>(
+ mock_bus_.get(), kFreedesktopNotificationsName,
+ dbus::ObjectPath(kFreedesktopNotificationsPath));
+
+ EXPECT_CALL(*mock_bus_.get(),
+ GetObjectProxy(kFreedesktopNotificationsName,
+ dbus::ObjectPath(kFreedesktopNotificationsPath)))
+ .WillOnce(testing::Return(mock_notification_proxy_.get()));
+
+ EXPECT_CALL(*mock_notification_proxy_.get(),
+ ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked",
+ testing::_, testing::_))
+ .WillOnce(RegisterSignalCallback(&action_invoked_callback_));
+
+ EXPECT_CALL(*mock_notification_proxy_.get(),
+ ConnectToSignal(kFreedesktopNotificationsName,
+ "NotificationClosed", testing::_, testing::_))
+ .WillOnce(RegisterSignalCallback(&notification_closed_callback_));
+
+ notification_bridge_linux_.reset(new NotificationPlatformBridgeLinux(
+ new FakeTaskRunner(), new FakeTaskRunner(), mock_bus_));
+
+ testing::Mock::VerifyAndClearExpectations(mock_bus_.get());
+ }
+
+ void TearDown() override {
+ EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock());
+ notification_bridge_linux_->CleanUp();
+ notification_bridge_linux_.reset();
+ mock_notification_proxy_ = nullptr;
+ mock_bus_ = nullptr;
+ }
+
+ protected:
+ scoped_refptr<dbus::MockBus> mock_bus_;
+ scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_;
+
+ base::Callback<void(dbus::Signal*)> action_invoked_callback_;
+ base::Callback<void(dbus::Signal*)> notification_closed_callback_;
+
+ std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest);
+};
+
+TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {}

Powered by Google App Engine
This is Rietveld 408576698