Chromium Code Reviews| Index: ash/focus_cycler_unittest.cc |
| diff --git a/ash/focus_cycler_unittest.cc b/ash/focus_cycler_unittest.cc |
| index 664a32f020953aca75f1f3e0af2cdb1a9c4082ad..9ddfb870db2837406a04158b1dc85d894bd35cdd 100644 |
| --- a/ash/focus_cycler_unittest.cc |
| +++ b/ash/focus_cycler_unittest.cc |
| @@ -7,6 +7,7 @@ |
| #include <memory> |
| #include "ash/common/shell_window_ids.h" |
|
James Cook
2016/06/24 23:04:14
nit: do you need this include?
Qiang(Joe) Xu
2016/06/24 23:34:08
Both are not needed. And "ash/common/wm_window.h"
|
| +#include "ash/common/wm_root_window_controller.h" |
|
James Cook
2016/06/24 23:04:14
nit: or this one?
|
| #include "ash/common/wm_shell.h" |
| #include "ash/common/wm_window.h" |
| #include "ash/shelf/shelf.h" |
| @@ -15,6 +16,7 @@ |
| #include "ash/system/status_area_widget_delegate.h" |
| #include "ash/system/tray/system_tray.h" |
| #include "ash/test/ash_test_base.h" |
| +#include "ash/test/status_area_widget_test_helper.h" |
| #include "ash/wm/window_util.h" |
| #include "ui/aura/test/test_windows.h" |
| #include "ui/aura/window.h" |
| @@ -74,13 +76,10 @@ class FocusCyclerTest : public AshTestBase { |
| } |
| void TearDown() override { |
| - if (tray_) { |
| - GetStatusAreaWidgetDelegate(tray_->GetWidget())-> |
| - SetFocusCyclerForTesting(NULL); |
| - tray_.reset(); |
| - } |
| + GetStatusAreaWidgetDelegate(GetSystemTray()->GetWidget()) |
| + ->SetFocusCyclerForTesting(nullptr); |
| - shelf_widget()->SetFocusCycler(NULL); |
| + shelf_widget()->SetFocusCycler(nullptr); |
| focus_cycler_.reset(); |
| @@ -88,30 +87,22 @@ class FocusCyclerTest : public AshTestBase { |
| } |
| protected: |
| - // Creates the system tray, returning true on success. |
| - bool CreateTray() { |
| - if (tray_) |
| - return false; |
| - WmWindow* parent = |
| - WmShell::Get()->GetRootWindowForNewWindows()->GetChildByShellWindowId( |
| - kShellWindowId_StatusContainer); |
| - |
| - StatusAreaWidget* widget = new StatusAreaWidget(parent, GetPrimaryShelf()); |
| + // Setup the system tray using StatusAreaWidgetTestHelper and focus_cycler. |
| + void SetUpTrayFocusCycle() { |
| + StatusAreaWidget* widget = |
| + StatusAreaWidgetTestHelper::GetStatusAreaWidget(); |
| widget->CreateTrayViews(); |
| widget->Show(); |
| - tray_.reset(widget->system_tray()); |
| - if (!tray_->GetWidget()) |
| - return false; |
| - focus_cycler_->AddWidget(tray()->GetWidget()); |
| - GetStatusAreaWidgetDelegate(tray_->GetWidget())->SetFocusCyclerForTesting( |
| - focus_cycler()); |
| + views::Widget* system_tray_widget = GetPrimarySystemTray()->GetWidget(); |
| + ASSERT_TRUE(system_tray_widget); |
| + focus_cycler_->AddWidget(system_tray_widget); |
| + GetStatusAreaWidgetDelegate(system_tray_widget) |
| + ->SetFocusCyclerForTesting(focus_cycler()); |
| return true; |
| } |
| FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| - SystemTray* tray() { return tray_.get(); } |
| - |
| ShelfWidget* shelf_widget() { |
| return Shelf::ForPrimaryDisplay()->shelf_widget(); |
| } |
| @@ -123,7 +114,6 @@ class FocusCyclerTest : public AshTestBase { |
| private: |
| std::unique_ptr<FocusCycler> focus_cycler_; |
| - std::unique_ptr<SystemTray> tray_; |
| DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); |
| }; |
| @@ -140,7 +130,7 @@ TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
| } |
| TEST_F(FocusCyclerTest, CycleFocusForward) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| @@ -151,7 +141,7 @@ TEST_F(FocusCyclerTest, CycleFocusForward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the shelf. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| @@ -163,7 +153,7 @@ TEST_F(FocusCyclerTest, CycleFocusForward) { |
| } |
| TEST_F(FocusCyclerTest, CycleFocusBackward) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| @@ -178,7 +168,7 @@ TEST_F(FocusCyclerTest, CycleFocusBackward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the browser. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| @@ -186,7 +176,7 @@ TEST_F(FocusCyclerTest, CycleFocusBackward) { |
| } |
| TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| @@ -201,7 +191,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the browser. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| @@ -209,7 +199,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the shelf. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| @@ -221,7 +211,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| } |
| TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| @@ -230,7 +220,7 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the shelf. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| @@ -238,7 +228,7 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the shelf. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| @@ -246,12 +236,12 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| } |
| // Tests that focus cycles from the active browser to the status area and back. |
| TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| shelf_widget()->Hide(); |
| @@ -264,7 +254,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the browser. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| @@ -272,11 +262,11 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| } |
| TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| shelf_widget()->Hide(); |
| @@ -287,7 +277,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the browser. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| @@ -295,7 +285,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
| } |
| TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
| - ASSERT_TRUE(CreateTray()); |
| + SetUpTrayFocusCycle(); |
| InstallFocusCycleOnShelf(); |
| @@ -347,7 +337,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
| // Cycle focus to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Cycle focus to the shelf. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| @@ -365,7 +355,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
| // Cycle focus back to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Reverse direction - back to the second pane in the browser. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| @@ -383,7 +373,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
| // Back to the status area. |
| focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| - EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| + EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
| // Pressing "Escape" while on the status area should |
| // deactivate it, and activate the browser window. |