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 void Display() override {} | 25 void Display() override {} |
26 void Error() override {} | |
27 void Close(bool by_user) override {} | 26 void Close(bool by_user) override {} |
28 void Click() override {} | 27 void Click() override {} |
29 std::string id() const override; | 28 std::string id() const override; |
30 | 29 |
31 private: | 30 private: |
32 ~MockNotificationDelegate() override; | 31 ~MockNotificationDelegate() override; |
33 | 32 |
34 std::string id_; | 33 std::string id_; |
35 | 34 |
36 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); | 35 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); |
37 }; | 36 }; |
38 | 37 |
39 // Mock implementation of Javascript object proxy which logs events that | 38 // Mock implementation of Javascript object proxy which logs events that |
40 // would have been fired on it. Useful for tests where the sequence of | 39 // would have been fired on it. Useful for tests where the sequence of |
41 // notification events needs to be verified. | 40 // notification events needs to be verified. |
42 // | 41 // |
43 // |Logger| class provided in template must implement method | 42 // |Logger| class provided in template must implement method |
44 // static void log(string); | 43 // static void log(string); |
45 template<class Logger> | 44 template<class Logger> |
46 class LoggingNotificationDelegate : public NotificationDelegate { | 45 class LoggingNotificationDelegate : public NotificationDelegate { |
47 public: | 46 public: |
48 explicit LoggingNotificationDelegate(std::string id) : notification_id_(id) {} | 47 explicit LoggingNotificationDelegate(std::string id) : notification_id_(id) {} |
49 | 48 |
50 // NotificationObjectProxy override | 49 // NotificationObjectProxy override |
51 virtual void Display() override { | 50 virtual void Display() override { |
52 Logger::log("notification displayed\n"); | 51 Logger::log("notification displayed\n"); |
53 } | 52 } |
54 virtual void Error() override { | |
55 Logger::log("notification error\n"); | |
56 } | |
57 virtual void Click() override { | 53 virtual void Click() override { |
58 Logger::log("notification clicked\n"); | 54 Logger::log("notification clicked\n"); |
59 } | 55 } |
60 virtual void ButtonClick(int index) override { | 56 virtual void ButtonClick(int index) override { |
61 Logger::log("notification button clicked\n"); | 57 Logger::log("notification button clicked\n"); |
62 } | 58 } |
63 virtual void Close(bool by_user) override { | 59 virtual void Close(bool by_user) override { |
64 if (by_user) | 60 if (by_user) |
65 Logger::log("notification closed by user\n"); | 61 Logger::log("notification closed by user\n"); |
66 else | 62 else |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); | 121 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
126 Notification notification_; | 122 Notification notification_; |
127 Profile* profile_; | 123 Profile* profile_; |
128 std::string dismissed_id_; | 124 std::string dismissed_id_; |
129 GURL welcome_origin_; | 125 GURL welcome_origin_; |
130 bool welcomed_; | 126 bool welcomed_; |
131 size_t added_notifications_; | 127 size_t added_notifications_; |
132 }; | 128 }; |
133 | 129 |
134 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ | 130 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ |
OLD | NEW |