Index: athena/home/home_card_unittest.cc |
diff --git a/athena/home/home_card_unittest.cc b/athena/home/home_card_unittest.cc |
index 63653051696bbf0a091b2ce6515aaeab72fb686d..46a32514aeaaadff77d97dc5d9d1f6167470b833 100644 |
--- a/athena/home/home_card_unittest.cc |
+++ b/athena/home/home_card_unittest.cc |
@@ -14,6 +14,9 @@ |
#include "ui/events/test/event_generator.h" |
#include "ui/gfx/display.h" |
#include "ui/gfx/screen.h" |
+#include "ui/views/controls/textfield/textfield.h" |
+#include "ui/views/focus/focus_manager.h" |
+#include "ui/views/widget/widget.h" |
namespace athena { |
@@ -22,6 +25,12 @@ aura::Window* GetHomeCardWindow() { |
GetHomeCardWindowForTest(); |
} |
+// Returns true if the keyboard focus is on the search box. |
+bool IsSearchBoxFocused(aura::Window* home_card) { |
+ return views::Widget::GetWidgetForNativeWindow(home_card)-> |
+ GetContentsView()->GetViewByID(kHomeCardSearchBoxId)->HasFocus(); |
+} |
+ |
typedef test::AthenaTestBase HomeCardTest; |
TEST_F(HomeCardTest, BasicTransition) { |
@@ -220,4 +229,33 @@ TEST_F(HomeCardTest, GesturesToFullDirectly) { |
EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive()); |
} |
+TEST_F(HomeCardTest, KeyboardFocus) { |
+ ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); |
+ aura::Window* home_card = GetHomeCardWindow(); |
+ ASSERT_FALSE(IsSearchBoxFocused(home_card)); |
+ |
+ WindowManager::GetInstance()->ToggleOverview(); |
+ ASSERT_FALSE(IsSearchBoxFocused(home_card)); |
+ |
+ ui::test::EventGenerator generator(root_window()); |
+ gfx::Rect screen_rect(root_window()->bounds()); |
+ |
+ const int bottom = screen_rect.bottom(); |
+ const int x = screen_rect.x() + 1; |
+ |
+ generator.GestureScrollSequence(gfx::Point(x, bottom - 40), |
+ gfx::Point(x, 10), |
+ base::TimeDelta::FromSeconds(1), |
+ 10); |
+ EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState()); |
+ EXPECT_TRUE(IsSearchBoxFocused(home_card)); |
+ |
+ generator.GestureScrollSequence(gfx::Point(x, 10), |
+ gfx::Point(x, bottom - 100), |
+ base::TimeDelta::FromSeconds(1), |
+ 10); |
+ EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); |
+ EXPECT_FALSE(IsSearchBoxFocused(home_card)); |
+} |
+ |
} // namespace athena |