Peter Beverloo | 14d352b | 2017-08-22 19:32:41 | [diff] [blame] | 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 | #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 Beverloo | b3310e6 | 2017-08-23 18:52:54 | [diff] [blame^] | 10 | #include "base/callback_forward.h" |
Peter Beverloo | 14d352b | 2017-08-22 19:32:41 | [diff] [blame] | 11 | #include "base/macros.h" |
| 12 | #include "chrome/browser/notifications/notification_common.h" |
| 13 | |
| 14 | class Notification; |
| 15 | class Profile; |
| 16 | class 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. |
| 23 | class NotificationDisplayServiceTester { |
| 24 | public: |
| 25 | explicit NotificationDisplayServiceTester(Profile* profile); |
| 26 | ~NotificationDisplayServiceTester(); |
| 27 | |
Peter Beverloo | b3310e6 | 2017-08-23 18:52:54 | [diff] [blame^] | 28 | // Sets |closure| to be invoked when any notification has been added. |
| 29 | void SetNotificationAddedClosure(base::RepeatingClosure closure); |
| 30 | |
Peter Beverloo | 14d352b | 2017-08-22 19:32:41 | [diff] [blame] | 31 | // 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_ |