Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | |
| 9 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 10 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/system_tray_item.h" | 17 #include "ash/system/tray/system_tray_item.h" |
| 17 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 18 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 18 #include "ash/test/ash_test_base.h" | 19 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/status_area_widget_test_helper.h" | 20 #include "ash/test/status_area_widget_test_helper.h" |
| 20 #include "ash/test/test_system_tray_delegate.h" | 21 #include "ash/test/test_system_tray_delegate.h" |
| 22 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
| 21 #include "ash/wm/window_state.h" | 23 #include "ash/wm/window_state.h" |
| 24 #include "base/command_line.h" | |
| 22 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 24 #include "ui/aura/client/aura_constants.h" | 27 #include "ui/aura/client/aura_constants.h" |
| 25 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 29 #include "ui/events/event.h" | |
| 26 #include "ui/events/test/event_generator.h" | 30 #include "ui/events/test/event_generator.h" |
| 27 #include "ui/gfx/display.h" | 31 #include "ui/gfx/display.h" |
| 32 #include "ui/gfx/point.h" | |
| 33 #include "ui/gfx/rect.h" | |
| 28 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 29 #include "ui/message_center/message_center_style.h" | 35 #include "ui/message_center/message_center_style.h" |
| 30 #include "ui/message_center/message_center_tray.h" | 36 #include "ui/message_center/message_center_tray.h" |
| 31 #include "ui/message_center/notification_list.h" | 37 #include "ui/message_center/notification_list.h" |
| 32 #include "ui/message_center/notification_types.h" | 38 #include "ui/message_center/notification_types.h" |
| 33 #include "ui/message_center/views/message_center_bubble.h" | 39 #include "ui/message_center/views/message_center_bubble.h" |
| 34 #include "ui/message_center/views/message_popup_collection.h" | 40 #include "ui/message_center/views/message_popup_collection.h" |
| 35 #include "ui/views/controls/label.h" | 41 #include "ui/views/controls/label.h" |
| 36 #include "ui/views/layout/fill_layout.h" | 42 #include "ui/views/layout/fill_layout.h" |
| 37 #include "ui/views/view.h" | 43 #include "ui/views/view.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 DISALLOW_COPY_AND_ASSIGN(TestItem); | 89 DISALLOW_COPY_AND_ASSIGN(TestItem); |
| 84 }; | 90 }; |
| 85 | 91 |
| 86 } // namespace | 92 } // namespace |
| 87 | 93 |
| 88 class WebNotificationTrayTest : public test::AshTestBase { | 94 class WebNotificationTrayTest : public test::AshTestBase { |
| 89 public: | 95 public: |
| 90 WebNotificationTrayTest() {} | 96 WebNotificationTrayTest() {} |
| 91 virtual ~WebNotificationTrayTest() {} | 97 virtual ~WebNotificationTrayTest() {} |
| 92 | 98 |
| 99 #if defined(OS_CHROMEOS) | |
| 100 virtual void SetUp() OVERRIDE { | |
| 101 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 102 switches::kAshEnableTouchViewTouchFeedback); | |
| 103 test::AshTestBase::SetUp(); | |
| 104 } | |
| 105 #endif | |
| 106 | |
| 93 virtual void TearDown() OVERRIDE { | 107 virtual void TearDown() OVERRIDE { |
| 94 GetMessageCenter()->RemoveAllNotifications(false); | 108 GetMessageCenter()->RemoveAllNotifications(false); |
| 95 test::AshTestBase::TearDown(); | 109 test::AshTestBase::TearDown(); |
| 96 } | 110 } |
| 97 | 111 |
| 98 protected: | 112 protected: |
| 99 void AddNotification(const std::string& id) { | 113 void AddNotification(const std::string& id) { |
| 100 scoped_ptr<message_center::Notification> notification; | 114 scoped_ptr<message_center::Notification> notification; |
| 101 notification.reset(new message_center::Notification( | 115 notification.reset(new message_center::Notification( |
| 102 message_center::NOTIFICATION_TYPE_SIMPLE, | 116 message_center::NOTIFICATION_TYPE_SIMPLE, |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 int bottom = GetPopupWorkAreaBottom(); | 474 int bottom = GetPopupWorkAreaBottom(); |
| 461 int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray()); | 475 int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray()); |
| 462 | 476 |
| 463 // System tray is created on the primary display. The popups in the secondary | 477 // System tray is created on the primary display. The popups in the secondary |
| 464 // tray aren't affected. | 478 // tray aren't affected. |
| 465 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 479 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 466 EXPECT_GT(bottom, GetPopupWorkAreaBottom()); | 480 EXPECT_GT(bottom, GetPopupWorkAreaBottom()); |
| 467 EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray())); | 481 EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray())); |
| 468 } | 482 } |
| 469 | 483 |
| 484 // TODO(jonross): Replace manually creating TouchEvent with | |
| 485 // EventGenerator.PressTouch/ReleaseTouch. Currently they set a width on the | |
| 486 // touch event causing the gesture recognizer to target a different view. | |
| 487 #if defined(OS_CHROMEOS) | |
| 488 #define MAYBE_NoTouchFeedback NoTouchFeedback | |
| 489 #define MAYBE_MaximizeModeTouchFeedback MaximizeModeTouchFeedback | |
| 490 #define MAYBE_TouchFeedbackCancellation TouchFeedbackCancellation | |
|
flackr
2014/08/29 15:34:10
Assuming we do want this CHROMEOS only I'd just pu
jonross
2014/08/29 17:20:21
Done.
| |
| 491 #else | |
| 492 #define MAYBE_NoTouchFeedback DISABLED_NoTouchFeedback | |
| 493 #define MAYBE_MaximizeModeTouchFeedback DISABLED_MaximizeModeTouchFeedback | |
| 494 #define MAYBE_TouchFeedbackCancellation DISABLED_TouchFeedbackCancellation | |
| 495 #endif | |
| 496 // Tests that while there is no visual feedback for touch presses while in | |
| 497 // normal mode. | |
| 498 TEST_F(WebNotificationTrayTest, MAYBE_NoTouchFeedback) { | |
| 499 AddNotification("test_id"); | |
| 500 RunAllPendingInMessageLoop(); | |
| 501 WebNotificationTray* tray = GetTray(); | |
| 502 EXPECT_TRUE(tray->visible()); | |
| 503 | |
| 504 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 505 const int touch_id = 0; | |
| 506 gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint(); | |
| 507 | |
| 508 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, | |
| 509 generator.Now()); | |
| 510 generator.Dispatch(&press); | |
| 511 RunAllPendingInMessageLoop(); | |
| 512 EXPECT_FALSE(tray->draw_background_as_active()); | |
| 513 | |
| 514 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id, | |
| 515 press.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | |
| 516 generator.Dispatch(&release); | |
| 517 RunAllPendingInMessageLoop(); | |
| 518 EXPECT_TRUE(tray->draw_background_as_active()); | |
| 519 EXPECT_TRUE(tray->IsMessageCenterBubbleVisible()); | |
| 520 | |
| 521 generator.GestureTapAt(center_point); | |
| 522 RunAllPendingInMessageLoop(); | |
| 523 EXPECT_FALSE(tray->draw_background_as_active()); | |
| 524 } | |
| 525 | |
| 526 // Tests that while in MaximizeMode that there is visual feedback for touch | |
| 527 // presses. | |
| 528 TEST_F(WebNotificationTrayTest, MAYBE_MaximizeModeTouchFeedback) { | |
| 529 AddNotification("test_id"); | |
| 530 RunAllPendingInMessageLoop(); | |
| 531 WebNotificationTray* tray = GetTray(); | |
| 532 EXPECT_TRUE(tray->visible()); | |
| 533 | |
| 534 Shell::GetInstance()->maximize_mode_controller()-> | |
| 535 EnableMaximizeModeWindowManager(true); | |
| 536 | |
| 537 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 538 const int touch_id = 0; | |
| 539 gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint(); | |
| 540 | |
| 541 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, | |
| 542 generator.Now()); | |
| 543 generator.Dispatch(&press); | |
| 544 RunAllPendingInMessageLoop(); | |
| 545 EXPECT_TRUE(tray->draw_background_as_active()); | |
| 546 | |
| 547 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id, | |
| 548 press.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | |
| 549 generator.Dispatch(&release); | |
| 550 RunAllPendingInMessageLoop(); | |
| 551 EXPECT_TRUE(tray->draw_background_as_active()); | |
| 552 EXPECT_TRUE(tray->IsMessageCenterBubbleVisible()); | |
| 553 | |
| 554 generator.GestureTapAt(center_point); | |
| 555 RunAllPendingInMessageLoop(); | |
| 556 EXPECT_FALSE(tray->draw_background_as_active()); | |
| 557 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | |
| 558 } | |
| 559 | |
| 560 // Tests that while touch presses trigger visual feedback, that subsequent non | |
| 561 // tap gestures cancel the feedback without triggering the message center. | |
| 562 TEST_F(WebNotificationTrayTest, MAYBE_TouchFeedbackCancellation) { | |
| 563 AddNotification("test_id"); | |
| 564 RunAllPendingInMessageLoop(); | |
| 565 WebNotificationTray* tray = GetTray(); | |
| 566 EXPECT_TRUE(tray->visible()); | |
| 567 | |
| 568 Shell::GetInstance()->maximize_mode_controller()-> | |
| 569 EnableMaximizeModeWindowManager(true); | |
| 570 | |
| 571 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 572 const int touch_id = 0; | |
| 573 gfx::Rect bounds = tray->GetBoundsInScreen(); | |
| 574 gfx::Point center_point = bounds.CenterPoint(); | |
| 575 | |
| 576 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, | |
| 577 generator.Now()); | |
| 578 generator.Dispatch(&press); | |
| 579 RunAllPendingInMessageLoop(); | |
| 580 EXPECT_TRUE(tray->draw_background_as_active()); | |
| 581 | |
| 582 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); | |
| 583 ui::TouchEvent move(ui::ET_TOUCH_MOVED, out_of_bounds, touch_id, | |
| 584 press.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | |
| 585 generator.Dispatch(&move); | |
| 586 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id, | |
| 587 move.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | |
| 588 generator.Dispatch(&release); | |
| 589 RunAllPendingInMessageLoop(); | |
| 590 EXPECT_FALSE(tray->draw_background_as_active()); | |
| 591 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | |
| 592 } | |
| 593 | |
| 470 } // namespace ash | 594 } // namespace ash |
| OLD | NEW |