[email protected] | 8d167c2 | 2011-02-15 22:10:01 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 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_TEST_UTIL_H_ | ||||
6 | #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 8 | |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 9 | #include <string> |
10 | |||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 11 | #include "chrome/browser/notifications/notification_object_proxy.h" |
12 | #include "chrome/browser/notifications/balloon.h" | ||||
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 13 | #include "ui/gfx/size.h" |
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 14 | |
[email protected] | 38baba4 | 2010-11-04 21:12:00 | [diff] [blame] | 15 | // NotificationDelegate which does nothing, useful for testing when |
16 | // the notification events are not important. | ||||
17 | class MockNotificationDelegate : public NotificationDelegate { | ||||
18 | public: | ||||
[email protected] | 8d167c2 | 2011-02-15 22:10:01 | [diff] [blame] | 19 | explicit MockNotificationDelegate(const std::string& id); |
20 | virtual ~MockNotificationDelegate(); | ||||
[email protected] | 38baba4 | 2010-11-04 21:12:00 | [diff] [blame] | 21 | |
22 | // NotificationDelegate interface. | ||||
23 | virtual void Display() {} | ||||
24 | virtual void Error() {} | ||||
25 | virtual void Close(bool by_user) {} | ||||
26 | virtual void Click() {} | ||||
[email protected] | 8d167c2 | 2011-02-15 22:10:01 | [diff] [blame] | 27 | virtual std::string id() const; |
[email protected] | 38baba4 | 2010-11-04 21:12:00 | [diff] [blame] | 28 | |
29 | private: | ||||
30 | std::string id_; | ||||
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 31 | |
32 | DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); | ||||
[email protected] | 38baba4 | 2010-11-04 21:12:00 | [diff] [blame] | 33 | }; |
34 | |||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 35 | // Mock implementation of Javascript object proxy which logs events that |
[email protected] | 38baba4 | 2010-11-04 21:12:00 | [diff] [blame] | 36 | // would have been fired on it. Useful for tests where the sequence of |
37 | // notification events needs to be verified. | ||||
38 | // | ||||
39 | // |Logger| class provided in template must implement method | ||||
40 | // static void log(string); | ||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 41 | template<class Logger> |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 42 | class LoggingNotificationDelegate : public NotificationDelegate { |
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 43 | public: |
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 44 | explicit LoggingNotificationDelegate(std::string id) |
45 | : notification_id_(id) { | ||||
46 | } | ||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 47 | |
48 | // NotificationObjectProxy override | ||||
49 | virtual void Display() { | ||||
50 | Logger::log("notification displayed\n"); | ||||
51 | } | ||||
52 | virtual void Error() { | ||||
53 | Logger::log("notification error\n"); | ||||
54 | } | ||||
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 55 | virtual void Click() { |
56 | Logger::log("notification clicked\n"); | ||||
57 | } | ||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 58 | virtual void Close(bool by_user) { |
59 | if (by_user) | ||||
60 | Logger::log("notification closed by user\n"); | ||||
61 | else | ||||
62 | Logger::log("notification closed by script\n"); | ||||
63 | } | ||||
[email protected] | 24c5013f | 2010-11-19 22:21:08 | [diff] [blame] | 64 | virtual std::string id() const { |
65 | return notification_id_; | ||||
66 | } | ||||
67 | private: | ||||
68 | std::string notification_id_; | ||||
69 | |||||
70 | DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate); | ||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 71 | }; |
72 | |||||
73 | // Test version of a balloon view which doesn't do anything | ||||
74 | // viewable, but does know how to close itself the same as a regular | ||||
75 | // BalloonView. | ||||
76 | class MockBalloonView : public BalloonView { | ||||
77 | public: | ||||
78 | explicit MockBalloonView(Balloon * balloon) : | ||||
79 | balloon_(balloon) {} | ||||
[email protected] | 8d167c2 | 2011-02-15 22:10:01 | [diff] [blame] | 80 | |
81 | // BalloonView: | ||||
82 | virtual void Show(Balloon* balloon) {} | ||||
83 | virtual void Update() {} | ||||
84 | virtual void RepositionToBalloon() {} | ||||
85 | virtual void Close(bool by_user); | ||||
86 | virtual gfx::Size GetSize() const; | ||||
87 | virtual BalloonHost* GetHost() const; | ||||
[email protected] | f83198c | 2010-03-16 09:30:32 | [diff] [blame] | 88 | |
89 | private: | ||||
90 | // Non-owned pointer. | ||||
91 | Balloon* balloon_; | ||||
92 | }; | ||||
93 | |||||
94 | #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ |