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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc

Issue 2886903005: Linux native notifications: Require 'actions' and 'body' capabilities (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // https://developer.gnome.org/notification-spec/#command-close-notification 186 // https://developer.gnome.org/notification-spec/#command-close-notification
187 dbus::MethodCall* method_call = arg0; 187 dbus::MethodCall* method_call = arg0;
188 dbus::MessageReader reader(method_call); 188 dbus::MessageReader reader(method_call);
189 uint32_t uint32; 189 uint32_t uint32;
190 EXPECT_TRUE(reader.PopUint32(&uint32)); 190 EXPECT_TRUE(reader.PopUint32(&uint32));
191 EXPECT_FALSE(reader.HasMoreData()); 191 EXPECT_FALSE(reader.HasMoreData());
192 192
193 return dbus::Response::CreateEmpty().release(); 193 return dbus::Response::CreateEmpty().release();
194 } 194 }
195 195
196 ACTION_P(OnNotificationBridgeReady, success) {
197 EXPECT_EQ(success, arg0);
198 }
199
196 // Matches a method call to the specified dbus target. 200 // Matches a method call to the specified dbus target.
197 MATCHER_P(Calls, member, "") { 201 MATCHER_P(Calls, member, "") {
198 return arg->GetMember() == member; 202 return arg->GetMember() == member;
199 } 203 }
200 204
201 } // namespace 205 } // namespace
202 206
203 class NotificationPlatformBridgeLinuxTest : public testing::Test { 207 class NotificationPlatformBridgeLinuxTest : public testing::Test {
204 public: 208 public:
205 NotificationPlatformBridgeLinuxTest() = default; 209 NotificationPlatformBridgeLinuxTest() = default;
206 ~NotificationPlatformBridgeLinuxTest() override = default; 210 ~NotificationPlatformBridgeLinuxTest() override = default;
207 211
208 void SetUp() override { 212 void SetUp() override {
209 mock_bus_ = new dbus::MockBus(dbus::Bus::Options()); 213 mock_bus_ = new dbus::MockBus(dbus::Bus::Options());
210 mock_notification_proxy_ = new StrictMock<dbus::MockObjectProxy>( 214 mock_notification_proxy_ = new StrictMock<dbus::MockObjectProxy>(
211 mock_bus_.get(), kFreedesktopNotificationsName, 215 mock_bus_.get(), kFreedesktopNotificationsName,
212 dbus::ObjectPath(kFreedesktopNotificationsPath)); 216 dbus::ObjectPath(kFreedesktopNotificationsPath));
213
214 EXPECT_CALL(*mock_bus_.get(),
215 GetObjectProxy(kFreedesktopNotificationsName,
216 dbus::ObjectPath(kFreedesktopNotificationsPath)))
217 .WillOnce(Return(mock_notification_proxy_.get()));
218
219 EXPECT_CALL(*mock_notification_proxy_.get(),
220 MockCallMethodAndBlock(Calls("GetCapabilities"), _))
221 .WillOnce(OnGetCapabilities(std::vector<std::string>{
222 "body", "body-hyperlinks", "body-images", "body-markup"}));
223
224 EXPECT_CALL(
225 *mock_notification_proxy_.get(),
226 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _))
227 .WillOnce(RegisterSignalCallback(&action_invoked_callback_));
228
229 EXPECT_CALL(*mock_notification_proxy_.get(),
230 ConnectToSignal(kFreedesktopNotificationsName,
231 "NotificationClosed", _, _))
232 .WillOnce(RegisterSignalCallback(&notification_closed_callback_));
233 } 217 }
234 218
235 void TearDown() override { 219 void TearDown() override {
236 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock());
237 notification_bridge_linux_->CleanUp(); 220 notification_bridge_linux_->CleanUp();
238 content::RunAllBlockingPoolTasksUntilIdle(); 221 content::RunAllBlockingPoolTasksUntilIdle();
239 notification_bridge_linux_.reset(); 222 notification_bridge_linux_.reset();
240 mock_notification_proxy_ = nullptr; 223 mock_notification_proxy_ = nullptr;
241 mock_bus_ = nullptr; 224 mock_bus_ = nullptr;
242 } 225 }
243 226
244 protected: 227 protected:
245 void CreateNotificationBridgeLinux() { 228 void CreateNotificationBridgeLinux() {
229 CreateNotificationBridgeLinux(
230 std::vector<std::string>{"actions", "body", "body-hyperlinks",
231 "body-images", "body-markup"},
232 true, true, true);
233 }
234
235 void CreateNotificationBridgeLinux(
236 const std::vector<std::string>& capabilities,
237 bool expect_init_success,
238 bool expect_shutdown,
239 bool connect_signals) {
240 EXPECT_CALL(*mock_bus_.get(),
241 GetObjectProxy(kFreedesktopNotificationsName,
242 dbus::ObjectPath(kFreedesktopNotificationsPath)))
243 .WillOnce(Return(mock_notification_proxy_.get()));
244
245 EXPECT_CALL(*mock_notification_proxy_.get(),
246 MockCallMethodAndBlock(Calls("GetCapabilities"), _))
247 .WillOnce(OnGetCapabilities(capabilities));
248
249 if (connect_signals) {
250 EXPECT_CALL(
251 *mock_notification_proxy_.get(),
252 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _))
253 .WillOnce(RegisterSignalCallback(&action_invoked_callback_));
254
255 EXPECT_CALL(*mock_notification_proxy_.get(),
256 ConnectToSignal(kFreedesktopNotificationsName,
257 "NotificationClosed", _, _))
258 .WillOnce(RegisterSignalCallback(&notification_closed_callback_));
259 }
260
261 EXPECT_CALL(*this, MockableNotificationBridgeReadyCallback(_))
262 .WillOnce(OnNotificationBridgeReady(expect_init_success));
263
264 if (expect_shutdown)
265 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock());
266
246 notification_bridge_linux_ = 267 notification_bridge_linux_ =
247 base::WrapUnique(new NotificationPlatformBridgeLinux(mock_bus_)); 268 base::WrapUnique(new NotificationPlatformBridgeLinux(mock_bus_));
269 notification_bridge_linux_->SetReadyCallback(
270 base::BindOnce(&NotificationPlatformBridgeLinuxTest::
271 MockableNotificationBridgeReadyCallback,
272 base::Unretained(this)));
248 content::RunAllBlockingPoolTasksUntilIdle(); 273 content::RunAllBlockingPoolTasksUntilIdle();
249 } 274 }
250 275
276 MOCK_METHOD1(MockableNotificationBridgeReadyCallback, void(bool));
277
251 content::TestBrowserThreadBundle thread_bundle_; 278 content::TestBrowserThreadBundle thread_bundle_;
252 279
253 scoped_refptr<dbus::MockBus> mock_bus_; 280 scoped_refptr<dbus::MockBus> mock_bus_;
254 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_; 281 scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_;
255 282
256 base::Callback<void(dbus::Signal*)> action_invoked_callback_; 283 base::Callback<void(dbus::Signal*)> action_invoked_callback_;
257 base::Callback<void(dbus::Signal*)> notification_closed_callback_; 284 base::Callback<void(dbus::Signal*)> notification_closed_callback_;
258 285
259 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_; 286 std::unique_ptr<NotificationPlatformBridgeLinux> notification_bridge_linux_;
260 287
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 1)); 427 1));
401 428
402 CreateNotificationBridgeLinux(); 429 CreateNotificationBridgeLinux();
403 notification_bridge_linux_->Display( 430 notification_bridge_linux_->Display(
404 NotificationCommon::PERSISTENT, "", "", false, 431 NotificationCommon::PERSISTENT, "", "", false,
405 NotificationBuilder("") 432 NotificationBuilder("")
406 .SetMessage(base::ASCIIToUTF16("Body text")) 433 .SetMessage(base::ASCIIToUTF16("Body text"))
407 .SetOriginUrl(GURL("https://google.com/search?q=test&ie=UTF8")) 434 .SetOriginUrl(GURL("https://google.com/search?q=test&ie=UTF8"))
408 .GetResult()); 435 .GetResult());
409 } 436 }
437
438 TEST_F(NotificationPlatformBridgeLinuxTest, MissingActionsCapability) {
439 CreateNotificationBridgeLinux(std::vector<std::string>{"body"}, false, true,
440 false);
441 }
442
443 TEST_F(NotificationPlatformBridgeLinuxTest, MissingBodyCapability) {
444 CreateNotificationBridgeLinux(std::vector<std::string>{"actions"}, false,
445 true, false);
446 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698