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

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

Issue 2964973002: Use shared NotificationControlButtonsView for non-arc notification buttons (Closed)
Patch Set: Created 3 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
24 #include "ui/message_center/message_center_style.h" 24 #include "ui/message_center/message_center_style.h"
25 #include "ui/message_center/notification.h" 25 #include "ui/message_center/notification.h"
26 #include "ui/message_center/notification_list.h" 26 #include "ui/message_center/notification_list.h"
27 #include "ui/message_center/notification_types.h" 27 #include "ui/message_center/notification_types.h"
28 #include "ui/message_center/views/constants.h" 28 #include "ui/message_center/views/constants.h"
29 #include "ui/message_center/views/message_center_controller.h" 29 #include "ui/message_center/views/message_center_controller.h"
30 #include "ui/message_center/views/message_view_factory.h" 30 #include "ui/message_center/views/message_view_factory.h"
31 #include "ui/message_center/views/notification_button.h" 31 #include "ui/message_center/views/notification_button.h"
32 #include "ui/message_center/views/notification_control_buttons_view.h"
33 #include "ui/message_center/views/padded_button.h"
32 #include "ui/message_center/views/proportional_image_view.h" 34 #include "ui/message_center/views/proportional_image_view.h"
33 #include "ui/views/controls/button/image_button.h" 35 #include "ui/views/controls/button/image_button.h"
34 #include "ui/views/layout/fill_layout.h" 36 #include "ui/views/layout/fill_layout.h"
35 #include "ui/views/test/views_test_base.h" 37 #include "ui/views/test/views_test_base.h"
36 #include "ui/views/test/widget_test.h" 38 #include "ui/views/test/widget_test.h"
37 #include "ui/views/widget/widget_delegate.h" 39 #include "ui/views/widget/widget_delegate.h"
38 40
39 namespace message_center { 41 namespace message_center {
40 42
41 // A test delegate used for tests that deal with the notification settings 43 // A test delegate used for tests that deal with the notification settings
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 155
154 gfx::Point current_point = (*current)->origin(); 156 gfx::Point current_point = (*current)->origin();
155 views::View::ConvertPointToTarget( 157 views::View::ConvertPointToTarget(
156 (*current), notification_view(), &current_point); 158 (*current), notification_view(), &current_point);
157 159
158 EXPECT_LT(last_point.y(), current_point.y()); 160 EXPECT_LT(last_point.y(), current_point.y());
159 last = current++; 161 last = current++;
160 } 162 }
161 } 163 }
162 164
163 views::ImageButton* GetCloseButton() { 165 PaddedButton* GetCloseButton() {
164 return notification_view()->close_button(); 166 return notification_view()
167 ->control_buttons_view_->close_button_for_testing();
168 }
169
170 PaddedButton* GetSettingsButton() {
171 return notification_view()
172 ->control_buttons_view_->settings_button_for_testing();
165 } 173 }
166 174
167 void UpdateNotificationViews() { 175 void UpdateNotificationViews() {
168 notification_view()->UpdateWithNotification(*notification()); 176 notification_view()->UpdateWithNotification(*notification());
169 } 177 }
170 178
171 float GetNotificationSlideAmount() const { 179 float GetNotificationSlideAmount() const {
172 return notification_view_->GetSlideOutLayer() 180 return notification_view_->GetSlideOutLayer()
173 ->transform() 181 ->transform()
174 .To2dTranslation() 182 .To2dTranslation()
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 313
306 notification()->set_image(gfx::Image()); 314 notification()->set_image(gfx::Image());
307 notification()->set_title(base::ASCIIToUTF16("")); 315 notification()->set_title(base::ASCIIToUTF16(""));
308 notification()->set_message(base::ASCIIToUTF16("")); 316 notification()->set_message(base::ASCIIToUTF16(""));
309 notification()->set_icon(gfx::Image()); 317 notification()->set_icon(gfx::Image());
310 318
311 notification_view()->CreateOrUpdateViews(*notification()); 319 notification_view()->CreateOrUpdateViews(*notification());
312 EXPECT_TRUE(NULL == notification_view()->title_view_); 320 EXPECT_TRUE(NULL == notification_view()->title_view_);
313 EXPECT_TRUE(NULL == notification_view()->message_view_); 321 EXPECT_TRUE(NULL == notification_view()->message_view_);
314 EXPECT_TRUE(NULL == notification_view()->image_view_); 322 EXPECT_TRUE(NULL == notification_view()->image_view_);
315 EXPECT_TRUE(NULL == notification_view()->settings_button_view_); 323 // Notification must have a control buttons view.
324 EXPECT_TRUE(NULL != notification_view()->control_buttons_view_);
325 // Notification is not pinned and have a close button by default.
326 EXPECT_TRUE(NULL != GetCloseButton());
327 // Notification doesn't have a settings button by default.
328 EXPECT_TRUE(NULL == GetSettingsButton());
316 // We still expect an icon view for all layouts. 329 // We still expect an icon view for all layouts.
317 EXPECT_TRUE(NULL != notification_view()->icon_view_); 330 EXPECT_TRUE(NULL != notification_view()->icon_view_);
318 } 331 }
319 332
320 TEST_F(NotificationViewTest, CreateOrUpdateTestSettingsButton) { 333 TEST_F(NotificationViewTest, CreateOrUpdateTestSettingsButton) {
321 scoped_refptr<NotificationSettingsDelegate> delegate = 334 scoped_refptr<NotificationSettingsDelegate> delegate =
322 new NotificationSettingsDelegate(); 335 new NotificationSettingsDelegate();
323 Notification notf(NOTIFICATION_TYPE_BASE_FORMAT, 336 Notification notf(NOTIFICATION_TYPE_BASE_FORMAT,
324 std::string("notification id"), base::UTF8ToUTF16("title"), 337 std::string("notification id"), base::UTF8ToUTF16("title"),
325 base::UTF8ToUTF16("message"), CreateTestImage(80, 80), 338 base::UTF8ToUTF16("message"), CreateTestImage(80, 80),
326 base::UTF8ToUTF16("display source"), 339 base::UTF8ToUTF16("display source"),
327 GURL("https://hello.com"), 340 GURL("https://hello.com"),
328 NotifierId(NotifierId::APPLICATION, "extension_id"), 341 NotifierId(NotifierId::APPLICATION, "extension_id"),
329 *data(), delegate.get()); 342 *data(), delegate.get());
330 343
331 notification_view()->CreateOrUpdateViews(notf); 344 notification_view()->CreateOrUpdateViews(notf);
332 EXPECT_TRUE(NULL != notification_view()->title_view_); 345 EXPECT_TRUE(NULL != notification_view()->title_view_);
333 EXPECT_TRUE(NULL != notification_view()->message_view_); 346 EXPECT_TRUE(NULL != notification_view()->message_view_);
334 EXPECT_TRUE(NULL != notification_view()->context_message_view_); 347 EXPECT_TRUE(NULL != notification_view()->context_message_view_);
335 EXPECT_TRUE(NULL != notification_view()->settings_button_view_); 348 EXPECT_TRUE(NULL != GetCloseButton());
349 EXPECT_TRUE(NULL != GetSettingsButton());
336 EXPECT_TRUE(NULL != notification_view()->icon_view_); 350 EXPECT_TRUE(NULL != notification_view()->icon_view_);
337 351
338 EXPECT_TRUE(NULL == notification_view()->image_view_); 352 EXPECT_TRUE(NULL == notification_view()->image_view_);
339 } 353 }
340 354
341 TEST_F(NotificationViewTest, TestLineLimits) { 355 TEST_F(NotificationViewTest, TestLineLimits) {
342 notification()->set_image(CreateTestImage(0, 0)); 356 notification()->set_image(CreateTestImage(0, 0));
343 notification()->set_context_message(base::ASCIIToUTF16("")); 357 notification()->set_context_message(base::ASCIIToUTF16(""));
344 notification_view()->CreateOrUpdateViews(*notification()); 358 notification_view()->CreateOrUpdateViews(*notification());
345 359
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 std::string("notification id"), base::UTF8ToUTF16("title"), 547 std::string("notification id"), base::UTF8ToUTF16("title"),
534 base::UTF8ToUTF16("message"), CreateTestImage(80, 80), 548 base::UTF8ToUTF16("message"), CreateTestImage(80, 80),
535 base::UTF8ToUTF16("display source"), 549 base::UTF8ToUTF16("display source"),
536 GURL("https://hello.com"), 550 GURL("https://hello.com"),
537 NotifierId(NotifierId::APPLICATION, "extension_id"), 551 NotifierId(NotifierId::APPLICATION, "extension_id"),
538 *data(), delegate.get()); 552 *data(), delegate.get());
539 notification_view()->CreateOrUpdateViews(notf); 553 notification_view()->CreateOrUpdateViews(notf);
540 widget()->Show(); 554 widget()->Show();
541 notification_view()->Layout(); 555 notification_view()->Layout();
542 556
543 EXPECT_TRUE(NULL != notification_view()->settings_button_view_); 557 EXPECT_TRUE(NULL != GetSettingsButton());
544 EXPECT_EQ(views::CustomButton::STATE_NORMAL, 558 EXPECT_EQ(views::CustomButton::STATE_NORMAL, GetSettingsButton()->state());
545 notification_view()->settings_button_view_->state());
546 559
547 // Now construct a mouse move event 1 pixel inside the boundary of the action 560 // Now construct a mouse move event 1 pixel inside the boundary of the action
548 // button. 561 // button.
549 gfx::Point cursor_location(1, 1); 562 gfx::Point cursor_location(1, 1);
550 views::View::ConvertPointToScreen(notification_view()->settings_button_view_, 563 views::View::ConvertPointToScreen(GetSettingsButton(), &cursor_location);
551 &cursor_location);
552 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 564 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
553 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 565 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
554 widget()->OnMouseEvent(&move); 566 widget()->OnMouseEvent(&move);
555 ui::EventDispatchDetails details = 567 ui::EventDispatchDetails details =
556 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move); 568 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move);
557 EXPECT_FALSE(details.dispatcher_destroyed); 569 EXPECT_FALSE(details.dispatcher_destroyed);
558 570
559 EXPECT_EQ(views::CustomButton::STATE_HOVERED, 571 EXPECT_EQ(views::CustomButton::STATE_HOVERED, GetSettingsButton()->state());
560 notification_view()->settings_button_view_->state());
561 572
562 // Now construct a mouse move event 1 pixel outside the boundary of the 573 // Now construct a mouse move event 1 pixel outside the boundary of the
563 // widget. 574 // widget.
564 cursor_location = gfx::Point(-1, -1); 575 cursor_location = gfx::Point(-1, -1);
565 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 576 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
566 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 577 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
567 widget()->OnMouseEvent(&move); 578 widget()->OnMouseEvent(&move);
568 579
569 EXPECT_EQ(views::CustomButton::STATE_NORMAL, 580 EXPECT_EQ(views::CustomButton::STATE_NORMAL, GetSettingsButton()->state());
570 notification_view()->settings_button_view_->state());
571 } 581 }
572 582
573 TEST_F(NotificationViewTest, ViewOrderingTest) { 583 TEST_F(NotificationViewTest, ViewOrderingTest) {
574 // Tests that views are created in the correct vertical order. 584 // Tests that views are created in the correct vertical order.
575 notification()->set_buttons(CreateButtons(2)); 585 notification()->set_buttons(CreateButtons(2));
576 586
577 // Layout the initial views. 587 // Layout the initial views.
578 UpdateNotificationViews(); 588 UpdateNotificationViews();
579 589
580 // Double-check that vertical order is correct. 590 // Double-check that vertical order is correct.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 TEST_F(NotificationViewTest, Pinned) { 737 TEST_F(NotificationViewTest, Pinned) {
728 notification()->set_pinned(true); 738 notification()->set_pinned(true);
729 739
730 UpdateNotificationViews(); 740 UpdateNotificationViews();
731 EXPECT_EQ(NULL, GetCloseButton()); 741 EXPECT_EQ(NULL, GetCloseButton());
732 } 742 }
733 743
734 #endif // defined(OS_CHROMEOS) 744 #endif // defined(OS_CHROMEOS)
735 745
736 } // namespace message_center 746 } // namespace message_center
OLDNEW
« ui/message_center/views/notification_view.cc ('K') | « ui/message_center/views/notification_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698