Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1656)

Unified Diff: ash/focus_cycler_unittest.cc

Issue 2096153002: GetStatusAreaWidget from ash/test in focus_cycler_unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/focus_cycler_unittest.cc
diff --git a/ash/focus_cycler_unittest.cc b/ash/focus_cycler_unittest.cc
index 664a32f020953aca75f1f3e0af2cdb1a9c4082ad..2f1b912ee846d5c7ebab86b46fb33ee6243c142c 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"
+#include "ash/common/wm_root_window_controller.h"
#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"
@@ -57,6 +59,10 @@ class PanedWidgetDelegate : public views::WidgetDelegate {
std::vector<views::View*> accessible_panes_;
};
+SystemTray* GetSystemTray() {
James Cook 2016/06/24 22:31:42 Use AshTestBase::GetPrimarySystemTray() instead of
Qiang(Joe) Xu 2016/06/24 22:56:37 Done.
+ return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray();
+}
+
} // namespace
// TODO(jamescook): Migrate this test to //ash/common after the status area
@@ -73,14 +79,26 @@ class FocusCyclerTest : public AshTestBase {
ASSERT_TRUE(Shelf::ForPrimaryDisplay());
}
+ // Setup the system tray using StatusAreaWidgetTestHelper, returning true
+ // on success.
+ bool SetUpTrayFocusCycle() {
James Cook 2016/06/24 22:31:42 Keep this protected.
Qiang(Joe) Xu 2016/06/24 22:56:37 Done.
+ StatusAreaWidget* widget =
+ StatusAreaWidgetTestHelper::GetStatusAreaWidget();
+ widget->CreateTrayViews();
+ widget->Show();
+ if (!GetSystemTray()->GetWidget())
James Cook 2016/06/24 22:31:42 GetWidget() should always return a non-null pointe
Qiang(Joe) Xu 2016/06/24 22:56:37 Done.
+ return false;
+ focus_cycler_->AddWidget(GetSystemTray()->GetWidget());
James Cook 2016/06/24 22:31:42 nit: cache GetSystemTray()->GetWidget() in a local
Qiang(Joe) Xu 2016/06/24 22:56:37 Done.
+ GetStatusAreaWidgetDelegate(GetSystemTray()->GetWidget())
+ ->SetFocusCyclerForTesting(focus_cycler());
+ return true;
+ }
+
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);
James Cook 2016/06/24 22:31:42 Thanks for fixing these.
focus_cycler_.reset();
@@ -88,30 +106,8 @@ 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());
- 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());
- return true;
- }
-
FocusCycler* focus_cycler() { return focus_cycler_.get(); }
- SystemTray* tray() { return tray_.get(); }
-
ShelfWidget* shelf_widget() {
return Shelf::ForPrimaryDisplay()->shelf_widget();
}
@@ -123,7 +119,6 @@ class FocusCyclerTest : public AshTestBase {
private:
std::unique_ptr<FocusCycler> focus_cycler_;
- std::unique_ptr<SystemTray> tray_;
DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
};
@@ -140,7 +135,7 @@ TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
}
TEST_F(FocusCyclerTest, CycleFocusForward) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
James Cook 2016/06/24 22:31:42 with the assert above you won't need all these oth
InstallFocusCycleOnShelf();
@@ -151,7 +146,7 @@ TEST_F(FocusCyclerTest, CycleFocusForward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the shelf.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
@@ -163,7 +158,7 @@ TEST_F(FocusCyclerTest, CycleFocusForward) {
}
TEST_F(FocusCyclerTest, CycleFocusBackward) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
@@ -178,7 +173,7 @@ TEST_F(FocusCyclerTest, CycleFocusBackward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the browser.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
@@ -186,7 +181,7 @@ TEST_F(FocusCyclerTest, CycleFocusBackward) {
}
TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
@@ -201,7 +196,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the browser.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
@@ -209,7 +204,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the shelf.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
@@ -221,7 +216,7 @@ TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
}
TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
@@ -230,7 +225,7 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the shelf.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
@@ -238,7 +233,7 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the shelf.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
@@ -246,12 +241,12 @@ TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
}
// Tests that focus cycles from the active browser to the status area and back.
TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
shelf_widget()->Hide();
@@ -264,7 +259,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the browser.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
@@ -272,11 +267,11 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
}
TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
shelf_widget()->Hide();
@@ -287,7 +282,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the browser.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
@@ -295,7 +290,7 @@ TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
}
TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
- ASSERT_TRUE(CreateTray());
+ ASSERT_TRUE(SetUpTrayFocusCycle());
InstallFocusCycleOnShelf();
@@ -347,7 +342,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
// Cycle focus to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Cycle focus to the shelf.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
@@ -365,7 +360,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
// Cycle focus back to the status area.
focus_cycler()->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Reverse direction - back to the second pane in the browser.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
@@ -383,7 +378,7 @@ TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
// Back to the status area.
focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray()->GetWidget()->IsActive());
+ EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive());
// Pressing "Escape" while on the status area should
// deactivate it, and activate the browser window.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698