| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_object_proxy.h" | 12 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 13 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 14 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 14 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 | 17 |
| 18 // NotificationDelegate which does nothing, useful for testing when | 18 // NotificationDelegate which does nothing, useful for testing when |
| 19 // the notification events are not important. | 19 // the notification events are not important. |
| 20 class MockNotificationDelegate : public NotificationDelegate { | 20 class MockNotificationDelegate : public NotificationDelegate { |
| 21 public: | 21 public: |
| 22 explicit MockNotificationDelegate(const std::string& id); | 22 explicit MockNotificationDelegate(const std::string& id); |
| 23 | 23 |
| 24 // NotificationDelegate interface. | 24 // NotificationDelegate interface. |
| 25 virtual void Display() override {} | 25 void Display() override {} |
| 26 virtual void Error() override {} | 26 void Error() override {} |
| 27 virtual void Close(bool by_user) override {} | 27 void Close(bool by_user) override {} |
| 28 virtual void Click() override {} | 28 void Click() override {} |
| 29 virtual std::string id() const override; | 29 std::string id() const override; |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 virtual ~MockNotificationDelegate(); | 32 ~MockNotificationDelegate() override; |
| 33 | 33 |
| 34 std::string id_; | 34 std::string id_; |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); | 36 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Mock implementation of Javascript object proxy which logs events that | 39 // Mock implementation of Javascript object proxy which logs events that |
| 40 // would have been fired on it. Useful for tests where the sequence of | 40 // would have been fired on it. Useful for tests where the sequence of |
| 41 // notification events needs to be verified. | 41 // notification events needs to be verified. |
| 42 // | 42 // |
| (...skipping 29 matching lines...) Expand all Loading... |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 std::string notification_id_; | 74 std::string notification_id_; |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate); | 76 DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 class StubNotificationUIManager : public NotificationUIManager { | 79 class StubNotificationUIManager : public NotificationUIManager { |
| 80 public: | 80 public: |
| 81 explicit StubNotificationUIManager(const GURL& welcome_origin); | 81 explicit StubNotificationUIManager(const GURL& welcome_origin); |
| 82 virtual ~StubNotificationUIManager(); | 82 ~StubNotificationUIManager() override; |
| 83 | 83 |
| 84 // Adds a notification to be displayed. Virtual for unit test override. | 84 // Adds a notification to be displayed. Virtual for unit test override. |
| 85 virtual void Add(const Notification& notification, Profile* profile) override; | 85 void Add(const Notification& notification, Profile* profile) override; |
| 86 virtual bool Update(const Notification& notification, | 86 bool Update(const Notification& notification, Profile* profile) override; |
| 87 Profile* profile) override; | |
| 88 | 87 |
| 89 // Returns NULL if no notifications match the supplied ID, either currently | 88 // Returns NULL if no notifications match the supplied ID, either currently |
| 90 // displayed or in the queue. | 89 // displayed or in the queue. |
| 91 virtual const Notification* FindById(const std::string& delegate_id, | 90 const Notification* FindById(const std::string& delegate_id, |
| 92 ProfileID profile_id) const override; | 91 ProfileID profile_id) const override; |
| 93 | 92 |
| 94 // Removes any notifications matching the supplied ID, either currently | 93 // Removes any notifications matching the supplied ID, either currently |
| 95 // displayed or in the queue. Returns true if anything was removed. | 94 // displayed or in the queue. Returns true if anything was removed. |
| 96 virtual bool CancelById(const std::string& delegate_id, | 95 bool CancelById(const std::string& delegate_id, |
| 97 ProfileID profile_id) override; | 96 ProfileID profile_id) override; |
| 98 | 97 |
| 99 // Adds the delegate_id for each outstanding notification to the set | 98 // Adds the delegate_id for each outstanding notification to the set |
| 100 // |delegate_ids| (must not be NULL). | 99 // |delegate_ids| (must not be NULL). |
| 101 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 100 std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
| 102 Profile* profile, | 101 Profile* profile, |
| 103 const GURL& source) override; | 102 const GURL& source) override; |
| 104 | 103 |
| 105 // Removes notifications matching the |source_origin| (which could be an | 104 // Removes notifications matching the |source_origin| (which could be an |
| 106 // extension ID). Returns true if anything was removed. | 105 // extension ID). Returns true if anything was removed. |
| 107 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) override; | 106 bool CancelAllBySourceOrigin(const GURL& source_origin) override; |
| 108 | 107 |
| 109 // Removes notifications matching |profile|. Returns true if any were removed. | 108 // Removes notifications matching |profile|. Returns true if any were removed. |
| 110 virtual bool CancelAllByProfile(ProfileID profile_id) override; | 109 bool CancelAllByProfile(ProfileID profile_id) override; |
| 111 | 110 |
| 112 // Cancels all pending notifications and closes anything currently showing. | 111 // Cancels all pending notifications and closes anything currently showing. |
| 113 // Used when the app is terminating. | 112 // Used when the app is terminating. |
| 114 virtual void CancelAll() override; | 113 void CancelAll() override; |
| 115 | 114 |
| 116 // Test hook to get the notification so we can check it | 115 // Test hook to get the notification so we can check it |
| 117 const Notification& notification() const { return notification_; } | 116 const Notification& notification() const { return notification_; } |
| 118 | 117 |
| 119 // Test hook to check the ID of the last notification cancelled. | 118 // Test hook to check the ID of the last notification cancelled. |
| 120 std::string& dismissed_id() { return dismissed_id_; } | 119 std::string& dismissed_id() { return dismissed_id_; } |
| 121 | 120 |
| 122 size_t added_notifications() const { return added_notifications_; } | 121 size_t added_notifications() const { return added_notifications_; } |
| 123 bool welcomed() const { return welcomed_; } | 122 bool welcomed() const { return welcomed_; } |
| 124 | 123 |
| 125 private: | 124 private: |
| 126 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); | 125 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
| 127 Notification notification_; | 126 Notification notification_; |
| 128 Profile* profile_; | 127 Profile* profile_; |
| 129 std::string dismissed_id_; | 128 std::string dismissed_id_; |
| 130 GURL welcome_origin_; | 129 GURL welcome_origin_; |
| 131 bool welcomed_; | 130 bool welcomed_; |
| 132 size_t added_notifications_; | 131 size_t added_notifications_; |
| 133 }; | 132 }; |
| 134 | 133 |
| 135 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ | 134 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ |
| OLD | NEW |