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

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

Issue 2856833002: Fix a bug that old height is set in DoUpdateIfPossible(). (Closed)
Patch Set: rebase Created 3 years, 7 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/views/message_list_view.cc ('k') | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/message_center/fake_message_center.h" 14 #include "ui/message_center/fake_message_center.h"
15 #include "ui/message_center/notification.h" 15 #include "ui/message_center/notification.h"
16 #include "ui/message_center/notification_list.h" 16 #include "ui/message_center/notification_list.h"
17 #include "ui/message_center/views/message_center_controller.h" 17 #include "ui/message_center/views/message_center_controller.h"
18 #include "ui/message_center/views/message_list_view.h" 18 #include "ui/message_center/views/message_list_view.h"
19 #include "ui/message_center/views/notification_view.h" 19 #include "ui/message_center/views/notification_view.h"
20 #include "ui/views/test/views_test_base.h" 20 #include "ui/views/test/views_test_base.h"
21 21
22 using ::testing::ElementsAre; 22 using ::testing::ElementsAre;
23 23
24 namespace message_center { 24 namespace message_center {
25 25
26 static const char* kNotificationId1 = "notification id 1"; 26 static const char* kNotificationId1 = "notification id 1";
27 static const char* kNotificationId2 = "notification id 2";
27 28
28 namespace { 29 namespace {
29 30
30 /* Types **********************************************************************/ 31 /* Types **********************************************************************/
31 32
32 enum CallType { GET_PREFERRED_SIZE, GET_HEIGHT_FOR_WIDTH, LAYOUT }; 33 enum CallType { GET_PREFERRED_SIZE, GET_HEIGHT_FOR_WIDTH, LAYOUT };
33 34
34 /* Instrumented/Mock NotificationView subclass ********************************/ 35 /* Instrumented/Mock NotificationView subclass ********************************/
35 36
36 class MockNotificationView : public NotificationView { 37 class MockNotificationView : public NotificationView {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 protected: 126 protected:
126 MessageListView* message_list_view() const { 127 MessageListView* message_list_view() const {
127 return message_list_view_.get(); 128 return message_list_view_.get();
128 } 129 }
129 130
130 int& reposition_top() { return message_list_view_->reposition_top_; } 131 int& reposition_top() { return message_list_view_->reposition_top_; }
131 132
132 int& fixed_height() { return message_list_view_->fixed_height_; } 133 int& fixed_height() { return message_list_view_->fixed_height_; }
133 134
135 views::BoundsAnimator& animator() { return message_list_view_->animator_; }
136
134 std::vector<int> ComputeRepositionOffsets(const std::vector<int>& heights, 137 std::vector<int> ComputeRepositionOffsets(const std::vector<int>& heights,
135 const std::vector<bool>& deleting, 138 const std::vector<bool>& deleting,
136 int target_index, 139 int target_index,
137 int padding) { 140 int padding) {
138 return message_list_view_->ComputeRepositionOffsets(heights, deleting, 141 return message_list_view_->ComputeRepositionOffsets(heights, deleting,
139 target_index, padding); 142 target_index, padding);
140 } 143 }
141 144
142 MockNotificationView* CreateNotificationView( 145 MockNotificationView* CreateNotificationView(
143 const Notification& notification) { 146 const Notification& notification) {
144 return new MockNotificationView(this, notification, this); 147 return new MockNotificationView(this, notification, this);
145 } 148 }
146 149
150 void RunPendingAnimations() {
151 while (animator().IsAnimating())
152 RunPendingMessages();
153 }
154
147 private: 155 private:
148 // MockNotificationView::Test override 156 // MockNotificationView::Test override
149 void RegisterCall(CallType type) override {} 157 void RegisterCall(CallType type) override {}
150 158
151 // MessageListView::Observer override 159 // MessageListView::Observer override
152 void OnAllNotificationsCleared() override {} 160 void OnAllNotificationsCleared() override {}
153 161
154 // MessageCenterController override: 162 // MessageCenterController override:
155 void ClickOnNotification(const std::string& notification_id) override {} 163 void ClickOnNotification(const std::string& notification_id) override {}
156 void RemoveNotification(const std::string& notification_id, 164 void RemoveNotification(const std::string& notification_id,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 reposition_top() = 5 + top; 376 reposition_top() = 5 + top;
369 positions = 377 positions =
370 ComputeRepositionOffsets({5, 3, 3, 3}, {false, false, false, false}, 378 ComputeRepositionOffsets({5, 3, 3, 3}, {false, false, false, false},
371 1 /* target_index */, 2 /* padding */); 379 1 /* target_index */, 2 /* padding */);
372 EXPECT_THAT(positions, 380 EXPECT_THAT(positions,
373 ElementsAre(top, top + 7, top + 7 + 5, top + 7 + 5 + 5)); 381 ElementsAre(top, top + 7, top + 7 + 5, top + 7 + 5 + 5));
374 EXPECT_EQ(20 + insets.height() + 2, fixed_height()); 382 EXPECT_EQ(20 + insets.height() + 2, fixed_height());
375 EXPECT_EQ(5 + top + 2, reposition_top()); 383 EXPECT_EQ(5 + top + 2, reposition_top());
376 } 384 }
377 385
386 TEST_F(MessageListViewTest, RemoveNotification) {
387 message_list_view()->SetBounds(0, 0, 800, 600);
388
389 // Create dummy notifications.
390 auto* notification_view = CreateNotificationView(
391 Notification(NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
392 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"),
393 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
394 NotifierId(NotifierId::APPLICATION, "extension_id"),
395 message_center::RichNotificationData(), nullptr));
396
397 message_list_view()->AddNotificationAt(notification_view, 0);
398 EXPECT_EQ(1, message_list_view()->child_count());
399 EXPECT_TRUE(message_list_view()->Contains(notification_view));
400
401 RunPendingAnimations();
402
403 message_list_view()->RemoveNotification(notification_view);
404
405 RunPendingAnimations();
406
407 EXPECT_EQ(0, message_list_view()->child_count());
408 }
409
410 TEST_F(MessageListViewTest, ClearAllClosableNotifications) {
411 message_list_view()->SetBounds(0, 0, 800, 600);
412
413 // Create dummy notifications.
414 auto* notification_view1 = CreateNotificationView(
415 Notification(NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
416 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"),
417 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
418 NotifierId(NotifierId::APPLICATION, "extension_id"),
419 message_center::RichNotificationData(), nullptr));
420 auto* notification_view2 = CreateNotificationView(
421 Notification(NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
422 base::UTF8ToUTF16("title 2"), base::UTF8ToUTF16("message2"),
423 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
424 NotifierId(NotifierId::APPLICATION, "extension_id"),
425 message_center::RichNotificationData(), nullptr));
426
427 message_list_view()->AddNotificationAt(notification_view1, 0);
428 EXPECT_EQ(1, message_list_view()->child_count());
429 EXPECT_TRUE(notification_view1->visible());
430
431 RunPendingAnimations();
432
433 message_list_view()->AddNotificationAt(notification_view2, 1);
434 EXPECT_EQ(2, message_list_view()->child_count());
435 EXPECT_TRUE(notification_view2->visible());
436
437 RunPendingAnimations();
438
439 message_list_view()->ClearAllClosableNotifications(
440 message_list_view()->bounds());
441
442 RunPendingAnimations();
443
444 // TODO(yhanada): notification_view1 and notification_view2 should be deleted
445 // here. Uncomment the below test.
446 EXPECT_TRUE(gfx::IntersectRects(notification_view1->bounds(),
447 message_list_view()->bounds())
448 .IsEmpty());
449 EXPECT_TRUE(gfx::IntersectRects(notification_view2->bounds(),
450 message_list_view()->bounds())
451 .IsEmpty());
452 // EXPECT_EQ(0, message_list_view()->child_count());
453 }
454
378 } // namespace 455 } // namespace
OLDNEW
« no previous file with comments | « ui/message_center/views/message_list_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698