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

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: rebase 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
« athena/home/home_card_impl.cc ('K') | « 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. Assumed as if
29 // home card has textfield only for search box.
30 bool IsSearchBoxFocused(aura::Window* home_card) {
31 views::FocusManager* focus_manager =
32 views::Widget::GetWidgetForNativeWindow(home_card)->GetFocusManager();
33 return focus_manager->GetFocusedView() &&
34 focus_manager->GetFocusedView()->GetClassName() ==
35 views::Textfield::kViewClassName;
36 }
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.
37
25 typedef test::AthenaTestBase HomeCardTest; 38 typedef test::AthenaTestBase HomeCardTest;
26 39
27 TEST_F(HomeCardTest, BasicTransition) { 40 TEST_F(HomeCardTest, BasicTransition) {
28 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); 41 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
29 aura::Window* home_card = GetHomeCardWindow(); 42 aura::Window* home_card = GetHomeCardWindow();
30 const int screen_height = root_window()->bounds().height(); 43 const int screen_height = root_window()->bounds().height();
31 const int work_area_height = gfx::Screen::GetScreenFor(root_window())-> 44 const int work_area_height = gfx::Screen::GetScreenFor(root_window())->
32 GetDisplayNearestWindow(root_window()).work_area().height(); 45 GetDisplayNearestWindow(root_window()).work_area().height();
33 ASSERT_TRUE(home_card); 46 ASSERT_TRUE(home_card);
34 47
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const int x = screen_rect.x() + 1; 226 const int x = screen_rect.x() + 1;
214 227
215 generator.GestureScrollSequence(gfx::Point(x, bottom - 1), 228 generator.GestureScrollSequence(gfx::Point(x, bottom - 1),
216 gfx::Point(x, 20), 229 gfx::Point(x, 20),
217 base::TimeDelta::FromSeconds(1), 230 base::TimeDelta::FromSeconds(1),
218 10); 231 10);
219 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState()); 232 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
220 EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive()); 233 EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive());
221 } 234 }
222 235
236 TEST_F(HomeCardTest, KeyboardFocus) {
237 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
238 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.
239 ASSERT_FALSE(IsSearchBoxFocused(home_card));
240
241 WindowManager::GetInstance()->ToggleOverview();
242 ASSERT_FALSE(IsSearchBoxFocused(home_card));
243
244 ui::test::EventGenerator generator(root_window());
245 gfx::Rect screen_rect(root_window()->bounds());
246
247 const int bottom = screen_rect.bottom();
248 const int x = screen_rect.x() + 1;
249
250 generator.GestureScrollSequence(gfx::Point(x, bottom - 40),
251 gfx::Point(x, 10),
252 base::TimeDelta::FromSeconds(1),
253 10);
254 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
255 EXPECT_TRUE(IsSearchBoxFocused(home_card));
256
257 generator.GestureScrollSequence(gfx::Point(x, 10),
258 gfx::Point(x, bottom - 100),
259 base::TimeDelta::FromSeconds(1),
260 10);
261 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
262 EXPECT_FALSE(IsSearchBoxFocused(home_card));
263 }
264
223 } // namespace athena 265 } // namespace athena
OLDNEW
« athena/home/home_card_impl.cc ('K') | « athena/home/home_card_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698