Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: ui/message_center/cocoa/popup_collection_unittest.mm

Issue 1579863003: Convert Pass()→std::move() for Mac build. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/mac/bootstrap_sandbox.cc ('k') | ui/views/widget/native_widget_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/popup_collection.h" 5 #import "ui/message_center/cocoa/popup_collection.h"
6 6
7 #include <utility>
8
7 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #import "ui/gfx/test/ui_cocoa_test_helper.h" 15 #import "ui/gfx/test/ui_cocoa_test_helper.h"
14 #import "ui/message_center/cocoa/notification_controller.h" 16 #import "ui/message_center/cocoa/notification_controller.h"
15 #import "ui/message_center/cocoa/popup_controller.h" 17 #import "ui/message_center/cocoa/popup_controller.h"
16 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
(...skipping 30 matching lines...) Expand all
47 } 49 }
48 50
49 void AddThreeNotifications() { 51 void AddThreeNotifications() {
50 scoped_ptr<message_center::Notification> notification; 52 scoped_ptr<message_center::Notification> notification;
51 notification.reset(new message_center::Notification( 53 notification.reset(new message_center::Notification(
52 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 54 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
53 ASCIIToUTF16("This is the first notification to" 55 ASCIIToUTF16("This is the first notification to"
54 " be displayed"), 56 " be displayed"),
55 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 57 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
56 message_center::RichNotificationData(), NULL)); 58 message_center::RichNotificationData(), NULL));
57 center_->AddNotification(notification.Pass()); 59 center_->AddNotification(std::move(notification));
58 60
59 notification.reset(new message_center::Notification( 61 notification.reset(new message_center::Notification(
60 message_center::NOTIFICATION_TYPE_SIMPLE, "2", ASCIIToUTF16("Two"), 62 message_center::NOTIFICATION_TYPE_SIMPLE, "2", ASCIIToUTF16("Two"),
61 ASCIIToUTF16("This is the second notification."), gfx::Image(), 63 ASCIIToUTF16("This is the second notification."), gfx::Image(),
62 base::string16(), GURL(), DummyNotifierId(), 64 base::string16(), GURL(), DummyNotifierId(),
63 message_center::RichNotificationData(), NULL)); 65 message_center::RichNotificationData(), NULL));
64 center_->AddNotification(notification.Pass()); 66 center_->AddNotification(std::move(notification));
65 67
66 notification.reset(new message_center::Notification( 68 notification.reset(new message_center::Notification(
67 message_center::NOTIFICATION_TYPE_SIMPLE, "3", ASCIIToUTF16("Three"), 69 message_center::NOTIFICATION_TYPE_SIMPLE, "3", ASCIIToUTF16("Three"),
68 ASCIIToUTF16("This is the third notification " 70 ASCIIToUTF16("This is the third notification "
69 "that has a much longer body " 71 "that has a much longer body "
70 "than the other notifications. It " 72 "than the other notifications. It "
71 "may not fit on the screen if we " 73 "may not fit on the screen if we "
72 "set the screen size too small or " 74 "set the screen size too small or "
73 "if the notification is way too big"), 75 "if the notification is way too big"),
74 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 76 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
75 message_center::RichNotificationData(), NULL)); 77 message_center::RichNotificationData(), NULL));
76 center_->AddNotification(notification.Pass()); 78 center_->AddNotification(std::move(notification));
77 WaitForAnimationEnded(); 79 WaitForAnimationEnded();
78 } 80 }
79 81
80 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) { 82 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) {
81 CGFloat minY = NSMinY([[upper window] frame]); 83 CGFloat minY = NSMinY([[upper window] frame]);
82 CGFloat maxY = NSMaxY([[lower window] frame]); 84 CGFloat maxY = NSMaxY([[lower window] frame]);
83 CGFloat delta = minY - maxY; 85 CGFloat delta = minY - maxY;
84 EXPECT_EQ(message_center::kMarginBetweenItems, delta); 86 EXPECT_EQ(message_center::kMarginBetweenItems, delta);
85 return delta == message_center::kMarginBetweenItems; 87 return delta == message_center::kMarginBetweenItems;
86 } 88 }
(...skipping 29 matching lines...) Expand all
116 AddThreeNotifications(); 118 AddThreeNotifications();
117 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. 119 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen.
118 120
119 scoped_ptr<message_center::Notification> notification; 121 scoped_ptr<message_center::Notification> notification;
120 122
121 notification.reset(new message_center::Notification( 123 notification.reset(new message_center::Notification(
122 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"), 124 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"),
123 ASCIIToUTF16("This is the fourth notification."), gfx::Image(), 125 ASCIIToUTF16("This is the fourth notification."), gfx::Image(),
124 base::string16(), GURL(), DummyNotifierId(), 126 base::string16(), GURL(), DummyNotifierId(),
125 message_center::RichNotificationData(), NULL)); 127 message_center::RichNotificationData(), NULL));
126 center_->AddNotification(notification.Pass()); 128 center_->AddNotification(std::move(notification));
127 WaitForAnimationEnded(); 129 WaitForAnimationEnded();
128 130
129 // Remove "1" and "3" should fit on screen. 131 // Remove "1" and "3" should fit on screen.
130 center_->RemoveNotification("1", true); 132 center_->RemoveNotification("1", true);
131 WaitForAnimationEnded(); 133 WaitForAnimationEnded();
132 ASSERT_EQ(2u, [[collection_ popups] count]); 134 ASSERT_EQ(2u, [[collection_ popups] count]);
133 135
134 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]); 136 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]);
135 EXPECT_EQ("3", [[[collection_ popups] objectAtIndex:1] notificationID]); 137 EXPECT_EQ("3", [[[collection_ popups] objectAtIndex:1] notificationID]);
136 138
(...skipping 22 matching lines...) Expand all
159 [popups objectAtIndex:2])); 161 [popups objectAtIndex:2]));
160 162
161 // Set priority so that kMaxVisiblePopupNotifications does not hide it. 163 // Set priority so that kMaxVisiblePopupNotifications does not hide it.
162 message_center::RichNotificationData optional; 164 message_center::RichNotificationData optional;
163 optional.priority = message_center::HIGH_PRIORITY; 165 optional.priority = message_center::HIGH_PRIORITY;
164 scoped_ptr<message_center::Notification> notification; 166 scoped_ptr<message_center::Notification> notification;
165 notification.reset(new message_center::Notification( 167 notification.reset(new message_center::Notification(
166 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"), 168 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"),
167 ASCIIToUTF16("This is the fourth notification."), gfx::Image(), 169 ASCIIToUTF16("This is the fourth notification."), gfx::Image(),
168 base::string16(), GURL(), DummyNotifierId(), optional, NULL)); 170 base::string16(), GURL(), DummyNotifierId(), optional, NULL));
169 center_->AddNotification(notification.Pass()); 171 center_->AddNotification(std::move(notification));
170 WaitForAnimationEnded(); 172 WaitForAnimationEnded();
171 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], 173 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2],
172 [popups objectAtIndex:3])); 174 [popups objectAtIndex:3]));
173 175
174 // Remove "2". 176 // Remove "2".
175 center_->RemoveNotification("2", true); 177 center_->RemoveNotification("2", true);
176 WaitForAnimationEnded(); 178 WaitForAnimationEnded();
177 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 179 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
178 [popups objectAtIndex:1])); 180 [popups objectAtIndex:1]));
179 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 181 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
(...skipping 12 matching lines...) Expand all
192 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)]; 194 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)];
193 195
194 EXPECT_EQ(0u, [[collection_ popups] count]); 196 EXPECT_EQ(0u, [[collection_ popups] count]);
195 scoped_ptr<message_center::Notification> notification; 197 scoped_ptr<message_center::Notification> notification;
196 notification.reset(new message_center::Notification( 198 notification.reset(new message_center::Notification(
197 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 199 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
198 ASCIIToUTF16("This is the first notification to" 200 ASCIIToUTF16("This is the first notification to"
199 " be displayed"), 201 " be displayed"),
200 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 202 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
201 message_center::RichNotificationData(), NULL)); 203 message_center::RichNotificationData(), NULL));
202 center_->AddNotification(notification.Pass()); 204 center_->AddNotification(std::move(notification));
203 WaitForAnimationEnded(); 205 WaitForAnimationEnded();
204 EXPECT_EQ(1u, [[collection_ popups] count]); 206 EXPECT_EQ(1u, [[collection_ popups] count]);
205 207
206 // Now give the notification a longer message so that it no longer fits. 208 // Now give the notification a longer message so that it no longer fits.
207 notification.reset(new message_center::Notification( 209 notification.reset(new message_center::Notification(
208 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 210 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
209 ASCIIToUTF16("This is now a very very very very " 211 ASCIIToUTF16("This is now a very very very very "
210 "very very very very very very very " 212 "very very very very very very very "
211 "very very very very very very very " 213 "very very very very very very very "
212 "very very very very very very very " 214 "very very very very very very very "
213 "very very very very very very very " 215 "very very very very very very very "
214 "very very very very very very very " 216 "very very very very very very very "
215 "very very very very very very very " 217 "very very very very very very very "
216 "long notification."), 218 "long notification."),
217 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 219 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
218 message_center::RichNotificationData(), NULL)); 220 message_center::RichNotificationData(), NULL));
219 center_->UpdateNotification("1", notification.Pass()); 221 center_->UpdateNotification("1", std::move(notification));
220 WaitForAnimationEnded(); 222 WaitForAnimationEnded();
221 EXPECT_EQ(0u, [[collection_ popups] count]); 223 EXPECT_EQ(0u, [[collection_ popups] count]);
222 } 224 }
223 225
224 TEST_F(PopupCollectionTest, UpdateIconAndBody) { 226 TEST_F(PopupCollectionTest, UpdateIconAndBody) {
225 AddThreeNotifications(); 227 AddThreeNotifications();
226 NSArray* popups = [collection_ popups]; 228 NSArray* popups = [collection_ popups];
227 229
228 EXPECT_EQ(3u, [popups count]); 230 EXPECT_EQ(3u, [popups count]);
229 231
(...skipping 19 matching lines...) Expand all
249 notification.reset(new message_center::Notification( 251 notification.reset(new message_center::Notification(
250 message_center::NOTIFICATION_TYPE_SIMPLE, "1", 252 message_center::NOTIFICATION_TYPE_SIMPLE, "1",
251 ASCIIToUTF16("One is going to get a much longer " 253 ASCIIToUTF16("One is going to get a much longer "
252 "title than it previously had."), 254 "title than it previously had."),
253 ASCIIToUTF16("This is the first notification to " 255 ASCIIToUTF16("This is the first notification to "
254 "be displayed, but it will also be " 256 "be displayed, but it will also be "
255 "updated to have a significantly " 257 "updated to have a significantly "
256 "longer body"), 258 "longer body"),
257 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 259 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
258 message_center::RichNotificationData(), NULL)); 260 message_center::RichNotificationData(), NULL));
259 center_->AddNotification(notification.Pass()); 261 center_->AddNotification(std::move(notification));
260 WaitForAnimationEnded(); 262 WaitForAnimationEnded();
261 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); 263 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame));
262 264
263 // Test updated spacing. 265 // Test updated spacing.
264 EXPECT_EQ(3u, [popups count]); 266 EXPECT_EQ(3u, [popups count]);
265 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 267 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
266 [popups objectAtIndex:1])); 268 [popups objectAtIndex:1]));
267 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 269 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
268 [popups objectAtIndex:2])); 270 [popups objectAtIndex:2]));
269 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); 271 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]);
270 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); 272 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]);
271 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); 273 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]);
272 } 274 }
273 275
274 TEST_F(PopupCollectionTest, UpdatePriority) { 276 TEST_F(PopupCollectionTest, UpdatePriority) {
275 scoped_ptr<message_center::Notification> notification; 277 scoped_ptr<message_center::Notification> notification;
276 notification.reset(new message_center::Notification( 278 notification.reset(new message_center::Notification(
277 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 279 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
278 ASCIIToUTF16("This notification should not yet toast."), gfx::Image(), 280 ASCIIToUTF16("This notification should not yet toast."), gfx::Image(),
279 base::string16(), GURL(), DummyNotifierId(), 281 base::string16(), GURL(), DummyNotifierId(),
280 message_center::RichNotificationData(), NULL)); 282 message_center::RichNotificationData(), NULL));
281 notification->set_priority(-1); 283 notification->set_priority(-1);
282 284
283 center_->AddNotification(notification.Pass()); 285 center_->AddNotification(std::move(notification));
284 WaitForAnimationEnded(); 286 WaitForAnimationEnded();
285 NSArray* popups = [collection_ popups]; 287 NSArray* popups = [collection_ popups];
286 EXPECT_EQ(0u, [popups count]); 288 EXPECT_EQ(0u, [popups count]);
287 289
288 // Raise priority -1 to 1. Notification should display. 290 // Raise priority -1 to 1. Notification should display.
289 notification.reset(new message_center::Notification( 291 notification.reset(new message_center::Notification(
290 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 292 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
291 ASCIIToUTF16("This notification should now toast"), gfx::Image(), 293 ASCIIToUTF16("This notification should now toast"), gfx::Image(),
292 base::string16(), GURL(), DummyNotifierId(), 294 base::string16(), GURL(), DummyNotifierId(),
293 message_center::RichNotificationData(), NULL)); 295 message_center::RichNotificationData(), NULL));
294 notification->set_priority(1); 296 notification->set_priority(1);
295 297
296 center_->UpdateNotification("1", notification.Pass()); 298 center_->UpdateNotification("1", std::move(notification));
297 WaitForAnimationEnded(); 299 WaitForAnimationEnded();
298 EXPECT_EQ(1u, [popups count]); 300 EXPECT_EQ(1u, [popups count]);
299 } 301 }
300 302
301 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) { 303 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) {
302 // Add a notification and don't wait for the animation to finish. 304 // Add a notification and don't wait for the animation to finish.
303 scoped_ptr<message_center::Notification> notification; 305 scoped_ptr<message_center::Notification> notification;
304 notification.reset(new message_center::Notification( 306 notification.reset(new message_center::Notification(
305 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 307 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
306 ASCIIToUTF16("This is the first notification to" 308 ASCIIToUTF16("This is the first notification to"
307 " be displayed"), 309 " be displayed"),
308 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 310 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
309 message_center::RichNotificationData(), NULL)); 311 message_center::RichNotificationData(), NULL));
310 center_->AddNotification(notification.Pass()); 312 center_->AddNotification(std::move(notification));
311 313
312 // Release the popup collection before the animation ends. No crash should 314 // Release the popup collection before the animation ends. No crash should
313 // be expected. 315 // be expected.
314 collection_.reset(); 316 collection_.reset();
315 } 317 }
316 318
317 TEST_F(PopupCollectionTest, CloseCollectionBeforeClosePopupAnimationEnds) { 319 TEST_F(PopupCollectionTest, CloseCollectionBeforeClosePopupAnimationEnds) {
318 AddThreeNotifications(); 320 AddThreeNotifications();
319 321
320 // Remove a notification and don't wait for the animation to finish. 322 // Remove a notification and don't wait for the animation to finish.
321 center_->RemoveNotification("1", true); 323 center_->RemoveNotification("1", true);
322 324
323 // Release the popup collection before the animation ends. No crash should 325 // Release the popup collection before the animation ends. No crash should
324 // be expected. 326 // be expected.
325 collection_.reset(); 327 collection_.reset();
326 } 328 }
327 329
328 TEST_F(PopupCollectionTest, CloseCollectionBeforeUpdatePopupAnimationEnds) { 330 TEST_F(PopupCollectionTest, CloseCollectionBeforeUpdatePopupAnimationEnds) {
329 AddThreeNotifications(); 331 AddThreeNotifications();
330 332
331 // Update a notification and don't wait for the animation to finish. 333 // Update a notification and don't wait for the animation to finish.
332 scoped_ptr<message_center::Notification> notification; 334 scoped_ptr<message_center::Notification> notification;
333 notification.reset(new message_center::Notification( 335 notification.reset(new message_center::Notification(
334 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 336 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
335 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(), 337 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(),
336 DummyNotifierId(), message_center::RichNotificationData(), NULL)); 338 DummyNotifierId(), message_center::RichNotificationData(), NULL));
337 center_->UpdateNotification("1", notification.Pass()); 339 center_->UpdateNotification("1", std::move(notification));
338 340
339 // Release the popup collection before the animation ends. No crash should 341 // Release the popup collection before the animation ends. No crash should
340 // be expected. 342 // be expected.
341 collection_.reset(); 343 collection_.reset();
342 } 344 }
343 345
344 } // namespace message_center 346 } // namespace message_center
OLDNEW
« no previous file with comments | « sandbox/mac/bootstrap_sandbox.cc ('k') | ui/views/widget/native_widget_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698