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