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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 base::MessageLoopForUI message_loop_; | 65 base::MessageLoopForUI message_loop_; |
66 scoped_ptr<base::RunLoop> nested_run_loop_; | 66 scoped_ptr<base::RunLoop> nested_run_loop_; |
67 base::scoped_nsobject<MCTrayViewController> tray_; | 67 base::scoped_nsobject<MCTrayViewController> tray_; |
68 }; | 68 }; |
69 | 69 |
70 TEST_F(TrayViewControllerTest, AddRemoveOne) { | 70 TEST_F(TrayViewControllerTest, AddRemoveOne) { |
71 NSScrollView* view = [[tray_ scrollView] documentView]; | 71 NSScrollView* view = [[tray_ scrollView] documentView]; |
72 EXPECT_EQ(0u, [[view subviews] count]); | 72 EXPECT_EQ(0u, [[view subviews] count]); |
73 scoped_ptr<message_center::Notification> notification_data; | 73 scoped_ptr<message_center::Notification> notification_data; |
74 notification_data.reset(new message_center::Notification( | 74 notification_data.reset(new message_center::Notification( |
75 message_center::NOTIFICATION_TYPE_SIMPLE, | 75 message_center::NOTIFICATION_TYPE_SIMPLE, "1", |
76 "1", | |
77 ASCIIToUTF16("First notification"), | 76 ASCIIToUTF16("First notification"), |
78 ASCIIToUTF16("This is a simple test."), | 77 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
79 gfx::Image(), | 78 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
80 base::string16(), | |
81 DummyNotifierId(), | |
82 message_center::RichNotificationData(), | |
83 NULL)); | |
84 center_->AddNotification(notification_data.Pass()); | 79 center_->AddNotification(notification_data.Pass()); |
85 [tray_ onMessageCenterTrayChanged]; | 80 [tray_ onMessageCenterTrayChanged]; |
86 ASSERT_EQ(1u, [[view subviews] count]); | 81 ASSERT_EQ(1u, [[view subviews] count]); |
87 | 82 |
88 // The view should have padding around it. | 83 // The view should have padding around it. |
89 NSView* notification = [[view subviews] objectAtIndex:0]; | 84 NSView* notification = [[view subviews] objectAtIndex:0]; |
90 NSRect notification_frame = [notification frame]; | 85 NSRect notification_frame = [notification frame]; |
91 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, | 86 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, |
92 NSHeight([view frame]) - NSHeight(notification_frame)); | 87 NSHeight([view frame]) - NSHeight(notification_frame)); |
93 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, | 88 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, |
94 NSWidth([view frame]) - NSWidth(notification_frame)); | 89 NSWidth([view frame]) - NSWidth(notification_frame)); |
95 EXPECT_GT(NSHeight([[tray_ view] frame]), | 90 EXPECT_GT(NSHeight([[tray_ view] frame]), |
96 NSHeight([[tray_ scrollView] frame])); | 91 NSHeight([[tray_ scrollView] frame])); |
97 | 92 |
98 center_->RemoveNotification("1", true); | 93 center_->RemoveNotification("1", true); |
99 [tray_ onMessageCenterTrayChanged]; | 94 [tray_ onMessageCenterTrayChanged]; |
100 EXPECT_EQ(0u, [[view subviews] count]); | 95 EXPECT_EQ(0u, [[view subviews] count]); |
101 // The empty tray is now 100px tall to accommodate | 96 // The empty tray is now 100px tall to accommodate |
102 // the empty message. | 97 // the empty message. |
103 EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight, | 98 EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight, |
104 NSHeight([view frame])); | 99 NSHeight([view frame])); |
105 } | 100 } |
106 | 101 |
107 TEST_F(TrayViewControllerTest, AddThreeClearAll) { | 102 TEST_F(TrayViewControllerTest, AddThreeClearAll) { |
108 NSScrollView* view = [[tray_ scrollView] documentView]; | 103 NSScrollView* view = [[tray_ scrollView] documentView]; |
109 EXPECT_EQ(0u, [[view subviews] count]); | 104 EXPECT_EQ(0u, [[view subviews] count]); |
110 scoped_ptr<message_center::Notification> notification; | 105 scoped_ptr<message_center::Notification> notification; |
111 notification.reset(new message_center::Notification( | 106 notification.reset(new message_center::Notification( |
112 message_center::NOTIFICATION_TYPE_SIMPLE, | 107 message_center::NOTIFICATION_TYPE_SIMPLE, "1", |
113 "1", | |
114 ASCIIToUTF16("First notification"), | 108 ASCIIToUTF16("First notification"), |
115 ASCIIToUTF16("This is a simple test."), | 109 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
116 gfx::Image(), | 110 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
117 base::string16(), | |
118 DummyNotifierId(), | |
119 message_center::RichNotificationData(), | |
120 NULL)); | |
121 center_->AddNotification(notification.Pass()); | 111 center_->AddNotification(notification.Pass()); |
122 notification.reset(new message_center::Notification( | 112 notification.reset(new message_center::Notification( |
123 message_center::NOTIFICATION_TYPE_SIMPLE, | 113 message_center::NOTIFICATION_TYPE_SIMPLE, "2", |
124 "2", | |
125 ASCIIToUTF16("Second notification"), | 114 ASCIIToUTF16("Second notification"), |
126 ASCIIToUTF16("This is a simple test."), | 115 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
127 gfx::Image(), | 116 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
128 base::string16(), | |
129 DummyNotifierId(), | |
130 message_center::RichNotificationData(), | |
131 NULL)); | |
132 center_->AddNotification(notification.Pass()); | 117 center_->AddNotification(notification.Pass()); |
133 notification.reset(new message_center::Notification( | 118 notification.reset(new message_center::Notification( |
134 message_center::NOTIFICATION_TYPE_SIMPLE, | 119 message_center::NOTIFICATION_TYPE_SIMPLE, "3", |
135 "3", | |
136 ASCIIToUTF16("Third notification"), | 120 ASCIIToUTF16("Third notification"), |
137 ASCIIToUTF16("This is a simple test."), | 121 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
138 gfx::Image(), | 122 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
139 base::string16(), | |
140 DummyNotifierId(), | |
141 message_center::RichNotificationData(), | |
142 NULL)); | |
143 center_->AddNotification(notification.Pass()); | 123 center_->AddNotification(notification.Pass()); |
144 [tray_ onMessageCenterTrayChanged]; | 124 [tray_ onMessageCenterTrayChanged]; |
145 ASSERT_EQ(3u, [[view subviews] count]); | 125 ASSERT_EQ(3u, [[view subviews] count]); |
146 | 126 |
147 [tray_ clearAllNotifications:nil]; | 127 [tray_ clearAllNotifications:nil]; |
148 WaitForAnimationEnded(); | 128 WaitForAnimationEnded(); |
149 [tray_ onMessageCenterTrayChanged]; | 129 [tray_ onMessageCenterTrayChanged]; |
150 | 130 |
151 EXPECT_EQ(0u, [[view subviews] count]); | 131 EXPECT_EQ(0u, [[view subviews] count]); |
152 // The empty tray is now 100px tall to accommodate | 132 // The empty tray is now 100px tall to accommodate |
153 // the empty message. | 133 // the empty message. |
154 EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight, | 134 EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight, |
155 NSHeight([view frame])); | 135 NSHeight([view frame])); |
156 } | 136 } |
157 | 137 |
158 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { | 138 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { |
159 EXPECT_TRUE([tray_ pauseButton]); | 139 EXPECT_TRUE([tray_ pauseButton]); |
160 EXPECT_TRUE([tray_ clearAllButton]); | 140 EXPECT_TRUE([tray_ clearAllButton]); |
161 | 141 |
162 // With no notifications, the clear all button should be hidden. | 142 // With no notifications, the clear all button should be hidden. |
163 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); | 143 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); |
164 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), | 144 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), |
165 NSMinX([[tray_ pauseButton] frame])); | 145 NSMinX([[tray_ pauseButton] frame])); |
166 | 146 |
167 // Add a notification. | 147 // Add a notification. |
168 scoped_ptr<message_center::Notification> notification; | 148 scoped_ptr<message_center::Notification> notification; |
169 notification.reset(new message_center::Notification( | 149 notification.reset(new message_center::Notification( |
170 message_center::NOTIFICATION_TYPE_SIMPLE, | 150 message_center::NOTIFICATION_TYPE_SIMPLE, "1", |
171 "1", | |
172 ASCIIToUTF16("First notification"), | 151 ASCIIToUTF16("First notification"), |
173 ASCIIToUTF16("This is a simple test."), | 152 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
174 gfx::Image(), | 153 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
175 base::string16(), | |
176 DummyNotifierId(), | |
177 message_center::RichNotificationData(), | |
178 NULL)); | |
179 center_->AddNotification(notification.Pass()); | 154 center_->AddNotification(notification.Pass()); |
180 [tray_ onMessageCenterTrayChanged]; | 155 [tray_ onMessageCenterTrayChanged]; |
181 | 156 |
182 // Clear all should now be visible. | 157 // Clear all should now be visible. |
183 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 158 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
184 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 159 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
185 NSMinX([[tray_ pauseButton] frame])); | 160 NSMinX([[tray_ pauseButton] frame])); |
186 | 161 |
187 // Adding a second notification should keep things still visible. | 162 // Adding a second notification should keep things still visible. |
188 notification.reset(new message_center::Notification( | 163 notification.reset(new message_center::Notification( |
189 message_center::NOTIFICATION_TYPE_SIMPLE, | 164 message_center::NOTIFICATION_TYPE_SIMPLE, "2", |
190 "2", | |
191 ASCIIToUTF16("Second notification"), | 165 ASCIIToUTF16("Second notification"), |
192 ASCIIToUTF16("This is a simple test."), | 166 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
193 gfx::Image(), | 167 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
194 base::string16(), | |
195 DummyNotifierId(), | |
196 message_center::RichNotificationData(), | |
197 NULL)); | |
198 center_->AddNotification(notification.Pass()); | 168 center_->AddNotification(notification.Pass()); |
199 [tray_ onMessageCenterTrayChanged]; | 169 [tray_ onMessageCenterTrayChanged]; |
200 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 170 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
201 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 171 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
202 NSMinX([[tray_ pauseButton] frame])); | 172 NSMinX([[tray_ pauseButton] frame])); |
203 | 173 |
204 // Clear all notifications. | 174 // Clear all notifications. |
205 [tray_ clearAllNotifications:nil]; | 175 [tray_ clearAllNotifications:nil]; |
206 WaitForAnimationEnded(); | 176 WaitForAnimationEnded(); |
207 [tray_ onMessageCenterTrayChanged]; | 177 [tray_ onMessageCenterTrayChanged]; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 225 |
256 TEST_F(TrayViewControllerTest, EmptyCenter) { | 226 TEST_F(TrayViewControllerTest, EmptyCenter) { |
257 EXPECT_FALSE([[tray_ emptyDescription] isHidden]); | 227 EXPECT_FALSE([[tray_ emptyDescription] isHidden]); |
258 | 228 |
259 // With no notifications, the divider should be hidden. | 229 // With no notifications, the divider should be hidden. |
260 EXPECT_TRUE([[tray_ divider] isHidden]); | 230 EXPECT_TRUE([[tray_ divider] isHidden]); |
261 EXPECT_TRUE([[tray_ scrollView] isHidden]); | 231 EXPECT_TRUE([[tray_ scrollView] isHidden]); |
262 | 232 |
263 scoped_ptr<message_center::Notification> notification; | 233 scoped_ptr<message_center::Notification> notification; |
264 notification.reset(new message_center::Notification( | 234 notification.reset(new message_center::Notification( |
265 message_center::NOTIFICATION_TYPE_SIMPLE, | 235 message_center::NOTIFICATION_TYPE_SIMPLE, "1", |
266 "1", | |
267 ASCIIToUTF16("First notification"), | 236 ASCIIToUTF16("First notification"), |
268 ASCIIToUTF16("This is a simple test."), | 237 ASCIIToUTF16("This is a simple test."), gfx::Image(), base::string16(), |
269 gfx::Image(), | 238 GURL(), DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
270 base::string16(), | |
271 DummyNotifierId(), | |
272 message_center::RichNotificationData(), | |
273 NULL)); | |
274 center_->AddNotification(notification.Pass()); | 239 center_->AddNotification(notification.Pass()); |
275 [tray_ onMessageCenterTrayChanged]; | 240 [tray_ onMessageCenterTrayChanged]; |
276 | 241 |
277 EXPECT_FALSE([[tray_ divider] isHidden]); | 242 EXPECT_FALSE([[tray_ divider] isHidden]); |
278 EXPECT_FALSE([[tray_ scrollView] isHidden]); | 243 EXPECT_FALSE([[tray_ scrollView] isHidden]); |
279 EXPECT_TRUE([[tray_ emptyDescription] isHidden]); | 244 EXPECT_TRUE([[tray_ emptyDescription] isHidden]); |
280 } | 245 } |
281 | 246 |
282 } // namespace message_center | 247 } // namespace message_center |
OLD | NEW |