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