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/tray/system_tray.h" | 5 #include "ash/common/system/tray/system_tray.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/common/accessibility_delegate.h" | 9 #include "ash/common/accessibility_delegate.h" |
10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/system/status_area_widget.h" |
11 #include "ash/common/system/tray/system_tray_bubble.h" | 13 #include "ash/common/system/tray/system_tray_bubble.h" |
12 #include "ash/common/system/tray/system_tray_item.h" | 14 #include "ash/common/system/tray/system_tray_item.h" |
13 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
14 #include "ash/common/system/tray/tray_popup_item_container.h" | 16 #include "ash/common/system/tray/tray_popup_item_container.h" |
15 #include "ash/common/system/web_notification/web_notification_tray.h" | 17 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 18 #include "ash/common/wm_root_window_controller.h" |
16 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
17 #include "ash/shell.h" | 20 #include "ash/common/wm_window.h" |
18 #include "ash/system/status_area_widget.h" | |
19 #include "ash/test/ash_test_base.h" | 21 #include "ash/test/ash_test_base.h" |
20 #include "ash/test/status_area_widget_test_helper.h" | 22 #include "ash/test/status_area_widget_test_helper.h" |
21 #include "ash/wm/window_util.h" | |
22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
24 #include "ui/aura/window.h" | |
25 #include "ui/base/ui_base_types.h" | 25 #include "ui/base/ui_base_types.h" |
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
27 #include "ui/events/test/event_generator.h" | 27 #include "ui/events/test/event_generator.h" |
28 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
29 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
30 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
31 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
32 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
34 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
35 | 35 |
36 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
37 #include "base/win/windows_version.h" | 37 #include "base/win/windows_version.h" |
38 #endif | 38 #endif |
39 | 39 |
40 namespace ash { | 40 namespace ash { |
41 namespace test { | 41 namespace test { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
| 45 std::unique_ptr<views::Widget> CreateTestWidget(views::WidgetDelegate* delegate, |
| 46 int container_id) { |
| 47 std::unique_ptr<views::Widget> widget(new views::Widget); |
| 48 views::Widget::InitParams params; |
| 49 params.delegate = delegate; |
| 50 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 51 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 52 WmShell::Get() |
| 53 ->GetPrimaryRootWindow() |
| 54 ->GetRootWindowController() |
| 55 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, |
| 56 ¶ms); |
| 57 widget->Init(params); |
| 58 widget->Show(); |
| 59 return widget; |
| 60 } |
| 61 |
45 // Trivial item implementation that tracks its views for testing. | 62 // Trivial item implementation that tracks its views for testing. |
46 class TestItem : public SystemTrayItem { | 63 class TestItem : public SystemTrayItem { |
47 public: | 64 public: |
48 TestItem() | 65 TestItem() |
49 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()), | 66 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()), |
50 tray_view_(nullptr), | 67 tray_view_(nullptr), |
51 default_view_(nullptr), | 68 default_view_(nullptr), |
52 detailed_view_(nullptr), | 69 detailed_view_(nullptr), |
53 notification_view_(nullptr) {} | 70 notification_view_(nullptr) {} |
54 | 71 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); | 397 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); |
381 } | 398 } |
382 | 399 |
383 TEST_F(SystemTrayTest, PersistentBubble) { | 400 TEST_F(SystemTrayTest, PersistentBubble) { |
384 SystemTray* tray = GetPrimarySystemTray(); | 401 SystemTray* tray = GetPrimarySystemTray(); |
385 ASSERT_TRUE(tray->GetWidget()); | 402 ASSERT_TRUE(tray->GetWidget()); |
386 | 403 |
387 TestItem* test_item = new TestItem; | 404 TestItem* test_item = new TestItem; |
388 tray->AddTrayItem(test_item); | 405 tray->AddTrayItem(test_item); |
389 | 406 |
390 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 407 std::unique_ptr<views::Widget> widget( |
| 408 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer)); |
391 | 409 |
392 // Tests for usual default view. | 410 // Tests for usual default view while activating a window. |
393 // Activating window. | |
394 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 411 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
395 ASSERT_TRUE(tray->HasSystemBubble()); | 412 ASSERT_TRUE(tray->HasSystemBubble()); |
396 wm::ActivateWindow(window.get()); | 413 widget->Activate(); |
397 base::RunLoop().RunUntilIdle(); | 414 base::RunLoop().RunUntilIdle(); |
398 ASSERT_FALSE(tray->HasSystemBubble()); | 415 ASSERT_FALSE(tray->HasSystemBubble()); |
399 | 416 |
400 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 417 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
401 ASSERT_TRUE(tray->HasSystemBubble()); | 418 ASSERT_TRUE(tray->HasSystemBubble()); |
402 { | 419 { |
403 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 420 ui::test::EventGenerator& generator = GetEventGenerator(); |
404 gfx::Point(5, 5)); | 421 generator.set_current_location(gfx::Point(5, 5)); |
405 generator.ClickLeftButton(); | 422 generator.ClickLeftButton(); |
406 ASSERT_FALSE(tray->HasSystemBubble()); | 423 ASSERT_FALSE(tray->HasSystemBubble()); |
407 } | 424 } |
408 | 425 |
409 // Same tests for persistent default view. | 426 // Same tests for persistent default view. |
410 tray->ShowPersistentDefaultView(); | 427 tray->ShowPersistentDefaultView(); |
411 ASSERT_TRUE(tray->HasSystemBubble()); | 428 ASSERT_TRUE(tray->HasSystemBubble()); |
412 wm::ActivateWindow(window.get()); | 429 widget->Activate(); |
413 base::RunLoop().RunUntilIdle(); | 430 base::RunLoop().RunUntilIdle(); |
414 ASSERT_TRUE(tray->HasSystemBubble()); | 431 ASSERT_TRUE(tray->HasSystemBubble()); |
415 | 432 |
416 { | 433 { |
417 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 434 ui::test::EventGenerator& generator = GetEventGenerator(); |
418 gfx::Point(5, 5)); | 435 generator.set_current_location(gfx::Point(5, 5)); |
419 generator.ClickLeftButton(); | 436 generator.ClickLeftButton(); |
420 ASSERT_TRUE(tray->HasSystemBubble()); | 437 ASSERT_TRUE(tray->HasSystemBubble()); |
421 } | 438 } |
422 } | 439 } |
423 | 440 |
424 #if defined(OS_CHROMEOS) | 441 #if defined(OS_CHROMEOS) |
425 // Accessibility/Settings tray items are available only on cros. | 442 // Accessibility/Settings tray items are available only on cros. |
426 #define MAYBE_WithSystemModal WithSystemModal | 443 #define MAYBE_WithSystemModal WithSystemModal |
427 #else | 444 #else |
428 #define MAYBE_WithSystemModal DISABLED_WithSystemModal | 445 #define MAYBE_WithSystemModal DISABLED_WithSystemModal |
429 #endif | 446 #endif |
430 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { | 447 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { |
431 // Check if the accessibility item is created even with system modal dialog. | 448 // Check if the accessibility item is created even with system modal dialog. |
432 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(true); | 449 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(true); |
433 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 450 std::unique_ptr<views::Widget> widget(CreateTestWidget( |
434 new ModalWidgetDelegate(), Shell::GetPrimaryRootWindow(), | 451 new ModalWidgetDelegate, kShellWindowId_SystemModalContainer)); |
435 gfx::Rect(0, 0, 100, 100)); | |
436 widget->Show(); | |
437 | 452 |
438 SystemTray* tray = GetPrimarySystemTray(); | 453 SystemTray* tray = GetPrimarySystemTray(); |
439 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 454 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
440 | 455 |
441 ASSERT_TRUE(tray->HasSystemBubble()); | 456 ASSERT_TRUE(tray->HasSystemBubble()); |
442 const views::View* accessibility = | 457 const views::View* accessibility = |
443 tray->GetSystemBubble()->bubble_view()->GetViewByID( | 458 tray->GetSystemBubble()->bubble_view()->GetViewByID( |
444 test::kAccessibilityTrayItemViewId); | 459 test::kAccessibilityTrayItemViewId); |
445 ASSERT_TRUE(accessibility); | 460 ASSERT_TRUE(accessibility); |
446 EXPECT_TRUE(accessibility->visible()); | 461 EXPECT_TRUE(accessibility->visible()); |
447 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID( | 462 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID( |
448 test::kSettingsTrayItemViewId)); | 463 test::kSettingsTrayItemViewId)); |
449 | 464 |
450 widget->Close(); | 465 // Close the modal dialog. |
| 466 widget.reset(); |
451 | 467 |
452 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 468 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
453 // System modal is gone. The bubble should now contains settings | 469 // System modal is gone. The bubble should now contains settings |
454 // as well. | 470 // as well. |
455 accessibility = tray->GetSystemBubble()->bubble_view()->GetViewByID( | 471 accessibility = tray->GetSystemBubble()->bubble_view()->GetViewByID( |
456 test::kAccessibilityTrayItemViewId); | 472 test::kAccessibilityTrayItemViewId); |
457 ASSERT_TRUE(accessibility); | 473 ASSERT_TRUE(accessibility); |
458 EXPECT_TRUE(accessibility->visible()); | 474 EXPECT_TRUE(accessibility->visible()); |
459 | 475 |
460 const views::View* settings = | 476 const views::View* settings = |
(...skipping 27 matching lines...) Expand all Loading... |
488 // Tests that touch on an item in the system bubble triggers it to become | 504 // Tests that touch on an item in the system bubble triggers it to become |
489 // active. | 505 // active. |
490 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { | 506 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { |
491 SystemTray* tray = GetPrimarySystemTray(); | 507 SystemTray* tray = GetPrimarySystemTray(); |
492 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 508 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
493 | 509 |
494 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( | 510 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( |
495 tray->GetSystemBubble()->bubble_view()->child_at(0)); | 511 tray->GetSystemBubble()->bubble_view()->child_at(0)); |
496 EXPECT_FALSE(view->active()); | 512 EXPECT_FALSE(view->active()); |
497 | 513 |
498 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 514 ui::test::EventGenerator& generator = GetEventGenerator(); |
499 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | 515 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); |
500 generator.PressTouch(); | 516 generator.PressTouch(); |
501 EXPECT_TRUE(view->active()); | 517 EXPECT_TRUE(view->active()); |
502 | 518 |
503 generator.ReleaseTouch(); | 519 generator.ReleaseTouch(); |
504 EXPECT_FALSE(view->active()); | 520 EXPECT_FALSE(view->active()); |
505 } | 521 } |
506 | 522 |
507 // Tests that touch events on an item in the system bubble cause it to stop | 523 // Tests that touch events on an item in the system bubble cause it to stop |
508 // being active. | 524 // being active. |
509 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { | 525 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { |
510 SystemTray* tray = GetPrimarySystemTray(); | 526 SystemTray* tray = GetPrimarySystemTray(); |
511 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 527 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
512 | 528 |
513 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( | 529 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( |
514 tray->GetSystemBubble()->bubble_view()->child_at(0)); | 530 tray->GetSystemBubble()->bubble_view()->child_at(0)); |
515 EXPECT_FALSE(view->active()); | 531 EXPECT_FALSE(view->active()); |
516 | 532 |
517 gfx::Rect view_bounds = view->GetBoundsInScreen(); | 533 gfx::Rect view_bounds = view->GetBoundsInScreen(); |
518 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 534 ui::test::EventGenerator& generator = GetEventGenerator(); |
519 generator.set_current_location(view_bounds.CenterPoint()); | 535 generator.set_current_location(view_bounds.CenterPoint()); |
520 generator.PressTouch(); | 536 generator.PressTouch(); |
521 EXPECT_TRUE(view->active()); | 537 EXPECT_TRUE(view->active()); |
522 | 538 |
523 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | 539 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
524 generator.MoveTouch(move_point); | 540 generator.MoveTouch(move_point); |
525 EXPECT_FALSE(view->active()); | 541 EXPECT_FALSE(view->active()); |
526 | 542 |
527 generator.set_current_location(move_point); | 543 generator.set_current_location(move_point); |
528 generator.ReleaseTouch(); | 544 generator.ReleaseTouch(); |
(...skipping 17 matching lines...) Expand all Loading... |
546 // Hide the default view, ensure the tray bubble height is back to zero. | 562 // Hide the default view, ensure the tray bubble height is back to zero. |
547 ASSERT_TRUE(tray->CloseSystemBubble()); | 563 ASSERT_TRUE(tray->CloseSystemBubble()); |
548 RunAllPendingInMessageLoop(); | 564 RunAllPendingInMessageLoop(); |
549 | 565 |
550 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | 566 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); |
551 } | 567 } |
552 #endif // OS_CHROMEOS | 568 #endif // OS_CHROMEOS |
553 | 569 |
554 } // namespace test | 570 } // namespace test |
555 } // namespace ash | 571 } // namespace ash |
OLD | NEW |