OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | |
6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | |
7 | |
8 #include <deque> | |
9 #include <string> | |
10 | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/prefs/testing_pref_service.h" | |
13 #include "chrome/browser/notifications/balloon_collection_impl.h" | |
14 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | |
15 #include "chrome/browser/notifications/desktop_notification_service.h" | |
16 #include "chrome/browser/notifications/notification.h" | |
17 #include "chrome/browser/notifications/notification_test_util.h" | |
18 #include "chrome/test/base/testing_browser_process.h" | |
19 #include "chrome/test/base/testing_profile.h" | |
20 #include "content/public/test/render_view_test.h" | |
21 #include "content/public/test/test_browser_thread.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | |
23 | |
24 #if defined(USE_AURA) | |
25 namespace wm { | |
26 class WMState; | |
27 } | |
28 #endif | |
29 | |
30 class ActiveDesktopMonitor; | |
31 class DesktopNotificationsTest; | |
32 typedef LoggingNotificationDelegate<DesktopNotificationsTest> | |
33 LoggingNotificationProxy; | |
34 | |
35 // Test version of the balloon collection which counts the number | |
36 // of notifications that are added to it. | |
37 class MockBalloonCollection : public BalloonCollectionImpl { | |
38 public: | |
39 MockBalloonCollection(); | |
40 virtual ~MockBalloonCollection(); | |
41 | |
42 // Our mock collection has an area large enough for a fixed number | |
43 // of balloons. | |
44 static const int kMockBalloonSpace; | |
45 int max_balloon_count() const { return kMockBalloonSpace; } | |
46 | |
47 // BalloonCollectionImpl overrides | |
48 virtual void Add(const Notification& notification, | |
49 Profile* profile) OVERRIDE; | |
50 virtual bool HasSpace() const OVERRIDE; | |
51 virtual Balloon* MakeBalloon(const Notification& notification, | |
52 Profile* profile) OVERRIDE; | |
53 virtual void DisplayChanged() OVERRIDE {} | |
54 virtual void OnBalloonClosed(Balloon* source) OVERRIDE; | |
55 virtual const BalloonCollection::Balloons& GetActiveBalloons() OVERRIDE; | |
56 | |
57 // Number of balloons being shown. | |
58 std::deque<Balloon*>& balloons() { return balloons_; } | |
59 int count() const { return balloons_.size(); } | |
60 | |
61 // Returns the highest y-coordinate of all the balloons in the collection. | |
62 int UppermostVerticalPosition(); | |
63 | |
64 // Returns the height bounds of a balloon. | |
65 int MinHeight() { return Layout::min_balloon_height(); } | |
66 int MaxHeight() { return Layout::max_balloon_height(); } | |
67 | |
68 // Returns the bounding box. | |
69 gfx::Rect GetBalloonsBoundingBox() { | |
70 return BalloonCollectionImpl::GetBalloonsBoundingBox(); | |
71 } | |
72 | |
73 private: | |
74 std::deque<Balloon*> balloons_; | |
75 }; | |
76 | |
77 class DesktopNotificationsTest : public testing::Test { | |
78 public: | |
79 DesktopNotificationsTest(); | |
80 virtual ~DesktopNotificationsTest(); | |
81 | |
82 static void log(const std::string& message) { | |
83 log_output_.append(message); | |
84 } | |
85 | |
86 Profile* profile() { return profile_.get(); } | |
87 | |
88 protected: | |
89 // testing::Test overrides | |
90 virtual void SetUp() OVERRIDE; | |
91 virtual void TearDown() OVERRIDE; | |
92 | |
93 void AllowOrigin(const GURL& origin) { | |
94 service_->GrantPermission(origin); | |
95 } | |
96 | |
97 void DenyOrigin(const GURL& origin) { | |
98 service_->DenyPermission(origin); | |
99 } | |
100 | |
101 // Constructs a notification parameter structure for use in tests. | |
102 content::ShowDesktopNotificationHostMsgParams StandardTestNotification(); | |
103 | |
104 // Must be first member. Because we're running a unit test in browser_tests | |
105 // we need to handle TestingBrowserProcess initialization ourselves. | |
106 TestingBrowserProcessInitializer initializer_; | |
107 | |
108 // Create a message loop to allow notifications code to post tasks, | |
109 // and a thread so that notifications code runs on the expected thread. | |
110 base::MessageLoopForUI message_loop_; | |
111 content::TestBrowserThread ui_thread_; | |
112 | |
113 // Local state mock. | |
114 TestingPrefServiceSimple local_state_; | |
115 | |
116 // Test profile. | |
117 scoped_ptr<TestingProfile> profile_; | |
118 | |
119 // Mock balloon collection -- owned by the NotificationUIManager | |
120 MockBalloonCollection* balloon_collection_; | |
121 | |
122 // Real UI manager. | |
123 scoped_ptr<BalloonNotificationUIManager> ui_manager_; | |
124 | |
125 // Real DesktopNotificationService | |
126 scoped_ptr<DesktopNotificationService> service_; | |
127 | |
128 // Contains the cumulative output of the unit test. | |
129 static std::string log_output_; | |
130 | |
131 private: | |
132 #if defined(USE_AURA) | |
133 scoped_ptr<wm::WMState> wm_state_; | |
134 #endif | |
135 | |
136 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationsTest); | |
137 }; | |
138 | |
139 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | |
OLD | NEW |