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

Side by Side Diff: athena/home/home_card_unittest.cc

Issue 512963002: Clears focus on gesture event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « athena/home/home_card_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/home/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include "athena/activity/public/activity_factory.h" 7 #include "athena/activity/public/activity_factory.h"
8 #include "athena/activity/public/activity_manager.h" 8 #include "athena/activity/public/activity_manager.h"
9 #include "athena/home/home_card_constants.h" 9 #include "athena/home/home_card_constants.h"
10 #include "athena/home/home_card_impl.h" 10 #include "athena/home/home_card_impl.h"
11 #include "athena/test/athena_test_base.h" 11 #include "athena/test/athena_test_base.h"
12 #include "athena/wm/public/window_manager.h" 12 #include "athena/wm/public/window_manager.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/events/test/event_generator.h" 14 #include "ui/events/test/event_generator.h"
15 #include "ui/gfx/display.h" 15 #include "ui/gfx/display.h"
16 #include "ui/gfx/screen.h" 16 #include "ui/gfx/screen.h"
17 #include "ui/views/controls/textfield/textfield.h"
18 #include "ui/views/focus/focus_manager.h"
19 #include "ui/views/widget/widget.h"
17 20
18 namespace athena { 21 namespace athena {
19 22
20 aura::Window* GetHomeCardWindow() { 23 aura::Window* GetHomeCardWindow() {
21 return static_cast<HomeCardImpl*>(HomeCard::Get())-> 24 return static_cast<HomeCardImpl*>(HomeCard::Get())->
22 GetHomeCardWindowForTest(); 25 GetHomeCardWindowForTest();
23 } 26 }
24 27
28 // Returns true if the keyboard focus is on the search box.
29 bool IsSearchBoxFocused(aura::Window* home_card) {
30 return views::Widget::GetWidgetForNativeWindow(home_card)->
31 GetContentsView()->GetViewByID(kHomeCardSearchBoxId)->HasFocus();
32 }
33
25 typedef test::AthenaTestBase HomeCardTest; 34 typedef test::AthenaTestBase HomeCardTest;
26 35
27 TEST_F(HomeCardTest, BasicTransition) { 36 TEST_F(HomeCardTest, BasicTransition) {
28 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); 37 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
29 aura::Window* home_card = GetHomeCardWindow(); 38 aura::Window* home_card = GetHomeCardWindow();
30 const int screen_height = root_window()->bounds().height(); 39 const int screen_height = root_window()->bounds().height();
31 const int work_area_height = gfx::Screen::GetScreenFor(root_window())-> 40 const int work_area_height = gfx::Screen::GetScreenFor(root_window())->
32 GetDisplayNearestWindow(root_window()).work_area().height(); 41 GetDisplayNearestWindow(root_window()).work_area().height();
33 ASSERT_TRUE(home_card); 42 ASSERT_TRUE(home_card);
34 43
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const int x = screen_rect.x() + 1; 222 const int x = screen_rect.x() + 1;
214 223
215 generator.GestureScrollSequence(gfx::Point(x, bottom - 1), 224 generator.GestureScrollSequence(gfx::Point(x, bottom - 1),
216 gfx::Point(x, 20), 225 gfx::Point(x, 20),
217 base::TimeDelta::FromSeconds(1), 226 base::TimeDelta::FromSeconds(1),
218 10); 227 10);
219 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState()); 228 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
220 EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive()); 229 EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive());
221 } 230 }
222 231
232 TEST_F(HomeCardTest, KeyboardFocus) {
233 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
234 aura::Window* home_card = GetHomeCardWindow();
235 ASSERT_FALSE(IsSearchBoxFocused(home_card));
236
237 WindowManager::GetInstance()->ToggleOverview();
238 ASSERT_FALSE(IsSearchBoxFocused(home_card));
239
240 ui::test::EventGenerator generator(root_window());
241 gfx::Rect screen_rect(root_window()->bounds());
242
243 const int bottom = screen_rect.bottom();
244 const int x = screen_rect.x() + 1;
245
246 generator.GestureScrollSequence(gfx::Point(x, bottom - 40),
247 gfx::Point(x, 10),
248 base::TimeDelta::FromSeconds(1),
249 10);
250 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
251 EXPECT_TRUE(IsSearchBoxFocused(home_card));
252
253 generator.GestureScrollSequence(gfx::Point(x, 10),
254 gfx::Point(x, bottom - 100),
255 base::TimeDelta::FromSeconds(1),
256 10);
257 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
258 EXPECT_FALSE(IsSearchBoxFocused(home_card));
259 }
260
223 } // namespace athena 261 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/home_card_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698