OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #import "ui/message_center/cocoa/tray_view_controller.h" | 5 #import "ui/message_center/cocoa/tray_view_controller.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #import "ui/base/test/ui_cocoa_test_helper.h" | 11 #import "ui/base/test/ui_cocoa_test_helper.h" |
12 #include "ui/message_center/fake_notifier_settings_provider.h" | 12 #include "ui/message_center/fake_notifier_settings_provider.h" |
13 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
14 #include "ui/message_center/message_center_impl.h" | 14 #include "ui/message_center/message_center_impl.h" |
15 #include "ui/message_center/message_center_style.h" | 15 #include "ui/message_center/message_center_style.h" |
16 #include "ui/message_center/notification.h" | 16 #include "ui/message_center/notification.h" |
17 #include "ui/message_center/notifier_settings.h" | 17 #include "ui/message_center/notifier_settings.h" |
18 | 18 |
| 19 namespace message_center { |
| 20 |
19 class TrayViewControllerTest : public ui::CocoaTest { | 21 class TrayViewControllerTest : public ui::CocoaTest { |
20 public: | 22 public: |
21 TrayViewControllerTest() | 23 TrayViewControllerTest() |
22 : center_(NULL), | 24 : center_(NULL), |
23 message_loop_(base::MessageLoop::TYPE_UI) { | 25 message_loop_(base::MessageLoop::TYPE_UI) { |
24 } | 26 } |
25 | 27 |
26 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
27 ui::CocoaTest::SetUp(); | 29 ui::CocoaTest::SetUp(); |
28 message_center::MessageCenter::Initialize(); | 30 message_center::MessageCenter::Initialize(); |
(...skipping 17 matching lines...) Expand all Loading... |
46 | 48 |
47 void WaitForAnimationEnded() { | 49 void WaitForAnimationEnded() { |
48 if (![tray_ isAnimating]) | 50 if (![tray_ isAnimating]) |
49 return; | 51 return; |
50 nested_run_loop_.reset(new base::RunLoop()); | 52 nested_run_loop_.reset(new base::RunLoop()); |
51 nested_run_loop_->Run(); | 53 nested_run_loop_->Run(); |
52 nested_run_loop_.reset(); | 54 nested_run_loop_.reset(); |
53 } | 55 } |
54 | 56 |
55 protected: | 57 protected: |
| 58 message_center::NotifierId DummyNotifierId() { |
| 59 return message_center::NotifierId(); |
| 60 } |
| 61 |
56 message_center::MessageCenter* center_; // Weak, global. | 62 message_center::MessageCenter* center_; // Weak, global. |
57 | 63 |
58 base::MessageLoop message_loop_; | 64 base::MessageLoop message_loop_; |
59 scoped_ptr<base::RunLoop> nested_run_loop_; | 65 scoped_ptr<base::RunLoop> nested_run_loop_; |
60 base::scoped_nsobject<MCTrayViewController> tray_; | 66 base::scoped_nsobject<MCTrayViewController> tray_; |
61 }; | 67 }; |
62 | 68 |
63 TEST_F(TrayViewControllerTest, AddRemoveOne) { | 69 TEST_F(TrayViewControllerTest, AddRemoveOne) { |
64 NSScrollView* view = [[tray_ scrollView] documentView]; | 70 NSScrollView* view = [[tray_ scrollView] documentView]; |
65 EXPECT_EQ(0u, [[view subviews] count]); | 71 EXPECT_EQ(0u, [[view subviews] count]); |
66 scoped_ptr<message_center::Notification> notification_data; | 72 scoped_ptr<message_center::Notification> notification_data; |
67 notification_data.reset(new message_center::Notification( | 73 notification_data.reset(new message_center::Notification( |
68 message_center::NOTIFICATION_TYPE_SIMPLE, | 74 message_center::NOTIFICATION_TYPE_SIMPLE, |
69 "1", | 75 "1", |
70 ASCIIToUTF16("First notification"), | 76 ASCIIToUTF16("First notification"), |
71 ASCIIToUTF16("This is a simple test."), | 77 ASCIIToUTF16("This is a simple test."), |
72 gfx::Image(), | 78 gfx::Image(), |
73 string16(), | 79 string16(), |
74 message_center::NotifierId(), | 80 DummyNotifierId(), |
75 message_center::RichNotificationData(), | 81 message_center::RichNotificationData(), |
76 NULL)); | 82 NULL)); |
77 center_->AddNotification(notification_data.Pass()); | 83 center_->AddNotification(notification_data.Pass()); |
78 [tray_ onMessageCenterTrayChanged]; | 84 [tray_ onMessageCenterTrayChanged]; |
79 ASSERT_EQ(1u, [[view subviews] count]); | 85 ASSERT_EQ(1u, [[view subviews] count]); |
80 | 86 |
81 // The view should have padding around it. | 87 // The view should have padding around it. |
82 NSView* notification = [[view subviews] objectAtIndex:0]; | 88 NSView* notification = [[view subviews] objectAtIndex:0]; |
83 NSRect notification_frame = [notification frame]; | 89 NSRect notification_frame = [notification frame]; |
84 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, | 90 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, |
(...skipping 13 matching lines...) Expand all Loading... |
98 NSScrollView* view = [[tray_ scrollView] documentView]; | 104 NSScrollView* view = [[tray_ scrollView] documentView]; |
99 EXPECT_EQ(0u, [[view subviews] count]); | 105 EXPECT_EQ(0u, [[view subviews] count]); |
100 scoped_ptr<message_center::Notification> notification; | 106 scoped_ptr<message_center::Notification> notification; |
101 notification.reset(new message_center::Notification( | 107 notification.reset(new message_center::Notification( |
102 message_center::NOTIFICATION_TYPE_SIMPLE, | 108 message_center::NOTIFICATION_TYPE_SIMPLE, |
103 "1", | 109 "1", |
104 ASCIIToUTF16("First notification"), | 110 ASCIIToUTF16("First notification"), |
105 ASCIIToUTF16("This is a simple test."), | 111 ASCIIToUTF16("This is a simple test."), |
106 gfx::Image(), | 112 gfx::Image(), |
107 string16(), | 113 string16(), |
108 message_center::NotifierId(), | 114 DummyNotifierId(), |
109 message_center::RichNotificationData(), | 115 message_center::RichNotificationData(), |
110 NULL)); | 116 NULL)); |
111 center_->AddNotification(notification.Pass()); | 117 center_->AddNotification(notification.Pass()); |
112 notification.reset(new message_center::Notification( | 118 notification.reset(new message_center::Notification( |
113 message_center::NOTIFICATION_TYPE_SIMPLE, | 119 message_center::NOTIFICATION_TYPE_SIMPLE, |
114 "2", | 120 "2", |
115 ASCIIToUTF16("Second notification"), | 121 ASCIIToUTF16("Second notification"), |
116 ASCIIToUTF16("This is a simple test."), | 122 ASCIIToUTF16("This is a simple test."), |
117 gfx::Image(), | 123 gfx::Image(), |
118 string16(), | 124 string16(), |
119 message_center::NotifierId(), | 125 DummyNotifierId(), |
120 message_center::RichNotificationData(), | 126 message_center::RichNotificationData(), |
121 NULL)); | 127 NULL)); |
122 center_->AddNotification(notification.Pass()); | 128 center_->AddNotification(notification.Pass()); |
123 notification.reset(new message_center::Notification( | 129 notification.reset(new message_center::Notification( |
124 message_center::NOTIFICATION_TYPE_SIMPLE, | 130 message_center::NOTIFICATION_TYPE_SIMPLE, |
125 "3", | 131 "3", |
126 ASCIIToUTF16("Third notification"), | 132 ASCIIToUTF16("Third notification"), |
127 ASCIIToUTF16("This is a simple test."), | 133 ASCIIToUTF16("This is a simple test."), |
128 gfx::Image(), | 134 gfx::Image(), |
129 string16(), | 135 string16(), |
130 message_center::NotifierId(), | 136 DummyNotifierId(), |
131 message_center::RichNotificationData(), | 137 message_center::RichNotificationData(), |
132 NULL)); | 138 NULL)); |
133 center_->AddNotification(notification.Pass()); | 139 center_->AddNotification(notification.Pass()); |
134 [tray_ onMessageCenterTrayChanged]; | 140 [tray_ onMessageCenterTrayChanged]; |
135 ASSERT_EQ(3u, [[view subviews] count]); | 141 ASSERT_EQ(3u, [[view subviews] count]); |
136 | 142 |
137 [tray_ clearAllNotifications:nil]; | 143 [tray_ clearAllNotifications:nil]; |
138 WaitForAnimationEnded(); | 144 WaitForAnimationEnded(); |
139 [tray_ onMessageCenterTrayChanged]; | 145 [tray_ onMessageCenterTrayChanged]; |
140 | 146 |
(...skipping 12 matching lines...) Expand all Loading... |
153 | 159 |
154 // Add a notification. | 160 // Add a notification. |
155 scoped_ptr<message_center::Notification> notification; | 161 scoped_ptr<message_center::Notification> notification; |
156 notification.reset(new message_center::Notification( | 162 notification.reset(new message_center::Notification( |
157 message_center::NOTIFICATION_TYPE_SIMPLE, | 163 message_center::NOTIFICATION_TYPE_SIMPLE, |
158 "1", | 164 "1", |
159 ASCIIToUTF16("First notification"), | 165 ASCIIToUTF16("First notification"), |
160 ASCIIToUTF16("This is a simple test."), | 166 ASCIIToUTF16("This is a simple test."), |
161 gfx::Image(), | 167 gfx::Image(), |
162 string16(), | 168 string16(), |
163 message_center::NotifierId(), | 169 DummyNotifierId(), |
164 message_center::RichNotificationData(), | 170 message_center::RichNotificationData(), |
165 NULL)); | 171 NULL)); |
166 center_->AddNotification(notification.Pass()); | 172 center_->AddNotification(notification.Pass()); |
167 [tray_ onMessageCenterTrayChanged]; | 173 [tray_ onMessageCenterTrayChanged]; |
168 | 174 |
169 // Clear all should now be visible. | 175 // Clear all should now be visible. |
170 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 176 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
171 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 177 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
172 NSMinX([[tray_ pauseButton] frame])); | 178 NSMinX([[tray_ pauseButton] frame])); |
173 | 179 |
174 // Adding a second notification should keep things still visible. | 180 // Adding a second notification should keep things still visible. |
175 notification.reset(new message_center::Notification( | 181 notification.reset(new message_center::Notification( |
176 message_center::NOTIFICATION_TYPE_SIMPLE, | 182 message_center::NOTIFICATION_TYPE_SIMPLE, |
177 "2", | 183 "2", |
178 ASCIIToUTF16("Second notification"), | 184 ASCIIToUTF16("Second notification"), |
179 ASCIIToUTF16("This is a simple test."), | 185 ASCIIToUTF16("This is a simple test."), |
180 gfx::Image(), | 186 gfx::Image(), |
181 string16(), | 187 string16(), |
182 message_center::NotifierId(), | 188 DummyNotifierId(), |
183 message_center::RichNotificationData(), | 189 message_center::RichNotificationData(), |
184 NULL)); | 190 NULL)); |
185 center_->AddNotification(notification.Pass()); | 191 center_->AddNotification(notification.Pass()); |
186 [tray_ onMessageCenterTrayChanged]; | 192 [tray_ onMessageCenterTrayChanged]; |
187 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 193 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
188 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 194 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
189 NSMinX([[tray_ pauseButton] frame])); | 195 NSMinX([[tray_ pauseButton] frame])); |
190 | 196 |
191 // Clear all notifications. | 197 // Clear all notifications. |
192 [tray_ clearAllNotifications:nil]; | 198 [tray_ clearAllNotifications:nil]; |
193 WaitForAnimationEnded(); | 199 WaitForAnimationEnded(); |
194 [tray_ onMessageCenterTrayChanged]; | 200 [tray_ onMessageCenterTrayChanged]; |
195 | 201 |
196 // The button should be hidden again. | 202 // The button should be hidden again. |
197 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); | 203 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); |
198 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), | 204 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), |
199 NSMinX([[tray_ pauseButton] frame])); | 205 NSMinX([[tray_ pauseButton] frame])); |
200 } | 206 } |
201 | 207 |
202 namespace message_center { | |
203 | |
204 namespace { | 208 namespace { |
205 | 209 |
206 Notifier* NewNotifier(const std::string& id, | 210 Notifier* NewNotifier(const std::string& id, |
207 const std::string& title, | 211 const std::string& title, |
208 bool enabled) { | 212 bool enabled) { |
209 NotifierId notifier_id(NotifierId::APPLICATION, id); | 213 NotifierId notifier_id(NotifierId::APPLICATION, id); |
210 return new Notifier(notifier_id, base::UTF8ToUTF16(title), enabled); | 214 return new Notifier(notifier_id, base::UTF8ToUTF16(title), enabled); |
211 } | 215 } |
212 | 216 |
213 } // namespace | 217 } // namespace |
(...skipping 19 matching lines...) Expand all Loading... |
233 | 237 |
234 [tray_ showMessages:nil]; | 238 [tray_ showMessages:nil]; |
235 EXPECT_EQ(1, provider.closed_called_count()); | 239 EXPECT_EQ(1, provider.closed_called_count()); |
236 EXPECT_TRUE(center_->IsMessageCenterVisible()); | 240 EXPECT_TRUE(center_->IsMessageCenterVisible()); |
237 | 241 |
238 // The tray should be back at its previous height now. | 242 // The tray should be back at its previous height now. |
239 EXPECT_EQ(trayHeight, NSHeight([[tray_ view] frame])); | 243 EXPECT_EQ(trayHeight, NSHeight([[tray_ view] frame])); |
240 } | 244 } |
241 | 245 |
242 } // namespace message_center | 246 } // namespace message_center |
OLD | NEW |