| 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/common/system/tray/system_tray.h" | 5 #include "ash/common/system/tray/system_tray.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/accelerators/accelerator_controller.h" |
| 10 #include "ash/common/accessibility_delegate.h" | 11 #include "ash/common/accessibility_delegate.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/common/system/status_area_widget.h" | 14 #include "ash/common/system/status_area_widget.h" |
| 14 #include "ash/common/system/tray/system_tray_bubble.h" | 15 #include "ash/common/system/tray/system_tray_bubble.h" |
| 15 #include "ash/common/system/tray/system_tray_item.h" | 16 #include "ash/common/system/tray/system_tray_item.h" |
| 16 #include "ash/common/system/tray/tray_constants.h" | 17 #include "ash/common/system/tray/tray_constants.h" |
| 17 #include "ash/common/system/tray/tray_popup_item_container.h" | 18 #include "ash/common/system/tray/tray_popup_item_container.h" |
| 18 #include "ash/common/system/web_notification/web_notification_tray.h" | 19 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 19 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ASSERT_TRUE(tray->GetWidget()); | 197 ASSERT_TRUE(tray->GetWidget()); |
| 197 | 198 |
| 198 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 199 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 199 | 200 |
| 200 // Ensure that closing the bubble destroys it. | 201 // Ensure that closing the bubble destroys it. |
| 201 ASSERT_TRUE(tray->CloseSystemBubble()); | 202 ASSERT_TRUE(tray->CloseSystemBubble()); |
| 202 RunAllPendingInMessageLoop(); | 203 RunAllPendingInMessageLoop(); |
| 203 ASSERT_FALSE(tray->CloseSystemBubble()); | 204 ASSERT_FALSE(tray->CloseSystemBubble()); |
| 204 } | 205 } |
| 205 | 206 |
| 207 // Make sure the opening system tray bubble will not deactivate the |
| 208 // other window. crbug.com/120680. |
| 209 TEST_F(SystemTrayTest, Activation) { |
| 210 SystemTray* tray = GetPrimarySystemTray(); |
| 211 std::unique_ptr<views::Widget> widget(CreateTestWidget( |
| 212 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 100, 100))); |
| 213 EXPECT_TRUE(widget->IsActive()); |
| 214 |
| 215 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 216 ASSERT_TRUE(tray->GetWidget()); |
| 217 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive()); |
| 218 EXPECT_TRUE(widget->IsActive()); |
| 219 |
| 220 tray->ActivateBubble(); |
| 221 EXPECT_TRUE(tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive()); |
| 222 EXPECT_FALSE(widget->IsActive()); |
| 223 |
| 224 // Accelerator will activate the bubble. |
| 225 tray->CloseSystemBubble(); |
| 226 |
| 227 EXPECT_TRUE(widget->IsActive()); |
| 228 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
| 229 SHOW_SYSTEM_TRAY_BUBBLE); |
| 230 EXPECT_TRUE(tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive()); |
| 231 EXPECT_FALSE(widget->IsActive()); |
| 232 } |
| 233 |
| 206 // Opening and closing the bubble should change the coloring of the tray. | 234 // Opening and closing the bubble should change the coloring of the tray. |
| 207 TEST_F(SystemTrayTest, SystemTrayColoring) { | 235 TEST_F(SystemTrayTest, SystemTrayColoring) { |
| 208 SystemTray* tray = GetPrimarySystemTray(); | 236 SystemTray* tray = GetPrimarySystemTray(); |
| 209 ASSERT_TRUE(tray->GetWidget()); | 237 ASSERT_TRUE(tray->GetWidget()); |
| 210 // At the beginning the tray coloring is not active. | 238 // At the beginning the tray coloring is not active. |
| 211 ASSERT_FALSE(tray->draw_background_as_active()); | 239 ASSERT_FALSE(tray->draw_background_as_active()); |
| 212 | 240 |
| 213 // Showing the system bubble should show the background as active. | 241 // Showing the system bubble should show the background as active. |
| 214 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 242 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 215 ASSERT_TRUE(tray->draw_background_as_active()); | 243 ASSERT_TRUE(tray->draw_background_as_active()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 ASSERT_TRUE(tray->GetWidget()); | 466 ASSERT_TRUE(tray->GetWidget()); |
| 439 | 467 |
| 440 TestSystemTrayItem* test_item = new TestSystemTrayItem(); | 468 TestSystemTrayItem* test_item = new TestSystemTrayItem(); |
| 441 tray->AddTrayItem(test_item); | 469 tray->AddTrayItem(test_item); |
| 442 | 470 |
| 443 std::unique_ptr<views::Widget> widget(CreateTestWidget( | 471 std::unique_ptr<views::Widget> widget(CreateTestWidget( |
| 444 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 100, 100))); | 472 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 100, 100))); |
| 445 | 473 |
| 446 // Tests for usual default view while activating a window. | 474 // Tests for usual default view while activating a window. |
| 447 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 475 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 476 tray->ActivateBubble(); |
| 448 ASSERT_TRUE(tray->HasSystemBubble()); | 477 ASSERT_TRUE(tray->HasSystemBubble()); |
| 449 widget->Activate(); | 478 widget->Activate(); |
| 450 base::RunLoop().RunUntilIdle(); | 479 base::RunLoop().RunUntilIdle(); |
| 451 ASSERT_FALSE(tray->HasSystemBubble()); | 480 ASSERT_FALSE(tray->HasSystemBubble()); |
| 452 | 481 |
| 453 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 482 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 454 ASSERT_TRUE(tray->HasSystemBubble()); | 483 ASSERT_TRUE(tray->HasSystemBubble()); |
| 455 { | 484 { |
| 456 ui::test::EventGenerator& generator = GetEventGenerator(); | 485 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 457 generator.set_current_location(gfx::Point(5, 5)); | 486 generator.set_current_location(gfx::Point(5, 5)); |
| 458 generator.ClickLeftButton(); | 487 generator.ClickLeftButton(); |
| 459 ASSERT_FALSE(tray->HasSystemBubble()); | 488 ASSERT_FALSE(tray->HasSystemBubble()); |
| 460 } | 489 } |
| 461 | 490 |
| 462 // Same tests for persistent default view. | 491 // Same tests for persistent default view. |
| 463 tray->ShowPersistentDefaultView(); | 492 tray->ShowPersistentDefaultView(); |
| 464 ASSERT_TRUE(tray->HasSystemBubble()); | 493 ASSERT_TRUE(tray->HasSystemBubble()); |
| 465 widget->Activate(); | 494 widget->Activate(); |
| 466 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
| 467 ASSERT_TRUE(tray->HasSystemBubble()); | 496 ASSERT_TRUE(tray->HasSystemBubble()); |
| 468 | 497 |
| 469 { | 498 { |
| 470 ui::test::EventGenerator& generator = GetEventGenerator(); | 499 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 471 generator.set_current_location(gfx::Point(5, 5)); | 500 generator.set_current_location(gfx::Point(5, 5)); |
| 472 generator.ClickLeftButton(); | 501 generator.ClickLeftButton(); |
| 473 ASSERT_TRUE(tray->HasSystemBubble()); | 502 ASSERT_TRUE(tray->HasSystemBubble()); |
| 474 } | 503 } |
| 504 |
| 505 // Same tests for persistent default view with activation. |
| 506 tray->ShowPersistentDefaultView(); |
| 507 EXPECT_TRUE(tray->HasSystemBubble()); |
| 508 widget->Activate(); |
| 509 base::RunLoop().RunUntilIdle(); |
| 510 EXPECT_TRUE(tray->HasSystemBubble()); |
| 511 |
| 512 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 513 generator.set_current_location(gfx::Point(5, 5)); |
| 514 generator.ClickLeftButton(); |
| 515 EXPECT_TRUE(tray->HasSystemBubble()); |
| 475 } | 516 } |
| 476 | 517 |
| 477 #if defined(OS_CHROMEOS) | 518 #if defined(OS_CHROMEOS) |
| 478 // Accessibility/Settings tray items are available only on cros. | 519 // Accessibility/Settings tray items are available only on cros. |
| 479 #define MAYBE_WithSystemModal WithSystemModal | 520 #define MAYBE_WithSystemModal WithSystemModal |
| 480 #else | 521 #else |
| 481 #define MAYBE_WithSystemModal DISABLED_WithSystemModal | 522 #define MAYBE_WithSystemModal DISABLED_WithSystemModal |
| 482 #endif | 523 #endif |
| 483 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { | 524 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { |
| 484 // Check if the accessibility item is created even with system modal dialog. | 525 // Check if the accessibility item is created even with system modal dialog. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // Hide the default view, ensure the tray bubble height is back to zero. | 640 // Hide the default view, ensure the tray bubble height is back to zero. |
| 600 ASSERT_TRUE(tray->CloseSystemBubble()); | 641 ASSERT_TRUE(tray->CloseSystemBubble()); |
| 601 RunAllPendingInMessageLoop(); | 642 RunAllPendingInMessageLoop(); |
| 602 | 643 |
| 603 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | 644 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); |
| 604 } | 645 } |
| 605 #endif // OS_CHROMEOS | 646 #endif // OS_CHROMEOS |
| 606 | 647 |
| 607 } // namespace test | 648 } // namespace test |
| 608 } // namespace ash | 649 } // namespace ash |
| OLD | NEW |