extensions: chrome.windows: rework window event dispatch
[chromium-blink-merge.git] / ui / keyboard / keyboard_controller_unittest.cc
blob116e43e9ad633b30a747c3c632c32af8fa72d5fa
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"
7 #include "base/bind.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"
35 namespace keyboard {
36 namespace {
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()),
44 keyboard->bounds());
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 {
67 public:
68 explicit TestFocusController(aura::Window* root)
69 : root_(root) {
70 root_->AddPreTargetHandler(this);
73 ~TestFocusController() override { root_->RemovePreTargetHandler(this); }
75 private:
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);
85 aura::Window* root_;
86 DISALLOW_COPY_AND_ASSIGN(TestFocusController);
89 class TestKeyboardControllerProxy : public KeyboardControllerProxy {
90 public:
91 TestKeyboardControllerProxy()
92 : KeyboardControllerProxy(nullptr),
93 input_method_(
94 ui::CreateInputMethod(nullptr, gfx::kNullAcceleratedWidget)) {}
96 ~TestKeyboardControllerProxy() override {
97 // Destroy the window before the delegate.
98 window_.reset();
101 // Overridden from KeyboardControllerProxy:
102 bool HasKeyboardWindow() const override { return window_; }
103 aura::Window* GetKeyboardWindow() override {
104 if (!window_) {
105 window_.reset(new aura::Window(&delegate_));
106 window_->Init(ui::LAYER_NOT_DRAWN);
107 window_->set_owned_by_parent(false);
109 return window_.get();
111 ui::InputMethod* GetInputMethod() override { return input_method_.get(); }
112 void RequestAudioInput(
113 content::WebContents* web_contents,
114 const content::MediaStreamRequest& request,
115 const content::MediaResponseCallback& callback) override {
116 return;
118 void LoadSystemKeyboard() override{};
119 void ReloadKeyboardIfNeeded() override{};
121 private:
122 scoped_ptr<aura::Window> window_;
123 aura::test::TestWindowDelegate delegate_;
124 scoped_ptr<ui::InputMethod> input_method_;
126 DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy);
129 // Keeps a count of all the events a window receives.
130 class EventObserver : public ui::EventHandler {
131 public:
132 EventObserver() {}
133 ~EventObserver() override {}
135 int GetEventCount(ui::EventType type) {
136 return event_counts_[type];
139 private:
140 // Overridden from ui::EventHandler:
141 void OnEvent(ui::Event* event) override {
142 ui::EventHandler::OnEvent(event);
143 event_counts_[event->type()]++;
146 std::map<ui::EventType, int> event_counts_;
147 DISALLOW_COPY_AND_ASSIGN(EventObserver);
150 class KeyboardContainerObserver : public aura::WindowObserver {
151 public:
152 explicit KeyboardContainerObserver(aura::Window* window) : window_(window) {
153 window_->AddObserver(this);
155 ~KeyboardContainerObserver() override { window_->RemoveObserver(this); }
157 private:
158 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
159 if (!visible)
160 base::MessageLoop::current()->Quit();
163 aura::Window* window_;
165 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver);
168 } // namespace
170 class KeyboardControllerTest : public testing::Test,
171 public KeyboardControllerObserver {
172 public:
173 KeyboardControllerTest() : number_of_calls_(0) {}
174 ~KeyboardControllerTest() override {}
176 void SetUp() override {
177 // The ContextFactory must exist before any Compositors are created.
178 bool enable_pixel_output = false;
179 ui::ContextFactory* context_factory =
180 ui::InitializeContextFactoryForTests(enable_pixel_output);
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 ui::SetUpInputMethodFactoryForTesting();
186 focus_controller_.reset(new TestFocusController(root_window()));
187 proxy_ = new TestKeyboardControllerProxy();
188 controller_.reset(new KeyboardController(proxy_));
189 controller()->AddObserver(this);
192 void TearDown() override {
193 controller()->RemoveObserver(this);
194 controller_.reset();
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(),
213 gfx::Rect(0,
215 root_bounds.height(),
216 root_bounds.width()));
219 protected:
220 // KeyboardControllerObserver overrides
221 void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override {
222 notified_bounds_ = new_bounds;
223 number_of_calls_++;
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_;
256 private:
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
273 // height.
274 ASSERT_EQ(gfx::Rect(), initial_bounds);
275 VerifyKeyboardWindowSize(container, keyboard);
277 gfx::Rect new_bounds(0, 0, 50, 50);
279 // In FULL_WIDTH mode, attempt to change window width or move window up from
280 // the bottom are ignored. Changing window height is supported.
281 gfx::Rect expected_bounds(0,
282 screen_bounds.height() - 50,
283 screen_bounds.width(),
284 50);
286 keyboard->SetBounds(new_bounds);
287 ASSERT_EQ(expected_bounds, container->bounds());
288 VerifyKeyboardWindowSize(container, keyboard);
290 MockRotateScreen();
291 // The above call should resize keyboard to new width while keeping the old
292 // height.
293 ASSERT_EQ(gfx::Rect(0,
294 screen_bounds.width() - 50,
295 screen_bounds.height(),
296 50),
297 container->bounds());
298 VerifyKeyboardWindowSize(container, keyboard);
301 TEST_F(KeyboardControllerTest, FloatingKeyboardSize) {
302 aura::Window* container(controller()->GetContainerWindow());
303 aura::Window* keyboard(proxy()->GetKeyboardWindow());
304 gfx::Rect screen_bounds = root_window()->bounds();
305 root_window()->AddChild(container);
306 controller()->SetKeyboardMode(FLOATING);
307 container->AddChild(keyboard);
308 gfx::Rect new_bounds(0, 50, 50, 50);
309 keyboard->SetBounds(new_bounds);
310 ASSERT_EQ(new_bounds, container->bounds());
311 VerifyKeyboardWindowSize(container, keyboard);
314 // Tests that tapping/clicking inside the keyboard does not give it focus.
315 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
316 const gfx::Rect& root_bounds = root_window()->bounds();
317 aura::test::EventCountDelegate delegate;
318 scoped_ptr<aura::Window> window(new aura::Window(&delegate));
319 window->Init(ui::LAYER_NOT_DRAWN);
320 window->SetBounds(root_bounds);
321 root_window()->AddChild(window.get());
322 window->Show();
323 window->Focus();
325 aura::Window* keyboard_container(controller()->GetContainerWindow());
327 root_window()->AddChild(keyboard_container);
328 keyboard_container->Show();
330 ShowKeyboard();
332 EXPECT_TRUE(window->IsVisible());
333 EXPECT_TRUE(keyboard_container->IsVisible());
334 EXPECT_TRUE(window->HasFocus());
335 EXPECT_FALSE(keyboard_container->HasFocus());
337 // Click on the keyboard. Make sure the keyboard receives the event, but does
338 // not get focus.
339 EventObserver observer;
340 keyboard_container->AddPreTargetHandler(&observer);
342 ui::test::EventGenerator generator(root_window());
343 generator.MoveMouseTo(keyboard_container->bounds().CenterPoint());
344 generator.ClickLeftButton();
345 EXPECT_TRUE(window->HasFocus());
346 EXPECT_FALSE(keyboard_container->HasFocus());
347 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset());
348 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED));
349 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED));
351 // Click outside of the keyboard. It should reach the window behind.
352 generator.MoveMouseTo(gfx::Point());
353 generator.ClickLeftButton();
354 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
355 keyboard_container->RemovePreTargetHandler(&observer);
358 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
359 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
360 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
361 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
362 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
363 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
365 aura::Window* keyboard_container(controller()->GetContainerWindow());
366 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
367 new KeyboardContainerObserver(keyboard_container));
368 root_window()->AddChild(keyboard_container);
370 SetFocus(&input_client_0);
372 EXPECT_TRUE(keyboard_container->IsVisible());
374 SetFocus(&no_input_client_0);
375 // Keyboard should not immediately hide itself. It is delayed to avoid layout
376 // flicker when the focus of input field quickly change.
377 EXPECT_TRUE(keyboard_container->IsVisible());
378 EXPECT_TRUE(WillHideKeyboard());
379 // Wait for hide keyboard to finish.
380 base::MessageLoop::current()->Run();
381 EXPECT_FALSE(keyboard_container->IsVisible());
383 SetFocus(&input_client_1);
384 EXPECT_TRUE(keyboard_container->IsVisible());
386 // Schedule to hide keyboard.
387 SetFocus(&no_input_client_1);
388 EXPECT_TRUE(WillHideKeyboard());
389 // Cancel keyboard hide.
390 SetFocus(&input_client_2);
392 EXPECT_FALSE(WillHideKeyboard());
393 EXPECT_TRUE(keyboard_container->IsVisible());
396 // Test to prevent spurious overscroll boxes when changing tabs during keyboard
397 // hide. Refer to crbug.com/401670 for more context.
398 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
399 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
400 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
402 aura::Window* keyboard_container(controller()->GetContainerWindow());
403 root_window()->AddChild(keyboard_container);
405 // Enable touch keyboard / overscroll mode to test insets.
406 keyboard::SetTouchKeyboardEnabled(true);
407 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
409 SetFocus(&input_client);
410 SetFocus(&no_input_client);
411 // Insets should not be enabled for new windows while keyboard is in the
412 // process of hiding when overscroll is enabled.
413 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
414 // Cancel keyboard hide.
415 SetFocus(&input_client);
416 // Insets should be enabled for new windows as hide was cancelled.
417 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
420 // Verify switch to FLOATING mode will reset the overscroll or resize and when
421 // in FLOATING mode, overscroll or resize wont be triggered.
422 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) {
423 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
424 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
426 aura::Window* container(controller()->GetContainerWindow());
427 root_window()->AddChild(container);
428 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
429 new KeyboardContainerObserver(container));
430 gfx::Rect screen_bounds = root_window()->bounds();
431 keyboard::SetTouchKeyboardEnabled(true);
433 SetFocus(&input_client);
434 gfx::Rect expected_bounds(
435 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight,
436 screen_bounds.width(), kDefaultVirtualKeyboardHeight);
437 // Verify overscroll or resize is in effect.
438 EXPECT_EQ(expected_bounds, notified_bounds());
439 EXPECT_EQ(1, number_of_calls());
441 controller()->SetKeyboardMode(FLOATING);
442 // Switch to FLOATING should clear overscroll or resize.
443 EXPECT_EQ(gfx::Rect(), notified_bounds());
444 EXPECT_EQ(2, number_of_calls());
445 SetFocus(&no_input_client);
446 base::MessageLoop::current()->Run();
447 EXPECT_EQ(gfx::Rect(), notified_bounds());
448 EXPECT_EQ(3, number_of_calls());
449 SetFocus(&input_client);
450 // In FLOATING mode, no overscroll or resize should be triggered.
451 EXPECT_EQ(3, number_of_calls());
452 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
455 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right
456 // place and sets the correct overscroll.
457 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) {
458 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
460 aura::Window* container(controller()->GetContainerWindow());
461 root_window()->AddChild(container);
462 gfx::Rect screen_bounds = root_window()->bounds();
463 keyboard::SetTouchKeyboardEnabled(true);
464 SetFocus(&input_client);
466 controller()->SetKeyboardMode(FLOATING);
467 EXPECT_EQ(gfx::Rect(), notified_bounds());
468 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
470 controller()->SetKeyboardMode(FULL_WIDTH);
471 gfx::Rect expected_bounds(
472 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight,
473 screen_bounds.width(), kDefaultVirtualKeyboardHeight);
474 EXPECT_EQ(expected_bounds, notified_bounds());
475 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds());
478 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
479 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
480 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
481 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
482 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
484 aura::Window* keyboard_container(controller()->GetContainerWindow());
485 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
486 new KeyboardContainerObserver(keyboard_container));
487 root_window()->AddChild(keyboard_container);
489 SetFocus(&input_client_0);
491 EXPECT_TRUE(keyboard_container->IsVisible());
493 // Lock keyboard.
494 controller()->set_lock_keyboard(true);
496 SetFocus(&no_input_client_0);
497 // Keyboard should not try to hide itself as it is locked.
498 EXPECT_TRUE(keyboard_container->IsVisible());
499 EXPECT_FALSE(WillHideKeyboard());
501 SetFocus(&input_client_1);
502 EXPECT_TRUE(keyboard_container->IsVisible());
504 // Unlock keyboard.
505 controller()->set_lock_keyboard(false);
507 // Keyboard should hide when focus on no input client.
508 SetFocus(&no_input_client_1);
509 EXPECT_TRUE(WillHideKeyboard());
511 // Wait for hide keyboard to finish.
512 base::MessageLoop::current()->Run();
513 EXPECT_FALSE(keyboard_container->IsVisible());
516 class KeyboardControllerAnimationTest : public KeyboardControllerTest {
517 public:
518 KeyboardControllerAnimationTest() {}
519 ~KeyboardControllerAnimationTest() override {}
521 void SetUp() override {
522 // We cannot short-circuit animations for this test.
523 ui::ScopedAnimationDurationScaleMode test_duration_mode(
524 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
526 KeyboardControllerTest::SetUp();
528 const gfx::Rect& root_bounds = root_window()->bounds();
529 keyboard_container()->SetBounds(root_bounds);
530 root_window()->AddChild(keyboard_container());
533 void TearDown() override {
534 KeyboardControllerTest::TearDown();
537 protected:
538 aura::Window* keyboard_container() {
539 return controller()->GetContainerWindow();
542 aura::Window* keyboard_window() {
543 return proxy()->GetKeyboardWindow();
546 private:
547 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest);
550 // Tests virtual keyboard has correct show and hide animation.
551 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
552 ui::Layer* layer = keyboard_container()->layer();
553 ShowKeyboard();
555 // Keyboard container and window should immediately become visible before
556 // animation starts.
557 EXPECT_TRUE(keyboard_container()->IsVisible());
558 EXPECT_TRUE(keyboard_window()->IsVisible());
559 float show_start_opacity = layer->opacity();
560 gfx::Transform transform;
561 transform.Translate(0, kAnimationDistance);
562 EXPECT_EQ(transform, layer->transform());
563 EXPECT_EQ(gfx::Rect(), notified_bounds());
565 RunAnimationForLayer(layer);
566 EXPECT_TRUE(keyboard_container()->IsVisible());
567 EXPECT_TRUE(keyboard_window()->IsVisible());
568 float show_end_opacity = layer->opacity();
569 EXPECT_LT(show_start_opacity, show_end_opacity);
570 EXPECT_EQ(gfx::Transform(), layer->transform());
571 // KeyboardController should notify the bounds of container window to its
572 // observers after show animation finished.
573 EXPECT_EQ(keyboard_container()->bounds(), notified_bounds());
575 // Directly hide keyboard without delay.
576 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
577 EXPECT_TRUE(keyboard_container()->IsVisible());
578 EXPECT_TRUE(keyboard_container()->layer()->visible());
579 EXPECT_TRUE(keyboard_window()->IsVisible());
580 float hide_start_opacity = layer->opacity();
581 // KeyboardController should notify the bounds of keyboard window to its
582 // observers before hide animation starts.
583 EXPECT_EQ(gfx::Rect(), notified_bounds());
585 RunAnimationForLayer(layer);
586 EXPECT_FALSE(keyboard_container()->IsVisible());
587 EXPECT_FALSE(keyboard_container()->layer()->visible());
588 EXPECT_FALSE(keyboard_window()->IsVisible());
589 float hide_end_opacity = layer->opacity();
590 EXPECT_GT(hide_start_opacity, hide_end_opacity);
591 EXPECT_EQ(transform, layer->transform());
592 EXPECT_EQ(gfx::Rect(), notified_bounds());
595 // Show keyboard during keyboard hide animation should abort the hide animation
596 // and the keyboard should animate in.
597 // Test for crbug.com/333284.
598 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) {
599 ui::Layer* layer = keyboard_container()->layer();
600 ShowKeyboard();
601 RunAnimationForLayer(layer);
603 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
604 // Before hide animation finishes, show keyboard again.
605 ShowKeyboard();
606 RunAnimationForLayer(layer);
607 EXPECT_TRUE(keyboard_container()->IsVisible());
608 EXPECT_TRUE(keyboard_window()->IsVisible());
609 EXPECT_EQ(1.0, layer->opacity());
610 EXPECT_EQ(gfx::Transform(), layer->transform());
613 } // namespace keyboard