Revert of Removing Chrome Gamepad transition cruft (https://codereview.chromium.org...
[chromium-blink-merge.git] / ui / keyboard / keyboard_controller_unittest.cc
blobd8c711e5e46a9433e9fbfae26d272e1364519b71
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 "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/layout_manager.h"
12 #include "ui/aura/test/aura_test_helper.h"
13 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/base/ime/input_method.h"
18 #include "ui/base/ime/input_method_factory.h"
19 #include "ui/base/ime/text_input_client.h"
20 #include "ui/compositor/layer_type.h"
21 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
22 #include "ui/compositor/test/context_factories_for_test.h"
23 #include "ui/compositor/test/layer_animator_test_controller.h"
24 #include "ui/gfx/rect.h"
25 #include "ui/keyboard/keyboard_controller.h"
26 #include "ui/keyboard/keyboard_controller_observer.h"
27 #include "ui/keyboard/keyboard_controller_proxy.h"
28 #include "ui/keyboard/keyboard_switches.h"
30 namespace keyboard {
31 namespace {
33 // Steps a layer animation until it is completed. Animations must be enabled.
34 void RunAnimationForLayer(ui::Layer* layer) {
35 // Animations must be enabled for stepping to work.
36 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
37 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
39 ui::LayerAnimatorTestController controller(layer->GetAnimator());
40 gfx::AnimationContainerElement* element = layer->GetAnimator();
41 // Multiple steps are required to complete complex animations.
42 // TODO(vollick): This should not be necessary. crbug.com/154017
43 while (controller.animator()->is_animating()) {
44 controller.StartThreadedAnimationsIfNeeded();
45 base::TimeTicks step_time = controller.animator()->last_step_time();
46 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
50 // An event handler that focuses a window when it is clicked/touched on. This is
51 // used to match the focus manger behaviour in ash and views.
52 class TestFocusController : public ui::EventHandler {
53 public:
54 explicit TestFocusController(aura::Window* root)
55 : root_(root) {
56 root_->AddPreTargetHandler(this);
59 virtual ~TestFocusController() {
60 root_->RemovePreTargetHandler(this);
63 private:
64 // Overridden from ui::EventHandler:
65 virtual void OnEvent(ui::Event* event) OVERRIDE {
66 aura::Window* target = static_cast<aura::Window*>(event->target());
67 if (event->type() == ui::ET_MOUSE_PRESSED ||
68 event->type() == ui::ET_TOUCH_PRESSED) {
69 aura::client::GetFocusClient(target)->FocusWindow(target);
73 aura::Window* root_;
74 DISALLOW_COPY_AND_ASSIGN(TestFocusController);
77 class TestKeyboardControllerProxy : public KeyboardControllerProxy {
78 public:
79 TestKeyboardControllerProxy()
80 : window_(new aura::Window(&delegate_)),
81 input_method_(ui::CreateInputMethod(NULL,
82 gfx::kNullAcceleratedWidget)) {
83 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
84 window_->set_owned_by_parent(false);
87 virtual ~TestKeyboardControllerProxy() {
88 // Destroy the window before the delegate.
89 window_.reset();
92 // Overridden from KeyboardControllerProxy:
93 virtual bool HasKeyboardWindow() const OVERRIDE { return true; }
94 virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); }
95 virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; }
96 virtual ui::InputMethod* GetInputMethod() OVERRIDE {
97 return input_method_.get();
99 virtual void RequestAudioInput(content::WebContents* web_contents,
100 const content::MediaStreamRequest& request,
101 const content::MediaResponseCallback& callback) OVERRIDE { return; }
103 private:
104 scoped_ptr<aura::Window> window_;
105 aura::test::TestWindowDelegate delegate_;
106 scoped_ptr<ui::InputMethod> input_method_;
108 DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy);
111 // Keeps a count of all the events a window receives.
112 class EventObserver : public ui::EventHandler {
113 public:
114 EventObserver() {}
115 virtual ~EventObserver() {}
117 int GetEventCount(ui::EventType type) {
118 return event_counts_[type];
121 private:
122 // Overridden from ui::EventHandler:
123 virtual void OnEvent(ui::Event* event) OVERRIDE {
124 ui::EventHandler::OnEvent(event);
125 event_counts_[event->type()]++;
128 std::map<ui::EventType, int> event_counts_;
129 DISALLOW_COPY_AND_ASSIGN(EventObserver);
132 class TestTextInputClient : public ui::TextInputClient {
133 public:
134 explicit TestTextInputClient(ui::TextInputType type)
135 : type_(type) {}
136 virtual ~TestTextInputClient() {}
138 private:
139 // Overridden from ui::TextInputClient:
140 virtual void SetCompositionText(
141 const ui::CompositionText& composition) OVERRIDE {}
142 virtual void ConfirmCompositionText() OVERRIDE {}
143 virtual void ClearCompositionText() OVERRIDE {}
144 virtual void InsertText(const base::string16& text) OVERRIDE {}
145 virtual void InsertChar(base::char16 ch, int flags) OVERRIDE {}
146 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE {
147 return static_cast<gfx::NativeWindow>(NULL);
149 virtual ui::TextInputType GetTextInputType() const OVERRIDE {
150 return type_;
152 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE {
153 return ui::TEXT_INPUT_MODE_DEFAULT;
155 virtual bool CanComposeInline() const OVERRIDE { return false; }
156 virtual gfx::Rect GetCaretBounds() const OVERRIDE { return gfx::Rect(); }
158 virtual bool GetCompositionCharacterBounds(
159 uint32 index,
160 gfx::Rect* rect) const OVERRIDE {
161 return false;
163 virtual bool HasCompositionText() const OVERRIDE { return false; }
164 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE { return false; }
165 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE {
166 return false;
168 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE {
169 return false;
171 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE {
172 return false;
174 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE { return false; }
175 virtual bool GetTextFromRange(const gfx::Range& range,
176 base::string16* text) const OVERRIDE {
177 return false;
179 virtual void OnInputMethodChanged() OVERRIDE {}
180 virtual bool ChangeTextDirectionAndLayoutAlignment(
181 base::i18n::TextDirection direction) OVERRIDE { return false; }
182 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE {}
183 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE {}
184 virtual void OnCandidateWindowShown() OVERRIDE {}
185 virtual void OnCandidateWindowUpdated() OVERRIDE {}
186 virtual void OnCandidateWindowHidden() OVERRIDE {}
188 ui::TextInputType type_;
190 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient);
193 class KeyboardContainerObserver : public aura::WindowObserver {
194 public:
195 explicit KeyboardContainerObserver(aura::Window* window) : window_(window) {
196 window_->AddObserver(this);
198 virtual ~KeyboardContainerObserver() {
199 window_->RemoveObserver(this);
202 private:
203 virtual void OnWindowVisibilityChanged(aura::Window* window,
204 bool visible) OVERRIDE {
205 if (!visible)
206 base::MessageLoop::current()->Quit();
209 aura::Window* window_;
211 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver);
214 } // namespace
216 class KeyboardControllerTest : public testing::Test {
217 public:
218 KeyboardControllerTest() {}
219 virtual ~KeyboardControllerTest() {}
221 virtual void SetUp() OVERRIDE {
222 // The ContextFactory must exist before any Compositors are created.
223 bool enable_pixel_output = false;
224 ui::InitializeContextFactoryForTests(enable_pixel_output);
226 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
227 aura_test_helper_->SetUp();
228 ui::SetUpInputMethodFactoryForTesting();
229 focus_controller_.reset(new TestFocusController(root_window()));
230 proxy_ = new TestKeyboardControllerProxy();
231 controller_.reset(new KeyboardController(proxy_));
234 virtual void TearDown() OVERRIDE {
235 controller_.reset();
236 focus_controller_.reset();
237 aura_test_helper_->TearDown();
238 ui::TerminateContextFactoryForTests();
241 aura::Window* root_window() { return aura_test_helper_->root_window(); }
242 KeyboardControllerProxy* proxy() { return proxy_; }
243 KeyboardController* controller() { return controller_.get(); }
245 void ShowKeyboard() {
246 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT);
247 SetFocus(&test_text_input_client);
250 protected:
251 void SetFocus(ui::TextInputClient* client) {
252 ui::InputMethod* input_method = proxy()->GetInputMethod();
253 input_method->SetFocusedTextInputClient(client);
254 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
255 input_method->ShowImeIfNeeded();
258 bool WillHideKeyboard() {
259 return controller_->WillHideKeyboard();
262 base::MessageLoopForUI message_loop_;
263 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
264 scoped_ptr<TestFocusController> focus_controller_;
266 private:
267 KeyboardControllerProxy* proxy_;
268 scoped_ptr<KeyboardController> controller_;
270 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest);
273 TEST_F(KeyboardControllerTest, KeyboardSize) {
274 aura::Window* container(controller()->GetContainerWindow());
275 gfx::Rect bounds(0, 0, 100, 100);
276 container->SetBounds(bounds);
278 const gfx::Rect& before_bounds = proxy()->GetKeyboardWindow()->bounds();
279 gfx::Rect new_bounds(
280 before_bounds.x(), before_bounds.y(),
281 before_bounds.width() / 2, before_bounds.height() / 2);
283 // The KeyboardController's LayoutManager shouldn't let this happen
284 proxy()->GetKeyboardWindow()->SetBounds(new_bounds);
285 ASSERT_EQ(before_bounds, proxy()->GetKeyboardWindow()->bounds());
288 // Tests that tapping/clicking inside the keyboard does not give it focus.
289 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
290 const gfx::Rect& root_bounds = root_window()->bounds();
291 aura::test::EventCountDelegate delegate;
292 scoped_ptr<aura::Window> window(new aura::Window(&delegate));
293 window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
294 window->SetBounds(root_bounds);
295 root_window()->AddChild(window.get());
296 window->Show();
297 window->Focus();
299 aura::Window* keyboard_container(controller()->GetContainerWindow());
300 keyboard_container->SetBounds(root_bounds);
302 root_window()->AddChild(keyboard_container);
303 keyboard_container->Show();
305 ShowKeyboard();
307 EXPECT_TRUE(window->IsVisible());
308 EXPECT_TRUE(keyboard_container->IsVisible());
309 EXPECT_TRUE(window->HasFocus());
310 EXPECT_FALSE(keyboard_container->HasFocus());
312 // Click on the keyboard. Make sure the keyboard receives the event, but does
313 // not get focus.
314 EventObserver observer;
315 keyboard_container->AddPreTargetHandler(&observer);
317 aura::test::EventGenerator generator(root_window());
318 generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint());
319 generator.ClickLeftButton();
320 EXPECT_TRUE(window->HasFocus());
321 EXPECT_FALSE(keyboard_container->HasFocus());
322 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset());
323 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED));
324 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED));
326 // Click outside of the keyboard. It should reach the window behind.
327 generator.MoveMouseTo(gfx::Point());
328 generator.ClickLeftButton();
329 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
330 keyboard_container->RemovePreTargetHandler(&observer);
333 TEST_F(KeyboardControllerTest, EventHitTestingInContainer) {
334 const gfx::Rect& root_bounds = root_window()->bounds();
335 aura::test::EventCountDelegate delegate;
336 scoped_ptr<aura::Window> window(new aura::Window(&delegate));
337 window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
338 window->SetBounds(root_bounds);
339 root_window()->AddChild(window.get());
340 window->Show();
341 window->Focus();
343 aura::Window* keyboard_container(controller()->GetContainerWindow());
344 keyboard_container->SetBounds(root_bounds);
346 root_window()->AddChild(keyboard_container);
347 keyboard_container->Show();
349 ShowKeyboard();
351 EXPECT_TRUE(window->IsVisible());
352 EXPECT_TRUE(keyboard_container->IsVisible());
353 EXPECT_TRUE(window->HasFocus());
354 EXPECT_FALSE(keyboard_container->HasFocus());
356 // Make sure hit testing works correctly while the keyboard is visible.
357 aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
358 ui::EventTarget* root = root_window();
359 ui::EventTargeter* targeter = root->GetEventTargeter();
360 gfx::Point location = keyboard_window->bounds().CenterPoint();
361 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
362 ui::EF_NONE);
363 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1));
366 location.set_y(keyboard_window->bounds().y() - 5);
367 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
368 ui::EF_NONE);
369 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2));
372 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
373 const gfx::Rect& root_bounds = root_window()->bounds();
375 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
376 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
377 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
378 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
379 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
381 aura::Window* keyboard_container(controller()->GetContainerWindow());
382 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
383 new KeyboardContainerObserver(keyboard_container));
384 keyboard_container->SetBounds(root_bounds);
385 root_window()->AddChild(keyboard_container);
387 SetFocus(&input_client_0);
389 EXPECT_TRUE(keyboard_container->IsVisible());
391 SetFocus(&no_input_client_0);
392 // Keyboard should not immediately hide itself. It is delayed to avoid layout
393 // flicker when the focus of input field quickly change.
394 EXPECT_TRUE(keyboard_container->IsVisible());
395 EXPECT_TRUE(WillHideKeyboard());
396 // Wait for hide keyboard to finish.
397 base::MessageLoop::current()->Run();
398 EXPECT_FALSE(keyboard_container->IsVisible());
400 SetFocus(&input_client_1);
401 EXPECT_TRUE(keyboard_container->IsVisible());
403 // Schedule to hide keyboard.
404 SetFocus(&no_input_client_1);
405 EXPECT_TRUE(WillHideKeyboard());
406 // Cancel keyboard hide.
407 SetFocus(&input_client_2);
409 EXPECT_FALSE(WillHideKeyboard());
410 EXPECT_TRUE(keyboard_container->IsVisible());
413 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
414 const gfx::Rect& root_bounds = root_window()->bounds();
416 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
417 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
418 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
419 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
421 aura::Window* keyboard_container(controller()->GetContainerWindow());
422 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
423 new KeyboardContainerObserver(keyboard_container));
424 keyboard_container->SetBounds(root_bounds);
425 root_window()->AddChild(keyboard_container);
427 SetFocus(&input_client_0);
429 EXPECT_TRUE(keyboard_container->IsVisible());
431 // Lock keyboard.
432 controller()->set_lock_keyboard(true);
434 SetFocus(&no_input_client_0);
435 // Keyboard should not try to hide itself as it is locked.
436 EXPECT_TRUE(keyboard_container->IsVisible());
437 EXPECT_FALSE(WillHideKeyboard());
439 SetFocus(&input_client_1);
440 EXPECT_TRUE(keyboard_container->IsVisible());
442 // Unlock keyboard.
443 controller()->set_lock_keyboard(false);
445 // Keyboard should hide when focus on no input client.
446 SetFocus(&no_input_client_1);
447 EXPECT_TRUE(WillHideKeyboard());
449 // Wait for hide keyboard to finish.
450 base::MessageLoop::current()->Run();
451 EXPECT_FALSE(keyboard_container->IsVisible());
454 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) {
455 aura::Window* keyboard_container = controller()->GetContainerWindow();
456 aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
457 keyboard_container->SetBounds(gfx::Rect(800, 600));
458 keyboard_container->AddChild(keyboard_window);
460 // Default keyboard size.
461 EXPECT_EQ(180, keyboard_window->bounds().height());
463 // Resizes from contents when flag is unset.
464 keyboard_window->SetBounds(gfx::Rect(100, 80));
465 EXPECT_EQ(180, keyboard_window->bounds().height());
467 // Resizes from contents when flag is set.
468 proxy()->set_resizing_from_contents(true);
469 keyboard_window->SetBounds(gfx::Rect(100, 80));
470 EXPECT_EQ(80, keyboard_window->bounds().height());
472 // Resizes from container when flag is set.
473 keyboard_container->SetBounds(gfx::Rect(400, 300));
474 EXPECT_EQ(80, keyboard_window->bounds().height());
476 // Resizes from container when flag is unset.
477 proxy()->set_resizing_from_contents(false);
478 keyboard_container->SetBounds(gfx::Rect(800, 600));
479 EXPECT_EQ(180, keyboard_window->bounds().height());
482 class KeyboardControllerAnimationTest : public KeyboardControllerTest,
483 public KeyboardControllerObserver {
484 public:
485 KeyboardControllerAnimationTest() {}
486 virtual ~KeyboardControllerAnimationTest() {}
488 virtual void SetUp() OVERRIDE {
489 // We cannot short-circuit animations for this test.
490 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
491 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
493 KeyboardControllerTest::SetUp();
495 const gfx::Rect& root_bounds = root_window()->bounds();
496 keyboard_container()->SetBounds(root_bounds);
497 root_window()->AddChild(keyboard_container());
498 controller()->AddObserver(this);
501 virtual void TearDown() OVERRIDE {
502 controller()->RemoveObserver(this);
503 KeyboardControllerTest::TearDown();
506 protected:
507 // KeyboardControllerObserver overrides
508 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE {
509 notified_bounds_ = new_bounds;
512 const gfx::Rect& notified_bounds() { return notified_bounds_; }
514 aura::Window* keyboard_container() {
515 return controller()->GetContainerWindow();
518 aura::Window* keyboard_window() {
519 return proxy()->GetKeyboardWindow();
522 private:
523 gfx::Rect notified_bounds_;
525 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest);
528 // Tests virtual keyboard has correct show and hide animation.
529 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
530 ui::Layer* layer = keyboard_container()->layer();
531 ShowKeyboard();
533 // Keyboard container and window should immediately become visible before
534 // animation starts.
535 EXPECT_TRUE(keyboard_container()->IsVisible());
536 EXPECT_TRUE(keyboard_window()->IsVisible());
537 float show_start_opacity = layer->opacity();
538 gfx::Transform transform;
539 transform.Translate(0, keyboard_window()->bounds().height());
540 EXPECT_EQ(transform, layer->transform());
541 EXPECT_EQ(gfx::Rect(), notified_bounds());
543 RunAnimationForLayer(layer);
544 EXPECT_TRUE(keyboard_container()->IsVisible());
545 EXPECT_TRUE(keyboard_window()->IsVisible());
546 float show_end_opacity = layer->opacity();
547 EXPECT_LT(show_start_opacity, show_end_opacity);
548 EXPECT_EQ(gfx::Transform(), layer->transform());
549 // KeyboardController should notify the bounds of keyboard window to its
550 // observers after show animation finished.
551 EXPECT_EQ(keyboard_window()->bounds(), notified_bounds());
553 // Directly hide keyboard without delay.
554 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
555 EXPECT_TRUE(keyboard_container()->IsVisible());
556 EXPECT_TRUE(keyboard_container()->layer()->visible());
557 EXPECT_TRUE(keyboard_window()->IsVisible());
558 float hide_start_opacity = layer->opacity();
559 // KeyboardController should notify the bounds of keyboard window to its
560 // observers before hide animation starts.
561 EXPECT_EQ(gfx::Rect(), notified_bounds());
563 RunAnimationForLayer(layer);
564 EXPECT_FALSE(keyboard_container()->IsVisible());
565 EXPECT_FALSE(keyboard_container()->layer()->visible());
566 EXPECT_FALSE(keyboard_window()->IsVisible());
567 float hide_end_opacity = layer->opacity();
568 EXPECT_GT(hide_start_opacity, hide_end_opacity);
569 EXPECT_EQ(transform, layer->transform());
570 EXPECT_EQ(gfx::Rect(), notified_bounds());
573 // Show keyboard during keyboard hide animation should abort the hide animation
574 // and the keyboard should animate in.
575 // Test for crbug.com/333284.
576 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) {
577 ui::Layer* layer = keyboard_container()->layer();
578 ShowKeyboard();
579 RunAnimationForLayer(layer);
581 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
582 // Before hide animation finishes, show keyboard again.
583 ShowKeyboard();
584 RunAnimationForLayer(layer);
585 EXPECT_TRUE(keyboard_container()->IsVisible());
586 EXPECT_TRUE(keyboard_window()->IsVisible());
587 EXPECT_EQ(1.0, layer->opacity());
588 EXPECT_EQ(gfx::Transform(), layer->transform());
591 class KeyboardControllerUsabilityTest : public KeyboardControllerTest {
592 public:
593 KeyboardControllerUsabilityTest() {}
594 virtual ~KeyboardControllerUsabilityTest() {}
596 virtual void SetUp() OVERRIDE {
597 CommandLine::ForCurrentProcess()->AppendSwitch(
598 switches::kKeyboardUsabilityExperiment);
599 KeyboardControllerTest::SetUp();
602 private:
603 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest);
606 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) {
607 const gfx::Rect& root_bounds = root_window()->bounds();
609 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
610 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
612 aura::Window* keyboard_container(controller()->GetContainerWindow());
613 keyboard_container->SetBounds(root_bounds);
614 root_window()->AddChild(keyboard_container);
616 SetFocus(&input_client);
617 EXPECT_TRUE(keyboard_container->IsVisible());
619 SetFocus(&no_input_client);
620 // Keyboard should not hide itself after lost focus.
621 EXPECT_TRUE(keyboard_container->IsVisible());
622 EXPECT_FALSE(WillHideKeyboard());
625 } // namespace keyboard