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

Side by Side Diff: ui/message_center/message_center_tray_unittest.cc

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
« no previous file with comments | « ui/message_center/message_center_tray.cc ('k') | ui/message_center/notification.h » ('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 #include "ui/message_center/message_center_tray.h" 5 #include "ui/message_center/message_center_tray.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 void AddNotification(const std::string& id) { 74 void AddNotification(const std::string& id) {
75 AddNotification(id, DummyNotifierId()); 75 AddNotification(id, DummyNotifierId());
76 } 76 }
77 77
78 void EnableChangeQueue(bool enabled) { 78 void EnableChangeQueue(bool enabled) {
79 message_center_->EnableChangeQueueForTest(enabled); 79 message_center_->EnableChangeQueueForTest(enabled);
80 } 80 }
81 81
82 void AddNotification(const std::string& id, NotifierId notifier_id) { 82 void AddNotification(const std::string& id, NotifierId notifier_id) {
83 scoped_ptr<Notification> notification(new Notification( 83 std::unique_ptr<Notification> notification(new Notification(
84 message_center::NOTIFICATION_TYPE_SIMPLE, id, 84 message_center::NOTIFICATION_TYPE_SIMPLE, id,
85 ASCIIToUTF16("Test Web Notification"), 85 ASCIIToUTF16("Test Web Notification"),
86 ASCIIToUTF16("Notification message body."), gfx::Image(), 86 ASCIIToUTF16("Notification message body."), gfx::Image(),
87 ASCIIToUTF16("www.test.org"), GURL(), notifier_id, 87 ASCIIToUTF16("www.test.org"), GURL(), notifier_id,
88 message_center::RichNotificationData(), NULL /* delegate */)); 88 message_center::RichNotificationData(), NULL /* delegate */));
89 message_center_->AddNotification(std::move(notification)); 89 message_center_->AddNotification(std::move(notification));
90 } 90 }
91 scoped_ptr<MockDelegate> delegate_; 91 std::unique_ptr<MockDelegate> delegate_;
92 scoped_ptr<MessageCenterTray> message_center_tray_; 92 std::unique_ptr<MessageCenterTray> message_center_tray_;
93 MessageCenter* message_center_; 93 MessageCenter* message_center_;
94 94
95 private: 95 private:
96 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest); 96 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest);
97 }; 97 };
98 98
99 TEST_F(MessageCenterTrayTest, BasicMessageCenter) { 99 TEST_F(MessageCenterTrayTest, BasicMessageCenter) {
100 ASSERT_FALSE(message_center_tray_->popups_visible()); 100 ASSERT_FALSE(message_center_tray_->popups_visible());
101 ASSERT_FALSE(message_center_tray_->message_center_visible()); 101 ASSERT_FALSE(message_center_tray_->message_center_visible());
102 102
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 message_center_tray_->ShowMessageCenterBubble(); 214 message_center_tray_->ShowMessageCenterBubble();
215 message_center_tray_->HideMessageCenterBubble(); 215 message_center_tray_->HideMessageCenterBubble();
216 ASSERT_FALSE(message_center_tray_->popups_visible()); 216 ASSERT_FALSE(message_center_tray_->popups_visible());
217 ASSERT_FALSE(message_center_tray_->message_center_visible()); 217 ASSERT_FALSE(message_center_tray_->message_center_visible());
218 } 218 }
219 219
220 TEST_F(MessageCenterTrayTest, MessageCenterReopenPopupsForSystemPriority) { 220 TEST_F(MessageCenterTrayTest, MessageCenterReopenPopupsForSystemPriority) {
221 ASSERT_FALSE(message_center_tray_->popups_visible()); 221 ASSERT_FALSE(message_center_tray_->popups_visible());
222 ASSERT_FALSE(message_center_tray_->message_center_visible()); 222 ASSERT_FALSE(message_center_tray_->message_center_visible());
223 223
224 scoped_ptr<Notification> notification(new Notification( 224 std::unique_ptr<Notification> notification(new Notification(
225 message_center::NOTIFICATION_TYPE_SIMPLE, 225 message_center::NOTIFICATION_TYPE_SIMPLE,
226 "MessageCenterReopnPopupsForSystemPriority", 226 "MessageCenterReopnPopupsForSystemPriority",
227 ASCIIToUTF16("Test Web Notification"), 227 ASCIIToUTF16("Test Web Notification"),
228 ASCIIToUTF16("Notification message body."), gfx::Image(), 228 ASCIIToUTF16("Notification message body."), gfx::Image(),
229 ASCIIToUTF16("www.test.org"), GURL(), DummyNotifierId(), 229 ASCIIToUTF16("www.test.org"), GURL(), DummyNotifierId(),
230 message_center::RichNotificationData(), NULL /* delegate */)); 230 message_center::RichNotificationData(), NULL /* delegate */));
231 notification->SetSystemPriority(); 231 notification->SetSystemPriority();
232 message_center_->AddNotification(std::move(notification)); 232 message_center_->AddNotification(std::move(notification));
233 233
234 ASSERT_TRUE(message_center_tray_->popups_visible()); 234 ASSERT_TRUE(message_center_tray_->popups_visible());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 TEST_F(MessageCenterTrayTest, ContextMenuTestWithMessageCenter) { 287 TEST_F(MessageCenterTrayTest, ContextMenuTestWithMessageCenter) {
288 const std::string id1 = "id1"; 288 const std::string id1 = "id1";
289 const std::string id2 = "id2"; 289 const std::string id2 = "id2";
290 const std::string id3 = "id3"; 290 const std::string id3 = "id3";
291 AddNotification(id1); 291 AddNotification(id1);
292 292
293 base::string16 display_source = ASCIIToUTF16("www.test.org"); 293 base::string16 display_source = ASCIIToUTF16("www.test.org");
294 NotifierId notifier_id = DummyNotifierId(); 294 NotifierId notifier_id = DummyNotifierId();
295 295
296 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app"); 296 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app");
297 scoped_ptr<Notification> notification(new Notification( 297 std::unique_ptr<Notification> notification(new Notification(
298 message_center::NOTIFICATION_TYPE_SIMPLE, id2, 298 message_center::NOTIFICATION_TYPE_SIMPLE, id2,
299 ASCIIToUTF16("Test Web Notification"), 299 ASCIIToUTF16("Test Web Notification"),
300 ASCIIToUTF16("Notification message body."), gfx::Image(), 300 ASCIIToUTF16("Notification message body."), gfx::Image(),
301 base::string16() /* empty display source */, GURL(), notifier_id2, 301 base::string16() /* empty display source */, GURL(), notifier_id2,
302 message_center::RichNotificationData(), NULL /* delegate */)); 302 message_center::RichNotificationData(), NULL /* delegate */));
303 message_center_->AddNotification(std::move(notification)); 303 message_center_->AddNotification(std::move(notification));
304 304
305 AddNotification(id3); 305 AddNotification(id3);
306 306
307 scoped_ptr<ui::MenuModel> model( 307 std::unique_ptr<ui::MenuModel> model(
308 message_center_tray_->CreateNotificationMenuModel( 308 message_center_tray_->CreateNotificationMenuModel(notifier_id,
309 notifier_id, display_source)); 309 display_source));
310 EXPECT_EQ(2, model->GetItemCount()); 310 EXPECT_EQ(2, model->GetItemCount());
311 const int second_command = model->GetCommandIdAt(1); 311 const int second_command = model->GetCommandIdAt(1);
312 312
313 // The second item is to open the settings. 313 // The second item is to open the settings.
314 EXPECT_TRUE(model->IsEnabledAt(0)); 314 EXPECT_TRUE(model->IsEnabledAt(0));
315 EXPECT_TRUE(model->IsEnabledAt(1)); 315 EXPECT_TRUE(model->IsEnabledAt(1));
316 model->ActivatedAt(1); 316 model->ActivatedAt(1);
317 EXPECT_TRUE(message_center_tray_->message_center_visible()); 317 EXPECT_TRUE(message_center_tray_->message_center_visible());
318 318
319 message_center_tray_->HideMessageCenterBubble(); 319 message_center_tray_->HideMessageCenterBubble();
(...skipping 25 matching lines...) Expand all
345 const std::string id1 = "id1"; 345 const std::string id1 = "id1";
346 const std::string id2 = "id2"; 346 const std::string id2 = "id2";
347 const std::string id3 = "id3"; 347 const std::string id3 = "id3";
348 348
349 base::string16 display_source = ASCIIToUTF16("https://www.test.org"); 349 base::string16 display_source = ASCIIToUTF16("https://www.test.org");
350 NotifierId notifier_id(GURL("https://www.test.org")); 350 NotifierId notifier_id(GURL("https://www.test.org"));
351 351
352 AddNotification(id1, notifier_id); 352 AddNotification(id1, notifier_id);
353 353
354 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app"); 354 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app");
355 scoped_ptr<Notification> notification(new Notification( 355 std::unique_ptr<Notification> notification(new Notification(
356 message_center::NOTIFICATION_TYPE_SIMPLE, id2, 356 message_center::NOTIFICATION_TYPE_SIMPLE, id2,
357 ASCIIToUTF16("Test Web Notification"), 357 ASCIIToUTF16("Test Web Notification"),
358 ASCIIToUTF16("Notification message body."), gfx::Image(), 358 ASCIIToUTF16("Notification message body."), gfx::Image(),
359 base::string16() /* empty display source */, GURL(), notifier_id2, 359 base::string16() /* empty display source */, GURL(), notifier_id2,
360 message_center::RichNotificationData(), NULL /* delegate */)); 360 message_center::RichNotificationData(), NULL /* delegate */));
361 message_center_->AddNotification(std::move(notification)); 361 message_center_->AddNotification(std::move(notification));
362 362
363 AddNotification(id3, notifier_id); 363 AddNotification(id3, notifier_id);
364 364
365 // The dummy notifier is SYSTEM_COMPONENT so no context menu is visible. 365 // The dummy notifier is SYSTEM_COMPONENT so no context menu is visible.
366 scoped_ptr<ui::MenuModel> model( 366 std::unique_ptr<ui::MenuModel> model(
367 message_center_tray_->CreateNotificationMenuModel(DummyNotifierId(), 367 message_center_tray_->CreateNotificationMenuModel(DummyNotifierId(),
368 display_source)); 368 display_source));
369 EXPECT_EQ(nullptr, model.get()); 369 EXPECT_EQ(nullptr, model.get());
370 370
371 model = message_center_tray_->CreateNotificationMenuModel(notifier_id, 371 model = message_center_tray_->CreateNotificationMenuModel(notifier_id,
372 display_source); 372 display_source);
373 EXPECT_EQ(1, model->GetItemCount()); 373 EXPECT_EQ(1, model->GetItemCount());
374 374
375 // The first item is to disable notifications from the notifier id. It also 375 // The first item is to disable notifications from the notifier id. It also
376 // removes all notifications from the same notifier, i.e. id1 and id3. 376 // removes all notifications from the same notifier, i.e. id1 and id3.
(...skipping 17 matching lines...) Expand all
394 394
395 TEST_F(MessageCenterTrayTest, DelegateDisabledContextMenu) { 395 TEST_F(MessageCenterTrayTest, DelegateDisabledContextMenu) {
396 const std::string id1 = "id1"; 396 const std::string id1 = "id1";
397 base::string16 display_source = ASCIIToUTF16("www.test.org"); 397 base::string16 display_source = ASCIIToUTF16("www.test.org");
398 AddNotification(id1); 398 AddNotification(id1);
399 NotifierId notifier_id(GURL("www.test.org")); 399 NotifierId notifier_id(GURL("www.test.org"));
400 400
401 delegate_->enable_context_menu_ = false; 401 delegate_->enable_context_menu_ = false;
402 // id2 doesn't have the display source, so it don't have the menu item for 402 // id2 doesn't have the display source, so it don't have the menu item for
403 // disabling notifications. 403 // disabling notifications.
404 scoped_ptr<ui::MenuModel> model( 404 std::unique_ptr<ui::MenuModel> model(
405 message_center_tray_->CreateNotificationMenuModel(notifier_id, 405 message_center_tray_->CreateNotificationMenuModel(notifier_id,
406 display_source)); 406 display_source));
407 407
408 // The commands are disabled because delegate disables context menu. 408 // The commands are disabled because delegate disables context menu.
409 #ifndef OS_CHROMEOS 409 #ifndef OS_CHROMEOS
410 EXPECT_EQ(1, model->GetItemCount()); 410 EXPECT_EQ(1, model->GetItemCount());
411 #else 411 #else
412 EXPECT_EQ(2, model->GetItemCount()); 412 EXPECT_EQ(2, model->GetItemCount());
413 EXPECT_FALSE(model->IsEnabledAt(1)); 413 EXPECT_FALSE(model->IsEnabledAt(1));
414 #endif 414 #endif
415 415
416 EXPECT_FALSE(model->IsEnabledAt(0)); 416 EXPECT_FALSE(model->IsEnabledAt(0));
417 } 417 }
418 418
419 } // namespace message_center 419 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_tray.cc ('k') | ui/message_center/notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698