| 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/common/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/shelf/shelf_layout_manager.h" | 11 #include "ash/common/shelf/shelf_layout_manager.h" |
| 12 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
| 13 #include "ash/common/system/status_area_widget.h" | 13 #include "ash/common/system/status_area_widget.h" |
| 14 #include "ash/common/system/tray/system_tray.h" | 14 #include "ash/common/system/tray/system_tray.h" |
| 15 #include "ash/common/system/tray/system_tray_item.h" | 15 #include "ash/common/system/tray/system_tray_item.h" |
| 16 #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" | 16 #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" |
| 17 #include "ash/common/test/test_system_tray_delegate.h" | 17 #include "ash/common/test/test_system_tray_delegate.h" |
| 18 #include "ash/common/wm/window_state.h" | 18 #include "ash/common/wm/window_state.h" |
| 19 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
| 20 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
| 21 #include "ash/public/cpp/shell_window_ids.h" | 21 #include "ash/public/cpp/shell_window_ids.h" |
| 22 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 23 #include "ash/system/chromeos/screen_layout_observer.h" |
| 23 #include "ash/test/ash_md_test_base.h" | 24 #include "ash/test/ash_md_test_base.h" |
| 24 #include "ash/test/status_area_widget_test_helper.h" | 25 #include "ash/test/status_area_widget_test_helper.h" |
| 25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "ui/display/display.h" | 28 #include "ui/display/display.h" |
| 28 #include "ui/display/manager/display_manager.h" | 29 #include "ui/display/manager/display_manager.h" |
| 29 #include "ui/display/screen.h" | 30 #include "ui/display/screen.h" |
| 30 #include "ui/events/test/event_generator.h" | 31 #include "ui/events/test/event_generator.h" |
| 31 #include "ui/gfx/geometry/point.h" | 32 #include "ui/gfx/geometry/point.h" |
| 32 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/message_center/message_center_style.h" | 34 #include "ui/message_center/message_center_style.h" |
| 34 #include "ui/message_center/message_center_tray.h" | 35 #include "ui/message_center/message_center_tray.h" |
| 35 #include "ui/message_center/notification_list.h" | 36 #include "ui/message_center/notification_list.h" |
| 36 #include "ui/message_center/notification_types.h" | 37 #include "ui/message_center/notification_types.h" |
| 37 #include "ui/message_center/views/message_center_bubble.h" | 38 #include "ui/message_center/views/message_center_bubble.h" |
| 38 #include "ui/message_center/views/message_popup_collection.h" | 39 #include "ui/message_center/views/message_popup_collection.h" |
| 39 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| 40 #include "ui/views/layout/fill_layout.h" | 41 #include "ui/views/layout/fill_layout.h" |
| 41 #include "ui/views/view.h" | 42 #include "ui/views/view.h" |
| 42 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 43 | 44 |
| 44 #if defined(OS_CHROMEOS) | |
| 45 #include "ash/system/chromeos/screen_layout_observer.h" | |
| 46 #endif | |
| 47 | |
| 48 namespace ash { | 45 namespace ash { |
| 49 | 46 |
| 50 namespace { | 47 namespace { |
| 51 | 48 |
| 52 WebNotificationTray* GetTray() { | 49 WebNotificationTray* GetTray() { |
| 53 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() | 50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() |
| 54 ->web_notification_tray(); | 51 ->web_notification_tray(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 #if defined(OS_CHROMEOS) | |
| 58 | |
| 59 WebNotificationTray* GetSecondaryTray() { | 54 WebNotificationTray* GetSecondaryTray() { |
| 60 StatusAreaWidget* status_area_widget = | 55 StatusAreaWidget* status_area_widget = |
| 61 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget(); | 56 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget(); |
| 62 if (status_area_widget) | 57 if (status_area_widget) |
| 63 return status_area_widget->web_notification_tray(); | 58 return status_area_widget->web_notification_tray(); |
| 64 return NULL; | 59 return NULL; |
| 65 } | 60 } |
| 66 | 61 |
| 67 #endif | |
| 68 | |
| 69 message_center::MessageCenter* GetMessageCenter() { | 62 message_center::MessageCenter* GetMessageCenter() { |
| 70 return GetTray()->message_center(); | 63 return GetTray()->message_center(); |
| 71 } | 64 } |
| 72 | 65 |
| 73 SystemTray* GetSystemTray() { | 66 SystemTray* GetSystemTray() { |
| 74 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray(); | 67 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray(); |
| 75 } | 68 } |
| 76 | 69 |
| 77 // Trivial item implementation for testing PopupAndSystemTray test case. | 70 // Trivial item implementation for testing PopupAndSystemTray test case. |
| 78 class TestItem : public SystemTrayItem { | 71 class TestItem : public SystemTrayItem { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 AddNotification(id); | 256 AddNotification(id); |
| 264 } | 257 } |
| 265 GetTray()->ShowPopups(); | 258 GetTray()->ShowPopups(); |
| 266 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 259 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 267 EXPECT_EQ(notifications_to_add, GetMessageCenter()->NotificationCount()); | 260 EXPECT_EQ(notifications_to_add, GetMessageCenter()->NotificationCount()); |
| 268 NotificationList::PopupNotifications popups = | 261 NotificationList::PopupNotifications popups = |
| 269 GetMessageCenter()->GetPopupNotifications(); | 262 GetMessageCenter()->GetPopupNotifications(); |
| 270 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); | 263 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); |
| 271 } | 264 } |
| 272 | 265 |
| 273 // Display notification is ChromeOS only. | |
| 274 #if defined(OS_CHROMEOS) | |
| 275 | |
| 276 // Verifies if the notification appears on both displays when extended mode. | 266 // Verifies if the notification appears on both displays when extended mode. |
| 277 TEST_P(WebNotificationTrayTest, PopupShownOnBothDisplays) { | 267 TEST_P(WebNotificationTrayTest, PopupShownOnBothDisplays) { |
| 278 if (!SupportsMultipleDisplays()) | 268 if (!SupportsMultipleDisplays()) |
| 279 return; | 269 return; |
| 280 | 270 |
| 281 Shell::GetInstance() | 271 Shell::GetInstance() |
| 282 ->screen_layout_observer() | 272 ->screen_layout_observer() |
| 283 ->set_show_notifications_for_testing(true); | 273 ->set_show_notifications_for_testing(true); |
| 284 UpdateDisplay("400x400,200x200"); | 274 UpdateDisplay("400x400,200x200"); |
| 285 // UpdateDisplay() creates the display notifications, so popup is visible. | 275 // UpdateDisplay() creates the display notifications, so popup is visible. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 299 EXPECT_FALSE(GetSecondaryTray()); | 289 EXPECT_FALSE(GetSecondaryTray()); |
| 300 | 290 |
| 301 display_manager()->SetMultiDisplayMode(display::DisplayManager::EXTENDED); | 291 display_manager()->SetMultiDisplayMode(display::DisplayManager::EXTENDED); |
| 302 UpdateDisplay("400x400,200x200"); | 292 UpdateDisplay("400x400,200x200"); |
| 303 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 293 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 304 secondary_tray = GetSecondaryTray(); | 294 secondary_tray = GetSecondaryTray(); |
| 305 ASSERT_TRUE(secondary_tray); | 295 ASSERT_TRUE(secondary_tray); |
| 306 EXPECT_TRUE(secondary_tray->IsPopupVisible()); | 296 EXPECT_TRUE(secondary_tray->IsPopupVisible()); |
| 307 } | 297 } |
| 308 | 298 |
| 309 #endif // defined(OS_CHROMEOS) | |
| 310 | |
| 311 // PopupAndSystemTray may fail in platforms other than ChromeOS because the | 299 // PopupAndSystemTray may fail in platforms other than ChromeOS because the |
| 312 // RootWindow's bound can be bigger than display::Display's work area so that | 300 // RootWindow's bound can be bigger than display::Display's work area so that |
| 313 // openingsystem tray doesn't affect at all the work area of popups. | 301 // openingsystem tray doesn't affect at all the work area of popups. |
| 314 #if defined(OS_CHROMEOS) | |
| 315 | |
| 316 TEST_P(WebNotificationTrayTest, PopupAndSystemTray) { | 302 TEST_P(WebNotificationTrayTest, PopupAndSystemTray) { |
| 317 TestItem* test_item = new TestItem; | 303 TestItem* test_item = new TestItem; |
| 318 GetSystemTray()->AddTrayItem(test_item); | 304 GetSystemTray()->AddTrayItem(test_item); |
| 319 | 305 |
| 320 AddNotification("test_id"); | 306 AddNotification("test_id"); |
| 321 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 307 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 322 int bottom = GetPopupWorkAreaBottom(); | 308 int bottom = GetPopupWorkAreaBottom(); |
| 323 | 309 |
| 324 // System tray is created, the popup's work area should be narrowed but still | 310 // System tray is created, the popup's work area should be narrowed but still |
| 325 // visible. | 311 // visible. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | 431 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); |
| 446 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); | 432 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); |
| 447 | 433 |
| 448 generator.MoveMouseTo( | 434 generator.MoveMouseTo( |
| 449 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint()); | 435 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint()); |
| 450 shelf->UpdateVisibilityState(); | 436 shelf->UpdateVisibilityState(); |
| 451 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 437 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 452 EXPECT_EQ(bottom_auto_hidden, GetPopupWorkAreaBottom()); | 438 EXPECT_EQ(bottom_auto_hidden, GetPopupWorkAreaBottom()); |
| 453 } | 439 } |
| 454 | 440 |
| 455 #endif // defined(OS_CHROMEOS) | |
| 456 | |
| 457 // Display notification is ChromeOS only. | |
| 458 #if defined(OS_CHROMEOS) | |
| 459 | |
| 460 TEST_P(WebNotificationTrayTest, PopupAndSystemTrayMultiDisplay) { | 441 TEST_P(WebNotificationTrayTest, PopupAndSystemTrayMultiDisplay) { |
| 461 UpdateDisplay("800x600,600x400"); | 442 UpdateDisplay("800x600,600x400"); |
| 462 | 443 |
| 463 AddNotification("test_id"); | 444 AddNotification("test_id"); |
| 464 int bottom = GetPopupWorkAreaBottom(); | 445 int bottom = GetPopupWorkAreaBottom(); |
| 465 int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray()); | 446 int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray()); |
| 466 | 447 |
| 467 // System tray is created on the primary display. The popups in the secondary | 448 // System tray is created on the primary display. The popups in the secondary |
| 468 // tray aren't affected. | 449 // tray aren't affected. |
| 469 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 450 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 470 EXPECT_GT(bottom, GetPopupWorkAreaBottom()); | 451 EXPECT_GT(bottom, GetPopupWorkAreaBottom()); |
| 471 EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray())); | 452 EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray())); |
| 472 } | 453 } |
| 473 | 454 |
| 474 #endif // defined(OS_CHROMEOS) | |
| 475 | |
| 476 #if defined(OS_CHROMEOS) | |
| 477 | |
| 478 // Tests that there is visual feedback for touch presses. | 455 // Tests that there is visual feedback for touch presses. |
| 479 TEST_P(WebNotificationTrayTest, TouchFeedback) { | 456 TEST_P(WebNotificationTrayTest, TouchFeedback) { |
| 480 // Touch feedback is not available in material mode. | 457 // Touch feedback is not available in material mode. |
| 481 if (MaterialDesignController::IsShelfMaterial()) | 458 if (MaterialDesignController::IsShelfMaterial()) |
| 482 return; | 459 return; |
| 483 | 460 |
| 484 AddNotification("test_id"); | 461 AddNotification("test_id"); |
| 485 RunAllPendingInMessageLoop(); | 462 RunAllPendingInMessageLoop(); |
| 486 WebNotificationTray* tray = GetTray(); | 463 WebNotificationTray* tray = GetTray(); |
| 487 EXPECT_TRUE(tray->visible()); | 464 EXPECT_TRUE(tray->visible()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 501 |
| 525 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); | 502 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); |
| 526 generator.MoveTouch(out_of_bounds); | 503 generator.MoveTouch(out_of_bounds); |
| 527 EXPECT_FALSE(tray->is_active()); | 504 EXPECT_FALSE(tray->is_active()); |
| 528 | 505 |
| 529 generator.ReleaseTouch(); | 506 generator.ReleaseTouch(); |
| 530 EXPECT_FALSE(tray->is_active()); | 507 EXPECT_FALSE(tray->is_active()); |
| 531 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | 508 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); |
| 532 } | 509 } |
| 533 | 510 |
| 534 #endif // OS_CHROMEOS | |
| 535 | |
| 536 } // namespace ash | 511 } // namespace ash |
| OLD | NEW |