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/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" |
11 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
13 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_item.h" | 16 #include "ash/system/tray/system_tray_item.h" |
15 #include "ash/system/tray/test_system_tray_delegate.h" | 17 #include "ash/system/tray/test_system_tray_delegate.h" |
16 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
19 #include "ui/message_center/message_center_style.h" | 21 #include "ui/message_center/message_center_style.h" |
20 #include "ui/message_center/message_center_tray.h" | 22 #include "ui/message_center/message_center_tray.h" |
21 #include "ui/message_center/message_center_util.h" | 23 #include "ui/message_center/message_center_util.h" |
22 #include "ui/message_center/notification_list.h" | 24 #include "ui/message_center/notification_list.h" |
23 #include "ui/message_center/notification_types.h" | 25 #include "ui/message_center/notification_types.h" |
(...skipping 25 matching lines...) Expand all Loading... |
49 } | 51 } |
50 } | 52 } |
51 | 53 |
52 return NULL; | 54 return NULL; |
53 } | 55 } |
54 | 56 |
55 message_center::MessageCenter* GetMessageCenter() { | 57 message_center::MessageCenter* GetMessageCenter() { |
56 return GetTray()->message_center(); | 58 return GetTray()->message_center(); |
57 } | 59 } |
58 | 60 |
| 61 SystemTray* GetSystemTray() { |
| 62 return Shell::GetPrimaryRootWindowController()->shelf()-> |
| 63 status_area_widget()->system_tray(); |
| 64 } |
| 65 |
| 66 // Trivial item implementation for testing PopupAndSystemTray test case. |
| 67 class TestItem : public SystemTrayItem { |
| 68 public: |
| 69 TestItem() : SystemTrayItem(GetSystemTray()) {} |
| 70 |
| 71 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { |
| 72 views::View* default_view = new views::View; |
| 73 default_view->SetLayoutManager(new views::FillLayout); |
| 74 default_view->AddChildView(new views::Label(UTF8ToUTF16("Default"))); |
| 75 return default_view; |
| 76 } |
| 77 |
| 78 virtual views::View* CreateNotificationView( |
| 79 user::LoginStatus status) OVERRIDE { |
| 80 return new views::View; |
| 81 } |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(TestItem); |
| 85 }; |
| 86 |
| 87 } // namespace |
| 88 |
59 class WebNotificationTrayTest : public test::AshTestBase { | 89 class WebNotificationTrayTest : public test::AshTestBase { |
60 public: | 90 public: |
61 WebNotificationTrayTest() {} | 91 WebNotificationTrayTest() {} |
62 virtual ~WebNotificationTrayTest() {} | 92 virtual ~WebNotificationTrayTest() {} |
63 | 93 |
64 virtual void TearDown() OVERRIDE { | 94 virtual void TearDown() OVERRIDE { |
65 GetMessageCenter()->RemoveAllNotifications(false); | 95 GetMessageCenter()->RemoveAllNotifications(false); |
66 test::AshTestBase::TearDown(); | 96 test::AshTestBase::TearDown(); |
67 } | 97 } |
68 | 98 |
(...skipping 30 matching lines...) Expand all Loading... |
99 } | 129 } |
100 | 130 |
101 void RemoveNotification(const std::string& id) { | 131 void RemoveNotification(const std::string& id) { |
102 GetMessageCenter()->RemoveNotification(id, false); | 132 GetMessageCenter()->RemoveNotification(id, false); |
103 } | 133 } |
104 | 134 |
105 views::Widget* GetWidget() { | 135 views::Widget* GetWidget() { |
106 return GetTray()->GetWidget(); | 136 return GetTray()->GetWidget(); |
107 } | 137 } |
108 | 138 |
| 139 gfx::Rect GetPopupWorkArea() { |
| 140 return GetPopupWorkAreaForTray(GetTray()); |
| 141 } |
| 142 |
| 143 gfx::Rect GetPopupWorkAreaForTray(WebNotificationTray* tray) { |
| 144 return tray->popup_collection_->work_area_; |
| 145 } |
| 146 |
109 private: | 147 private: |
110 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); | 148 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); |
111 }; | 149 }; |
112 | 150 |
113 } // namespace | |
114 | |
115 TEST_F(WebNotificationTrayTest, WebNotifications) { | 151 TEST_F(WebNotificationTrayTest, WebNotifications) { |
116 // TODO(mukai): move this test case to ui/message_center. | 152 // TODO(mukai): move this test case to ui/message_center. |
117 ASSERT_TRUE(GetWidget()); | 153 ASSERT_TRUE(GetWidget()); |
118 | 154 |
119 // Add a notification. | 155 // Add a notification. |
120 AddNotification("test_id1"); | 156 AddNotification("test_id1"); |
121 EXPECT_EQ(1u, GetMessageCenter()->NotificationCount()); | 157 EXPECT_EQ(1u, GetMessageCenter()->NotificationCount()); |
122 EXPECT_TRUE(GetMessageCenter()->HasNotification("test_id1")); | 158 EXPECT_TRUE(GetMessageCenter()->HasNotification("test_id1")); |
123 AddNotification("test_id2"); | 159 AddNotification("test_id2"); |
124 AddNotification("test_id2"); | 160 AddNotification("test_id2"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 225 |
190 // Flakily times out. http://crbug.com/229792 | 226 // Flakily times out. http://crbug.com/229792 |
191 TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) { | 227 TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) { |
192 // Add the max visible popup notifications +1, ensure the correct num visible. | 228 // Add the max visible popup notifications +1, ensure the correct num visible. |
193 size_t notifications_to_add = | 229 size_t notifications_to_add = |
194 message_center::kMaxVisiblePopupNotifications + 1; | 230 message_center::kMaxVisiblePopupNotifications + 1; |
195 for (size_t i = 0; i < notifications_to_add; ++i) { | 231 for (size_t i = 0; i < notifications_to_add; ++i) { |
196 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); | 232 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); |
197 AddNotification(id); | 233 AddNotification(id); |
198 } | 234 } |
199 // Hide and reshow the bubble so that it is updated immediately, not delayed. | 235 GetTray()->ShowPopups(); |
200 GetTray()->SetHidePopupBubble(true); | |
201 GetTray()->SetHidePopupBubble(false); | |
202 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 236 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
203 EXPECT_EQ(notifications_to_add, | 237 EXPECT_EQ(notifications_to_add, |
204 GetMessageCenter()->NotificationCount()); | 238 GetMessageCenter()->NotificationCount()); |
205 NotificationList::PopupNotifications popups = | 239 NotificationList::PopupNotifications popups = |
206 GetMessageCenter()->GetPopupNotifications(); | 240 GetMessageCenter()->GetPopupNotifications(); |
207 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); | 241 EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); |
208 } | 242 } |
209 | 243 |
210 #if defined(OS_CHROMEOS) | 244 #if defined(OS_CHROMEOS) |
211 // Display notification is ChromeOS only. | 245 // Display notification is ChromeOS only. |
212 #define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays | 246 #define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays |
| 247 #define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay |
213 #else | 248 #else |
214 #define MAYBE_PopupShownOnBothDisplays DISABLED_PopupShownOnBothDisplays | 249 #define MAYBE_PopupShownOnBothDisplays DISABLED_PopupShownOnBothDisplays |
| 250 #define MAYBE_PopupAndSystemTrayMultiDisplay \ |
| 251 DISABLED_PopupAndSystemTrayMultiDisplay |
215 #endif | 252 #endif |
216 | 253 |
217 // Verifies if the notification appears on both displays when extended mode. | 254 // Verifies if the notification appears on both displays when extended mode. |
218 TEST_F(WebNotificationTrayTest, MAYBE_PopupShownOnBothDisplays) { | 255 TEST_F(WebNotificationTrayTest, MAYBE_PopupShownOnBothDisplays) { |
219 if (!SupportsMultipleDisplays()) | 256 if (!SupportsMultipleDisplays()) |
220 return; | 257 return; |
221 | 258 |
222 // Enables to appear the notification for display changes. | 259 // Enables to appear the notification for display changes. |
223 test::TestSystemTrayDelegate* tray_delegate = | 260 test::TestSystemTrayDelegate* tray_delegate = |
224 static_cast<test::TestSystemTrayDelegate*>( | 261 static_cast<test::TestSystemTrayDelegate*>( |
(...skipping 20 matching lines...) Expand all Loading... |
245 EXPECT_FALSE(GetSecondaryTray()); | 282 EXPECT_FALSE(GetSecondaryTray()); |
246 | 283 |
247 display_manager->SetSoftwareMirroring(false); | 284 display_manager->SetSoftwareMirroring(false); |
248 UpdateDisplay("400x400,200x200"); | 285 UpdateDisplay("400x400,200x200"); |
249 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 286 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
250 secondary_tray = GetSecondaryTray(); | 287 secondary_tray = GetSecondaryTray(); |
251 ASSERT_TRUE(secondary_tray); | 288 ASSERT_TRUE(secondary_tray); |
252 EXPECT_TRUE(secondary_tray->IsPopupVisible()); | 289 EXPECT_TRUE(secondary_tray->IsPopupVisible()); |
253 } | 290 } |
254 | 291 |
| 292 #if defined(OS_CHROMEOS) |
| 293 // PopupAndSystemTray may fail in platforms other than ChromeOS because the |
| 294 // RootWindow's bound can be bigger than gfx::Display's work area so that |
| 295 // openingsystem tray doesn't affect at all the work area of popups. |
| 296 #define MAYBE_PopupAndSystemTray PopupAndSystemTray |
| 297 #else |
| 298 #define MAYBE_PopupAndSystemTray DISABLED_PopupAndSystemTray |
| 299 #endif |
| 300 |
| 301 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) { |
| 302 TestItem* test_item = new TestItem; |
| 303 GetSystemTray()->AddTrayItem(test_item); |
| 304 |
| 305 AddNotification("test_id"); |
| 306 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 307 gfx::Rect work_area = GetPopupWorkArea(); |
| 308 |
| 309 // System tray is created, the popup's work area should be narrowed but still |
| 310 // visible. |
| 311 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 312 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 313 gfx::Rect work_area_with_tray = GetPopupWorkArea(); |
| 314 EXPECT_GT(work_area.size().GetArea(), work_area_with_tray.size().GetArea()); |
| 315 |
| 316 // System tray notification is also created, the popup's work area is narrowed |
| 317 // even more, but still visible. |
| 318 GetSystemTray()->ShowNotificationView(test_item); |
| 319 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 320 gfx::Rect work_area_with_tray_notificaiton = GetPopupWorkArea(); |
| 321 EXPECT_GT(work_area.size().GetArea(), |
| 322 work_area_with_tray_notificaiton.size().GetArea()); |
| 323 EXPECT_GT(work_area_with_tray.size().GetArea(), |
| 324 work_area_with_tray_notificaiton.size().GetArea()); |
| 325 |
| 326 // Close system tray, only system tray notifications. |
| 327 GetSystemTray()->ClickedOutsideBubble(); |
| 328 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 329 gfx::Rect work_area_with_notification = GetPopupWorkArea(); |
| 330 EXPECT_GT(work_area.size().GetArea(), |
| 331 work_area_with_notification.size().GetArea()); |
| 332 EXPECT_LT(work_area_with_tray_notificaiton.size().GetArea(), |
| 333 work_area_with_notification.size().GetArea()); |
| 334 |
| 335 // Close the notifications. |
| 336 GetSystemTray()->HideNotificationView(test_item); |
| 337 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 338 EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); |
| 339 } |
| 340 |
| 341 TEST_F(WebNotificationTrayTest, PopupAndSystemTrayAlignment) { |
| 342 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> |
| 343 SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 344 AddNotification("test_id"); |
| 345 gfx::Rect work_area = GetPopupWorkArea(); |
| 346 |
| 347 // System tray is created, but the work area is not affected since the tray |
| 348 // appears at the left-bottom while the popups appear at the right bottom. |
| 349 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 350 EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); |
| 351 } |
| 352 |
| 353 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) { |
| 354 UpdateDisplay("800x600,600x400"); |
| 355 |
| 356 AddNotification("test_id"); |
| 357 gfx::Rect work_area = GetPopupWorkArea(); |
| 358 gfx::Rect work_area_second = GetPopupWorkAreaForTray(GetSecondaryTray()); |
| 359 |
| 360 // System tray is created on the primary display. The popups in the secondary |
| 361 // tray aren't affected. |
| 362 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 363 EXPECT_GT(work_area.size().GetArea(), GetPopupWorkArea().size().GetArea()); |
| 364 EXPECT_EQ(work_area_second.ToString(), |
| 365 GetPopupWorkAreaForTray(GetSecondaryTray()).ToString()); |
| 366 } |
| 367 |
255 } // namespace ash | 368 } // namespace ash |
OLD | NEW |