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

Side by Side Diff: ui/message_center/views/message_center_view_unittest.cc

Issue 2478843003: Remove stl_util's deletion function use from message_center views. (Closed)
Patch Set: almost Created 4 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/views/message_center_view.h" 5 #include "ui/message_center/views/message_center_view.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/message_center/fake_message_center.h" 17 #include "ui/message_center/fake_message_center.h"
17 #include "ui/message_center/message_center_style.h" 18 #include "ui/message_center/message_center_style.h"
18 #include "ui/message_center/notification.h" 19 #include "ui/message_center/notification.h"
19 #include "ui/message_center/notification_list.h" 20 #include "ui/message_center/notification_list.h"
20 #include "ui/message_center/notification_types.h" 21 #include "ui/message_center/notification_types.h"
21 #include "ui/message_center/views/message_center_button_bar.h" 22 #include "ui/message_center/views/message_center_button_bar.h"
22 #include "ui/message_center/views/message_center_controller.h" 23 #include "ui/message_center/views/message_center_controller.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 bool locked_ = false; 115 bool locked_ = false;
115 }; 116 };
116 117
117 /* Test fixture ***************************************************************/ 118 /* Test fixture ***************************************************************/
118 119
119 class MessageCenterViewTest : public views::ViewsTestBase, 120 class MessageCenterViewTest : public views::ViewsTestBase,
120 public MockNotificationView::Test, 121 public MockNotificationView::Test,
121 public MessageCenterController { 122 public MessageCenterController {
122 public: 123 public:
123 // Expose the private enum class MessageCenter::Mode for this test. 124 // Expose the private enum class MessageCenter::Mode for this test.
124 typedef MessageCenterView::Mode Mode; 125 using Mode = MessageCenterView::Mode;
125 126
126 MessageCenterViewTest(); 127 MessageCenterViewTest();
127 ~MessageCenterViewTest() override; 128 ~MessageCenterViewTest() override;
128 129
129 void SetUp() override; 130 void SetUp() override;
130 void TearDown() override; 131 void TearDown() override;
131 132
133 NotificationList::Notifications Notifications();
132 MessageCenterView* GetMessageCenterView(); 134 MessageCenterView* GetMessageCenterView();
133 MessageListView* GetMessageListView(); 135 MessageListView* GetMessageListView();
134 FakeMessageCenterImpl* GetMessageCenter() const; 136 FakeMessageCenterImpl* GetMessageCenter() const;
135 MessageView* GetNotificationView(const std::string& id); 137 MessageView* GetNotificationView(const std::string& id);
136 views::BoundsAnimator* GetAnimator(); 138 views::BoundsAnimator* GetAnimator();
137 int GetNotificationCount(); 139 int GetNotificationCount();
138 int GetCallCount(CallType type); 140 int GetCallCount(CallType type);
139 int GetCalculatedMessageListViewHeight(); 141 int GetCalculatedMessageListViewHeight();
140 void SetLockedState(bool locked); 142 void SetLockedState(bool locked);
141 Mode GetMessageCenterViewInternalMode(); 143 Mode GetMessageCenterViewInternalMode();
(...skipping 20 matching lines...) Expand all
162 164
163 void LogBounds(int depth, views::View* view); 165 void LogBounds(int depth, views::View* view);
164 166
165 MessageCenterButtonBar* GetButtonBar() const; 167 MessageCenterButtonBar* GetButtonBar() const;
166 168
167 void RemoveDefaultNotifications(); 169 void RemoveDefaultNotifications();
168 170
169 private: 171 private:
170 views::View* MakeParent(views::View* child1, views::View* child2); 172 views::View* MakeParent(views::View* child1, views::View* child2);
171 173
172 NotificationList::Notifications notifications_; 174 // The ownership map of notifications; the key is the id.
175 std::map<std::string, std::unique_ptr<Notification>> notifications_;
173 std::unique_ptr<views::Widget> widget_; 176 std::unique_ptr<views::Widget> widget_;
174 std::unique_ptr<MessageCenterView> message_center_view_; 177 std::unique_ptr<MessageCenterView> message_center_view_;
175 std::unique_ptr<FakeMessageCenterImpl> message_center_; 178 std::unique_ptr<FakeMessageCenterImpl> message_center_;
176 std::map<CallType,int> callCounts_; 179 std::map<CallType,int> callCounts_;
177 180
178 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); 181 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest);
179 }; 182 };
180 183
181 MessageCenterViewTest::MessageCenterViewTest() { 184 MessageCenterViewTest::MessageCenterViewTest() {
182 } 185 }
183 186
184 MessageCenterViewTest::~MessageCenterViewTest() { 187 MessageCenterViewTest::~MessageCenterViewTest() {
185 } 188 }
186 189
187 void MessageCenterViewTest::SetUp() { 190 void MessageCenterViewTest::SetUp() {
188 views::ViewsTestBase::SetUp(); 191 views::ViewsTestBase::SetUp();
189 MessageCenterView::disable_animation_for_testing = true; 192 MessageCenterView::disable_animation_for_testing = true;
190 message_center_.reset(new FakeMessageCenterImpl()); 193 message_center_.reset(new FakeMessageCenterImpl());
191 194
192 // Create a dummy notification. 195 // Create a dummy notification.
193 Notification* notification1 = new Notification( 196 std::unique_ptr<Notification> notification1 = base::MakeUnique<Notification>(
194 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), 197 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
195 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(), 198 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(),
196 base::UTF8ToUTF16("display source"), GURL(), 199 base::UTF8ToUTF16("display source"), GURL(),
197 NotifierId(NotifierId::APPLICATION, "extension_id"), 200 NotifierId(NotifierId::APPLICATION, "extension_id"),
198 message_center::RichNotificationData(), NULL); 201 message_center::RichNotificationData(), nullptr);
199 202
200 Notification* notification2 = new Notification( 203 std::unique_ptr<Notification> notification2 = base::MakeUnique<Notification>(
201 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), 204 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
202 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(), 205 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(),
203 base::UTF8ToUTF16("display source"), GURL(), 206 base::UTF8ToUTF16("display source"), GURL(),
204 NotifierId(NotifierId::APPLICATION, "extension_id"), 207 NotifierId(NotifierId::APPLICATION, "extension_id"),
205 message_center::RichNotificationData(), NULL); 208 message_center::RichNotificationData(), nullptr);
206 209
207 // ...and a list for it. 210 // ...and a list for it.
208 notifications_.insert(notification1); 211 notifications_[std::string(kNotificationId1)] = std::move(notification1);
209 notifications_.insert(notification2); 212 notifications_[std::string(kNotificationId2)] = std::move(notification2);
210 message_center_->SetVisibleNotifications(notifications_); 213 NotificationList::Notifications notifications = Notifications();
214 message_center_->SetVisibleNotifications(notifications);
211 215
212 // Then create a new MessageCenterView with that single notification. 216 // Then create a new MessageCenterView with that single notification.
213 message_center_view_.reset(new MessageCenterView( 217 message_center_view_.reset(new MessageCenterView(
214 message_center_.get(), NULL, 100, false, /*top_down =*/false)); 218 message_center_.get(), NULL, 100, false, /*top_down =*/false));
215 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; 219 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true;
216 GetMessageCenterView()->SetBounds(0, 0, 380, 600); 220 GetMessageCenterView()->SetBounds(0, 0, 380, 600);
217 message_center_view_->SetNotifications(notifications_); 221 message_center_view_->SetNotifications(notifications);
218 message_center_view_->set_owned_by_client(); 222 message_center_view_->set_owned_by_client();
219 223
220 widget_.reset(new views::Widget()); 224 widget_.reset(new views::Widget());
221 views::Widget::InitParams params = 225 views::Widget::InitParams params =
222 CreateParams(views::Widget::InitParams::TYPE_POPUP); 226 CreateParams(views::Widget::InitParams::TYPE_POPUP);
223 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 227 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
224 params.bounds = gfx::Rect(50, 50, 650, 650); 228 params.bounds = gfx::Rect(50, 50, 650, 650);
225 widget_->Init(params); 229 widget_->Init(params);
226 views::View* root = widget_->GetRootView(); 230 views::View* root = widget_->GetRootView();
227 root->AddChildView(message_center_view_.get()); 231 root->AddChildView(message_center_view_.get());
228 widget_->Show(); 232 widget_->Show();
229 widget_->Activate(); 233 widget_->Activate();
230 234
231 // Wait until the animation finishes if available. 235 // Wait until the animation finishes if available.
232 if (GetAnimator()->IsAnimating()) 236 if (GetAnimator()->IsAnimating())
233 base::RunLoop().Run(); 237 base::RunLoop().Run();
234 } 238 }
235 239
236 void MessageCenterViewTest::TearDown() { 240 void MessageCenterViewTest::TearDown() {
237 widget_->CloseNow(); 241 widget_->CloseNow();
238 widget_.reset(); 242 widget_.reset();
239 message_center_view_.reset(); 243 message_center_view_.reset();
240 base::STLDeleteElements(&notifications_); 244 notifications_.clear();
241 views::ViewsTestBase::TearDown(); 245 views::ViewsTestBase::TearDown();
242 } 246 }
243 247
248 NotificationList::Notifications MessageCenterViewTest::Notifications() {
249 NotificationList::Notifications result;
250 for (const auto& notification_pair : notifications_)
251 result.insert(notification_pair.second.get());
252
253 return result;
254 }
255
244 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() { 256 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() {
245 return message_center_view_.get(); 257 return message_center_view_.get();
246 } 258 }
247 259
248 MessageListView* MessageCenterViewTest::GetMessageListView() { 260 MessageListView* MessageCenterViewTest::GetMessageListView() {
249 return message_center_view_->message_list_view_.get(); 261 return message_center_view_->message_list_view_.get();
250 } 262 }
251 263
252 FakeMessageCenterImpl* MessageCenterViewTest::GetMessageCenter() const { 264 FakeMessageCenterImpl* MessageCenterViewTest::GetMessageCenter() const {
253 return message_center_.get(); 265 return message_center_.get();
(...skipping 30 matching lines...) Expand all
284 296
285 void MessageCenterViewTest::ClickOnNotification( 297 void MessageCenterViewTest::ClickOnNotification(
286 const std::string& notification_id) { 298 const std::string& notification_id) {
287 // For this test, this method should not be invoked. 299 // For this test, this method should not be invoked.
288 NOTREACHED(); 300 NOTREACHED();
289 } 301 }
290 302
291 void MessageCenterViewTest::AddNotification( 303 void MessageCenterViewTest::AddNotification(
292 std::unique_ptr<Notification> notification) { 304 std::unique_ptr<Notification> notification) {
293 std::string notification_id = notification->id(); 305 std::string notification_id = notification->id();
294 notifications_.insert(notification.release()); 306 notifications_[notification_id] = std::move(notification);
295 message_center_->SetVisibleNotifications(notifications_); 307 message_center_->SetVisibleNotifications(Notifications());
296 message_center_view_->OnNotificationAdded(notification_id); 308 message_center_view_->OnNotificationAdded(notification_id);
297 } 309 }
298 310
299 void MessageCenterViewTest::UpdateNotification( 311 void MessageCenterViewTest::UpdateNotification(
300 const std::string& notification_id, 312 const std::string& notification_id,
301 std::unique_ptr<Notification> notification) { 313 std::unique_ptr<Notification> notification) {
302 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { 314 DCHECK_EQ(notification_id, notification->id());
303 if ((*it)->id() == notification_id) { 315 notifications_[notification_id] = std::move(notification);
304 delete *it; 316
305 notifications_.erase(it); 317 message_center_->SetVisibleNotifications(Notifications());
306 break;
307 }
308 }
309 // |notifications| is a "set" container so we don't need to be aware the
310 // order.
311 notifications_.insert(notification.release());
312 message_center_->SetVisibleNotifications(notifications_);
313 message_center_view_->OnNotificationUpdated(notification_id); 318 message_center_view_->OnNotificationUpdated(notification_id);
314 } 319 }
315 320
316 void MessageCenterViewTest::RemoveNotification( 321 void MessageCenterViewTest::RemoveNotification(
317 const std::string& notification_id, 322 const std::string& notification_id,
318 bool by_user) { 323 bool by_user) {
319 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { 324 notifications_.erase(notification_id);
320 if ((*it)->id() == notification_id) { 325
321 delete *it; 326 message_center_->SetVisibleNotifications(Notifications());
322 notifications_.erase(it);
323 break;
324 }
325 }
326 message_center_->SetVisibleNotifications(notifications_);
327 message_center_view_->OnNotificationRemoved(notification_id, by_user); 327 message_center_view_->OnNotificationRemoved(notification_id, by_user);
328 } 328 }
329 329
330 std::unique_ptr<ui::MenuModel> MessageCenterViewTest::CreateMenuModel( 330 std::unique_ptr<ui::MenuModel> MessageCenterViewTest::CreateMenuModel(
331 const NotifierId& notifier_id, 331 const NotifierId& notifier_id,
332 const base::string16& display_source) { 332 const base::string16& display_source) {
333 // For this test, this method should not be invoked. 333 // For this test, this method should not be invoked.
334 NOTREACHED(); 334 NOTREACHED();
335 return nullptr; 335 return nullptr;
336 } 336 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + 412 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
413 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + 413 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
414 GetMessageListView()->GetInsets().height()); 414 GetMessageListView()->GetInsets().height());
415 } 415 }
416 416
417 TEST_F(MessageCenterViewTest, SizeAfterUpdate) { 417 TEST_F(MessageCenterViewTest, SizeAfterUpdate) {
418 EXPECT_EQ(2, GetMessageListView()->child_count()); 418 EXPECT_EQ(2, GetMessageListView()->child_count());
419 int width = 419 int width =
420 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); 420 GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
421 421
422 std::unique_ptr<Notification> notification(new Notification( 422 std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
423 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), 423 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
424 base::UTF8ToUTF16("title2"), 424 base::UTF8ToUTF16("title2"),
425 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), 425 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
426 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), 426 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
427 NotifierId(NotifierId::APPLICATION, "extension_id"), 427 NotifierId(NotifierId::APPLICATION, "extension_id"),
428 message_center::RichNotificationData(), NULL)); 428 message_center::RichNotificationData(), nullptr);
429 429
430 EXPECT_EQ( 430 EXPECT_EQ(
431 GetMessageListView()->height(), 431 GetMessageListView()->height(),
432 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + 432 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
433 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + 433 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
434 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + 434 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
435 GetMessageListView()->GetInsets().height()); 435 GetMessageListView()->GetInsets().height());
436 436
437 int previous_height = GetMessageListView()->height(); 437 int previous_height = GetMessageListView()->height();
438 438
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // Make sure that the notification 2 is placed above the notification 1. 480 // Make sure that the notification 2 is placed above the notification 1.
481 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), 481 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
482 GetNotificationView(kNotificationId1)->bounds().y()); 482 GetNotificationView(kNotificationId1)->bounds().y());
483 483
484 int previous_vertical_pos_from_bottom = 484 int previous_vertical_pos_from_bottom =
485 GetMessageListView()->height() - 485 GetMessageListView()->height() -
486 GetNotificationView(kNotificationId1)->bounds().y(); 486 GetNotificationView(kNotificationId1)->bounds().y();
487 GetMessageListView()->SetRepositionTargetForTest( 487 GetMessageListView()->SetRepositionTargetForTest(
488 GetNotificationView(kNotificationId1)->bounds()); 488 GetNotificationView(kNotificationId1)->bounds());
489 489
490 std::unique_ptr<Notification> notification(new Notification( 490 std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
491 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), 491 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
492 base::UTF8ToUTF16("title2"), 492 base::UTF8ToUTF16("title2"),
493 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), 493 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
494 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), 494 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
495 NotifierId(NotifierId::APPLICATION, "extension_id"), 495 NotifierId(NotifierId::APPLICATION, "extension_id"),
496 message_center::RichNotificationData(), NULL)); 496 message_center::RichNotificationData(), nullptr);
497 UpdateNotification(kNotificationId2, std::move(notification)); 497 UpdateNotification(kNotificationId2, std::move(notification));
498 498
499 // Wait until the animation finishes if available. 499 // Wait until the animation finishes if available.
500 if (GetAnimator()->IsAnimating()) 500 if (GetAnimator()->IsAnimating())
501 base::RunLoop().Run(); 501 base::RunLoop().Run();
502 502
503 // The vertical position of the target from bottom should be kept over change. 503 // The vertical position of the target from bottom should be kept over change.
504 int current_vertical_pos_from_bottom = 504 int current_vertical_pos_from_bottom =
505 GetMessageListView()->height() - 505 GetMessageListView()->height() -
506 GetNotificationView(kNotificationId1)->bounds().y(); 506 GetNotificationView(kNotificationId1)->bounds().y();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // Pinned notification #2 606 // Pinned notification #2
607 Notification pinned_notification2( 607 Notification pinned_notification2(
608 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), 608 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
609 base::UTF8ToUTF16("title2"), 609 base::UTF8ToUTF16("title2"),
610 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), 610 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
611 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), 611 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
612 NotifierId(NotifierId::APPLICATION, "extension_id"), 612 NotifierId(NotifierId::APPLICATION, "extension_id"),
613 message_center::RichNotificationData(), NULL); 613 message_center::RichNotificationData(), NULL);
614 pinned_notification2.set_pinned(true); 614 pinned_notification2.set_pinned(true);
615 615
616 AddNotification( 616 AddNotification(base::MakeUnique<Notification>(normal_notification1));
617 std::unique_ptr<Notification>(new Notification(normal_notification1)));
618 617
619 // There should be 1 non-pinned notification. 618 // There should be 1 non-pinned notification.
620 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); 619 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
621 EXPECT_TRUE(close_button->enabled()); 620 EXPECT_TRUE(close_button->enabled());
622 621
623 UpdateNotification( 622 UpdateNotification(kNotificationId1,
624 kNotificationId1, 623 base::MakeUnique<Notification>(pinned_notification1));
625 std::unique_ptr<Notification>(new Notification(pinned_notification1)));
626 624
627 // There should be 1 pinned notification. 625 // There should be 1 pinned notification.
628 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); 626 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
629 EXPECT_FALSE(close_button->enabled()); 627 EXPECT_FALSE(close_button->enabled());
630 628
631 // Adds 1 pinned notification. 629 // Adds 1 pinned notification.
632 AddNotification( 630 AddNotification(base::MakeUnique<Notification>(pinned_notification2));
633 std::unique_ptr<Notification>(new Notification(pinned_notification2)));
634 631
635 // There should be 1 pinned notification. 632 // There should be 1 pinned notification.
636 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); 633 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size());
637 EXPECT_FALSE(close_button->enabled()); 634 EXPECT_FALSE(close_button->enabled());
638 635
639 UpdateNotification( 636 UpdateNotification(kNotificationId1,
640 kNotificationId1, 637 base::MakeUnique<Notification>(normal_notification1));
641 std::unique_ptr<Notification>(new Notification(normal_notification1)));
642 638
643 // There should be 1 normal notification and 1 pinned notification. 639 // There should be 1 normal notification and 1 pinned notification.
644 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); 640 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size());
645 EXPECT_TRUE(close_button->enabled()); 641 EXPECT_TRUE(close_button->enabled());
646 642
647 RemoveNotification(kNotificationId1, false); 643 RemoveNotification(kNotificationId1, false);
648 644
649 // There should be 1 pinned notification. 645 // There should be 1 pinned notification.
650 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); 646 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
651 EXPECT_FALSE(close_button->enabled()); 647 EXPECT_FALSE(close_button->enabled());
652 648
653 RemoveNotification(kNotificationId2, false); 649 RemoveNotification(kNotificationId2, false);
654 650
655 // There should be no notification. 651 // There should be no notification.
656 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); 652 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
657 EXPECT_FALSE(close_button->enabled()); 653 EXPECT_FALSE(close_button->enabled());
658 654
659 AddNotification( 655 AddNotification(base::MakeUnique<Notification>(pinned_notification2));
660 std::unique_ptr<Notification>(new Notification(pinned_notification2)));
661 656
662 // There should be 1 pinned notification. 657 // There should be 1 pinned notification.
663 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); 658 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
664 EXPECT_FALSE(close_button->enabled()); 659 EXPECT_FALSE(close_button->enabled());
665 #endif // defined(OS_CHROMEOS) 660 #endif // defined(OS_CHROMEOS)
666 } 661 }
667 662
668 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHidden) { 663 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHidden) {
669 // Check the initial state. 664 // Check the initial state.
670 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); 665 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode());
671 // Show the settings. 666 // Show the settings.
672 GetMessageCenterView()->SetSettingsVisible(true); 667 GetMessageCenterView()->SetSettingsVisible(true);
673 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); 668 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode());
674 // Hide the settings. 669 // Hide the settings.
675 GetMessageCenterView()->SetSettingsVisible(false); 670 GetMessageCenterView()->SetSettingsVisible(false);
676 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); 671 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode());
677 } 672 }
678 673
679 TEST_F(MessageCenterViewTest, CheckModeWithRemovingAndAddingNotifications) { 674 TEST_F(MessageCenterViewTest, CheckModeWithRemovingAndAddingNotifications) {
680 // Check the initial state. 675 // Check the initial state.
681 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); 676 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode());
682 677
683 // Remove notifications. 678 // Remove notifications.
684 RemoveDefaultNotifications(); 679 RemoveDefaultNotifications();
685 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); 680 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode());
686 681
687 // Add a notification. 682 // Add a notification.
688 Notification normal_notification( 683 AddNotification(base::MakeUnique<Notification>(
689 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), 684 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
690 base::UTF8ToUTF16("title2"), 685 base::UTF8ToUTF16("title2"),
691 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), 686 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
692 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), 687 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
693 NotifierId(NotifierId::APPLICATION, "extension_id"), 688 NotifierId(NotifierId::APPLICATION, "extension_id"),
694 message_center::RichNotificationData(), NULL); 689 message_center::RichNotificationData(), nullptr));
695 AddNotification(
696 std::unique_ptr<Notification>(new Notification(normal_notification)));
697 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); 690 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode());
698 } 691 }
699 692
700 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHiddenOnEmpty) { 693 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHiddenOnEmpty) {
701 // Set up by removing all existing notifications. 694 // Set up by removing all existing notifications.
702 RemoveDefaultNotifications(); 695 RemoveDefaultNotifications();
703 696
704 // Check the initial state. 697 // Check the initial state.
705 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); 698 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode());
706 // Show the settings. 699 // Show the settings.
(...skipping 28 matching lines...) Expand all
735 RemoveDefaultNotifications(); 728 RemoveDefaultNotifications();
736 729
737 // Check the initial state. 730 // Check the initial state.
738 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); 731 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode());
739 732
740 // Show the settings. 733 // Show the settings.
741 GetMessageCenterView()->SetSettingsVisible(true); 734 GetMessageCenterView()->SetSettingsVisible(true);
742 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); 735 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode());
743 736
744 // Add a notification during settings is visible. 737 // Add a notification during settings is visible.
745 Notification normal_notification( 738 AddNotification(base::MakeUnique<Notification>(
746 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), 739 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
747 base::UTF8ToUTF16("title2"), 740 base::UTF8ToUTF16("title2"),
748 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), 741 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
749 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), 742 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
750 NotifierId(NotifierId::APPLICATION, "extension_id"), 743 NotifierId(NotifierId::APPLICATION, "extension_id"),
751 message_center::RichNotificationData(), NULL); 744 message_center::RichNotificationData(), nullptr));
752 AddNotification(
753 std::unique_ptr<Notification>(new Notification(normal_notification)));
754 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); 745 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode());
755 746
756 // Hide the settings. 747 // Hide the settings.
757 GetMessageCenterView()->SetSettingsVisible(false); 748 GetMessageCenterView()->SetSettingsVisible(false);
758 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); 749 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode());
759 } 750 }
760 751
761 TEST_F(MessageCenterViewTest, LockScreen) { 752 TEST_F(MessageCenterViewTest, LockScreen) {
762 const int kLockedMessageCenterViewHeight = 50; 753 const int kLockedMessageCenterViewHeight = 50;
763 754
(...skipping 12 matching lines...) Expand all
776 RemoveNotification(kNotificationId1, false); 767 RemoveNotification(kNotificationId1, false);
777 768
778 GetMessageCenterView()->SizeToPreferredSize(); 769 GetMessageCenterView()->SizeToPreferredSize();
779 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); 770 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height());
780 771
781 RemoveNotification(kNotificationId2, false); 772 RemoveNotification(kNotificationId2, false);
782 773
783 GetMessageCenterView()->SizeToPreferredSize(); 774 GetMessageCenterView()->SizeToPreferredSize();
784 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); 775 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height());
785 776
786 AddNotification(std::unique_ptr<Notification>(new Notification( 777 AddNotification(base::MakeUnique<Notification>(
787 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), 778 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
788 base::UTF8ToUTF16("title1"), 779 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(),
789 base::UTF8ToUTF16("message"), 780 base::UTF8ToUTF16("display source"), GURL(),
790 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
791 NotifierId(NotifierId::APPLICATION, "extension_id"), 781 NotifierId(NotifierId::APPLICATION, "extension_id"),
792 message_center::RichNotificationData(), NULL))); 782 message_center::RichNotificationData(), nullptr));
793 EXPECT_FALSE(GetNotificationView(kNotificationId1)->IsDrawn()); 783 EXPECT_FALSE(GetNotificationView(kNotificationId1)->IsDrawn());
794 784
795 GetMessageCenterView()->SizeToPreferredSize(); 785 GetMessageCenterView()->SizeToPreferredSize();
796 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); 786 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height());
797 787
798 // Unlock! 788 // Unlock!
799 SetLockedState(false); 789 SetLockedState(false);
800 790
801 EXPECT_TRUE(GetNotificationView(kNotificationId1)->IsDrawn()); 791 EXPECT_TRUE(GetNotificationView(kNotificationId1)->IsDrawn());
802 792
(...skipping 14 matching lines...) Expand all
817 807
818 GetMessageCenterView()->SizeToPreferredSize(); 808 GetMessageCenterView()->SizeToPreferredSize();
819 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 809 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
820 RemoveNotification(kNotificationId1, false); 810 RemoveNotification(kNotificationId1, false);
821 GetMessageCenterView()->SizeToPreferredSize(); 811 GetMessageCenterView()->SizeToPreferredSize();
822 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 812 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
823 RemoveNotification(kNotificationId2, false); 813 RemoveNotification(kNotificationId2, false);
824 GetMessageCenterView()->SizeToPreferredSize(); 814 GetMessageCenterView()->SizeToPreferredSize();
825 EXPECT_EQ(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 815 EXPECT_EQ(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
826 816
827 AddNotification(std::unique_ptr<Notification>(new Notification( 817 AddNotification(base::MakeUnique<Notification>(
828 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), 818 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
829 base::UTF8ToUTF16("title1"), 819 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(),
830 base::UTF8ToUTF16("message"), 820 base::UTF8ToUTF16("display source"), GURL(),
831 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
832 NotifierId(NotifierId::APPLICATION, "extension_id"), 821 NotifierId(NotifierId::APPLICATION, "extension_id"),
833 message_center::RichNotificationData(), NULL))); 822 message_center::RichNotificationData(), nullptr));
834 823
835 GetMessageCenterView()->SizeToPreferredSize(); 824 GetMessageCenterView()->SizeToPreferredSize();
836 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 825 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
837 } 826 }
838 827
839 } // namespace message_center 828 } // namespace message_center
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698