1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/keyboard/keyboard_controller.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/test/aura_test_helper.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/ime/dummy_text_input_client.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_focus_manager.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_type.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/layer_animator_test_controller.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/keyboard/keyboard_controller_observer.h"
#include "ui/keyboard/keyboard_controller_proxy.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/wm/core/default_activation_client.h"
namespace keyboard {
namespace {
// Steps a layer animation until it is completed. Animations must be enabled.
void RunAnimationForLayer(ui::Layer* layer) {
// Animations must be enabled for stepping to work.
ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
ui::LayerAnimatorTestController controller(layer->GetAnimator());
// Multiple steps are required to complete complex animations.
// TODO(vollick): This should not be necessary. crbug.com/154017
while (controller.animator()->is_animating()) {
controller.StartThreadedAnimationsIfNeeded();
base::TimeTicks step_time = controller.animator()->last_step_time();
controller.animator()->Step(step_time +
base::TimeDelta::FromMilliseconds(1000));
}
}
// An event handler that focuses a window when it is clicked/touched on. This is
// used to match the focus manger behaviour in ash and views.
class TestFocusController : public ui::EventHandler {
public:
explicit TestFocusController(aura::Window* root)
: root_(root) {
root_->AddPreTargetHandler(this);
}
~TestFocusController() override { root_->RemovePreTargetHandler(this); }
private:
// Overridden from ui::EventHandler:
void OnEvent(ui::Event* event) override {
aura::Window* target = static_cast<aura::Window*>(event->target());
if (event->type() == ui::ET_MOUSE_PRESSED ||
event->type() == ui::ET_TOUCH_PRESSED) {
aura::client::GetFocusClient(target)->FocusWindow(target);
}
}
aura::Window* root_;
DISALLOW_COPY_AND_ASSIGN(TestFocusController);
};
class TestKeyboardControllerProxy : public KeyboardControllerProxy {
public:
TestKeyboardControllerProxy()
: KeyboardControllerProxy(nullptr),
input_method_(
ui::CreateInputMethod(nullptr, gfx::kNullAcceleratedWidget)) {}
~TestKeyboardControllerProxy() override {
// Destroy the window before the delegate.
window_.reset();
}
// Overridden from KeyboardControllerProxy:
bool HasKeyboardWindow() const override { return window_; }
aura::Window* GetKeyboardWindow() override {
if (!window_) {
window_.reset(new aura::Window(&delegate_));
window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
window_->set_owned_by_parent(false);
}
return window_.get();
}
ui::InputMethod* GetInputMethod() override { return input_method_.get(); }
void RequestAudioInput(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) override {
return;
}
void LoadSystemKeyboard() override{};
void ReloadKeyboardIfNeeded() override{};
private:
scoped_ptr<aura::Window> window_;
aura::test::TestWindowDelegate delegate_;
scoped_ptr<ui::InputMethod> input_method_;
DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy);
};
// Keeps a count of all the events a window receives.
class EventObserver : public ui::EventHandler {
public:
EventObserver() {}
~EventObserver() override {}
int GetEventCount(ui::EventType type) {
return event_counts_[type];
}
private:
// Overridden from ui::EventHandler:
void OnEvent(ui::Event* event) override {
ui::EventHandler::OnEvent(event);
event_counts_[event->type()]++;
}
std::map<ui::EventType, int> event_counts_;
DISALLOW_COPY_AND_ASSIGN(EventObserver);
};
class KeyboardContainerObserver : public aura::WindowObserver {
public:
explicit KeyboardContainerObserver(aura::Window* window) : window_(window) {
window_->AddObserver(this);
}
~KeyboardContainerObserver() override { window_->RemoveObserver(this); }
private:
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
if (!visible)
base::MessageLoop::current()->Quit();
}
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver);
};
} // namespace
class KeyboardControllerTest : public testing::Test {
public:
KeyboardControllerTest() {}
~KeyboardControllerTest() override {}
void SetUp() override {
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
ui::SetUpInputMethodFactoryForTesting();
if (::switches::IsTextInputFocusManagerEnabled())
ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL);
focus_controller_.reset(new TestFocusController(root_window()));
proxy_ = new TestKeyboardControllerProxy();
controller_.reset(new KeyboardController(proxy_));
}
void TearDown() override {
controller_.reset();
focus_controller_.reset();
if (::switches::IsTextInputFocusManagerEnabled())
ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL);
aura_test_helper_->TearDown();
ui::TerminateContextFactoryForTests();
}
aura::Window* root_window() { return aura_test_helper_->root_window(); }
KeyboardControllerProxy* proxy() { return proxy_; }
KeyboardController* controller() { return controller_.get(); }
void ShowKeyboard() {
test_text_input_client_.reset(
new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
SetFocus(test_text_input_client_.get());
}
protected:
void SetFocus(ui::TextInputClient* client) {
ui::InputMethod* input_method = proxy()->GetInputMethod();
if (::switches::IsTextInputFocusManagerEnabled()) {
ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client);
input_method->OnTextInputTypeChanged(client);
} else {
input_method->SetFocusedTextInputClient(client);
}
if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
input_method->ShowImeIfNeeded();
if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
// Set initial bounds for test keyboard window.
proxy_->GetKeyboardWindow()->SetBounds(
KeyboardBoundsFromWindowBounds(
controller()->GetContainerWindow()->bounds(), 100));
}
}
}
bool WillHideKeyboard() {
return controller_->WillHideKeyboard();
}
bool ShouldEnableInsets(aura::Window* window) {
return controller_->ShouldEnableInsets(window);
}
base::MessageLoopForUI message_loop_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<TestFocusController> focus_controller_;
private:
KeyboardControllerProxy* proxy_;
scoped_ptr<KeyboardController> controller_;
scoped_ptr<ui::TextInputClient> test_text_input_client_;
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest);
};
TEST_F(KeyboardControllerTest, KeyboardSize) {
aura::Window* container(controller()->GetContainerWindow());
aura::Window* keyboard(proxy()->GetKeyboardWindow());
container->SetBounds(gfx::Rect(0, 0, 200, 100));
container->AddChild(keyboard);
const gfx::Rect& before_bounds = keyboard->bounds();
// The initial keyboard should be positioned at the bottom of container and
// has 0 height.
ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds);
gfx::Rect new_bounds(
before_bounds.x(), before_bounds.y() - 50,
before_bounds.width(), 50);
keyboard->SetBounds(new_bounds);
ASSERT_EQ(new_bounds, keyboard->bounds());
// Mock a screen rotation.
container->SetBounds(gfx::Rect(0, 0, 100, 200));
// The above call should resize keyboard to new width while keeping the old
// height.
ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds());
}
// Tests that tapping/clicking inside the keyboard does not give it focus.
TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
const gfx::Rect& root_bounds = root_window()->bounds();
aura::test::EventCountDelegate delegate;
scoped_ptr<aura::Window> window(new aura::Window(&delegate));
window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
window->SetBounds(root_bounds);
root_window()->AddChild(window.get());
window->Show();
window->Focus();
aura::Window* keyboard_container(controller()->GetContainerWindow());
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
keyboard_container->Show();
ShowKeyboard();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(keyboard_container->IsVisible());
EXPECT_TRUE(window->HasFocus());
EXPECT_FALSE(keyboard_container->HasFocus());
// Click on the keyboard. Make sure the keyboard receives the event, but does
// not get focus.
EventObserver observer;
keyboard_container->AddPreTargetHandler(&observer);
ui::test::EventGenerator generator(root_window());
generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint());
generator.ClickLeftButton();
EXPECT_TRUE(window->HasFocus());
EXPECT_FALSE(keyboard_container->HasFocus());
EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset());
EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED));
EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED));
// Click outside of the keyboard. It should reach the window behind.
generator.MoveMouseTo(gfx::Point());
generator.ClickLeftButton();
EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
keyboard_container->RemovePreTargetHandler(&observer);
}
TEST_F(KeyboardControllerTest, EventHitTestingInContainer) {
const gfx::Rect& root_bounds = root_window()->bounds();
aura::test::EventCountDelegate delegate;
scoped_ptr<aura::Window> window(new aura::Window(&delegate));
window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
window->SetBounds(root_bounds);
root_window()->AddChild(window.get());
window->Show();
window->Focus();
aura::Window* keyboard_container(controller()->GetContainerWindow());
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
keyboard_container->Show();
ShowKeyboard();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(keyboard_container->IsVisible());
EXPECT_TRUE(window->HasFocus());
EXPECT_FALSE(keyboard_container->HasFocus());
// Make sure hit testing works correctly while the keyboard is visible.
aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
ui::EventTarget* root = root_window();
ui::EventTargeter* targeter = root->GetEventTargeter();
gfx::Point location = keyboard_window->bounds().CenterPoint();
ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
ui::EF_NONE);
EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1));
location.set_y(keyboard_window->bounds().y() - 5);
ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
ui::EF_NONE);
EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2));
}
TEST_F(KeyboardControllerTest, KeyboardWindowCreation) {
const gfx::Rect& root_bounds = root_window()->bounds();
aura::test::EventCountDelegate delegate;
scoped_ptr<aura::Window> window(new aura::Window(&delegate));
window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
window->SetBounds(root_bounds);
root_window()->AddChild(window.get());
window->Show();
window->Focus();
aura::Window* keyboard_container(controller()->GetContainerWindow());
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
keyboard_container->Show();
EXPECT_FALSE(proxy()->HasKeyboardWindow());
ui::EventTarget* root = root_window();
ui::EventTargeter* targeter = root->GetEventTargeter();
gfx::Point location(root_window()->bounds().width() / 2,
root_window()->bounds().height() - 10);
ui::MouseEvent mouse(
ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, ui::EF_NONE);
EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse));
EXPECT_FALSE(proxy()->HasKeyboardWindow());
EXPECT_EQ(
controller()->GetContainerWindow(),
controller()->GetContainerWindow()->GetEventHandlerForPoint(location));
EXPECT_FALSE(proxy()->HasKeyboardWindow());
}
TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
const gfx::Rect& root_bounds = root_window()->bounds();
ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
aura::Window* keyboard_container(controller()->GetContainerWindow());
scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
new KeyboardContainerObserver(keyboard_container));
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
SetFocus(&input_client_0);
EXPECT_TRUE(keyboard_container->IsVisible());
SetFocus(&no_input_client_0);
// Keyboard should not immediately hide itself. It is delayed to avoid layout
// flicker when the focus of input field quickly change.
EXPECT_TRUE(keyboard_container->IsVisible());
EXPECT_TRUE(WillHideKeyboard());
// Wait for hide keyboard to finish.
base::MessageLoop::current()->Run();
EXPECT_FALSE(keyboard_container->IsVisible());
SetFocus(&input_client_1);
EXPECT_TRUE(keyboard_container->IsVisible());
// Schedule to hide keyboard.
SetFocus(&no_input_client_1);
EXPECT_TRUE(WillHideKeyboard());
// Cancel keyboard hide.
SetFocus(&input_client_2);
EXPECT_FALSE(WillHideKeyboard());
EXPECT_TRUE(keyboard_container->IsVisible());
}
// Test to prevent spurious overscroll boxes when changing tabs during keyboard
// hide. Refer to crbug.com/401670 for more context.
TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
const gfx::Rect& root_bounds = root_window()->bounds();
ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
aura::Window* keyboard_container(controller()->GetContainerWindow());
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
// Enable touch keyboard / overscroll mode to test insets.
keyboard::SetTouchKeyboardEnabled(true);
EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
SetFocus(&input_client);
SetFocus(&no_input_client);
// Insets should not be enabled for new windows while keyboard is in the
// process of hiding when overscroll is enabled.
EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
// Cancel keyboard hide.
SetFocus(&input_client);
// Insets should be enabled for new windows as hide was cancelled.
EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
}
TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
const gfx::Rect& root_bounds = root_window()->bounds();
ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
aura::Window* keyboard_container(controller()->GetContainerWindow());
scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
new KeyboardContainerObserver(keyboard_container));
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
SetFocus(&input_client_0);
EXPECT_TRUE(keyboard_container->IsVisible());
// Lock keyboard.
controller()->set_lock_keyboard(true);
SetFocus(&no_input_client_0);
// Keyboard should not try to hide itself as it is locked.
EXPECT_TRUE(keyboard_container->IsVisible());
EXPECT_FALSE(WillHideKeyboard());
SetFocus(&input_client_1);
EXPECT_TRUE(keyboard_container->IsVisible());
// Unlock keyboard.
controller()->set_lock_keyboard(false);
// Keyboard should hide when focus on no input client.
SetFocus(&no_input_client_1);
EXPECT_TRUE(WillHideKeyboard());
// Wait for hide keyboard to finish.
base::MessageLoop::current()->Run();
EXPECT_FALSE(keyboard_container->IsVisible());
}
class KeyboardControllerAnimationTest : public KeyboardControllerTest,
public KeyboardControllerObserver {
public:
KeyboardControllerAnimationTest() {}
~KeyboardControllerAnimationTest() override {}
void SetUp() override {
// We cannot short-circuit animations for this test.
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
KeyboardControllerTest::SetUp();
const gfx::Rect& root_bounds = root_window()->bounds();
keyboard_container()->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container());
controller()->AddObserver(this);
}
void TearDown() override {
controller()->RemoveObserver(this);
KeyboardControllerTest::TearDown();
}
protected:
// KeyboardControllerObserver overrides
void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override {
notified_bounds_ = new_bounds;
}
const gfx::Rect& notified_bounds() { return notified_bounds_; }
aura::Window* keyboard_container() {
return controller()->GetContainerWindow();
}
aura::Window* keyboard_window() {
return proxy()->GetKeyboardWindow();
}
private:
gfx::Rect notified_bounds_;
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest);
};
// Tests virtual keyboard has correct show and hide animation.
TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
ui::Layer* layer = keyboard_container()->layer();
ShowKeyboard();
// Keyboard container and window should immediately become visible before
// animation starts.
EXPECT_TRUE(keyboard_container()->IsVisible());
EXPECT_TRUE(keyboard_window()->IsVisible());
float show_start_opacity = layer->opacity();
gfx::Transform transform;
transform.Translate(0, kAnimationDistance);
EXPECT_EQ(transform, layer->transform());
EXPECT_EQ(gfx::Rect(), notified_bounds());
RunAnimationForLayer(layer);
EXPECT_TRUE(keyboard_container()->IsVisible());
EXPECT_TRUE(keyboard_window()->IsVisible());
float show_end_opacity = layer->opacity();
EXPECT_LT(show_start_opacity, show_end_opacity);
EXPECT_EQ(gfx::Transform(), layer->transform());
// KeyboardController should notify the bounds of keyboard window to its
// observers after show animation finished.
EXPECT_EQ(keyboard_window()->bounds(), notified_bounds());
// Directly hide keyboard without delay.
controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
EXPECT_TRUE(keyboard_container()->IsVisible());
EXPECT_TRUE(keyboard_container()->layer()->visible());
EXPECT_TRUE(keyboard_window()->IsVisible());
float hide_start_opacity = layer->opacity();
// KeyboardController should notify the bounds of keyboard window to its
// observers before hide animation starts.
EXPECT_EQ(gfx::Rect(), notified_bounds());
RunAnimationForLayer(layer);
EXPECT_FALSE(keyboard_container()->IsVisible());
EXPECT_FALSE(keyboard_container()->layer()->visible());
EXPECT_FALSE(keyboard_window()->IsVisible());
float hide_end_opacity = layer->opacity();
EXPECT_GT(hide_start_opacity, hide_end_opacity);
EXPECT_EQ(transform, layer->transform());
EXPECT_EQ(gfx::Rect(), notified_bounds());
}
// Show keyboard during keyboard hide animation should abort the hide animation
// and the keyboard should animate in.
// Test for crbug.com/333284.
TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) {
ui::Layer* layer = keyboard_container()->layer();
ShowKeyboard();
RunAnimationForLayer(layer);
controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
// Before hide animation finishes, show keyboard again.
ShowKeyboard();
RunAnimationForLayer(layer);
EXPECT_TRUE(keyboard_container()->IsVisible());
EXPECT_TRUE(keyboard_window()->IsVisible());
EXPECT_EQ(1.0, layer->opacity());
EXPECT_EQ(gfx::Transform(), layer->transform());
}
} // namespace keyboard
|