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_layout_manager.h" |
12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
16 #include "ash/system/tray/system_tray_item.h" | 16 #include "ash/system/tray/system_tray_item.h" |
| 17 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
17 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
18 #include "ash/test/status_area_widget_test_helper.h" | 19 #include "ash/test/status_area_widget_test_helper.h" |
19 #include "ash/test/test_system_tray_delegate.h" | 20 #include "ash/test/test_system_tray_delegate.h" |
20 #include "ash/wm/window_state.h" | 21 #include "ash/wm/window_state.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
24 #include "ui/aura/test/event_generator.h" | 25 #include "ui/aura/test/event_generator.h" |
25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
26 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 128 } |
128 | 129 |
129 void RemoveNotification(const std::string& id) { | 130 void RemoveNotification(const std::string& id) { |
130 GetMessageCenter()->RemoveNotification(id, false); | 131 GetMessageCenter()->RemoveNotification(id, false); |
131 } | 132 } |
132 | 133 |
133 views::Widget* GetWidget() { | 134 views::Widget* GetWidget() { |
134 return GetTray()->GetWidget(); | 135 return GetTray()->GetWidget(); |
135 } | 136 } |
136 | 137 |
137 gfx::Rect GetPopupWorkArea() { | 138 int GetPopupWorkAreaBottom() { |
138 return GetPopupWorkAreaForTray(GetTray()); | 139 return GetPopupWorkAreaBottomForTray(GetTray()); |
139 } | 140 } |
140 | 141 |
141 gfx::Rect GetPopupWorkAreaForTray(WebNotificationTray* tray) { | 142 int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) { |
142 return tray->popup_collection_->work_area_; | 143 return tray->popup_alignment_delegate_->GetWorkAreaBottom(); |
143 } | 144 } |
144 | 145 |
145 bool IsPopupVisible() { | 146 bool IsPopupVisible() { |
146 return GetTray()->IsPopupVisible(); | 147 return GetTray()->IsPopupVisible(); |
147 } | 148 } |
148 | 149 |
149 private: | 150 private: |
150 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); | 151 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); |
151 }; | 152 }; |
152 | 153 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 #define MAYBE_PopupAndAutoHideShelf DISABLED_PopupAndAutoHideShelf | 313 #define MAYBE_PopupAndAutoHideShelf DISABLED_PopupAndAutoHideShelf |
313 #define MAYBE_PopupAndFullscreen DISABLED_PopupAndFullscreen | 314 #define MAYBE_PopupAndFullscreen DISABLED_PopupAndFullscreen |
314 #endif | 315 #endif |
315 | 316 |
316 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) { | 317 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) { |
317 TestItem* test_item = new TestItem; | 318 TestItem* test_item = new TestItem; |
318 GetSystemTray()->AddTrayItem(test_item); | 319 GetSystemTray()->AddTrayItem(test_item); |
319 | 320 |
320 AddNotification("test_id"); | 321 AddNotification("test_id"); |
321 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 322 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
322 gfx::Rect work_area = GetPopupWorkArea(); | 323 int bottom = GetPopupWorkAreaBottom(); |
323 | 324 |
324 // System tray is created, the popup's work area should be narrowed but still | 325 // System tray is created, the popup's work area should be narrowed but still |
325 // visible. | 326 // visible. |
326 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 327 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
327 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 328 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
328 gfx::Rect work_area_with_tray = GetPopupWorkArea(); | 329 int bottom_with_tray = GetPopupWorkAreaBottom(); |
329 EXPECT_GT(work_area.size().GetArea(), work_area_with_tray.size().GetArea()); | 330 EXPECT_GT(bottom, bottom_with_tray); |
330 | 331 |
331 // System tray notification is also created, the popup's work area is narrowed | 332 // System tray notification is also created, the popup's work area is narrowed |
332 // even more, but still visible. | 333 // even more, but still visible. |
333 GetSystemTray()->ShowNotificationView(test_item); | 334 GetSystemTray()->ShowNotificationView(test_item); |
334 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 335 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
335 gfx::Rect work_area_with_tray_notification = GetPopupWorkArea(); | 336 int bottom_with_tray_notification = GetPopupWorkAreaBottom(); |
336 EXPECT_GT(work_area.size().GetArea(), | 337 EXPECT_GT(bottom, bottom_with_tray_notification); |
337 work_area_with_tray_notification.size().GetArea()); | 338 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification); |
338 EXPECT_GT(work_area_with_tray.size().GetArea(), | |
339 work_area_with_tray_notification.size().GetArea()); | |
340 | 339 |
341 // Close system tray, only system tray notifications. | 340 // Close system tray, only system tray notifications. |
342 GetSystemTray()->ClickedOutsideBubble(); | 341 GetSystemTray()->ClickedOutsideBubble(); |
343 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 342 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
344 gfx::Rect work_area_with_notification = GetPopupWorkArea(); | 343 int bottom_with_notification = GetPopupWorkAreaBottom(); |
345 EXPECT_GT(work_area.size().GetArea(), | 344 EXPECT_GT(bottom, bottom_with_notification); |
346 work_area_with_notification.size().GetArea()); | 345 EXPECT_LT(bottom_with_tray_notification, bottom_with_notification); |
347 EXPECT_LT(work_area_with_tray_notification.size().GetArea(), | |
348 work_area_with_notification.size().GetArea()); | |
349 | 346 |
350 // Close the system tray notifications. | 347 // Close the system tray notifications. |
351 GetSystemTray()->HideNotificationView(test_item); | 348 GetSystemTray()->HideNotificationView(test_item); |
352 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 349 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
353 EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); | 350 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); |
354 } | 351 } |
355 | 352 |
356 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) { | 353 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) { |
357 AddNotification("test_id"); | 354 AddNotification("test_id"); |
358 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 355 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
359 gfx::Rect work_area = GetPopupWorkArea(); | 356 int bottom = GetPopupWorkAreaBottom(); |
360 | 357 |
361 // Shelf's auto-hide state won't be HIDDEN unless window exists. | 358 // Shelf's auto-hide state won't be HIDDEN unless window exists. |
362 scoped_ptr<aura::Window> window( | 359 scoped_ptr<aura::Window> window( |
363 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 360 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
364 ShelfLayoutManager* shelf = | 361 ShelfLayoutManager* shelf = |
365 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 362 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
366 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 363 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
367 | 364 |
368 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 365 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
369 gfx::Rect work_area_auto_hidden = GetPopupWorkArea(); | 366 int bottom_auto_hidden = GetPopupWorkAreaBottom(); |
370 EXPECT_LT(work_area.size().GetArea(), work_area_auto_hidden.size().GetArea()); | 367 EXPECT_LT(bottom, bottom_auto_hidden); |
371 | 368 |
372 // Close the window, which shows the shelf. | 369 // Close the window, which shows the shelf. |
373 window.reset(); | 370 window.reset(); |
374 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 371 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
375 gfx::Rect work_area_auto_shown = GetPopupWorkArea(); | 372 int bottom_auto_shown = GetPopupWorkAreaBottom(); |
376 EXPECT_EQ(work_area.ToString(), work_area_auto_shown.ToString()); | 373 EXPECT_EQ(bottom, bottom_auto_shown); |
377 | 374 |
378 // Create the system tray during auto-hide. | 375 // Create the system tray during auto-hide. |
379 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 376 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
380 TestItem* test_item = new TestItem; | 377 TestItem* test_item = new TestItem; |
381 GetSystemTray()->AddTrayItem(test_item); | 378 GetSystemTray()->AddTrayItem(test_item); |
382 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 379 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
383 | 380 |
384 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 381 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
385 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 382 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
386 gfx::Rect work_area_with_tray = GetPopupWorkArea(); | 383 int bottom_with_tray = GetPopupWorkAreaBottom(); |
387 EXPECT_GT(work_area_auto_shown.size().GetArea(), | 384 EXPECT_GT(bottom_auto_shown, bottom_with_tray); |
388 work_area_with_tray.size().GetArea()); | |
389 | 385 |
390 // Create tray notification. | 386 // Create tray notification. |
391 GetSystemTray()->ShowNotificationView(test_item); | 387 GetSystemTray()->ShowNotificationView(test_item); |
392 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 388 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
393 gfx::Rect work_area_with_tray_notification = GetPopupWorkArea(); | 389 int bottom_with_tray_notification = GetPopupWorkAreaBottom(); |
394 EXPECT_GT(work_area_with_tray.size().GetArea(), | 390 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification); |
395 work_area_with_tray_notification.size().GetArea()); | |
396 | 391 |
397 // Close the system tray. | 392 // Close the system tray. |
398 GetSystemTray()->ClickedOutsideBubble(); | 393 GetSystemTray()->ClickedOutsideBubble(); |
399 shelf->UpdateAutoHideState(); | 394 shelf->UpdateAutoHideState(); |
400 RunAllPendingInMessageLoop(); | 395 RunAllPendingInMessageLoop(); |
401 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 396 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
402 gfx::Rect work_area_hidden_with_tray_notification = GetPopupWorkArea(); | 397 int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom(); |
403 EXPECT_LT(work_area_with_tray_notification.size().GetArea(), | 398 EXPECT_LT(bottom_with_tray_notification, |
404 work_area_hidden_with_tray_notification.size().GetArea()); | 399 bottom_hidden_with_tray_notification); |
405 EXPECT_GT(work_area_auto_hidden.size().GetArea(), | 400 EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification); |
406 work_area_hidden_with_tray_notification.size().GetArea()); | |
407 | 401 |
408 // Close the window again, which shows the shelf. | 402 // Close the window again, which shows the shelf. |
409 window.reset(); | 403 window.reset(); |
410 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 404 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
411 gfx::Rect work_area_shown_with_tray_notification = GetPopupWorkArea(); | 405 int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom(); |
412 EXPECT_GT(work_area_hidden_with_tray_notification.size().GetArea(), | 406 EXPECT_GT(bottom_hidden_with_tray_notification, |
413 work_area_shown_with_tray_notification.size().GetArea()); | 407 bottom_shown_with_tray_notification); |
414 EXPECT_GT(work_area_auto_shown.size().GetArea(), | 408 EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification); |
415 work_area_shown_with_tray_notification.size().GetArea()); | |
416 } | 409 } |
417 | 410 |
418 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) { | 411 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) { |
419 AddNotification("test_id"); | 412 AddNotification("test_id"); |
420 EXPECT_TRUE(IsPopupVisible()); | 413 EXPECT_TRUE(IsPopupVisible()); |
421 gfx::Rect work_area = GetPopupWorkArea(); | 414 int bottom = GetPopupWorkAreaBottom(); |
422 | 415 |
423 // Checks the work area for normal auto-hidden state. | 416 // Checks the work area for normal auto-hidden state. |
424 scoped_ptr<aura::Window> window( | 417 scoped_ptr<aura::Window> window( |
425 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 418 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
426 ShelfLayoutManager* shelf = | 419 ShelfLayoutManager* shelf = |
427 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 420 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
428 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 421 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
429 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 422 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
430 gfx::Rect work_area_auto_hidden = GetPopupWorkArea(); | 423 int bottom_auto_hidden = GetPopupWorkAreaBottom(); |
431 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 424 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
432 | 425 |
433 // Put |window| into fullscreen without forcing the shelf to hide. Currently, | 426 // Put |window| into fullscreen without forcing the shelf to hide. Currently, |
434 // this is used by immersive fullscreen and forces the shelf to be auto | 427 // this is used by immersive fullscreen and forces the shelf to be auto |
435 // hidden. | 428 // hidden. |
436 wm::GetWindowState(window.get())->set_hide_shelf_when_fullscreen(false); | 429 wm::GetWindowState(window.get())->set_hide_shelf_when_fullscreen(false); |
437 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 430 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
438 RunAllPendingInMessageLoop(); | 431 RunAllPendingInMessageLoop(); |
439 | 432 |
440 // The work area for auto-hidden status of fullscreen is a bit larger | 433 // The work area for auto-hidden status of fullscreen is a bit larger |
441 // since it doesn't even have the 3-pixel width. | 434 // since it doesn't even have the 3-pixel width. |
442 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 435 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
443 gfx::Rect work_area_fullscreen_hidden = GetPopupWorkArea(); | 436 int bottom_fullscreen_hidden = GetPopupWorkAreaBottom(); |
444 EXPECT_EQ(work_area_auto_hidden.ToString(), | 437 EXPECT_EQ(bottom_auto_hidden, bottom_fullscreen_hidden); |
445 work_area_fullscreen_hidden.ToString()); | |
446 | 438 |
447 // Move the mouse cursor at the bottom, which shows the shelf. | 439 // Move the mouse cursor at the bottom, which shows the shelf. |
448 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 440 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
449 gfx::Point bottom_right = | 441 gfx::Point bottom_right = |
450 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom_right(); | 442 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom_right(); |
451 bottom_right.Offset(-1, -1); | 443 bottom_right.Offset(-1, -1); |
452 generator.MoveMouseTo(bottom_right); | 444 generator.MoveMouseTo(bottom_right); |
453 shelf->UpdateAutoHideStateNow(); | 445 shelf->UpdateAutoHideStateNow(); |
454 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 446 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
455 EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); | 447 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); |
456 | 448 |
457 generator.MoveMouseTo(work_area.CenterPoint()); | 449 generator.MoveMouseTo( |
| 450 Shell::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint()); |
458 shelf->UpdateAutoHideStateNow(); | 451 shelf->UpdateAutoHideStateNow(); |
459 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 452 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
460 EXPECT_EQ(work_area_auto_hidden.ToString(), GetPopupWorkArea().ToString()); | 453 EXPECT_EQ(bottom_auto_hidden, GetPopupWorkAreaBottom()); |
461 } | 454 } |
462 | 455 |
463 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) { | 456 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) { |
464 UpdateDisplay("800x600,600x400"); | 457 UpdateDisplay("800x600,600x400"); |
465 | 458 |
466 AddNotification("test_id"); | 459 AddNotification("test_id"); |
467 gfx::Rect work_area = GetPopupWorkArea(); | 460 int bottom = GetPopupWorkAreaBottom(); |
468 gfx::Rect work_area_second = GetPopupWorkAreaForTray(GetSecondaryTray()); | 461 int bottom_second = GetPopupWorkAreaBottomForTray(GetSecondaryTray()); |
469 | 462 |
470 // System tray is created on the primary display. The popups in the secondary | 463 // System tray is created on the primary display. The popups in the secondary |
471 // tray aren't affected. | 464 // tray aren't affected. |
472 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 465 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
473 EXPECT_GT(work_area.size().GetArea(), GetPopupWorkArea().size().GetArea()); | 466 EXPECT_GT(bottom, GetPopupWorkAreaBottom()); |
474 EXPECT_EQ(work_area_second.ToString(), | 467 EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray())); |
475 GetPopupWorkAreaForTray(GetSecondaryTray()).ToString()); | |
476 } | 468 } |
477 | 469 |
478 } // namespace ash | 470 } // namespace ash |
OLD | NEW |