blob: 039ba094077709dd9afe73062f69a8654b6672ea [file] [log] [blame]
Peter Beverloo14d352b2017-08-22 19:32:411// 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#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_TESTER_H_
6#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_TESTER_H_
7
8#include <vector>
9
Peter Beverloob3310e62017-08-23 18:52:5410#include "base/callback_forward.h"
Peter Beverloo14d352b2017-08-22 19:32:4111#include "base/macros.h"
12#include "chrome/browser/notifications/notification_common.h"
13
14class Notification;
15class Profile;
16class StubNotificationDisplayService;
17
18// Helper class that enables use of the NotificationDisplayService in tests. The
19// Profile* passed when constructing an instance must outlive this class, as
20// the service (or internals of the service) may be overridden.
21//
22// This class must only be used for testing purposes.
23class NotificationDisplayServiceTester {
24 public:
25 explicit NotificationDisplayServiceTester(Profile* profile);
26 ~NotificationDisplayServiceTester();
27
Peter Beverloob3310e62017-08-23 18:52:5428 // Sets |closure| to be invoked when any notification has been added.
29 void SetNotificationAddedClosure(base::RepeatingClosure closure);
30
Peter Beverloo14d352b2017-08-22 19:32:4131 // Synchronously gets a vector of the displayed Notifications for the |type|.
32 std::vector<Notification> GetDisplayedNotificationsForType(
33 NotificationCommon::Type type);
34
35 // Simulates the notification identified by |notification_id| being closed due
36 // to external events, such as the user dismissing it when |by_user| is set.
37 // When |silent| is set, the notification handlers won't be informed of the
38 // change to immitate behaviour of operating systems that don't inform apps
39 // about removed notifications.
40 void RemoveNotification(NotificationCommon::Type type,
41 const std::string& notification_id,
42 bool by_user,
43 bool silent = false);
44
45 // Removes all notifications of the given |type|.
46 void RemoveAllNotifications(NotificationCommon::Type type, bool by_user);
47
48 private:
49 Profile* profile_;
50 StubNotificationDisplayService* display_service_;
51
52 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayServiceTester);
53};
54
55#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_TESTER_H_