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/event_utils.h"
30 #include "ui/events/test/event_generator.h"
31 #include "ui/gfx/geometry/rect.h"
32 #include "ui/keyboard/keyboard_controller_observer.h"
33 #include "ui/keyboard/keyboard_controller_proxy.h"
34 #include "ui/keyboard/keyboard_util.h"
35 #include "ui/wm/core/default_activation_client.h"
40 const int kDefaultVirtualKeyboardHeight
= 100;
42 // Verify if the |keyboard| window covers the |container| window completely.
43 void VerifyKeyboardWindowSize(aura::Window
* container
, aura::Window
* keyboard
) {
44 ASSERT_EQ(gfx::Rect(0, 0, container
->bounds().width(),
45 container
->bounds().height()),
49 // Steps a layer animation until it is completed. Animations must be enabled.
50 void RunAnimationForLayer(ui::Layer
* layer
) {
51 // Animations must be enabled for stepping to work.
52 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
53 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION
);
55 ui::LayerAnimatorTestController
controller(layer
->GetAnimator());
56 // Multiple steps are required to complete complex animations.
57 // TODO(vollick): This should not be necessary. crbug.com/154017
58 while (controller
.animator()->is_animating()) {
59 controller
.StartThreadedAnimationsIfNeeded();
60 base::TimeTicks step_time
= controller
.animator()->last_step_time();
61 controller
.animator()->Step(step_time
+
62 base::TimeDelta::FromMilliseconds(1000));
66 // An event handler that focuses a window when it is clicked/touched on. This is
67 // used to match the focus manger behaviour in ash and views.
68 class TestFocusController
: public ui::EventHandler
{
70 explicit TestFocusController(aura::Window
* root
)
72 root_
->AddPreTargetHandler(this);
75 ~TestFocusController() override
{ root_
->RemovePreTargetHandler(this); }
78 // Overridden from ui::EventHandler:
79 void OnEvent(ui::Event
* event
) override
{
80 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
81 if (event
->type() == ui::ET_MOUSE_PRESSED
||
82 event
->type() == ui::ET_TOUCH_PRESSED
) {
83 aura::client::GetFocusClient(target
)->FocusWindow(target
);
88 DISALLOW_COPY_AND_ASSIGN(TestFocusController
);
91 class TestKeyboardControllerProxy
: public KeyboardControllerProxy
{
93 TestKeyboardControllerProxy()
94 : KeyboardControllerProxy(nullptr),
96 ui::CreateInputMethod(nullptr, gfx::kNullAcceleratedWidget
)) {}
98 ~TestKeyboardControllerProxy() override
{
99 // Destroy the window before the delegate.
103 // Overridden from KeyboardControllerProxy:
104 bool HasKeyboardWindow() const override
{ return window_
; }
105 aura::Window
* GetKeyboardWindow() override
{
107 window_
.reset(new aura::Window(&delegate_
));
108 window_
->Init(ui::LAYER_NOT_DRAWN
);
109 window_
->set_owned_by_parent(false);
111 return window_
.get();
113 ui::InputMethod
* GetInputMethod() override
{ return input_method_
.get(); }
114 void RequestAudioInput(
115 content::WebContents
* web_contents
,
116 const content::MediaStreamRequest
& request
,
117 const content::MediaResponseCallback
& callback
) override
{
120 void LoadSystemKeyboard() override
{};
121 void ReloadKeyboardIfNeeded() override
{};
124 scoped_ptr
<aura::Window
> window_
;
125 aura::test::TestWindowDelegate delegate_
;
126 scoped_ptr
<ui::InputMethod
> input_method_
;
128 DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy
);
131 // Keeps a count of all the events a window receives.
132 class EventObserver
: public ui::EventHandler
{
135 ~EventObserver() override
{}
137 int GetEventCount(ui::EventType type
) {
138 return event_counts_
[type
];
142 // Overridden from ui::EventHandler:
143 void OnEvent(ui::Event
* event
) override
{
144 ui::EventHandler::OnEvent(event
);
145 event_counts_
[event
->type()]++;
148 std::map
<ui::EventType
, int> event_counts_
;
149 DISALLOW_COPY_AND_ASSIGN(EventObserver
);
152 class KeyboardContainerObserver
: public aura::WindowObserver
{
154 explicit KeyboardContainerObserver(aura::Window
* window
) : window_(window
) {
155 window_
->AddObserver(this);
157 ~KeyboardContainerObserver() override
{ window_
->RemoveObserver(this); }
160 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
{
162 base::MessageLoop::current()->Quit();
165 aura::Window
* window_
;
167 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver
);
172 class KeyboardControllerTest
: public testing::Test
,
173 public KeyboardControllerObserver
{
175 KeyboardControllerTest() : number_of_calls_(0) {}
176 ~KeyboardControllerTest() override
{}
178 void SetUp() override
{
179 // The ContextFactory must exist before any Compositors are created.
180 bool enable_pixel_output
= false;
181 ui::ContextFactory
* context_factory
=
182 ui::InitializeContextFactoryForTests(enable_pixel_output
);
184 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
185 aura_test_helper_
->SetUp(context_factory
);
186 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
187 ui::SetUpInputMethodFactoryForTesting();
188 if (::switches::IsTextInputFocusManagerEnabled())
189 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL
);
190 focus_controller_
.reset(new TestFocusController(root_window()));
191 proxy_
= new TestKeyboardControllerProxy();
192 controller_
.reset(new KeyboardController(proxy_
));
193 controller()->AddObserver(this);
196 void TearDown() override
{
197 controller()->RemoveObserver(this);
199 focus_controller_
.reset();
200 if (::switches::IsTextInputFocusManagerEnabled())
201 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL
);
202 aura_test_helper_
->TearDown();
203 ui::TerminateContextFactoryForTests();
206 aura::Window
* root_window() { return aura_test_helper_
->root_window(); }
207 KeyboardControllerProxy
* proxy() { return proxy_
; }
208 KeyboardController
* controller() { return controller_
.get(); }
210 void ShowKeyboard() {
211 test_text_input_client_
.reset(
212 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT
));
213 SetFocus(test_text_input_client_
.get());
216 void MockRotateScreen() {
217 const gfx::Rect root_bounds
= root_window()->bounds();
218 controller_
->OnWindowBoundsChanged(root_window(), gfx::Rect(),
221 root_bounds
.height(),
222 root_bounds
.width()));
226 // KeyboardControllerObserver overrides
227 void OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) override
{
228 notified_bounds_
= new_bounds
;
232 int number_of_calls() const { return number_of_calls_
; }
234 const gfx::Rect
& notified_bounds() { return notified_bounds_
; }
236 void SetFocus(ui::TextInputClient
* client
) {
237 ui::InputMethod
* input_method
= proxy()->GetInputMethod();
238 if (::switches::IsTextInputFocusManagerEnabled()) {
239 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client
);
240 input_method
->OnTextInputTypeChanged(client
);
242 input_method
->SetFocusedTextInputClient(client
);
244 if (client
&& client
->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE
) {
245 input_method
->ShowImeIfNeeded();
246 if (proxy_
->GetKeyboardWindow()->bounds().height() == 0) {
247 // Set initial bounds for test keyboard window.
248 proxy_
->GetKeyboardWindow()->SetBounds(
249 FullWidthKeyboardBoundsFromRootBounds(
250 root_window()->bounds(), kDefaultVirtualKeyboardHeight
));
255 bool WillHideKeyboard() {
256 return controller_
->WillHideKeyboard();
259 bool ShouldEnableInsets(aura::Window
* window
) {
260 return controller_
->ShouldEnableInsets(window
);
263 base::MessageLoopForUI message_loop_
;
264 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
265 scoped_ptr
<TestFocusController
> focus_controller_
;
268 int number_of_calls_
;
269 gfx::Rect notified_bounds_
;
270 KeyboardControllerProxy
* proxy_
;
271 scoped_ptr
<KeyboardController
> controller_
;
272 scoped_ptr
<ui::TextInputClient
> test_text_input_client_
;
273 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest
);
276 TEST_F(KeyboardControllerTest
, KeyboardSize
) {
277 aura::Window
* container(controller()->GetContainerWindow());
278 aura::Window
* keyboard(proxy()->GetKeyboardWindow());
279 gfx::Rect screen_bounds
= root_window()->bounds();
280 root_window()->AddChild(container
);
281 container
->AddChild(keyboard
);
282 const gfx::Rect
& initial_bounds
= container
->bounds();
283 // The container should be positioned at the bottom of screen and has 0
285 ASSERT_EQ(gfx::Rect(), initial_bounds
);
286 VerifyKeyboardWindowSize(container
, keyboard
);
288 gfx::Rect
new_bounds(0, 0, 50, 50);
290 // In FULL_WIDTH mode, attempt to change window width or move window up from
291 // the bottom are ignored. Changing window height is supported.
292 gfx::Rect
expected_bounds(0,
293 screen_bounds
.height() - 50,
294 screen_bounds
.width(),
297 keyboard
->SetBounds(new_bounds
);
298 ASSERT_EQ(expected_bounds
, container
->bounds());
299 VerifyKeyboardWindowSize(container
, keyboard
);
302 // The above call should resize keyboard to new width while keeping the old
304 ASSERT_EQ(gfx::Rect(0,
305 screen_bounds
.width() - 50,
306 screen_bounds
.height(),
308 container
->bounds());
309 VerifyKeyboardWindowSize(container
, keyboard
);
312 TEST_F(KeyboardControllerTest
, FloatingKeyboardSize
) {
313 aura::Window
* container(controller()->GetContainerWindow());
314 aura::Window
* keyboard(proxy()->GetKeyboardWindow());
315 gfx::Rect screen_bounds
= root_window()->bounds();
316 root_window()->AddChild(container
);
317 controller()->SetKeyboardMode(FLOATING
);
318 container
->AddChild(keyboard
);
319 gfx::Rect
new_bounds(0, 50, 50, 50);
320 keyboard
->SetBounds(new_bounds
);
321 ASSERT_EQ(new_bounds
, container
->bounds());
322 VerifyKeyboardWindowSize(container
, keyboard
);
325 // Tests that tapping/clicking inside the keyboard does not give it focus.
326 TEST_F(KeyboardControllerTest
, ClickDoesNotFocusKeyboard
) {
327 const gfx::Rect
& root_bounds
= root_window()->bounds();
328 aura::test::EventCountDelegate delegate
;
329 scoped_ptr
<aura::Window
> window(new aura::Window(&delegate
));
330 window
->Init(ui::LAYER_NOT_DRAWN
);
331 window
->SetBounds(root_bounds
);
332 root_window()->AddChild(window
.get());
336 aura::Window
* keyboard_container(controller()->GetContainerWindow());
338 root_window()->AddChild(keyboard_container
);
339 keyboard_container
->Show();
343 EXPECT_TRUE(window
->IsVisible());
344 EXPECT_TRUE(keyboard_container
->IsVisible());
345 EXPECT_TRUE(window
->HasFocus());
346 EXPECT_FALSE(keyboard_container
->HasFocus());
348 // Click on the keyboard. Make sure the keyboard receives the event, but does
350 EventObserver observer
;
351 keyboard_container
->AddPreTargetHandler(&observer
);
353 ui::test::EventGenerator
generator(root_window());
354 generator
.MoveMouseTo(keyboard_container
->bounds().CenterPoint());
355 generator
.ClickLeftButton();
356 EXPECT_TRUE(window
->HasFocus());
357 EXPECT_FALSE(keyboard_container
->HasFocus());
358 EXPECT_EQ("0 0", delegate
.GetMouseButtonCountsAndReset());
359 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_PRESSED
));
360 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_RELEASED
));
362 // Click outside of the keyboard. It should reach the window behind.
363 generator
.MoveMouseTo(gfx::Point());
364 generator
.ClickLeftButton();
365 EXPECT_EQ("1 1", delegate
.GetMouseButtonCountsAndReset());
366 keyboard_container
->RemovePreTargetHandler(&observer
);
369 TEST_F(KeyboardControllerTest
, VisibilityChangeWithTextInputTypeChange
) {
370 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
371 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
372 ui::DummyTextInputClient
input_client_2(ui::TEXT_INPUT_TYPE_TEXT
);
373 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
374 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
376 aura::Window
* keyboard_container(controller()->GetContainerWindow());
377 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
378 new KeyboardContainerObserver(keyboard_container
));
379 root_window()->AddChild(keyboard_container
);
381 SetFocus(&input_client_0
);
383 EXPECT_TRUE(keyboard_container
->IsVisible());
385 SetFocus(&no_input_client_0
);
386 // Keyboard should not immediately hide itself. It is delayed to avoid layout
387 // flicker when the focus of input field quickly change.
388 EXPECT_TRUE(keyboard_container
->IsVisible());
389 EXPECT_TRUE(WillHideKeyboard());
390 // Wait for hide keyboard to finish.
391 base::MessageLoop::current()->Run();
392 EXPECT_FALSE(keyboard_container
->IsVisible());
394 SetFocus(&input_client_1
);
395 EXPECT_TRUE(keyboard_container
->IsVisible());
397 // Schedule to hide keyboard.
398 SetFocus(&no_input_client_1
);
399 EXPECT_TRUE(WillHideKeyboard());
400 // Cancel keyboard hide.
401 SetFocus(&input_client_2
);
403 EXPECT_FALSE(WillHideKeyboard());
404 EXPECT_TRUE(keyboard_container
->IsVisible());
407 // Test to prevent spurious overscroll boxes when changing tabs during keyboard
408 // hide. Refer to crbug.com/401670 for more context.
409 TEST_F(KeyboardControllerTest
, CheckOverscrollInsetDuringVisibilityChange
) {
410 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
411 ui::DummyTextInputClient
no_input_client(ui::TEXT_INPUT_TYPE_NONE
);
413 aura::Window
* keyboard_container(controller()->GetContainerWindow());
414 root_window()->AddChild(keyboard_container
);
416 // Enable touch keyboard / overscroll mode to test insets.
417 keyboard::SetTouchKeyboardEnabled(true);
418 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
420 SetFocus(&input_client
);
421 SetFocus(&no_input_client
);
422 // Insets should not be enabled for new windows while keyboard is in the
423 // process of hiding when overscroll is enabled.
424 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
425 // Cancel keyboard hide.
426 SetFocus(&input_client
);
427 // Insets should be enabled for new windows as hide was cancelled.
428 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
431 // Verify switch to FLOATING mode will reset the overscroll or resize and when
432 // in FLOATING mode, overscroll or resize wont be triggered.
433 TEST_F(KeyboardControllerTest
, FloatingKeyboardDontOverscrollOrResize
) {
434 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
435 ui::DummyTextInputClient
no_input_client(ui::TEXT_INPUT_TYPE_NONE
);
437 aura::Window
* container(controller()->GetContainerWindow());
438 root_window()->AddChild(container
);
439 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
440 new KeyboardContainerObserver(container
));
441 gfx::Rect screen_bounds
= root_window()->bounds();
442 keyboard::SetTouchKeyboardEnabled(true);
444 SetFocus(&input_client
);
445 gfx::Rect
expected_bounds(
446 0, screen_bounds
.height() - kDefaultVirtualKeyboardHeight
,
447 screen_bounds
.width(), kDefaultVirtualKeyboardHeight
);
448 // Verify overscroll or resize is in effect.
449 EXPECT_EQ(expected_bounds
, notified_bounds());
450 EXPECT_EQ(1, number_of_calls());
452 controller()->SetKeyboardMode(FLOATING
);
453 // Switch to FLOATING should clear overscroll or resize.
454 EXPECT_EQ(gfx::Rect(), notified_bounds());
455 EXPECT_EQ(2, number_of_calls());
456 SetFocus(&no_input_client
);
457 base::MessageLoop::current()->Run();
458 EXPECT_EQ(gfx::Rect(), notified_bounds());
459 EXPECT_EQ(3, number_of_calls());
460 SetFocus(&input_client
);
461 // In FLOATING mode, no overscroll or resize should be triggered.
462 EXPECT_EQ(3, number_of_calls());
463 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
466 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right
467 // place and sets the correct overscroll.
468 TEST_F(KeyboardControllerTest
, SwitchToFullWidthVirtualKeyboard
) {
469 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
471 aura::Window
* container(controller()->GetContainerWindow());
472 root_window()->AddChild(container
);
473 gfx::Rect screen_bounds
= root_window()->bounds();
474 keyboard::SetTouchKeyboardEnabled(true);
475 SetFocus(&input_client
);
477 controller()->SetKeyboardMode(FLOATING
);
478 EXPECT_EQ(gfx::Rect(), notified_bounds());
479 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
481 controller()->SetKeyboardMode(FULL_WIDTH
);
482 gfx::Rect
expected_bounds(
483 0, screen_bounds
.height() - kDefaultVirtualKeyboardHeight
,
484 screen_bounds
.width(), kDefaultVirtualKeyboardHeight
);
485 EXPECT_EQ(expected_bounds
, notified_bounds());
486 EXPECT_EQ(expected_bounds
, controller()->current_keyboard_bounds());
489 TEST_F(KeyboardControllerTest
, AlwaysVisibleWhenLocked
) {
490 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
491 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
492 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
493 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
495 aura::Window
* keyboard_container(controller()->GetContainerWindow());
496 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
497 new KeyboardContainerObserver(keyboard_container
));
498 root_window()->AddChild(keyboard_container
);
500 SetFocus(&input_client_0
);
502 EXPECT_TRUE(keyboard_container
->IsVisible());
505 controller()->set_lock_keyboard(true);
507 SetFocus(&no_input_client_0
);
508 // Keyboard should not try to hide itself as it is locked.
509 EXPECT_TRUE(keyboard_container
->IsVisible());
510 EXPECT_FALSE(WillHideKeyboard());
512 SetFocus(&input_client_1
);
513 EXPECT_TRUE(keyboard_container
->IsVisible());
516 controller()->set_lock_keyboard(false);
518 // Keyboard should hide when focus on no input client.
519 SetFocus(&no_input_client_1
);
520 EXPECT_TRUE(WillHideKeyboard());
522 // Wait for hide keyboard to finish.
523 base::MessageLoop::current()->Run();
524 EXPECT_FALSE(keyboard_container
->IsVisible());
527 class KeyboardControllerAnimationTest
: public KeyboardControllerTest
{
529 KeyboardControllerAnimationTest() {}
530 ~KeyboardControllerAnimationTest() override
{}
532 void SetUp() override
{
533 // We cannot short-circuit animations for this test.
534 ui::ScopedAnimationDurationScaleMode
test_duration_mode(
535 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
);
537 KeyboardControllerTest::SetUp();
539 const gfx::Rect
& root_bounds
= root_window()->bounds();
540 keyboard_container()->SetBounds(root_bounds
);
541 root_window()->AddChild(keyboard_container());
544 void TearDown() override
{
545 KeyboardControllerTest::TearDown();
549 aura::Window
* keyboard_container() {
550 return controller()->GetContainerWindow();
553 aura::Window
* keyboard_window() {
554 return proxy()->GetKeyboardWindow();
558 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest
);
561 // Tests virtual keyboard has correct show and hide animation.
562 TEST_F(KeyboardControllerAnimationTest
, ContainerAnimation
) {
563 ui::Layer
* layer
= keyboard_container()->layer();
566 // Keyboard container and window should immediately become visible before
568 EXPECT_TRUE(keyboard_container()->IsVisible());
569 EXPECT_TRUE(keyboard_window()->IsVisible());
570 float show_start_opacity
= layer
->opacity();
571 gfx::Transform transform
;
572 transform
.Translate(0, kAnimationDistance
);
573 EXPECT_EQ(transform
, layer
->transform());
574 EXPECT_EQ(gfx::Rect(), notified_bounds());
576 RunAnimationForLayer(layer
);
577 EXPECT_TRUE(keyboard_container()->IsVisible());
578 EXPECT_TRUE(keyboard_window()->IsVisible());
579 float show_end_opacity
= layer
->opacity();
580 EXPECT_LT(show_start_opacity
, show_end_opacity
);
581 EXPECT_EQ(gfx::Transform(), layer
->transform());
582 // KeyboardController should notify the bounds of container window to its
583 // observers after show animation finished.
584 EXPECT_EQ(keyboard_container()->bounds(), notified_bounds());
586 // Directly hide keyboard without delay.
587 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
588 EXPECT_TRUE(keyboard_container()->IsVisible());
589 EXPECT_TRUE(keyboard_container()->layer()->visible());
590 EXPECT_TRUE(keyboard_window()->IsVisible());
591 float hide_start_opacity
= layer
->opacity();
592 // KeyboardController should notify the bounds of keyboard window to its
593 // observers before hide animation starts.
594 EXPECT_EQ(gfx::Rect(), notified_bounds());
596 RunAnimationForLayer(layer
);
597 EXPECT_FALSE(keyboard_container()->IsVisible());
598 EXPECT_FALSE(keyboard_container()->layer()->visible());
599 EXPECT_FALSE(keyboard_window()->IsVisible());
600 float hide_end_opacity
= layer
->opacity();
601 EXPECT_GT(hide_start_opacity
, hide_end_opacity
);
602 EXPECT_EQ(transform
, layer
->transform());
603 EXPECT_EQ(gfx::Rect(), notified_bounds());
606 // Show keyboard during keyboard hide animation should abort the hide animation
607 // and the keyboard should animate in.
608 // Test for crbug.com/333284.
609 TEST_F(KeyboardControllerAnimationTest
, ContainerShowWhileHide
) {
610 ui::Layer
* layer
= keyboard_container()->layer();
612 RunAnimationForLayer(layer
);
614 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
615 // Before hide animation finishes, show keyboard again.
617 RunAnimationForLayer(layer
);
618 EXPECT_TRUE(keyboard_container()->IsVisible());
619 EXPECT_TRUE(keyboard_window()->IsVisible());
620 EXPECT_EQ(1.0, layer
->opacity());
621 EXPECT_EQ(gfx::Transform(), layer
->transform());
624 } // namespace keyboard