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/compositor/compositor.h"
23 #include "ui/compositor/layer_type.h"
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
25 #include "ui/compositor/test/context_factories_for_test.h"
26 #include "ui/compositor/test/layer_animator_test_controller.h"
27 #include "ui/events/event_utils.h"
28 #include "ui/events/test/event_generator.h"
29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/keyboard/keyboard_controller_observer.h"
31 #include "ui/keyboard/keyboard_controller_proxy.h"
32 #include "ui/keyboard/keyboard_util.h"
33 #include "ui/wm/core/default_activation_client.h"
38 const int kDefaultVirtualKeyboardHeight
= 100;
40 // Verify if the |keyboard| window covers the |container| window completely.
41 void VerifyKeyboardWindowSize(aura::Window
* container
, aura::Window
* keyboard
) {
42 ASSERT_EQ(gfx::Rect(0, 0, container
->bounds().width(),
43 container
->bounds().height()),
47 // Steps a layer animation until it is completed. Animations must be enabled.
48 void RunAnimationForLayer(ui::Layer
* layer
) {
49 // Animations must be enabled for stepping to work.
50 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
51 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION
);
53 ui::LayerAnimatorTestController
controller(layer
->GetAnimator());
54 // Multiple steps are required to complete complex animations.
55 // TODO(vollick): This should not be necessary. crbug.com/154017
56 while (controller
.animator()->is_animating()) {
57 controller
.StartThreadedAnimationsIfNeeded();
58 base::TimeTicks step_time
= controller
.animator()->last_step_time();
59 controller
.animator()->Step(step_time
+
60 base::TimeDelta::FromMilliseconds(1000));
64 // An event handler that focuses a window when it is clicked/touched on. This is
65 // used to match the focus manger behaviour in ash and views.
66 class TestFocusController
: public ui::EventHandler
{
68 explicit TestFocusController(aura::Window
* root
)
70 root_
->AddPreTargetHandler(this);
73 ~TestFocusController() override
{ root_
->RemovePreTargetHandler(this); }
76 // Overridden from ui::EventHandler:
77 void OnEvent(ui::Event
* event
) override
{
78 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
79 if (event
->type() == ui::ET_MOUSE_PRESSED
||
80 event
->type() == ui::ET_TOUCH_PRESSED
) {
81 aura::client::GetFocusClient(target
)->FocusWindow(target
);
86 DISALLOW_COPY_AND_ASSIGN(TestFocusController
);
89 class TestKeyboardControllerProxy
: public KeyboardControllerProxy
{
91 TestKeyboardControllerProxy(ui::InputMethod
* input_method
)
92 : KeyboardControllerProxy(nullptr),
93 input_method_(input_method
) {}
95 ~TestKeyboardControllerProxy() override
{
96 // Destroy the window before the delegate.
100 // Overridden from KeyboardControllerProxy:
101 bool HasKeyboardWindow() const override
{ return window_
; }
102 aura::Window
* GetKeyboardWindow() override
{
104 window_
.reset(new aura::Window(&delegate_
));
105 window_
->Init(ui::LAYER_NOT_DRAWN
);
106 window_
->set_owned_by_parent(false);
108 return window_
.get();
110 ui::InputMethod
* GetInputMethod() override
{ return input_method_
; }
111 void RequestAudioInput(
112 content::WebContents
* web_contents
,
113 const content::MediaStreamRequest
& request
,
114 const content::MediaResponseCallback
& callback
) override
{
117 void LoadSystemKeyboard() override
{};
118 void ReloadKeyboardIfNeeded() override
{};
121 scoped_ptr
<aura::Window
> window_
;
122 aura::test::TestWindowDelegate delegate_
;
123 ui::InputMethod
* input_method_
;
125 DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy
);
128 // Keeps a count of all the events a window receives.
129 class EventObserver
: public ui::EventHandler
{
132 ~EventObserver() override
{}
134 int GetEventCount(ui::EventType type
) {
135 return event_counts_
[type
];
139 // Overridden from ui::EventHandler:
140 void OnEvent(ui::Event
* event
) override
{
141 ui::EventHandler::OnEvent(event
);
142 event_counts_
[event
->type()]++;
145 std::map
<ui::EventType
, int> event_counts_
;
146 DISALLOW_COPY_AND_ASSIGN(EventObserver
);
149 class KeyboardContainerObserver
: public aura::WindowObserver
{
151 explicit KeyboardContainerObserver(aura::Window
* window
) : window_(window
) {
152 window_
->AddObserver(this);
154 ~KeyboardContainerObserver() override
{ window_
->RemoveObserver(this); }
157 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
{
159 base::MessageLoop::current()->Quit();
162 aura::Window
* window_
;
164 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver
);
169 class KeyboardControllerTest
: public testing::Test
,
170 public KeyboardControllerObserver
{
172 KeyboardControllerTest() : number_of_calls_(0), proxy_(nullptr) {}
173 ~KeyboardControllerTest() override
{}
175 void SetUp() override
{
176 // The ContextFactory must exist before any Compositors are created.
177 bool enable_pixel_output
= false;
178 ui::ContextFactory
* context_factory
=
179 ui::InitializeContextFactoryForTests(enable_pixel_output
);
181 ui::SetUpInputMethodFactoryForTesting();
182 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
183 aura_test_helper_
->SetUp(context_factory
);
184 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
185 focus_controller_
.reset(new TestFocusController(root_window()));
186 proxy_
= new TestKeyboardControllerProxy(
187 aura_test_helper_
->host()->GetInputMethod());
188 controller_
.reset(new KeyboardController(proxy_
));
189 controller()->AddObserver(this);
192 void TearDown() override
{
193 controller()->RemoveObserver(this);
195 focus_controller_
.reset();
196 aura_test_helper_
->TearDown();
197 ui::TerminateContextFactoryForTests();
200 aura::Window
* root_window() { return aura_test_helper_
->root_window(); }
201 KeyboardControllerProxy
* proxy() { return proxy_
; }
202 KeyboardController
* controller() { return controller_
.get(); }
204 void ShowKeyboard() {
205 test_text_input_client_
.reset(
206 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT
));
207 SetFocus(test_text_input_client_
.get());
210 void MockRotateScreen() {
211 const gfx::Rect root_bounds
= root_window()->bounds();
212 controller_
->OnWindowBoundsChanged(root_window(), gfx::Rect(),
215 root_bounds
.height(),
216 root_bounds
.width()));
220 // KeyboardControllerObserver overrides
221 void OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) override
{
222 notified_bounds_
= new_bounds
;
226 int number_of_calls() const { return number_of_calls_
; }
228 const gfx::Rect
& notified_bounds() { return notified_bounds_
; }
230 void SetFocus(ui::TextInputClient
* client
) {
231 ui::InputMethod
* input_method
= proxy()->GetInputMethod();
232 input_method
->SetFocusedTextInputClient(client
);
233 if (client
&& client
->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE
) {
234 input_method
->ShowImeIfNeeded();
235 if (proxy_
->GetKeyboardWindow()->bounds().height() == 0) {
236 // Set initial bounds for test keyboard window.
237 proxy_
->GetKeyboardWindow()->SetBounds(
238 FullWidthKeyboardBoundsFromRootBounds(
239 root_window()->bounds(), kDefaultVirtualKeyboardHeight
));
244 bool WillHideKeyboard() {
245 return controller_
->WillHideKeyboard();
248 bool ShouldEnableInsets(aura::Window
* window
) {
249 return controller_
->ShouldEnableInsets(window
);
252 base::MessageLoopForUI message_loop_
;
253 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
254 scoped_ptr
<TestFocusController
> focus_controller_
;
257 int number_of_calls_
;
258 gfx::Rect notified_bounds_
;
259 KeyboardControllerProxy
* proxy_
;
260 scoped_ptr
<KeyboardController
> controller_
;
261 scoped_ptr
<ui::TextInputClient
> test_text_input_client_
;
262 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest
);
265 TEST_F(KeyboardControllerTest
, KeyboardSize
) {
266 aura::Window
* container(controller()->GetContainerWindow());
267 aura::Window
* keyboard(proxy()->GetKeyboardWindow());
268 gfx::Rect screen_bounds
= root_window()->bounds();
269 root_window()->AddChild(container
);
270 container
->AddChild(keyboard
);
271 const gfx::Rect
& initial_bounds
= container
->bounds();
272 // The container should be positioned at the bottom of screen and has 0
274 ASSERT_EQ(gfx::Rect(), initial_bounds
);
275 VerifyKeyboardWindowSize(container
, keyboard
);
278 // In FULL_WIDTH mode, attempt to change window width or move window up from
279 // the bottom are ignored. Changing window height is supported.
280 gfx::Rect
expected_bounds(0,
281 screen_bounds
.height() - 50,
282 screen_bounds
.width(),
285 // The x position of new bounds may not be 0 if shelf is on the left side of
286 // screen. In FULL_WIDTH mode, the virtual keyboard should always align with
287 // the left edge of screen. See http://crbug.com/510595.
288 gfx::Rect
new_bounds(10, 0, 50, 50);
289 keyboard
->SetBounds(new_bounds
);
290 ASSERT_EQ(expected_bounds
, container
->bounds());
291 VerifyKeyboardWindowSize(container
, keyboard
);
294 // The above call should resize keyboard to new width while keeping the old
296 ASSERT_EQ(gfx::Rect(0,
297 screen_bounds
.width() - 50,
298 screen_bounds
.height(),
300 container
->bounds());
301 VerifyKeyboardWindowSize(container
, keyboard
);
304 TEST_F(KeyboardControllerTest
, FloatingKeyboardSize
) {
305 aura::Window
* container(controller()->GetContainerWindow());
306 aura::Window
* keyboard(proxy()->GetKeyboardWindow());
307 gfx::Rect screen_bounds
= root_window()->bounds();
308 root_window()->AddChild(container
);
309 controller()->SetKeyboardMode(FLOATING
);
310 container
->AddChild(keyboard
);
311 gfx::Rect
new_bounds(0, 50, 50, 50);
312 keyboard
->SetBounds(new_bounds
);
313 ASSERT_EQ(new_bounds
, container
->bounds());
314 VerifyKeyboardWindowSize(container
, keyboard
);
317 // Tests that tapping/clicking inside the keyboard does not give it focus.
318 TEST_F(KeyboardControllerTest
, ClickDoesNotFocusKeyboard
) {
319 const gfx::Rect
& root_bounds
= root_window()->bounds();
320 aura::test::EventCountDelegate delegate
;
321 scoped_ptr
<aura::Window
> window(new aura::Window(&delegate
));
322 window
->Init(ui::LAYER_NOT_DRAWN
);
323 window
->SetBounds(root_bounds
);
324 root_window()->AddChild(window
.get());
328 aura::Window
* keyboard_container(controller()->GetContainerWindow());
330 root_window()->AddChild(keyboard_container
);
331 keyboard_container
->Show();
335 EXPECT_TRUE(window
->IsVisible());
336 EXPECT_TRUE(keyboard_container
->IsVisible());
337 EXPECT_TRUE(window
->HasFocus());
338 EXPECT_FALSE(keyboard_container
->HasFocus());
340 // Click on the keyboard. Make sure the keyboard receives the event, but does
342 EventObserver observer
;
343 keyboard_container
->AddPreTargetHandler(&observer
);
345 ui::test::EventGenerator
generator(root_window());
346 generator
.MoveMouseTo(keyboard_container
->bounds().CenterPoint());
347 generator
.ClickLeftButton();
348 EXPECT_TRUE(window
->HasFocus());
349 EXPECT_FALSE(keyboard_container
->HasFocus());
350 EXPECT_EQ("0 0", delegate
.GetMouseButtonCountsAndReset());
351 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_PRESSED
));
352 EXPECT_EQ(1, observer
.GetEventCount(ui::ET_MOUSE_RELEASED
));
354 // Click outside of the keyboard. It should reach the window behind.
355 generator
.MoveMouseTo(gfx::Point());
356 generator
.ClickLeftButton();
357 EXPECT_EQ("1 1", delegate
.GetMouseButtonCountsAndReset());
358 keyboard_container
->RemovePreTargetHandler(&observer
);
361 TEST_F(KeyboardControllerTest
, VisibilityChangeWithTextInputTypeChange
) {
362 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
363 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
364 ui::DummyTextInputClient
input_client_2(ui::TEXT_INPUT_TYPE_TEXT
);
365 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
366 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
368 aura::Window
* keyboard_container(controller()->GetContainerWindow());
369 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
370 new KeyboardContainerObserver(keyboard_container
));
371 root_window()->AddChild(keyboard_container
);
373 SetFocus(&input_client_0
);
375 EXPECT_TRUE(keyboard_container
->IsVisible());
377 SetFocus(&no_input_client_0
);
378 // Keyboard should not immediately hide itself. It is delayed to avoid layout
379 // flicker when the focus of input field quickly change.
380 EXPECT_TRUE(keyboard_container
->IsVisible());
381 EXPECT_TRUE(WillHideKeyboard());
382 // Wait for hide keyboard to finish.
383 base::MessageLoop::current()->Run();
384 EXPECT_FALSE(keyboard_container
->IsVisible());
386 SetFocus(&input_client_1
);
387 EXPECT_TRUE(keyboard_container
->IsVisible());
389 // Schedule to hide keyboard.
390 SetFocus(&no_input_client_1
);
391 EXPECT_TRUE(WillHideKeyboard());
392 // Cancel keyboard hide.
393 SetFocus(&input_client_2
);
395 EXPECT_FALSE(WillHideKeyboard());
396 EXPECT_TRUE(keyboard_container
->IsVisible());
399 // Test to prevent spurious overscroll boxes when changing tabs during keyboard
400 // hide. Refer to crbug.com/401670 for more context.
401 TEST_F(KeyboardControllerTest
, CheckOverscrollInsetDuringVisibilityChange
) {
402 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
403 ui::DummyTextInputClient
no_input_client(ui::TEXT_INPUT_TYPE_NONE
);
405 aura::Window
* keyboard_container(controller()->GetContainerWindow());
406 root_window()->AddChild(keyboard_container
);
408 // Enable touch keyboard / overscroll mode to test insets.
409 keyboard::SetTouchKeyboardEnabled(true);
410 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
412 SetFocus(&input_client
);
413 SetFocus(&no_input_client
);
414 // Insets should not be enabled for new windows while keyboard is in the
415 // process of hiding when overscroll is enabled.
416 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
417 // Cancel keyboard hide.
418 SetFocus(&input_client
);
419 // Insets should be enabled for new windows as hide was cancelled.
420 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
423 // Verify switch to FLOATING mode will reset the overscroll or resize and when
424 // in FLOATING mode, overscroll or resize wont be triggered.
425 TEST_F(KeyboardControllerTest
, FloatingKeyboardDontOverscrollOrResize
) {
426 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
427 ui::DummyTextInputClient
no_input_client(ui::TEXT_INPUT_TYPE_NONE
);
429 aura::Window
* container(controller()->GetContainerWindow());
430 root_window()->AddChild(container
);
431 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
432 new KeyboardContainerObserver(container
));
433 gfx::Rect screen_bounds
= root_window()->bounds();
434 keyboard::SetTouchKeyboardEnabled(true);
436 SetFocus(&input_client
);
437 gfx::Rect
expected_bounds(
438 0, screen_bounds
.height() - kDefaultVirtualKeyboardHeight
,
439 screen_bounds
.width(), kDefaultVirtualKeyboardHeight
);
440 // Verify overscroll or resize is in effect.
441 EXPECT_EQ(expected_bounds
, notified_bounds());
442 EXPECT_EQ(1, number_of_calls());
444 controller()->SetKeyboardMode(FLOATING
);
445 // Switch to FLOATING should clear overscroll or resize.
446 EXPECT_EQ(gfx::Rect(), notified_bounds());
447 EXPECT_EQ(2, number_of_calls());
448 SetFocus(&no_input_client
);
449 base::MessageLoop::current()->Run();
450 EXPECT_EQ(gfx::Rect(), notified_bounds());
451 EXPECT_EQ(3, number_of_calls());
452 SetFocus(&input_client
);
453 // In FLOATING mode, no overscroll or resize should be triggered.
454 EXPECT_EQ(3, number_of_calls());
455 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
458 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right
459 // place and sets the correct overscroll.
460 TEST_F(KeyboardControllerTest
, SwitchToFullWidthVirtualKeyboard
) {
461 ui::DummyTextInputClient
input_client(ui::TEXT_INPUT_TYPE_TEXT
);
463 aura::Window
* container(controller()->GetContainerWindow());
464 root_window()->AddChild(container
);
465 gfx::Rect screen_bounds
= root_window()->bounds();
466 keyboard::SetTouchKeyboardEnabled(true);
467 SetFocus(&input_client
);
469 controller()->SetKeyboardMode(FLOATING
);
470 EXPECT_EQ(gfx::Rect(), notified_bounds());
471 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
473 controller()->SetKeyboardMode(FULL_WIDTH
);
474 gfx::Rect
expected_bounds(
475 0, screen_bounds
.height() - kDefaultVirtualKeyboardHeight
,
476 screen_bounds
.width(), kDefaultVirtualKeyboardHeight
);
477 EXPECT_EQ(expected_bounds
, notified_bounds());
478 EXPECT_EQ(expected_bounds
, controller()->current_keyboard_bounds());
481 TEST_F(KeyboardControllerTest
, AlwaysVisibleWhenLocked
) {
482 ui::DummyTextInputClient
input_client_0(ui::TEXT_INPUT_TYPE_TEXT
);
483 ui::DummyTextInputClient
input_client_1(ui::TEXT_INPUT_TYPE_TEXT
);
484 ui::DummyTextInputClient
no_input_client_0(ui::TEXT_INPUT_TYPE_NONE
);
485 ui::DummyTextInputClient
no_input_client_1(ui::TEXT_INPUT_TYPE_NONE
);
487 aura::Window
* keyboard_container(controller()->GetContainerWindow());
488 scoped_ptr
<KeyboardContainerObserver
> keyboard_container_observer(
489 new KeyboardContainerObserver(keyboard_container
));
490 root_window()->AddChild(keyboard_container
);
492 SetFocus(&input_client_0
);
494 EXPECT_TRUE(keyboard_container
->IsVisible());
497 controller()->set_lock_keyboard(true);
499 SetFocus(&no_input_client_0
);
500 // Keyboard should not try to hide itself as it is locked.
501 EXPECT_TRUE(keyboard_container
->IsVisible());
502 EXPECT_FALSE(WillHideKeyboard());
504 SetFocus(&input_client_1
);
505 EXPECT_TRUE(keyboard_container
->IsVisible());
508 controller()->set_lock_keyboard(false);
510 // Keyboard should hide when focus on no input client.
511 SetFocus(&no_input_client_1
);
512 EXPECT_TRUE(WillHideKeyboard());
514 // Wait for hide keyboard to finish.
515 base::MessageLoop::current()->Run();
516 EXPECT_FALSE(keyboard_container
->IsVisible());
519 class KeyboardControllerAnimationTest
: public KeyboardControllerTest
{
521 KeyboardControllerAnimationTest() {}
522 ~KeyboardControllerAnimationTest() override
{}
524 void SetUp() override
{
525 // We cannot short-circuit animations for this test.
526 ui::ScopedAnimationDurationScaleMode
test_duration_mode(
527 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
);
529 KeyboardControllerTest::SetUp();
531 const gfx::Rect
& root_bounds
= root_window()->bounds();
532 keyboard_container()->SetBounds(root_bounds
);
533 root_window()->AddChild(keyboard_container());
536 void TearDown() override
{
537 KeyboardControllerTest::TearDown();
541 aura::Window
* keyboard_container() {
542 return controller()->GetContainerWindow();
545 aura::Window
* keyboard_window() {
546 return proxy()->GetKeyboardWindow();
550 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest
);
553 // Tests virtual keyboard has correct show and hide animation.
554 TEST_F(KeyboardControllerAnimationTest
, ContainerAnimation
) {
555 ui::Layer
* layer
= keyboard_container()->layer();
558 // Keyboard container and window should immediately become visible before
560 EXPECT_TRUE(keyboard_container()->IsVisible());
561 EXPECT_TRUE(keyboard_window()->IsVisible());
562 float show_start_opacity
= layer
->opacity();
563 gfx::Transform transform
;
564 transform
.Translate(0, kAnimationDistance
);
565 EXPECT_EQ(transform
, layer
->transform());
566 EXPECT_EQ(gfx::Rect(), notified_bounds());
568 RunAnimationForLayer(layer
);
569 EXPECT_TRUE(keyboard_container()->IsVisible());
570 EXPECT_TRUE(keyboard_window()->IsVisible());
571 float show_end_opacity
= layer
->opacity();
572 EXPECT_LT(show_start_opacity
, show_end_opacity
);
573 EXPECT_EQ(gfx::Transform(), layer
->transform());
574 // KeyboardController should notify the bounds of container window to its
575 // observers after show animation finished.
576 EXPECT_EQ(keyboard_container()->bounds(), notified_bounds());
578 // Directly hide keyboard without delay.
579 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
580 EXPECT_TRUE(keyboard_container()->IsVisible());
581 EXPECT_TRUE(keyboard_container()->layer()->visible());
582 EXPECT_TRUE(keyboard_window()->IsVisible());
583 float hide_start_opacity
= layer
->opacity();
584 // KeyboardController should notify the bounds of keyboard window to its
585 // observers before hide animation starts.
586 EXPECT_EQ(gfx::Rect(), notified_bounds());
588 RunAnimationForLayer(layer
);
589 EXPECT_FALSE(keyboard_container()->IsVisible());
590 EXPECT_FALSE(keyboard_container()->layer()->visible());
591 EXPECT_FALSE(keyboard_window()->IsVisible());
592 float hide_end_opacity
= layer
->opacity();
593 EXPECT_GT(hide_start_opacity
, hide_end_opacity
);
594 EXPECT_EQ(transform
, layer
->transform());
595 EXPECT_EQ(gfx::Rect(), notified_bounds());
598 // Show keyboard during keyboard hide animation should abort the hide animation
599 // and the keyboard should animate in.
600 // Test for crbug.com/333284.
601 TEST_F(KeyboardControllerAnimationTest
, ContainerShowWhileHide
) {
602 ui::Layer
* layer
= keyboard_container()->layer();
604 RunAnimationForLayer(layer
);
606 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC
);
607 // Before hide animation finishes, show keyboard again.
609 RunAnimationForLayer(layer
);
610 EXPECT_TRUE(keyboard_container()->IsVisible());
611 EXPECT_TRUE(keyboard_window()->IsVisible());
612 EXPECT_EQ(1.0, layer
->opacity());
613 EXPECT_EQ(gfx::Transform(), layer
->transform());
616 } // namespace keyboard