| 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/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/system/tray/system_tray_bubble.h" | 10 #include "ash/common/system/tray/system_tray_bubble.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 SystemTray* tray = GetPrimarySystemTray(); | 200 SystemTray* tray = GetPrimarySystemTray(); |
| 201 ASSERT_TRUE(tray->GetWidget()); | 201 ASSERT_TRUE(tray->GetWidget()); |
| 202 | 202 |
| 203 TestItem* test_item = new TestItem; | 203 TestItem* test_item = new TestItem; |
| 204 TestItem* detailed_item = new TestItem; | 204 TestItem* detailed_item = new TestItem; |
| 205 tray->AddTrayItem(test_item); | 205 tray->AddTrayItem(test_item); |
| 206 tray->AddTrayItem(detailed_item); | 206 tray->AddTrayItem(detailed_item); |
| 207 | 207 |
| 208 // Check items have been added | 208 // Check items have been added |
| 209 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); | 209 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); |
| 210 ASSERT_TRUE( | 210 ASSERT_TRUE(std::find(items.begin(), items.end(), test_item) != items.end()); |
| 211 std::find(items.begin(), items.end(), test_item) != items.end()); | 211 ASSERT_TRUE(std::find(items.begin(), items.end(), detailed_item) != |
| 212 ASSERT_TRUE( | 212 items.end()); |
| 213 std::find(items.begin(), items.end(), detailed_item) != items.end()); | |
| 214 | 213 |
| 215 // Ensure the tray views are created. | 214 // Ensure the tray views are created. |
| 216 ASSERT_TRUE(test_item->tray_view() != NULL); | 215 ASSERT_TRUE(test_item->tray_view() != NULL); |
| 217 ASSERT_TRUE(detailed_item->tray_view() != NULL); | 216 ASSERT_TRUE(detailed_item->tray_view() != NULL); |
| 218 | 217 |
| 219 // Ensure a default views are created. | 218 // Ensure a default views are created. |
| 220 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 219 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 221 ASSERT_TRUE(test_item->default_view() != NULL); | 220 ASSERT_TRUE(test_item->default_view() != NULL); |
| 222 ASSERT_TRUE(detailed_item->default_view() != NULL); | 221 ASSERT_TRUE(detailed_item->default_view() != NULL); |
| 223 | 222 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 RunAllPendingInMessageLoop(); | 324 RunAllPendingInMessageLoop(); |
| 326 | 325 |
| 327 views::Widget* widget = test_item->default_view()->GetWidget(); | 326 views::Widget* widget = test_item->default_view()->GetWidget(); |
| 328 gfx::Rect bubble_bounds = widget->GetWindowBoundsInScreen(); | 327 gfx::Rect bubble_bounds = widget->GetWindowBoundsInScreen(); |
| 329 | 328 |
| 330 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 329 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 331 RunAllPendingInMessageLoop(); | 330 RunAllPendingInMessageLoop(); |
| 332 | 331 |
| 333 EXPECT_FALSE(test_item->default_view()); | 332 EXPECT_FALSE(test_item->default_view()); |
| 334 | 333 |
| 335 EXPECT_EQ(bubble_bounds.ToString(), test_item->detailed_view()->GetWidget()-> | 334 EXPECT_EQ(bubble_bounds.ToString(), test_item->detailed_view() |
| 336 GetWindowBoundsInScreen().ToString()); | 335 ->GetWidget() |
| 336 ->GetWindowBoundsInScreen() |
| 337 .ToString()); |
| 337 EXPECT_EQ(widget, test_item->detailed_view()->GetWidget()); | 338 EXPECT_EQ(widget, test_item->detailed_view()->GetWidget()); |
| 338 | 339 |
| 339 tray->ShowDefaultView(BUBBLE_USE_EXISTING); | 340 tray->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 340 RunAllPendingInMessageLoop(); | 341 RunAllPendingInMessageLoop(); |
| 341 | 342 |
| 342 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> | 343 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view() |
| 343 GetWindowBoundsInScreen().ToString()); | 344 ->GetWidget() |
| 345 ->GetWindowBoundsInScreen() |
| 346 .ToString()); |
| 344 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); | 347 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); |
| 345 } | 348 } |
| 346 | 349 |
| 347 // Tests that the tray view is laid out properly and is fully contained within | 350 // Tests that the tray view is laid out properly and is fully contained within |
| 348 // the shelf widget. | 351 // the shelf widget. |
| 349 TEST_F(SystemTrayTest, TrayBoundsInWidget) { | 352 TEST_F(SystemTrayTest, TrayBoundsInWidget) { |
| 350 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 353 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 351 StatusAreaWidget* widget = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); | 354 StatusAreaWidget* widget = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); |
| 352 SystemTray* tray = GetPrimarySystemTray(); | 355 SystemTray* tray = GetPrimarySystemTray(); |
| 353 | 356 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 #define MAYBE_WithSystemModal WithSystemModal | 425 #define MAYBE_WithSystemModal WithSystemModal |
| 423 #else | 426 #else |
| 424 #define MAYBE_WithSystemModal DISABLED_WithSystemModal | 427 #define MAYBE_WithSystemModal DISABLED_WithSystemModal |
| 425 #endif | 428 #endif |
| 426 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { | 429 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { |
| 427 // Check if the accessibility item is created even with system modal | 430 // Check if the accessibility item is created even with system modal |
| 428 // dialog. | 431 // dialog. |
| 429 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( | 432 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( |
| 430 true); | 433 true); |
| 431 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 434 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 432 new ModalWidgetDelegate(), | 435 new ModalWidgetDelegate(), Shell::GetPrimaryRootWindow(), |
| 433 Shell::GetPrimaryRootWindow(), | |
| 434 gfx::Rect(0, 0, 100, 100)); | 436 gfx::Rect(0, 0, 100, 100)); |
| 435 widget->Show(); | 437 widget->Show(); |
| 436 | 438 |
| 437 SystemTray* tray = GetPrimarySystemTray(); | 439 SystemTray* tray = GetPrimarySystemTray(); |
| 438 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 440 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 439 | 441 |
| 440 ASSERT_TRUE(tray->HasSystemBubble()); | 442 ASSERT_TRUE(tray->HasSystemBubble()); |
| 441 const views::View* accessibility = | 443 const views::View* accessibility = |
| 442 tray->GetSystemBubble()->bubble_view()->GetViewByID( | 444 tray->GetSystemBubble()->bubble_view()->GetViewByID( |
| 443 test::kAccessibilityTrayItemViewId); | 445 test::kAccessibilityTrayItemViewId); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 463 EXPECT_TRUE(settings->visible()); | 465 EXPECT_TRUE(settings->visible()); |
| 464 } | 466 } |
| 465 | 467 |
| 466 // Tests that if SetVisible(true) is called while animating to hidden that the | 468 // Tests that if SetVisible(true) is called while animating to hidden that the |
| 467 // tray becomes visible, and stops animating to hidden. | 469 // tray becomes visible, and stops animating to hidden. |
| 468 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) { | 470 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) { |
| 469 SystemTray* tray = GetPrimarySystemTray(); | 471 SystemTray* tray = GetPrimarySystemTray(); |
| 470 ASSERT_TRUE(tray->visible()); | 472 ASSERT_TRUE(tray->visible()); |
| 471 | 473 |
| 472 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration; | 474 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration; |
| 473 animation_duration.reset( | 475 animation_duration.reset(new ui::ScopedAnimationDurationScaleMode( |
| 474 new ui::ScopedAnimationDurationScaleMode( | 476 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| 475 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | |
| 476 tray->SetVisible(false); | 477 tray->SetVisible(false); |
| 477 EXPECT_TRUE(tray->visible()); | 478 EXPECT_TRUE(tray->visible()); |
| 478 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity()); | 479 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity()); |
| 479 | 480 |
| 480 tray->SetVisible(true); | 481 tray->SetVisible(true); |
| 481 animation_duration.reset(); | 482 animation_duration.reset(); |
| 482 tray->layer()->GetAnimator()->StopAnimating(); | 483 tray->layer()->GetAnimator()->StopAnimating(); |
| 483 EXPECT_TRUE(tray->visible()); | 484 EXPECT_TRUE(tray->visible()); |
| 484 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity()); | 485 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity()); |
| 485 } | 486 } |
| 486 | 487 |
| 487 #if defined(OS_CHROMEOS) | 488 #if defined(OS_CHROMEOS) |
| 488 // Tests that touch on an item in the system bubble triggers it to become | 489 // Tests that touch on an item in the system bubble triggers it to become |
| 489 // active. | 490 // active. |
| 490 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { | 491 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { |
| 491 SystemTray* tray = GetPrimarySystemTray(); | 492 SystemTray* tray = GetPrimarySystemTray(); |
| 492 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 493 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 493 | 494 |
| 494 TrayPopupItemContainer* view = | 495 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( |
| 495 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> | 496 tray->GetSystemBubble()->bubble_view()->child_at(0)); |
| 496 bubble_view()->child_at(0)); | |
| 497 EXPECT_FALSE(view->active()); | 497 EXPECT_FALSE(view->active()); |
| 498 | 498 |
| 499 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 499 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 500 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | 500 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); |
| 501 generator.PressTouch(); | 501 generator.PressTouch(); |
| 502 EXPECT_TRUE(view->active()); | 502 EXPECT_TRUE(view->active()); |
| 503 | 503 |
| 504 generator.ReleaseTouch(); | 504 generator.ReleaseTouch(); |
| 505 EXPECT_FALSE(view->active()); | 505 EXPECT_FALSE(view->active()); |
| 506 } | 506 } |
| 507 | 507 |
| 508 // Tests that touch events on an item in the system bubble cause it to stop | 508 // Tests that touch events on an item in the system bubble cause it to stop |
| 509 // being active. | 509 // being active. |
| 510 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { | 510 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { |
| 511 SystemTray* tray = GetPrimarySystemTray(); | 511 SystemTray* tray = GetPrimarySystemTray(); |
| 512 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 512 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 513 | 513 |
| 514 TrayPopupItemContainer* view = | 514 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( |
| 515 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> | 515 tray->GetSystemBubble()->bubble_view()->child_at(0)); |
| 516 bubble_view()->child_at(0)); | |
| 517 EXPECT_FALSE(view->active()); | 516 EXPECT_FALSE(view->active()); |
| 518 | 517 |
| 519 gfx::Rect view_bounds = view->GetBoundsInScreen(); | 518 gfx::Rect view_bounds = view->GetBoundsInScreen(); |
| 520 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 519 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 521 generator.set_current_location(view_bounds.CenterPoint()); | 520 generator.set_current_location(view_bounds.CenterPoint()); |
| 522 generator.PressTouch(); | 521 generator.PressTouch(); |
| 523 EXPECT_TRUE(view->active()); | 522 EXPECT_TRUE(view->active()); |
| 524 | 523 |
| 525 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | 524 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
| 526 generator.MoveTouch(move_point); | 525 generator.MoveTouch(move_point); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 548 // Hide the default view, ensure the system tray height is back to zero. | 547 // Hide the default view, ensure the system tray height is back to zero. |
| 549 ASSERT_TRUE(tray->CloseSystemBubble()); | 548 ASSERT_TRUE(tray->CloseSystemBubble()); |
| 550 RunAllPendingInMessageLoop(); | 549 RunAllPendingInMessageLoop(); |
| 551 | 550 |
| 552 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); | 551 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); |
| 553 } | 552 } |
| 554 #endif // OS_CHROMEOS | 553 #endif // OS_CHROMEOS |
| 555 | 554 |
| 556 } // namespace test | 555 } // namespace test |
| 557 } // namespace ash | 556 } // namespace ash |
| OLD | NEW |