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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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
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 <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #import "ui/gfx/test/ui_cocoa_test_helper.h" 15 #import "ui/gfx/test/ui_cocoa_test_helper.h"
16 #import "ui/message_center/cocoa/notification_controller.h" 16 #import "ui/message_center/cocoa/notification_controller.h"
17 #import "ui/message_center/cocoa/popup_controller.h" 17 #import "ui/message_center/cocoa/popup_controller.h"
18 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/message_center_style.h" 19 #include "ui/message_center/message_center_style.h"
20 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
(...skipping 21 matching lines...) Expand all
42 ui::CocoaTest::TearDown(); 42 ui::CocoaTest::TearDown();
43 } 43 }
44 44
45 ~PopupCollectionTest() override { message_center::MessageCenter::Shutdown(); } 45 ~PopupCollectionTest() override { message_center::MessageCenter::Shutdown(); }
46 46
47 message_center::NotifierId DummyNotifierId() { 47 message_center::NotifierId DummyNotifierId() {
48 return message_center::NotifierId(); 48 return message_center::NotifierId();
49 } 49 }
50 50
51 void AddThreeNotifications() { 51 void AddThreeNotifications() {
52 scoped_ptr<message_center::Notification> notification; 52 std::unique_ptr<message_center::Notification> notification;
53 notification.reset(new message_center::Notification( 53 notification.reset(new message_center::Notification(
54 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 54 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
55 ASCIIToUTF16("This is the first notification to" 55 ASCIIToUTF16("This is the first notification to"
56 " be displayed"), 56 " be displayed"),
57 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 57 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
58 message_center::RichNotificationData(), NULL)); 58 message_center::RichNotificationData(), NULL));
59 center_->AddNotification(std::move(notification)); 59 center_->AddNotification(std::move(notification));
60 60
61 notification.reset(new message_center::Notification( 61 notification.reset(new message_center::Notification(
62 message_center::NOTIFICATION_TYPE_SIMPLE, "2", ASCIIToUTF16("Two"), 62 message_center::NOTIFICATION_TYPE_SIMPLE, "2", ASCIIToUTF16("Two"),
(...skipping 26 matching lines...) Expand all
89 89
90 void WaitForAnimationEnded() { 90 void WaitForAnimationEnded() {
91 if (![collection_ isAnimating]) 91 if (![collection_ isAnimating])
92 return; 92 return;
93 nested_run_loop_.reset(new base::RunLoop()); 93 nested_run_loop_.reset(new base::RunLoop());
94 nested_run_loop_->Run(); 94 nested_run_loop_->Run();
95 nested_run_loop_.reset(); 95 nested_run_loop_.reset();
96 } 96 }
97 97
98 base::MessageLoopForUI message_loop_; 98 base::MessageLoopForUI message_loop_;
99 scoped_ptr<base::RunLoop> nested_run_loop_; 99 std::unique_ptr<base::RunLoop> nested_run_loop_;
100 message_center::MessageCenter* center_; 100 message_center::MessageCenter* center_;
101 base::scoped_nsobject<MCPopupCollection> collection_; 101 base::scoped_nsobject<MCPopupCollection> collection_;
102 }; 102 };
103 103
104 TEST_F(PopupCollectionTest, AddThreeCloseOne) { 104 TEST_F(PopupCollectionTest, AddThreeCloseOne) {
105 EXPECT_EQ(0u, [[collection_ popups] count]); 105 EXPECT_EQ(0u, [[collection_ popups] count]);
106 AddThreeNotifications(); 106 AddThreeNotifications();
107 EXPECT_EQ(3u, [[collection_ popups] count]); 107 EXPECT_EQ(3u, [[collection_ popups] count]);
108 108
109 center_->RemoveNotification("2", true); 109 center_->RemoveNotification("2", true);
110 WaitForAnimationEnded(); 110 WaitForAnimationEnded();
111 EXPECT_EQ(2u, [[collection_ popups] count]); 111 EXPECT_EQ(2u, [[collection_ popups] count]);
112 } 112 }
113 113
114 TEST_F(PopupCollectionTest, AttemptFourOneOffscreen) { 114 TEST_F(PopupCollectionTest, AttemptFourOneOffscreen) {
115 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 300)]; 115 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 300)];
116 116
117 EXPECT_EQ(0u, [[collection_ popups] count]); 117 EXPECT_EQ(0u, [[collection_ popups] count]);
118 AddThreeNotifications(); 118 AddThreeNotifications();
119 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.
120 120
121 scoped_ptr<message_center::Notification> notification; 121 std::unique_ptr<message_center::Notification> notification;
122 122
123 notification.reset(new message_center::Notification( 123 notification.reset(new message_center::Notification(
124 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"), 124 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"),
125 ASCIIToUTF16("This is the fourth notification."), gfx::Image(), 125 ASCIIToUTF16("This is the fourth notification."), gfx::Image(),
126 base::string16(), GURL(), DummyNotifierId(), 126 base::string16(), GURL(), DummyNotifierId(),
127 message_center::RichNotificationData(), NULL)); 127 message_center::RichNotificationData(), NULL));
128 center_->AddNotification(std::move(notification)); 128 center_->AddNotification(std::move(notification));
129 WaitForAnimationEnded(); 129 WaitForAnimationEnded();
130 130
131 // Remove "1" and "3" should fit on screen. 131 // Remove "1" and "3" should fit on screen.
(...skipping 24 matching lines...) Expand all
156 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame])); 156 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame]));
157 157
158 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 158 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
159 [popups objectAtIndex:1])); 159 [popups objectAtIndex:1]));
160 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 160 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
161 [popups objectAtIndex:2])); 161 [popups objectAtIndex:2]));
162 162
163 // Set priority so that kMaxVisiblePopupNotifications does not hide it. 163 // Set priority so that kMaxVisiblePopupNotifications does not hide it.
164 message_center::RichNotificationData optional; 164 message_center::RichNotificationData optional;
165 optional.priority = message_center::HIGH_PRIORITY; 165 optional.priority = message_center::HIGH_PRIORITY;
166 scoped_ptr<message_center::Notification> notification; 166 std::unique_ptr<message_center::Notification> notification;
167 notification.reset(new message_center::Notification( 167 notification.reset(new message_center::Notification(
168 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"), 168 message_center::NOTIFICATION_TYPE_SIMPLE, "4", ASCIIToUTF16("Four"),
169 ASCIIToUTF16("This is the fourth notification."), gfx::Image(), 169 ASCIIToUTF16("This is the fourth notification."), gfx::Image(),
170 base::string16(), GURL(), DummyNotifierId(), optional, NULL)); 170 base::string16(), GURL(), DummyNotifierId(), optional, NULL));
171 center_->AddNotification(std::move(notification)); 171 center_->AddNotification(std::move(notification));
172 WaitForAnimationEnded(); 172 WaitForAnimationEnded();
173 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], 173 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2],
174 [popups objectAtIndex:3])); 174 [popups objectAtIndex:3]));
175 175
176 // Remove "2". 176 // Remove "2".
(...skipping 10 matching lines...) Expand all
187 EXPECT_EQ(message_center::kMarginBetweenItems, 187 EXPECT_EQ(message_center::kMarginBetweenItems,
188 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame])); 188 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame]));
189 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 189 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
190 [popups objectAtIndex:1])); 190 [popups objectAtIndex:1]));
191 } 191 }
192 192
193 TEST_F(PopupCollectionTest, TinyScreen) { 193 TEST_F(PopupCollectionTest, TinyScreen) {
194 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)]; 194 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)];
195 195
196 EXPECT_EQ(0u, [[collection_ popups] count]); 196 EXPECT_EQ(0u, [[collection_ popups] count]);
197 scoped_ptr<message_center::Notification> notification; 197 std::unique_ptr<message_center::Notification> notification;
198 notification.reset(new message_center::Notification( 198 notification.reset(new message_center::Notification(
199 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 199 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
200 ASCIIToUTF16("This is the first notification to" 200 ASCIIToUTF16("This is the first notification to"
201 " be displayed"), 201 " be displayed"),
202 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 202 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
203 message_center::RichNotificationData(), NULL)); 203 message_center::RichNotificationData(), NULL));
204 center_->AddNotification(std::move(notification)); 204 center_->AddNotification(std::move(notification));
205 WaitForAnimationEnded(); 205 WaitForAnimationEnded();
206 EXPECT_EQ(1u, [[collection_ popups] count]); 206 EXPECT_EQ(1u, [[collection_ popups] count]);
207 207
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 EXPECT_EQ(3u, [popups count]); 241 EXPECT_EQ(3u, [popups count]);
242 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 242 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
243 [popups objectAtIndex:1])); 243 [popups objectAtIndex:1]));
244 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 244 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
245 [popups objectAtIndex:2])); 245 [popups objectAtIndex:2]));
246 246
247 // Replace "1". 247 // Replace "1".
248 controller = [[popups objectAtIndex:0] notificationController]; 248 controller = [[popups objectAtIndex:0] notificationController];
249 NSRect old_frame = [[controller view] frame]; 249 NSRect old_frame = [[controller view] frame];
250 scoped_ptr<message_center::Notification> notification; 250 std::unique_ptr<message_center::Notification> notification;
251 notification.reset(new message_center::Notification( 251 notification.reset(new message_center::Notification(
252 message_center::NOTIFICATION_TYPE_SIMPLE, "1", 252 message_center::NOTIFICATION_TYPE_SIMPLE, "1",
253 ASCIIToUTF16("One is going to get a much longer " 253 ASCIIToUTF16("One is going to get a much longer "
254 "title than it previously had."), 254 "title than it previously had."),
255 ASCIIToUTF16("This is the first notification to " 255 ASCIIToUTF16("This is the first notification to "
256 "be displayed, but it will also be " 256 "be displayed, but it will also be "
257 "updated to have a significantly " 257 "updated to have a significantly "
258 "longer body"), 258 "longer body"),
259 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 259 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
260 message_center::RichNotificationData(), NULL)); 260 message_center::RichNotificationData(), NULL));
261 center_->AddNotification(std::move(notification)); 261 center_->AddNotification(std::move(notification));
262 WaitForAnimationEnded(); 262 WaitForAnimationEnded();
263 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); 263 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame));
264 264
265 // Test updated spacing. 265 // Test updated spacing.
266 EXPECT_EQ(3u, [popups count]); 266 EXPECT_EQ(3u, [popups count]);
267 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 267 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
268 [popups objectAtIndex:1])); 268 [popups objectAtIndex:1]));
269 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 269 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
270 [popups objectAtIndex:2])); 270 [popups objectAtIndex:2]));
271 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); 271 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]);
272 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); 272 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]);
273 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); 273 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]);
274 } 274 }
275 275
276 TEST_F(PopupCollectionTest, UpdatePriority) { 276 TEST_F(PopupCollectionTest, UpdatePriority) {
277 scoped_ptr<message_center::Notification> notification; 277 std::unique_ptr<message_center::Notification> notification;
278 notification.reset(new message_center::Notification( 278 notification.reset(new message_center::Notification(
279 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 279 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
280 ASCIIToUTF16("This notification should not yet toast."), gfx::Image(), 280 ASCIIToUTF16("This notification should not yet toast."), gfx::Image(),
281 base::string16(), GURL(), DummyNotifierId(), 281 base::string16(), GURL(), DummyNotifierId(),
282 message_center::RichNotificationData(), NULL)); 282 message_center::RichNotificationData(), NULL));
283 notification->set_priority(-1); 283 notification->set_priority(-1);
284 284
285 center_->AddNotification(std::move(notification)); 285 center_->AddNotification(std::move(notification));
286 WaitForAnimationEnded(); 286 WaitForAnimationEnded();
287 NSArray* popups = [collection_ popups]; 287 NSArray* popups = [collection_ popups];
288 EXPECT_EQ(0u, [popups count]); 288 EXPECT_EQ(0u, [popups count]);
289 289
290 // Raise priority -1 to 1. Notification should display. 290 // Raise priority -1 to 1. Notification should display.
291 notification.reset(new message_center::Notification( 291 notification.reset(new message_center::Notification(
292 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 292 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
293 ASCIIToUTF16("This notification should now toast"), gfx::Image(), 293 ASCIIToUTF16("This notification should now toast"), gfx::Image(),
294 base::string16(), GURL(), DummyNotifierId(), 294 base::string16(), GURL(), DummyNotifierId(),
295 message_center::RichNotificationData(), NULL)); 295 message_center::RichNotificationData(), NULL));
296 notification->set_priority(1); 296 notification->set_priority(1);
297 297
298 center_->UpdateNotification("1", std::move(notification)); 298 center_->UpdateNotification("1", std::move(notification));
299 WaitForAnimationEnded(); 299 WaitForAnimationEnded();
300 EXPECT_EQ(1u, [popups count]); 300 EXPECT_EQ(1u, [popups count]);
301 } 301 }
302 302
303 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) { 303 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) {
304 // 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.
305 scoped_ptr<message_center::Notification> notification; 305 std::unique_ptr<message_center::Notification> notification;
306 notification.reset(new message_center::Notification( 306 notification.reset(new message_center::Notification(
307 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 307 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
308 ASCIIToUTF16("This is the first notification to" 308 ASCIIToUTF16("This is the first notification to"
309 " be displayed"), 309 " be displayed"),
310 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), 310 gfx::Image(), base::string16(), GURL(), DummyNotifierId(),
311 message_center::RichNotificationData(), NULL)); 311 message_center::RichNotificationData(), NULL));
312 center_->AddNotification(std::move(notification)); 312 center_->AddNotification(std::move(notification));
313 313
314 // Release the popup collection before the animation ends. No crash should 314 // Release the popup collection before the animation ends. No crash should
315 // be expected. 315 // be expected.
316 collection_.reset(); 316 collection_.reset();
317 } 317 }
318 318
319 TEST_F(PopupCollectionTest, CloseCollectionBeforeClosePopupAnimationEnds) { 319 TEST_F(PopupCollectionTest, CloseCollectionBeforeClosePopupAnimationEnds) {
320 AddThreeNotifications(); 320 AddThreeNotifications();
321 321
322 // 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.
323 center_->RemoveNotification("1", true); 323 center_->RemoveNotification("1", true);
324 324
325 // Release the popup collection before the animation ends. No crash should 325 // Release the popup collection before the animation ends. No crash should
326 // be expected. 326 // be expected.
327 collection_.reset(); 327 collection_.reset();
328 } 328 }
329 329
330 TEST_F(PopupCollectionTest, CloseCollectionBeforeUpdatePopupAnimationEnds) { 330 TEST_F(PopupCollectionTest, CloseCollectionBeforeUpdatePopupAnimationEnds) {
331 AddThreeNotifications(); 331 AddThreeNotifications();
332 332
333 // 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.
334 scoped_ptr<message_center::Notification> notification; 334 std::unique_ptr<message_center::Notification> notification;
335 notification.reset(new message_center::Notification( 335 notification.reset(new message_center::Notification(
336 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"), 336 message_center::NOTIFICATION_TYPE_SIMPLE, "1", ASCIIToUTF16("One"),
337 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(), 337 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(),
338 DummyNotifierId(), message_center::RichNotificationData(), NULL)); 338 DummyNotifierId(), message_center::RichNotificationData(), NULL));
339 center_->UpdateNotification("1", std::move(notification)); 339 center_->UpdateNotification("1", std::move(notification));
340 340
341 // Release the popup collection before the animation ends. No crash should 341 // Release the popup collection before the animation ends. No crash should
342 // be expected. 342 // be expected.
343 collection_.reset(); 343 collection_.reset();
344 } 344 }
345 345
346 } // namespace message_center 346 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/cocoa/popup_collection.h ('k') | ui/message_center/cocoa/popup_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698