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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
23 #include "ui/views/controls/button/image_button.h" | 23 #include "ui/views/controls/button/image_button.h" |
24 #include "ui/views/test/views_test_base.h" | 24 #include "ui/views/test/views_test_base.h" |
25 | 25 |
26 namespace message_center { | 26 namespace message_center { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const SkColor kBackgroundColor = SK_ColorGREEN; | 30 const SkColor kBackgroundColor = SK_ColorGREEN; |
31 | 31 |
| 32 std::unique_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) { |
| 33 ui::GestureEventDetails detail(type); |
| 34 std::unique_ptr<ui::GestureEvent> event( |
| 35 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail)); |
| 36 return event; |
| 37 } |
| 38 |
| 39 std::unique_ptr<ui::GestureEvent> GenerateGestureHorizontalScrollUpdateEvent( |
| 40 int dx) { |
| 41 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0); |
| 42 std::unique_ptr<ui::GestureEvent> event( |
| 43 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail)); |
| 44 return event; |
| 45 } |
| 46 |
32 class TestCustomView : public views::View { | 47 class TestCustomView : public views::View { |
33 public: | 48 public: |
34 TestCustomView() { | 49 TestCustomView() { |
35 SetFocusBehavior(FocusBehavior::ALWAYS); | 50 SetFocusBehavior(FocusBehavior::ALWAYS); |
36 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 51 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
37 } | 52 } |
38 ~TestCustomView() override {} | 53 ~TestCustomView() override {} |
39 | 54 |
40 void Reset() { | 55 void Reset() { |
41 mouse_event_count_ = 0; | 56 mouse_event_count_ = 0; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 241 |
227 void KeyPress(ui::KeyboardCode key_code) { | 242 void KeyPress(ui::KeyboardCode key_code) { |
228 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); | 243 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); |
229 widget()->OnKeyEvent(&event); | 244 widget()->OnKeyEvent(&event); |
230 } | 245 } |
231 | 246 |
232 void UpdateNotificationViews() { | 247 void UpdateNotificationViews() { |
233 notification_view()->UpdateWithNotification(*notification()); | 248 notification_view()->UpdateWithNotification(*notification()); |
234 } | 249 } |
235 | 250 |
| 251 float GetNotificationScrollAmount() const { |
| 252 return notification_view_->GetTransform().To2dTranslation().x(); |
| 253 } |
| 254 |
236 TestMessageCenterController* controller() { return &controller_; } | 255 TestMessageCenterController* controller() { return &controller_; } |
237 Notification* notification() { return notification_.get(); } | 256 Notification* notification() { return notification_.get(); } |
238 TestCustomView* custom_view() { | 257 TestCustomView* custom_view() { |
239 return static_cast<TestCustomView*>(notification_view_->contents_view_); | 258 return static_cast<TestCustomView*>(notification_view_->contents_view_); |
240 } | 259 } |
241 views::Widget* widget() { return notification_view_->GetWidget(); } | 260 views::Widget* widget() { return notification_view_->GetWidget(); } |
242 CustomNotificationView* notification_view() { | 261 CustomNotificationView* notification_view() { |
243 return notification_view_.get(); | 262 return notification_view_.get(); |
244 } | 263 } |
245 | 264 |
(...skipping 23 matching lines...) Expand all Loading... |
269 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 288 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
270 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 289 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
271 widget()->OnMouseEvent(&move); | 290 widget()->OnMouseEvent(&move); |
272 EXPECT_EQ(3, custom_view()->mouse_event_count()); | 291 EXPECT_EQ(3, custom_view()->mouse_event_count()); |
273 | 292 |
274 EXPECT_EQ(0, custom_view()->keyboard_event_count()); | 293 EXPECT_EQ(0, custom_view()->keyboard_event_count()); |
275 KeyPress(ui::VKEY_A); | 294 KeyPress(ui::VKEY_A); |
276 EXPECT_EQ(1, custom_view()->keyboard_event_count()); | 295 EXPECT_EQ(1, custom_view()->keyboard_event_count()); |
277 } | 296 } |
278 | 297 |
| 298 TEST_F(CustomNotificationViewTest, SlideOut) { |
| 299 UpdateNotificationViews(); |
| 300 std::string notification_id = notification()->id(); |
| 301 |
| 302 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
| 303 auto event_scroll10 = GenerateGestureHorizontalScrollUpdateEvent(-10); |
| 304 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500); |
| 305 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
| 306 |
| 307 notification_view()->OnGestureEvent(event_begin.get()); |
| 308 notification_view()->OnGestureEvent(event_scroll10.get()); |
| 309 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 310 EXPECT_EQ(-10.f, GetNotificationScrollAmount()); |
| 311 notification_view()->OnGestureEvent(event_end.get()); |
| 312 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 313 EXPECT_EQ(0.f, GetNotificationScrollAmount()); |
| 314 |
| 315 notification_view()->OnGestureEvent(event_begin.get()); |
| 316 notification_view()->OnGestureEvent(event_scroll500.get()); |
| 317 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 318 EXPECT_EQ(-500.f, GetNotificationScrollAmount()); |
| 319 notification_view()->OnGestureEvent(event_end.get()); |
| 320 EXPECT_TRUE(controller()->IsRemoved(notification_id)); |
| 321 } |
| 322 |
| 323 // Pinning notification is ChromeOS only feature. |
| 324 #if defined(OS_CHROMEOS) |
| 325 |
| 326 TEST_F(CustomNotificationViewTest, SlideOutPinned) { |
| 327 notification()->set_pinned(true); |
| 328 UpdateNotificationViews(); |
| 329 std::string notification_id = notification()->id(); |
| 330 |
| 331 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
| 332 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500); |
| 333 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
| 334 |
| 335 notification_view()->OnGestureEvent(event_begin.get()); |
| 336 notification_view()->OnGestureEvent(event_scroll500.get()); |
| 337 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 338 EXPECT_LT(-500.f, GetNotificationScrollAmount()); |
| 339 notification_view()->OnGestureEvent(event_end.get()); |
| 340 EXPECT_FALSE(controller()->IsRemoved(notification_id)); |
| 341 } |
| 342 |
| 343 #endif // defined(OS_CHROMEOS) |
| 344 |
279 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { | 345 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { |
280 std::string notification_id = notification()->id(); | 346 std::string notification_id = notification()->id(); |
281 custom_view()->RequestFocus(); | 347 custom_view()->RequestFocus(); |
282 | 348 |
283 ui::InputMethod* input_method = custom_view()->GetInputMethod(); | 349 ui::InputMethod* input_method = custom_view()->GetInputMethod(); |
284 ASSERT_TRUE(input_method); | 350 ASSERT_TRUE(input_method); |
285 TestTextInputClient text_input_client; | 351 TestTextInputClient text_input_client; |
286 input_method->SetFocusedTextInputClient(&text_input_client); | 352 input_method->SetFocusedTextInputClient(&text_input_client); |
287 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); | 353 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); |
288 | 354 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 EXPECT_EQ("360x10", size.ToString()); | 391 EXPECT_EQ("360x10", size.ToString()); |
326 | 392 |
327 // The long notification. | 393 // The long notification. |
328 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); | 394 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); |
329 size = notification_view()->GetPreferredSize(); | 395 size = notification_view()->GetPreferredSize(); |
330 size.Enlarge(0, -notification_view()->GetInsets().height()); | 396 size.Enlarge(0, -notification_view()->GetInsets().height()); |
331 EXPECT_EQ("360x1000", size.ToString()); | 397 EXPECT_EQ("360x1000", size.ToString()); |
332 } | 398 } |
333 | 399 |
334 } // namespace message_center | 400 } // namespace message_center |
OLD | NEW |