| OLD | NEW |
| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/base/ime/dummy_text_input_client.h" | 12 #include "ui/base/ime/dummy_text_input_client.h" |
| 13 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
| 14 #include "ui/base/ime/text_input_client.h" | 14 #include "ui/base/ime/text_input_client.h" |
| 15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 15 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 16 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 18 #include "ui/events/test/event_generator.h" |
| 17 #include "ui/message_center/notification.h" | 19 #include "ui/message_center/notification.h" |
| 18 #include "ui/message_center/notification_delegate.h" | 20 #include "ui/message_center/notification_delegate.h" |
| 19 #include "ui/message_center/views/custom_notification_view.h" | 21 #include "ui/message_center/views/custom_notification_view.h" |
| 20 #include "ui/message_center/views/message_center_controller.h" | 22 #include "ui/message_center/views/message_center_controller.h" |
| 21 #include "ui/message_center/views/message_view_factory.h" | 23 #include "ui/message_center/views/message_view_factory.h" |
| 22 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| 23 #include "ui/views/controls/button/image_button.h" | 25 #include "ui/views/controls/button/image_button.h" |
| 24 #include "ui/views/test/views_test_base.h" | 26 #include "ui/views/test/views_test_base.h" |
| 25 | 27 |
| 26 namespace message_center { | 28 namespace message_center { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 73 |
| 72 DISALLOW_COPY_AND_ASSIGN(TestCustomView); | 74 DISALLOW_COPY_AND_ASSIGN(TestCustomView); |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 class TestContentViewDelegate : public CustomNotificationContentViewDelegate { | 77 class TestContentViewDelegate : public CustomNotificationContentViewDelegate { |
| 76 public: | 78 public: |
| 77 bool IsCloseButtonFocused() const override { return false; } | 79 bool IsCloseButtonFocused() const override { return false; } |
| 78 void RequestFocusOnCloseButton() override {} | 80 void RequestFocusOnCloseButton() override {} |
| 79 bool IsPinned() const override { return false; } | 81 bool IsPinned() const override { return false; } |
| 80 void UpdateControlButtonsVisibility() override {} | 82 void UpdateControlButtonsVisibility() override {} |
| 83 void OnSlideChanged() override {} |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 class TestNotificationDelegate : public NotificationDelegate { | 86 class TestNotificationDelegate : public NotificationDelegate { |
| 84 public: | 87 public: |
| 85 TestNotificationDelegate() {} | 88 TestNotificationDelegate() {} |
| 86 | 89 |
| 87 // NotificateDelegate | 90 // NotificateDelegate |
| 88 std::unique_ptr<CustomContent> CreateCustomContent() override { | 91 std::unique_ptr<CustomContent> CreateCustomContent() override { |
| 89 return base::MakeUnique<CustomContent>( | 92 return base::MakeUnique<CustomContent>( |
| 90 base::MakeUnique<TestCustomView>(), | 93 base::MakeUnique<TestCustomView>(), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 notification_view_.reset(static_cast<CustomNotificationView*>( | 190 notification_view_.reset(static_cast<CustomNotificationView*>( |
| 188 MessageViewFactory::Create(controller(), *notification_, true))); | 191 MessageViewFactory::Create(controller(), *notification_, true))); |
| 189 notification_view_->set_owned_by_client(); | 192 notification_view_->set_owned_by_client(); |
| 190 | 193 |
| 191 views::Widget::InitParams init_params( | 194 views::Widget::InitParams init_params( |
| 192 CreateParams(views::Widget::InitParams::TYPE_POPUP)); | 195 CreateParams(views::Widget::InitParams::TYPE_POPUP)); |
| 193 views::Widget* widget = new views::Widget(); | 196 views::Widget* widget = new views::Widget(); |
| 194 widget->Init(init_params); | 197 widget->Init(init_params); |
| 195 widget->SetContentsView(notification_view_.get()); | 198 widget->SetContentsView(notification_view_.get()); |
| 196 widget->SetSize(notification_view_->GetPreferredSize()); | 199 widget->SetSize(notification_view_->GetPreferredSize()); |
| 200 widget->Show(); |
| 197 } | 201 } |
| 198 | 202 |
| 199 void TearDown() override { | 203 void TearDown() override { |
| 200 widget()->Close(); | 204 widget()->Close(); |
| 201 notification_view_.reset(); | 205 notification_view_.reset(); |
| 202 views::ViewsTestBase::TearDown(); | 206 views::ViewsTestBase::TearDown(); |
| 203 } | 207 } |
| 204 | 208 |
| 205 SkColor GetBackgroundColor() const { | 209 SkColor GetBackgroundColor() const { |
| 206 return notification_view_->background_view()->background()->get_color(); | 210 return notification_view_->background_view()->background()->get_color(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 226 | 230 |
| 227 void KeyPress(ui::KeyboardCode key_code) { | 231 void KeyPress(ui::KeyboardCode key_code) { |
| 228 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); | 232 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); |
| 229 widget()->OnKeyEvent(&event); | 233 widget()->OnKeyEvent(&event); |
| 230 } | 234 } |
| 231 | 235 |
| 232 void UpdateNotificationViews() { | 236 void UpdateNotificationViews() { |
| 233 notification_view()->UpdateWithNotification(*notification()); | 237 notification_view()->UpdateWithNotification(*notification()); |
| 234 } | 238 } |
| 235 | 239 |
| 240 float GetNotificationSlideAmount() const { |
| 241 return notification_view_->GetSlideOutLayer() |
| 242 ->transform() |
| 243 .To2dTranslation() |
| 244 .x(); |
| 245 } |
| 246 |
| 247 void DispatchGesture(const ui::GestureEventDetails& details) { |
| 248 ui::test::EventGenerator generator( |
| 249 notification_view()->GetWidget()->GetNativeWindow()); |
| 250 ui::GestureEvent event(0, 0, 0, ui::EventTimeForNow(), details); |
| 251 generator.Dispatch(&event); |
| 252 } |
| 253 |
| 254 void BeginScroll() { |
| 255 DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 256 } |
| 257 |
| 258 void EndScroll() { |
| 259 DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); |
| 260 } |
| 261 |
| 262 void ScrollBy(int dx) { |
| 263 DispatchGesture( |
| 264 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0)); |
| 265 } |
| 266 |
| 236 TestMessageCenterController* controller() { return &controller_; } | 267 TestMessageCenterController* controller() { return &controller_; } |
| 237 Notification* notification() { return notification_.get(); } | 268 Notification* notification() { return notification_.get(); } |
| 238 TestCustomView* custom_view() { | 269 TestCustomView* custom_view() { |
| 239 return static_cast<TestCustomView*>(notification_view_->contents_view_); | 270 return static_cast<TestCustomView*>(notification_view_->contents_view_); |
| 240 } | 271 } |
| 241 views::Widget* widget() { return notification_view_->GetWidget(); } | 272 views::Widget* widget() { return notification_view_->GetWidget(); } |
| 242 CustomNotificationView* notification_view() { | 273 CustomNotificationView* notification_view() { |
| 243 return notification_view_.get(); | 274 return notification_view_.get(); |
| 244 } | 275 } |
| 245 | 276 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 269 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 300 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 270 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 301 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 271 widget()->OnMouseEvent(&move); | 302 widget()->OnMouseEvent(&move); |
| 272 EXPECT_EQ(3, custom_view()->mouse_event_count()); | 303 EXPECT_EQ(3, custom_view()->mouse_event_count()); |
| 273 | 304 |
| 274 EXPECT_EQ(0, custom_view()->keyboard_event_count()); | 305 EXPECT_EQ(0, custom_view()->keyboard_event_count()); |
| 275 KeyPress(ui::VKEY_A); | 306 KeyPress(ui::VKEY_A); |
| 276 EXPECT_EQ(1, custom_view()->keyboard_event_count()); | 307 EXPECT_EQ(1, custom_view()->keyboard_event_count()); |
| 277 } | 308 } |
| 278 | 309 |
| 310 TEST_F(CustomNotificationViewTest, SlideOut) { |
| 311 ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
| 312 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 313 |
| 314 UpdateNotificationViews(); |
| 315 std::string notification_id = notification()->id(); |
| 316 |
| 317 BeginScroll(); |
| 318 ScrollBy(-10); |
| 319 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 320 EXPECT_EQ(-10.f, GetNotificationSlideAmount()); |
| 321 EndScroll(); |
| 322 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 323 EXPECT_EQ(0.f, GetNotificationSlideAmount()); |
| 324 |
| 325 BeginScroll(); |
| 326 ScrollBy(-200); |
| 327 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 328 EXPECT_EQ(-200.f, GetNotificationSlideAmount()); |
| 329 EndScroll(); |
| 330 EXPECT_TRUE(controller()->IsRemoved(notification_id)); |
| 331 } |
| 332 |
| 333 TEST_F(CustomNotificationViewTest, SlideOutNested) { |
| 334 ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
| 335 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 336 |
| 337 UpdateNotificationViews(); |
| 338 notification_view()->SetIsNested(); |
| 339 std::string notification_id = notification()->id(); |
| 340 |
| 341 BeginScroll(); |
| 342 ScrollBy(-10); |
| 343 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 344 EXPECT_EQ(-10.f, GetNotificationSlideAmount()); |
| 345 EndScroll(); |
| 346 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 347 EXPECT_EQ(0.f, GetNotificationSlideAmount()); |
| 348 |
| 349 BeginScroll(); |
| 350 ScrollBy(-200); |
| 351 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 352 EXPECT_EQ(-200.f, GetNotificationSlideAmount()); |
| 353 EndScroll(); |
| 354 EXPECT_TRUE(controller()->IsRemoved(notification_id)); |
| 355 } |
| 356 |
| 357 // Pinning notification is ChromeOS only feature. |
| 358 #if defined(OS_CHROMEOS) |
| 359 |
| 360 TEST_F(CustomNotificationViewTest, SlideOutPinned) { |
| 361 ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
| 362 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 363 |
| 364 notification()->set_pinned(true); |
| 365 UpdateNotificationViews(); |
| 366 std::string notification_id = notification()->id(); |
| 367 |
| 368 BeginScroll(); |
| 369 ScrollBy(-200); |
| 370 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 371 EXPECT_LT(-200.f, GetNotificationSlideAmount()); |
| 372 EndScroll(); |
| 373 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 374 } |
| 375 |
| 376 #endif // defined(OS_CHROMEOS) |
| 377 |
| 279 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { | 378 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { |
| 280 std::string notification_id = notification()->id(); | 379 std::string notification_id = notification()->id(); |
| 281 custom_view()->RequestFocus(); | 380 custom_view()->RequestFocus(); |
| 282 | 381 |
| 283 ui::InputMethod* input_method = custom_view()->GetInputMethod(); | 382 ui::InputMethod* input_method = custom_view()->GetInputMethod(); |
| 284 ASSERT_TRUE(input_method); | 383 ASSERT_TRUE(input_method); |
| 285 TestTextInputClient text_input_client; | 384 TestTextInputClient text_input_client; |
| 286 input_method->SetFocusedTextInputClient(&text_input_client); | 385 input_method->SetFocusedTextInputClient(&text_input_client); |
| 287 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); | 386 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); |
| 288 | 387 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 EXPECT_EQ("360x10", size.ToString()); | 424 EXPECT_EQ("360x10", size.ToString()); |
| 326 | 425 |
| 327 // The long notification. | 426 // The long notification. |
| 328 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); | 427 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); |
| 329 size = notification_view()->GetPreferredSize(); | 428 size = notification_view()->GetPreferredSize(); |
| 330 size.Enlarge(0, -notification_view()->GetInsets().height()); | 429 size.Enlarge(0, -notification_view()->GetInsets().height()); |
| 331 EXPECT_EQ("360x1000", size.ToString()); | 430 EXPECT_EQ("360x1000", size.ToString()); |
| 332 } | 431 } |
| 333 | 432 |
| 334 } // namespace message_center | 433 } // namespace message_center |
| OLD | NEW |