1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/keyboard/keyboard_controller.h"
8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/layout_manager.h"
14 #include "ui/aura/test/aura_test_helper.h"
15 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/base/ime/dummy_text_input_client.h"
19 #include "ui/base/ime/input_method.h"
20 #include "ui/base/ime/input_method_factory.h"
21 #include "ui/base/ime/text_input_client.h"
22 #include "ui/base/ime/text_input_focus_manager.h"
23 #include "ui/base/ui_base_switches_util.h"
24 #include "ui/compositor/compositor.h"
25 #include "ui/compositor/layer_type.h"
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
27 #include "ui/compositor/test/context_factories_for_test.h"
28 #include "ui/compositor/test/layer_animator_test_controller.h"
29 #include "ui/events/test/event_generator.h"
30 #include "ui/gfx/geometry/rect.h"
31 #include "ui/keyboard/keyboard_controller_observer.h"
32 #include "ui/keyboard/keyboard_controller_proxy.h"
33 #include "ui/keyboard/keyboard_switches.h"
34 #include "ui/keyboard/keyboard_util.h"
35 #include "ui/wm/core/default_activation_client.h"
40 // Steps a layer animation until it is completed. Animations must be enabled.
41 void RunAnimationForLayer(ui::Layer
* layer
) {
42 // Animations must be enabled for stepping to work.
43 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
44 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION
);
46 ui::LayerAnimatorTestController
controller(layer
->GetAnimator());
47 // Multiple steps are required to complete complex animations.
48 // TODO(vollick): This should not be necessary. crbug.com/154017
49 while (controller
.animator()->is_animating()) {
50 controller
.StartThreadedAnimationsIfNeeded();
51 base::TimeTicks step_time
= controller
.animator()->last_step_time();
52 controller
.animator()->Step(step_time
+
53 base::TimeDelta::FromMilliseconds(1000));
57 // An event handler that focuses a window when it is clicked/touched on. This is
58 // used to match the focus manger behaviour in ash and views.
59 class TestFocusController
: public ui::EventHandler
{
61 explicit TestFocusController(aura::Window
* root
)
63 root_
->AddPreTargetHandler(this);
66 virtual ~TestFocusController() {
67 root_
->RemovePreTargetHandler(this);
71 // Overridden from ui::EventHandler:
72 virtual void OnEvent(ui::Event
* event
) OVERRIDE
{
73 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
74 if (event
->type() == ui::ET_MOUSE_PRESSED
||
75 event
->type() == ui::ET_TOUCH_PRESSED
) {
76 aura::client::GetFocusClient(target
)->FocusWindow(target
);
81 DISALLOW_COPY_AND_ASSIGN(TestFocusController
);
84 class TestKeyboardControllerProxy
: public KeyboardControllerProxy
{
86 TestKeyboardControllerProxy()
88 ui::CreateInputMethod(NULL
, gfx::kNullAcceleratedWidget
)) {}
90 virtual ~TestKeyboardControllerProxy() {
91 // Destroy the window before the delegate.
95 // Overridden from KeyboardControllerProxy:
96 virtual bool HasKeyboardWindow() const OVERRIDE
{ return window_
; }
97 virtual aura::Window
* GetKeyboardWindow() OVERRIDE
{
99 window_
.reset(new aura::Window(&delegate_
));
100 window_
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
101 window_
->set_owned_by_parent(false);
103 return window_
.get();
105 virtual content::BrowserContext
* GetBrowserContext() OVERRIDE
{ return NULL
; }
106 virtual ui::InputMethod
* GetInputMethod() OVERRIDE
{
107 return input_method_
.get();
109 virtual void RequestAudioInput(content::WebContents
* web_contents
,
110 const content::MediaStreamRequest
& request
,
111 const content::MediaResponseCallback
& callback
) OVERRIDE
{ return; }
112 virtual void LoadSystemKeyboard() OVERRIDE
{};
113 virtual void ReloadKeyboardIfNeeded() OVERRIDE
{};
116 scoped_ptr
<aura::Window
> window_
;
117 aura::test::TestWindowDelegate delegate_
;
118 scoped_ptr
<ui::InputMethod
> input_method_
;
120 DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy
);
123 // Keeps a count of all the events a window receives.
124 class EventObserver
: public ui::EventHandler
{
127 virtual ~EventObserver() {}
129 int GetEventCount(ui::EventType type
) {
130 return event_counts_
[type
];
134 // Overridden from ui::EventHandler:
135 virtual void OnEvent(ui::Event
* event
) OVERRIDE
{
136 ui::EventHandler::OnEvent(event
);
137 event_counts_
[event
->type()]++;
140 std::map
<ui::EventType
, int> event_counts_
;
141 DISALLOW_COPY_AND_ASSIGN(EventObserver
);
144 class KeyboardContainerObserver
: public aura::WindowObserver
{
146 explicit KeyboardContainerObserver(aura::Window
* window
) : window_(window
) {
147 window_
->AddObserver(this);
149 virtual ~KeyboardContainerObserver() {
150 window_
->RemoveObserver(this);
154 virtual void OnWindowVisibilityChanged(aura::Window
* window
,
155 bool visible
) OVERRIDE
{
157 base::MessageLoop::current()->Quit();
160 aura::Window
* window_
;
162 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver
);
167 class KeyboardControllerTest
: public testing::Test
{
169 KeyboardControllerTest() {}
170 virtual ~KeyboardControllerTest() {}
172 virtual void SetUp() OVERRIDE
{
173 // The ContextFactory must exist before any Compositors are created.
174 bool enable_pixel_output
= false;
175 ui::ContextFactory
* context_factory
=
176 ui::InitializeContextFactoryForTests(enable_pixel_output
);
178 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
179 aura_test_helper_
->SetUp(context_factory
);
180 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
181 ui::SetUpInputMethodFactoryForTesting();
182 if (::switches::IsTextInputFocusManagerEnabled())
183 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL
);
184 focus_controller_
.reset(new TestFocusController(root_window()));
185 proxy_
= new TestKeyboardControllerProxy();
186 controller_
.reset(new KeyboardController(proxy_
));
189 virtual void TearDown() OVERRIDE
{
191 focus_controller_
.reset();
192 if (::switches::IsTextInputFocusManagerEnabled())
193 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL
);
194 aura_test_helper_
->TearDown();
195 ui::TerminateContextFactoryForTests();
198 aura::Window
* root_window() { return aura_test_helper_
->root_window(); }
199 KeyboardControllerProxy
* proxy() { return proxy_
; }
200 KeyboardController
* controller() { return controller_
.get(); }
202 void ShowKeyboard() {
203 test_text_input_client_
.reset(
204 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT
));
205 SetFocus(test_text_input_client_
.get());
209 void SetFocus(ui::TextInputClient
* client
) {
210 ui::InputMethod
* input_method
= proxy()->GetInputMethod();
211 if (::switches::IsTextInputFocusManagerEnabled()) {
212 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client
);
213 input_method
->OnTextInputTypeChanged(client
);
215 input_method
->SetFocusedTextInputClient(client
);
217 if (client
&& client
->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE
) {
218 input_method
->ShowImeIfNeeded();
219 if (proxy_
->GetKeyboardWindow()->bounds().height() == 0) {
220 // Set initial bounds for test keyboard window.
221 proxy_
->GetKeyboardWindow()->SetBounds(
222 KeyboardBoundsFromWindowBounds(
223 controller()->GetContainerWindow()->bounds(), 100));
228 bool WillHideKeyboard() {
229 return controller_
->WillHideKeyboard();
232 base::MessageLoopForUI message_loop_
;
233 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
234 scoped_ptr
<TestFocusController
> focus_controller_
;
237 KeyboardControllerProxy
* proxy_
;
238 scoped_ptr
<KeyboardController
> controller_
;
239 scoped_ptr
<ui::TextInputClient
> test_text_input_client_
;
240 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest
);
243 TEST_F(KeyboardControllerTest
, KeyboardSize
) {
244 aura::Window
* container(controller()->GetContainerWindow());
245 aura::Window
* keyboard(proxy()->GetKeyboardWindow());
246 container
->SetBounds(gfx::Rect(0, 0, 200, 100));
248 container
->AddChild(keyboard
);
249 const gfx::Rect
& before_bounds
= keyboard
->bounds();
250 // The initial keyboard should be positioned at the bottom of container and
252 ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds
);
254 gfx::Rect
new_bounds(
255 before_bounds
.x(), before_bounds
.y() - 50,
256 before_bounds
.width(), 50);
258 keyboard
->SetBounds(new_bounds
);
259 ASSERT_EQ(new_bounds
, keyboard
->bounds());
261 // Mock a screen rotation.
262 container
->SetBounds(gfx::Rect(0, 0, 100, 200));
263 // The above call should resize keyboard to new width while keeping the old
265 ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard
->bounds());
268 // Tests that tapping/clicking inside the keyboard does not give it focus.
269 TEST_F(KeyboardControllerTest
, ClickDoesNotFocusKeyboard
) {
270 const gfx::Rect
& root_bounds
= root_window()->bounds();
271 aura::test::EventCountDelegate delegate
;
272 scoped_ptr
<aura::Window
> window(new aura::Window(&delegate
));
273 window
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
274 window
->SetBounds(root_bounds
);
275 root_window()->AddChild(window
.get());
279 aura::Window
* keyboard_container(controller()->GetContainerWindow());
280 keyboard_container
->SetBounds(root_bounds
);
282 root_window()->AddChild(keyboard_container
);
283 keyboard_container
->Show();
287 EXPECT_TRUE(window
->IsVisible());
288 EXPECT_TRUE(keyboard_container
->IsVisible());
289 EXPECT_TRUE(window
->HasFocus());
290 EXPECT_FALSE(keyboard_container
->HasFocus());
292 // Click on the keyboard. Make sure the keyboard receives the event, but does
294 EventObserver observer
;
295 keyboard_container
->AddPreTargetHandler(&observer
);
297 ui::test::EventGenerator
generator(root_window());
298 generator
.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint());
299 generator
.ClickLeftButton();
300 EXPECT_TRUE(window
->HasFocus());
301 EXPECT_FALSE(keyboard_container
->HasFocus());
302 EXPECT_EQ("0 0", delegate
.GetMouseButtonCountsAndReset());
303 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_PRESSED
));
304 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_RELEASED
));
306 // Click outside of the keyboard. It should reach the window behind.
307 generator
.MoveMouseTo(gfx::Point());
308 generator
.ClickLeftButton();
309 EXPECT_EQ("1 1", delegate
.GetMouseButtonCountsAndReset());
310 keyboard_container
->RemovePreTargetHandler(&observer
);
313 TEST_F(KeyboardControllerTest
, EventHitTestingInContainer
) {
314 const gfx::Rect
& root_bounds
= root_window()->bounds();
315 aura::test::EventCountDelegate delegate
;
316 scoped_ptr
<aura::Window
> window(new aura::Window(&delegate
));
317 window
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
318 window
->SetBounds(root_bounds
);
319 root_window()->AddChild(window
.get());
323 aura::Window
* keyboard_container(controller()->GetContainerWindow());
324 keyboard_container
->SetBounds(root_bounds
);
326 root_window()->AddChild(keyboard_container
);
327 keyboard_container
->Show();
331 EXPECT_TRUE(window
->IsVisible());
332 EXPECT_TRUE(keyboard_container
->IsVisible());
333 EXPECT_TRUE(window
->HasFocus());
334 EXPECT_FALSE(keyboard_container
->HasFocus());
336 // Make sure hit testing works correctly while the keyboard is visible.
337 aura::Window
* keyboard_window
= proxy()->GetKeyboardWindow();
338 ui::EventTarget
* root
= root_window();
339 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
340 gfx::Point location
= keyboard_window
->bounds().CenterPoint();
341 ui::MouseEvent
mouse1(ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
,
343 EXPECT_EQ(keyboard_window
, targeter
->FindTargetForEvent(root
, &mouse1
));
345 location
.set_y(keyboard_window
->bounds().y() - 5);
346 ui::MouseEvent
mouse2(ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
,
348 EXPECT_EQ(window
.get(), targeter
->FindTargetForEvent(root
, &mouse2
));
351 TEST_F(KeyboardControllerTest
, KeyboardWindowCreation
) {
352 const gfx::Rect
& root_bounds
= root_window()->bounds();
353 aura::test::EventCountDelegate delegate
;
354 scoped_ptr
<aura::Window
> window(new aura::Window(&delegate
));
355 window
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
356 window
->SetBounds(root_bounds
);
357 root_window()->AddChild(window
.get());
361 aura::Window
* keyboard_container(controller()->GetContainerWindow());
362 keyboard_container
->SetBounds(root_bounds
);
364 root_window()->AddChild(keyboard_container
);
365 keyboard_container
->Show();
367 EXPECT_FALSE(proxy()->HasKeyboardWindow());
369 ui::EventTarget
* root
= root_window();
370 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
371 gfx::Point
location(root_window()->bounds().width() / 2,
372 root_window()->bounds().height() - 10);
373 ui::MouseEvent
mouse(
374 ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
, ui::EF_NONE
);
375 EXPECT_EQ(window
.get(), targeter
->FindTargetForEvent(root
, &mouse
));
376 EXPECT_FALSE(proxy()->HasKeyboardWindow());
379 controller()->GetContainerWindow(),
380 controller()->GetContainerWindow()->GetEventHandlerForPoint(location
));
381 EXPECT_FALSE(proxy()->HasKeyboardWindow());
384 TEST_F(KeyboardControllerTest
, VisibilityChangeWithTextInputTypeChange
) {
385 const gfx::Rect
& root_bounds
= root_window()->bounds();
387 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
388 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
389 ui::DummyTextInputClient
input_client_2(ui::TEXT_INPUT_TYPE_TEXT
);
390 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
391 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
393 aura::Window
* keyboard_container(controller()->GetContainerWindow());
394 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
395 new KeyboardContainerObserver(keyboard_container
));
396 keyboard_container
->SetBounds(root_bounds
);
397 root_window()->AddChild(keyboard_container
);
399 SetFocus(&input_client_0
);
401 EXPECT_TRUE(keyboard_container
->IsVisible());
403 SetFocus(&no_input_client_0
);
404 // Keyboard should not immediately hide itself. It is delayed to avoid layout
405 // flicker when the focus of input field quickly change.
406 EXPECT_TRUE(keyboard_container
->IsVisible());
407 EXPECT_TRUE(WillHideKeyboard());
408 // Wait for hide keyboard to finish.
409 base::MessageLoop::current()->Run();
410 EXPECT_FALSE(keyboard_container
->IsVisible());
412 SetFocus(&input_client_1
);
413 EXPECT_TRUE(keyboard_container
->IsVisible());
415 // Schedule to hide keyboard.
416 SetFocus(&no_input_client_1
);
417 EXPECT_TRUE(WillHideKeyboard());
418 // Cancel keyboard hide.
419 SetFocus(&input_client_2
);
421 EXPECT_FALSE(WillHideKeyboard());
422 EXPECT_TRUE(keyboard_container
->IsVisible());
425 TEST_F(KeyboardControllerTest
, AlwaysVisibleWhenLocked
) {
426 const gfx::Rect
& root_bounds
= root_window()->bounds();
428 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
429 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
430 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
431 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
433 aura::Window
* keyboard_container(controller()->GetContainerWindow());
434 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
435 new KeyboardContainerObserver(keyboard_container
));
436 keyboard_container
->SetBounds(root_bounds
);
437 root_window()->AddChild(keyboard_container
);
439 SetFocus(&input_client_0
);
441 EXPECT_TRUE(keyboard_container
->IsVisible());
444 controller()->set_lock_keyboard(true);
446 SetFocus(&no_input_client_0
);
447 // Keyboard should not try to hide itself as it is locked.
448 EXPECT_TRUE(keyboard_container
->IsVisible());
449 EXPECT_FALSE(WillHideKeyboard());
451 SetFocus(&input_client_1
);
452 EXPECT_TRUE(keyboard_container
->IsVisible());
455 controller()->set_lock_keyboard(false);
457 // Keyboard should hide when focus on no input client.
458 SetFocus(&no_input_client_1
);
459 EXPECT_TRUE(WillHideKeyboard());
461 // Wait for hide keyboard to finish.
462 base::MessageLoop::current()->Run();
463 EXPECT_FALSE(keyboard_container
->IsVisible());
466 class KeyboardControllerAnimationTest
: public KeyboardControllerTest
,
467 public KeyboardControllerObserver
{
469 KeyboardControllerAnimationTest() {}
470 virtual ~KeyboardControllerAnimationTest() {}
472 virtual void SetUp() OVERRIDE
{
473 // We cannot short-circuit animations for this test.
474 ui::ScopedAnimationDurationScaleMode
test_duration_mode(
475 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
);
477 KeyboardControllerTest::SetUp();
479 const gfx::Rect
& root_bounds
= root_window()->bounds();
480 keyboard_container()->SetBounds(root_bounds
);
481 root_window()->AddChild(keyboard_container());
482 controller()->AddObserver(this);
485 virtual void TearDown() OVERRIDE
{
486 controller()->RemoveObserver(this);
487 KeyboardControllerTest::TearDown();
491 // KeyboardControllerObserver overrides
492 virtual void OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) OVERRIDE
{
493 notified_bounds_
= new_bounds
;
496 const gfx::Rect
& notified_bounds() { return notified_bounds_
; }
498 aura::Window
* keyboard_container() {
499 return controller()->GetContainerWindow();
502 aura::Window
* keyboard_window() {
503 return proxy()->GetKeyboardWindow();
507 gfx::Rect notified_bounds_
;
509 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest
);
512 // Tests virtual keyboard has correct show and hide animation.
513 TEST_F(KeyboardControllerAnimationTest
, ContainerAnimation
) {
514 ui::Layer
* layer
= keyboard_container()->layer();
517 // Keyboard container and window should immediately become visible before
519 EXPECT_TRUE(keyboard_container()->IsVisible());
520 EXPECT_TRUE(keyboard_window()->IsVisible());
521 float show_start_opacity
= layer
->opacity();
522 gfx::Transform transform
;
523 transform
.Translate(0, keyboard_window()->bounds().height());
524 EXPECT_EQ(transform
, layer
->transform());
525 EXPECT_EQ(gfx::Rect(), notified_bounds());
527 RunAnimationForLayer(layer
);
528 EXPECT_TRUE(keyboard_container()->IsVisible());
529 EXPECT_TRUE(keyboard_window()->IsVisible());
530 float show_end_opacity
= layer
->opacity();
531 EXPECT_LT(show_start_opacity
, show_end_opacity
);
532 EXPECT_EQ(gfx::Transform(), layer
->transform());
533 // KeyboardController should notify the bounds of keyboard window to its
534 // observers after show animation finished.
535 EXPECT_EQ(keyboard_window()->bounds(), notified_bounds());
537 // Directly hide keyboard without delay.
538 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
539 EXPECT_TRUE(keyboard_container()->IsVisible());
540 EXPECT_TRUE(keyboard_container()->layer()->visible());
541 EXPECT_TRUE(keyboard_window()->IsVisible());
542 float hide_start_opacity
= layer
->opacity();
543 // KeyboardController should notify the bounds of keyboard window to its
544 // observers before hide animation starts.
545 EXPECT_EQ(gfx::Rect(), notified_bounds());
547 RunAnimationForLayer(layer
);
548 EXPECT_FALSE(keyboard_container()->IsVisible());
549 EXPECT_FALSE(keyboard_container()->layer()->visible());
550 EXPECT_FALSE(keyboard_window()->IsVisible());
551 float hide_end_opacity
= layer
->opacity();
552 EXPECT_GT(hide_start_opacity
, hide_end_opacity
);
553 EXPECT_EQ(transform
, layer
->transform());
554 EXPECT_EQ(gfx::Rect(), notified_bounds());
557 // Show keyboard during keyboard hide animation should abort the hide animation
558 // and the keyboard should animate in.
559 // Test for crbug.com/333284.
560 TEST_F(KeyboardControllerAnimationTest
, ContainerShowWhileHide
) {
561 ui::Layer
* layer
= keyboard_container()->layer();
563 RunAnimationForLayer(layer
);
565 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
566 // Before hide animation finishes, show keyboard again.
568 RunAnimationForLayer(layer
);
569 EXPECT_TRUE(keyboard_container()->IsVisible());
570 EXPECT_TRUE(keyboard_window()->IsVisible());
571 EXPECT_EQ(1.0, layer
->opacity());
572 EXPECT_EQ(gfx::Transform(), layer
->transform());
575 class KeyboardControllerUsabilityTest
: public KeyboardControllerTest
{
577 KeyboardControllerUsabilityTest() {}
578 virtual ~KeyboardControllerUsabilityTest() {}
580 virtual void SetUp() OVERRIDE
{
581 CommandLine::ForCurrentProcess()->AppendSwitch(
582 switches::kKeyboardUsabilityExperiment
);
583 KeyboardControllerTest::SetUp();
587 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest
);
590 TEST_F(KeyboardControllerUsabilityTest
, KeyboardAlwaysVisibleInUsabilityTest
) {
591 const gfx::Rect
& root_bounds
= root_window()->bounds();
593 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
594 ui::DummyTextInputClient
no_input_client(ui::TEXT_INPUT_TYPE_NONE
);
596 aura::Window
* keyboard_container(controller()->GetContainerWindow());
597 keyboard_container
->SetBounds(root_bounds
);
598 root_window()->AddChild(keyboard_container
);
600 SetFocus(&input_client
);
601 EXPECT_TRUE(keyboard_container
->IsVisible());
603 SetFocus(&no_input_client
);
604 // Keyboard should not hide itself after lost focus.
605 EXPECT_TRUE(keyboard_container
->IsVisible());
606 EXPECT_FALSE(WillHideKeyboard());
609 } // namespace keyboard