| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| 41 #include "ui/views/layout/fill_layout.h" | 41 #include "ui/views/layout/fill_layout.h" |
| 42 #include "ui/views/view.h" | 42 #include "ui/views/view.h" |
| 43 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 44 | 44 |
| 45 namespace ash { | 45 namespace ash { |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 WebNotificationTray* GetTray() { | 49 WebNotificationTray* GetTray() { |
| 50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()-> | 50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() |
| 51 web_notification_tray(); | 51 ->web_notification_tray(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 WebNotificationTray* GetSecondaryTray() { | 54 WebNotificationTray* GetSecondaryTray() { |
| 55 StatusAreaWidget* status_area_widget = | 55 StatusAreaWidget* status_area_widget = |
| 56 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget(); | 56 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget(); |
| 57 if (status_area_widget) | 57 if (status_area_widget) |
| 58 return status_area_widget->web_notification_tray(); | 58 return status_area_widget->web_notification_tray(); |
| 59 return NULL; | 59 return NULL; |
| 60 } | 60 } |
| 61 | 61 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 base::ASCIIToUTF16("www.test.org"), GURL(), | 123 base::ASCIIToUTF16("www.test.org"), GURL(), |
| 124 message_center::NotifierId(), message_center::RichNotificationData(), | 124 message_center::NotifierId(), message_center::RichNotificationData(), |
| 125 NULL /* delegate */)); | 125 NULL /* delegate */)); |
| 126 GetMessageCenter()->UpdateNotification(old_id, std::move(notification)); | 126 GetMessageCenter()->UpdateNotification(old_id, std::move(notification)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void RemoveNotification(const std::string& id) { | 129 void RemoveNotification(const std::string& id) { |
| 130 GetMessageCenter()->RemoveNotification(id, false); | 130 GetMessageCenter()->RemoveNotification(id, false); |
| 131 } | 131 } |
| 132 | 132 |
| 133 views::Widget* GetWidget() { | 133 views::Widget* GetWidget() { return GetTray()->GetWidget(); } |
| 134 return GetTray()->GetWidget(); | |
| 135 } | |
| 136 | 134 |
| 137 int GetPopupWorkAreaBottom() { | 135 int GetPopupWorkAreaBottom() { |
| 138 return GetPopupWorkAreaBottomForTray(GetTray()); | 136 return GetPopupWorkAreaBottomForTray(GetTray()); |
| 139 } | 137 } |
| 140 | 138 |
| 141 int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) { | 139 int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) { |
| 142 return tray->popup_alignment_delegate_->GetWorkAreaBottom(); | 140 return tray->popup_alignment_delegate_->GetWorkAreaBottom(); |
| 143 } | 141 } |
| 144 | 142 |
| 145 bool IsPopupVisible() { | 143 bool IsPopupVisible() { return GetTray()->IsPopupVisible(); } |
| 146 return GetTray()->IsPopupVisible(); | |
| 147 } | |
| 148 | 144 |
| 149 std::unique_ptr<views::Widget> CreateTestWidget() { | 145 std::unique_ptr<views::Widget> CreateTestWidget() { |
| 150 std::unique_ptr<views::Widget> widget(new views::Widget); | 146 std::unique_ptr<views::Widget> widget(new views::Widget); |
| 151 views::Widget::InitParams params; | 147 views::Widget::InitParams params; |
| 152 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 148 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 153 params.bounds = gfx::Rect(1, 2, 3, 4); | 149 params.bounds = gfx::Rect(1, 2, 3, 4); |
| 154 WmShell::Get() | 150 WmShell::Get() |
| 155 ->GetPrimaryRootWindow() | 151 ->GetPrimaryRootWindow() |
| 156 ->GetRootWindowController() | 152 ->GetRootWindowController() |
| 157 ->ConfigureWidgetInitParamsForContainer( | 153 ->ConfigureWidgetInitParamsForContainer( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 218 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 223 | 219 |
| 224 GetTray()->message_center_tray_->ShowMessageCenterBubble(); | 220 GetTray()->message_center_tray_->ShowMessageCenterBubble(); |
| 225 GetTray()->message_center_tray_->HideMessageCenterBubble(); | 221 GetTray()->message_center_tray_->HideMessageCenterBubble(); |
| 226 | 222 |
| 227 EXPECT_FALSE(GetTray()->IsPopupVisible()); | 223 EXPECT_FALSE(GetTray()->IsPopupVisible()); |
| 228 } | 224 } |
| 229 | 225 |
| 230 using message_center::NotificationList; | 226 using message_center::NotificationList; |
| 231 | 227 |
| 232 | |
| 233 // Flakily fails. http://crbug.com/229791 | 228 // Flakily fails. http://crbug.com/229791 |
| 234 TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) { | 229 TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) { |
| 235 // Add the max visible notifications +1, ensure the correct visible number. | 230 // Add the max visible notifications +1, ensure the correct visible number. |
| 236 size_t notifications_to_add = | 231 size_t notifications_to_add = |
| 237 message_center::kMaxVisibleMessageCenterNotifications + 1; | 232 message_center::kMaxVisibleMessageCenterNotifications + 1; |
| 238 for (size_t i = 0; i < notifications_to_add; ++i) { | 233 for (size_t i = 0; i < notifications_to_add; ++i) { |
| 239 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); | 234 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); |
| 240 AddNotification(id); | 235 AddNotification(id); |
| 241 } | 236 } |
| 242 bool shown = GetTray()->message_center_tray_->ShowMessageCenterBubble(); | 237 bool shown = GetTray()->message_center_tray_->ShowMessageCenterBubble(); |
| 243 EXPECT_TRUE(shown); | 238 EXPECT_TRUE(shown); |
| 244 RunAllPendingInMessageLoop(); | 239 RunAllPendingInMessageLoop(); |
| 245 EXPECT_TRUE(GetTray()->message_center_bubble() != NULL); | 240 EXPECT_TRUE(GetTray()->message_center_bubble() != NULL); |
| 246 EXPECT_EQ(notifications_to_add, | 241 EXPECT_EQ(notifications_to_add, GetMessageCenter()->NotificationCount()); |
| 247 GetMessageCenter()->NotificationCount()); | 242 EXPECT_EQ( |
| 248 EXPECT_EQ(message_center::kMaxVisibleMessageCenterNotifications, | 243 message_center::kMaxVisibleMessageCenterNotifications, |
| 249 GetTray()->GetMessageCenterBubbleForTest()-> | 244 GetTray()->GetMessageCenterBubbleForTest()->NumMessageViewsForTest()); |
| 250 NumMessageViewsForTest()); | |
| 251 } | 245 } |
| 252 | 246 |
| 253 // Flakily times out. http://crbug.com/229792 | 247 // Flakily times out. http://crbug.com/229792 |
| 254 TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) { | 248 TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) { |
| 255 // Add the max visible popup notifications +1, ensure the correct num visible. | 249 // Add the max visible popup notifications +1, ensure the correct num visible. |
| 256 size_t notifications_to_add = | 250 size_t notifications_to_add = |
| 257 message_center::kMaxVisiblePopupNotifications + 1; | 251 message_center::kMaxVisiblePopupNotifications + 1; |
| 258 for (size_t i = 0; i < notifications_to_add; ++i) { | 252 for (size_t i = 0; i < notifications_to_add; ++i) { |
| 259 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); | 253 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); |
| 260 AddNotification(id); | 254 AddNotification(id); |
| 261 } | 255 } |
| 262 GetTray()->ShowPopups(); | 256 GetTray()->ShowPopups(); |
| 263 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 257 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 264 EXPECT_EQ(notifications_to_add, | 258 EXPECT_EQ(notifications_to_add, GetMessageCenter()->NotificationCount()); |
| 265 GetMessageCenter()->NotificationCount()); | |
| 266 NotificationList::PopupNotifications popups = | 259 NotificationList::PopupNotifications popups = |
| 267 GetMessageCenter()->GetPopupNotifications(); | 260 GetMessageCenter()->GetPopupNotifications(); |
| 268 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); | 261 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); |
| 269 } | 262 } |
| 270 | 263 |
| 271 #if defined(OS_CHROMEOS) | 264 #if defined(OS_CHROMEOS) |
| 272 // Display notification is ChromeOS only. | 265 // Display notification is ChromeOS only. |
| 273 #define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays | 266 #define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays |
| 274 #define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay | 267 #define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay |
| 275 #else | 268 #else |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 484 |
| 492 ui::test::EventGenerator& generator = GetEventGenerator(); | 485 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 493 const int touch_id = 0; | 486 const int touch_id = 0; |
| 494 gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint(); | 487 gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint(); |
| 495 | 488 |
| 496 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, | 489 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, |
| 497 generator.Now()); | 490 generator.Now()); |
| 498 generator.Dispatch(&press); | 491 generator.Dispatch(&press); |
| 499 EXPECT_TRUE(tray->draw_background_as_active()); | 492 EXPECT_TRUE(tray->draw_background_as_active()); |
| 500 | 493 |
| 501 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id, | 494 ui::TouchEvent release( |
| 495 ui::ET_TOUCH_RELEASED, center_point, touch_id, |
| 502 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); | 496 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 503 generator.Dispatch(&release); | 497 generator.Dispatch(&release); |
| 504 EXPECT_TRUE(tray->draw_background_as_active()); | 498 EXPECT_TRUE(tray->draw_background_as_active()); |
| 505 EXPECT_TRUE(tray->IsMessageCenterBubbleVisible()); | 499 EXPECT_TRUE(tray->IsMessageCenterBubbleVisible()); |
| 506 | 500 |
| 507 generator.GestureTapAt(center_point); | 501 generator.GestureTapAt(center_point); |
| 508 EXPECT_FALSE(tray->draw_background_as_active()); | 502 EXPECT_FALSE(tray->draw_background_as_active()); |
| 509 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | 503 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); |
| 510 } | 504 } |
| 511 | 505 |
| 512 // Tests that while touch presses trigger visual feedback, that subsequent non | 506 // Tests that while touch presses trigger visual feedback, that subsequent non |
| 513 // tap gestures cancel the feedback without triggering the message center. | 507 // tap gestures cancel the feedback without triggering the message center. |
| 514 TEST_F(WebNotificationTrayTest, TouchFeedbackCancellation) { | 508 TEST_F(WebNotificationTrayTest, TouchFeedbackCancellation) { |
| 515 AddNotification("test_id"); | 509 AddNotification("test_id"); |
| 516 RunAllPendingInMessageLoop(); | 510 RunAllPendingInMessageLoop(); |
| 517 WebNotificationTray* tray = GetTray(); | 511 WebNotificationTray* tray = GetTray(); |
| 518 EXPECT_TRUE(tray->visible()); | 512 EXPECT_TRUE(tray->visible()); |
| 519 | 513 |
| 520 ui::test::EventGenerator& generator = GetEventGenerator(); | 514 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 521 const int touch_id = 0; | 515 const int touch_id = 0; |
| 522 gfx::Rect bounds = tray->GetBoundsInScreen(); | 516 gfx::Rect bounds = tray->GetBoundsInScreen(); |
| 523 gfx::Point center_point = bounds.CenterPoint(); | 517 gfx::Point center_point = bounds.CenterPoint(); |
| 524 | 518 |
| 525 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, | 519 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id, |
| 526 generator.Now()); | 520 generator.Now()); |
| 527 generator.Dispatch(&press); | 521 generator.Dispatch(&press); |
| 528 EXPECT_TRUE(tray->draw_background_as_active()); | 522 EXPECT_TRUE(tray->draw_background_as_active()); |
| 529 | 523 |
| 530 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); | 524 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); |
| 531 ui::TouchEvent move(ui::ET_TOUCH_MOVED, out_of_bounds, touch_id, | 525 ui::TouchEvent move( |
| 532 press.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | 526 ui::ET_TOUCH_MOVED, out_of_bounds, touch_id, |
| 527 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 533 generator.Dispatch(&move); | 528 generator.Dispatch(&move); |
| 534 EXPECT_FALSE(tray->draw_background_as_active()); | 529 EXPECT_FALSE(tray->draw_background_as_active()); |
| 535 | 530 |
| 536 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id, | 531 ui::TouchEvent release( |
| 537 move.time_stamp()+base::TimeDelta::FromMilliseconds(50)); | 532 ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id, |
| 533 move.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 538 generator.Dispatch(&release); | 534 generator.Dispatch(&release); |
| 539 EXPECT_FALSE(tray->draw_background_as_active()); | 535 EXPECT_FALSE(tray->draw_background_as_active()); |
| 540 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | 536 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); |
| 541 } | 537 } |
| 542 | 538 |
| 543 #endif // OS_CHROMEOS | 539 #endif // OS_CHROMEOS |
| 544 | 540 |
| 545 } // namespace ash | 541 } // namespace ash |
| OLD | NEW |