Chromium Code Reviews| 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..7f04d9509f60229e34ef787215f6d8944968e4a0 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,16 @@ aura::Window* GetHomeCardWindow() { |
| GetHomeCardWindowForTest(); |
| } |
| +// Returns true if the keyboard focus is on the search box. Assumed as if |
| +// home card has textfield only for search box. |
| +bool IsSearchBoxFocused(aura::Window* home_card) { |
| + views::FocusManager* focus_manager = |
| + views::Widget::GetWidgetForNativeWindow(home_card)->GetFocusManager(); |
| + return focus_manager->GetFocusedView() && |
| + focus_manager->GetFocusedView()->GetClassName() == |
| + views::Textfield::kViewClassName; |
| +} |
|
oshima
2014/08/28 19:33:12
altenatively, you can use view ID to get the view
Jun Mukai
2014/08/28 21:26:25
Done.
|
| + |
| typedef test::AthenaTestBase HomeCardTest; |
| TEST_F(HomeCardTest, BasicTransition) { |
| @@ -220,4 +233,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 = HomeCard::Get()->GetHomeCardWindowForTest(); |
|
oshima
2014/08/28 19:33:12
don't you need to cast to impl?
Jun Mukai
2014/08/28 21:26:25
Fixed. Relies on old code.
|
| + 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 |