| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 
| 6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include <deque> | 9 #include <deque> | 
| 10 #include <string> | 10 #include <string> | 
| 11 | 11 | 
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" | 
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" | 
| 14 #include "chrome/browser/notifications/balloon_collection_impl.h" | 14 #include "chrome/browser/notifications/balloon_collection_impl.h" | 
| 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" | 
| 17 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" | 
| 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 
| 19 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 19 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 
| 20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" | 
| 21 #include "chrome/test/testing_profile.h" | 21 #include "chrome/test/testing_profile.h" | 
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" | 
| 23 | 23 | 
| 24 class DesktopNotificationsTest; | 24 class DesktopNotificationsTest; | 
| 25 typedef LoggingNotificationProxyBase<DesktopNotificationsTest> | 25 typedef LoggingNotificationDelegate<DesktopNotificationsTest> | 
| 26     LoggingNotificationProxy; | 26     LoggingNotificationProxy; | 
| 27 | 27 | 
| 28 // Test version of the balloon collection which counts the number | 28 // Test version of the balloon collection which counts the number | 
| 29 // of notifications that are added to it. | 29 // of notifications that are added to it. | 
| 30 class MockBalloonCollection : public BalloonCollectionImpl { | 30 class MockBalloonCollection : public BalloonCollectionImpl { | 
| 31  public: | 31  public: | 
| 32   MockBalloonCollection() : | 32   MockBalloonCollection() {} | 
| 33     log_proxy_(new LoggingNotificationProxy()) {} |  | 
| 34 | 33 | 
| 35   // Our mock collection has an area large enough for a fixed number | 34   // Our mock collection has an area large enough for a fixed number | 
| 36   // of balloons. | 35   // of balloons. | 
| 37   static const int kMockBalloonSpace; | 36   static const int kMockBalloonSpace; | 
| 38   int max_balloon_count() const { return kMockBalloonSpace; } | 37   int max_balloon_count() const { return kMockBalloonSpace; } | 
| 39 | 38 | 
| 40   // BalloonCollectionImpl overrides | 39   // BalloonCollectionImpl overrides | 
| 41   virtual void Add(const Notification& notification, | 40   virtual void Add(const Notification& notification, | 
| 42                    Profile* profile); | 41                    Profile* profile); | 
| 43   virtual bool Remove(const Notification& notification); |  | 
| 44   virtual bool HasSpace() const { return count() < kMockBalloonSpace; } | 42   virtual bool HasSpace() const { return count() < kMockBalloonSpace; } | 
| 45   virtual Balloon* MakeBalloon(const Notification& notification, | 43   virtual Balloon* MakeBalloon(const Notification& notification, | 
| 46                                Profile* profile); | 44                                Profile* profile); | 
| 47   virtual void DisplayChanged() {} | 45   virtual void DisplayChanged() {} | 
| 48   virtual void OnBalloonClosed(Balloon* source); | 46   virtual void OnBalloonClosed(Balloon* source); | 
| 49   virtual const BalloonCollection::Balloons& GetActiveBalloons() { | 47   virtual const BalloonCollection::Balloons& GetActiveBalloons() { | 
| 50     return balloons_; | 48     return balloons_; | 
| 51   } | 49   } | 
| 52 | 50 | 
| 53   // Number of balloons being shown. | 51   // Number of balloons being shown. | 
| 54   std::deque<Balloon*>& balloons() { return balloons_; } | 52   std::deque<Balloon*>& balloons() { return balloons_; } | 
| 55   int count() const { return balloons_.size(); } | 53   int count() const { return balloons_.size(); } | 
| 56 | 54 | 
| 57   // Returns the highest y-coordinate of all the balloons in the collection. | 55   // Returns the highest y-coordinate of all the balloons in the collection. | 
| 58   int UppermostVerticalPosition(); | 56   int UppermostVerticalPosition(); | 
| 59 | 57 | 
| 60   // Returns the height bounds of a balloon. | 58   // Returns the height bounds of a balloon. | 
| 61   int MinHeight() { return Layout::min_balloon_height(); } | 59   int MinHeight() { return Layout::min_balloon_height(); } | 
| 62   int MaxHeight() { return Layout::max_balloon_height(); } | 60   int MaxHeight() { return Layout::max_balloon_height(); } | 
| 63 | 61 | 
| 64  private: | 62  private: | 
| 65   std::deque<Balloon*> balloons_; | 63   std::deque<Balloon*> balloons_; | 
| 66   scoped_refptr<LoggingNotificationProxy> log_proxy_; |  | 
| 67 }; | 64 }; | 
| 68 | 65 | 
| 69 class DesktopNotificationsTest : public testing::Test { | 66 class DesktopNotificationsTest : public testing::Test { | 
| 70  public: | 67  public: | 
| 71   DesktopNotificationsTest(); | 68   DesktopNotificationsTest(); | 
| 72   ~DesktopNotificationsTest(); | 69   ~DesktopNotificationsTest(); | 
| 73 | 70 | 
| 74   static void log(const std::string& message) { | 71   static void log(const std::string& message) { | 
| 75     log_output_.append(message); | 72     log_output_.append(message); | 
| 76   } | 73   } | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 112   scoped_ptr<NotificationUIManager> ui_manager_; | 109   scoped_ptr<NotificationUIManager> ui_manager_; | 
| 113 | 110 | 
| 114   // Real DesktopNotificationService | 111   // Real DesktopNotificationService | 
| 115   scoped_ptr<DesktopNotificationService> service_; | 112   scoped_ptr<DesktopNotificationService> service_; | 
| 116 | 113 | 
| 117   // Contains the cumulative output of the unit test. | 114   // Contains the cumulative output of the unit test. | 
| 118   static std::string log_output_; | 115   static std::string log_output_; | 
| 119 }; | 116 }; | 
| 120 | 117 | 
| 121 #endif  // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 118 #endif  // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 
| OLD | NEW | 
|---|