keyboard_controller_unittest.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/bind.h" 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/command_line.h" 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 8ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/message_loop/message_loop.h" 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/client/focus_client.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/layout_manager.h" 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/test/aura_test_helper.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/test/event_generator.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/test/test_window_delegate.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/window.h" 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h" 17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/base/ime/dummy_text_input_client.h" 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/ime/input_method.h" 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/ime/input_method_factory.h" 20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/ime/text_input_client.h" 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/compositor/layer_type.h" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h" 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/compositor/test/context_factories_for_test.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/test/layer_animator_test_controller.h" 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/rect.h" 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/keyboard/keyboard_controller.h" 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/keyboard/keyboard_controller_observer.h" 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/keyboard/keyboard_controller_proxy.h" 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/keyboard/keyboard_switches.h" 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/keyboard/keyboard_util.h" 315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/wm/core/default_activation_client.h" 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace keyboard { 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace { 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Steps a layer animation until it is completed. Animations must be enabled. 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RunAnimationForLayer(ui::Layer* layer) { 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Animations must be enabled for stepping to work. 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::LayerAnimatorTestController controller(layer->GetAnimator()); 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::AnimationContainerElement* element = layer->GetAnimator(); 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Multiple steps are required to complete complex animations. 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(vollick): This should not be necessary. crbug.com/154017 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) while (controller.animator()->is_animating()) { 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller.StartThreadedAnimationsIfNeeded(); 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::TimeTicks step_time = controller.animator()->last_step_time(); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// An event handler that focuses a window when it is clicked/touched on. This is 54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// used to match the focus manger behaviour in ash and views. 55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestFocusController : public ui::EventHandler { 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) explicit TestFocusController(aura::Window* root) 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : root_(root) { 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) root_->AddPreTargetHandler(this); 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~TestFocusController() { 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) root_->RemovePreTargetHandler(this); 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Overridden from ui::EventHandler: 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnEvent(ui::Event* event) OVERRIDE { 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* target = static_cast<aura::Window*>(event->target()); 70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (event->type() == ui::ET_MOUSE_PRESSED || 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) event->type() == ui::ET_TOUCH_PRESSED) { 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::client::GetFocusClient(target)->FocusWindow(target); 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* root_; 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestFocusController); 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestKeyboardControllerProxy : public KeyboardControllerProxy { 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestKeyboardControllerProxy() 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : window_(new aura::Window(&delegate_)), 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) input_method_(ui::CreateInputMethod(NULL, 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::kNullAcceleratedWidget)) { 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_->set_owned_by_parent(false); 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~TestKeyboardControllerProxy() { 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Destroy the window before the delegate. 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_.reset(); 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Overridden from KeyboardControllerProxy: 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool HasKeyboardWindow() const OVERRIDE { return true; } 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); } 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; } 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ui::InputMethod* GetInputMethod() OVERRIDE { 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return input_method_.get(); 101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void RequestAudioInput(content::WebContents* web_contents, 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const content::MediaStreamRequest& request, 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const content::MediaResponseCallback& callback) OVERRIDE { return; } 10523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual void LoadSystemKeyboard() OVERRIDE {}; 10623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual void ReloadKeyboardIfNeeded() OVERRIDE {}; 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<aura::Window> window_; 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::test::TestWindowDelegate delegate_; 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<ui::InputMethod> input_method_; 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy); 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Keeps a count of all the events a window receives. 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class EventObserver : public ui::EventHandler { 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EventObserver() {} 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~EventObserver() {} 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int GetEventCount(ui::EventType type) { 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return event_counts_[type]; 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Overridden from ui::EventHandler: 128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnEvent(ui::Event* event) OVERRIDE { 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::EventHandler::OnEvent(event); 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) event_counts_[event->type()]++; 131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::map<ui::EventType, int> event_counts_; 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(EventObserver); 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 13758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class KeyboardContainerObserver : public aura::WindowObserver { 13858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) public: 13958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) explicit KeyboardContainerObserver(aura::Window* window) : window_(window) { 14058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) window_->AddObserver(this); 14158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 14258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual ~KeyboardContainerObserver() { 14358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) window_->RemoveObserver(this); 14458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 14558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 14658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) private: 14758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void OnWindowVisibilityChanged(aura::Window* window, 14858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool visible) OVERRIDE { 14958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!visible) 15058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::MessageLoop::current()->Quit(); 15158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 15258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 15358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) aura::Window* window_; 15458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 15558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); 15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}; 15758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace 159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class KeyboardControllerTest : public testing::Test { 161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) KeyboardControllerTest() {} 163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~KeyboardControllerTest() {} 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetUp() OVERRIDE { 166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The ContextFactory must exist before any Compositors are created. 167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool enable_pixel_output = false; 168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::InitializeContextFactoryForTests(enable_pixel_output); 169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) aura_test_helper_->SetUp(); 1725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu new wm::DefaultActivationClient(aura_test_helper_->root_window()); 173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::SetUpInputMethodFactoryForTesting(); 174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) focus_controller_.reset(new TestFocusController(root_window())); 17558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) proxy_ = new TestKeyboardControllerProxy(); 17658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) controller_.reset(new KeyboardController(proxy_)); 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void TearDown() OVERRIDE { 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller_.reset(); 181ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch focus_controller_.reset(); 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura_test_helper_->TearDown(); 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::TerminateContextFactoryForTests(); 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) aura::Window* root_window() { return aura_test_helper_->root_window(); } 18758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) KeyboardControllerProxy* proxy() { return proxy_; } 18858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) KeyboardController* controller() { return controller_.get(); } 189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 19058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void ShowKeyboard() { 191effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&test_text_input_client); 193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected: 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetFocus(ui::TextInputClient* client) { 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::InputMethod* input_method = proxy()->GetInputMethod(); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) input_method->SetFocusedTextInputClient(client); 1990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) input_method->ShowImeIfNeeded(); 2010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { 2020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Set initial bounds for test keyboard window. 2030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch proxy_->GetKeyboardWindow()->SetBounds( 2040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch KeyboardBoundsFromWindowBounds( 2050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch controller()->GetContainerWindow()->bounds(), 100)); 2060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 2070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 21058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool WillHideKeyboard() { 21158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return controller_->WillHideKeyboard(); 21258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 21358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoopForUI message_loop_; 215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<TestFocusController> focus_controller_; 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 21958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) KeyboardControllerProxy* proxy_; 22058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) scoped_ptr<KeyboardController> controller_; 22158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); 223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(KeyboardControllerTest, KeyboardSize) { 2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) aura::Window* container(controller()->GetContainerWindow()); 2270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch aura::Window* keyboard(proxy()->GetKeyboardWindow()); 2280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch container->SetBounds(gfx::Rect(0, 0, 200, 100)); 2290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 2300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch container->AddChild(keyboard); 2310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const gfx::Rect& before_bounds = keyboard->bounds(); 2320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The initial keyboard should be positioned at the bottom of container and 2330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // has 0 height. 2340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds); 235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect new_bounds( 2370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch before_bounds.x(), before_bounds.y() - 50, 2380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch before_bounds.width(), 50); 2390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 2400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch keyboard->SetBounds(new_bounds); 2410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ASSERT_EQ(new_bounds, keyboard->bounds()); 242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Mock a screen rotation. 2440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch container->SetBounds(gfx::Rect(0, 0, 100, 200)); 2450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The above call should resize keyboard to new width while keeping the old 2460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // height. 2470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds()); 248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that tapping/clicking inside the keyboard does not give it focus. 251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { 252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 253c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::test::EventCountDelegate delegate; 254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<aura::Window> window(new aura::Window(&delegate)); 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 256c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window->SetBounds(root_bounds); 257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) root_window()->AddChild(window.get()); 258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window->Show(); 259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window->Focus(); 260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) aura::Window* keyboard_container(controller()->GetContainerWindow()); 262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) keyboard_container->SetBounds(root_bounds); 263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) root_window()->AddChild(keyboard_container); 265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) keyboard_container->Show(); 266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ShowKeyboard(); 268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(window->IsVisible()); 270c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(window->HasFocus()); 272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(keyboard_container->HasFocus()); 273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Click on the keyboard. Make sure the keyboard receives the event, but does 275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // not get focus. 276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EventObserver observer; 277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) keyboard_container->AddPreTargetHandler(&observer); 278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::test::EventGenerator generator(root_window()); 28058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint()); 281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) generator.ClickLeftButton(); 282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(window->HasFocus()); 283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(keyboard_container->HasFocus()); 284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); 285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); 286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); 287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Click outside of the keyboard. It should reach the window behind. 289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) generator.MoveMouseTo(gfx::Point()); 290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) generator.ClickLeftButton(); 291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) keyboard_container->RemovePreTargetHandler(&observer); 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(KeyboardControllerTest, EventHitTestingInContainer) { 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::test::EventCountDelegate delegate; 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<aura::Window> window(new aura::Window(&delegate)); 2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->SetBounds(root_bounds); 3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) root_window()->AddChild(window.get()); 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Show(); 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Focus(); 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* keyboard_container(controller()->GetContainerWindow()); 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) keyboard_container->SetBounds(root_bounds); 3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) root_window()->AddChild(keyboard_container); 3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) keyboard_container->Show(); 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShowKeyboard(); 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(window->IsVisible()); 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(window->HasFocus()); 3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(keyboard_container->HasFocus()); 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Make sure hit testing works correctly while the keyboard is visible. 3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); 3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EventTarget* root = root_window(); 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EventTargeter* targeter = root->GetEventTargeter(); 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point location = keyboard_window->bounds().CenterPoint(); 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, 3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_NONE); 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) location.set_y(keyboard_window->bounds().y() - 5); 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, 3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_NONE); 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); 332c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 334c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { 335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 337effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); 338effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); 339effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); 340effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); 341effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); 34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) aura::Window* keyboard_container(controller()->GetContainerWindow()); 34458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( 3454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) new KeyboardContainerObserver(keyboard_container)); 346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) keyboard_container->SetBounds(root_bounds); 3474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) root_window()->AddChild(keyboard_container); 348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client_0); 3505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&no_input_client_0); 35458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Keyboard should not immediately hide itself. It is delayed to avoid layout 35558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // flicker when the focus of input field quickly change. 35658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 35758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_TRUE(WillHideKeyboard()); 35858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Wait for hide keyboard to finish. 35958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::MessageLoop::current()->Run(); 360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(keyboard_container->IsVisible()); 361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client_1); 36358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 36458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 36558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Schedule to hide keyboard. 3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&no_input_client_1); 36758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_TRUE(WillHideKeyboard()); 36858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Cancel keyboard hide. 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client_2); 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(WillHideKeyboard()); 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 378effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); 379effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); 380effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); 381effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* keyboard_container(controller()->GetContainerWindow()); 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new KeyboardContainerObserver(keyboard_container)); 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) keyboard_container->SetBounds(root_bounds); 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) root_window()->AddChild(keyboard_container); 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client_0); 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Lock keyboard. 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->set_lock_keyboard(true); 39558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&no_input_client_0); 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Keyboard should not try to hide itself as it is locked. 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 39958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_FALSE(WillHideKeyboard()); 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client_1); 402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Unlock keyboard. 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->set_lock_keyboard(false); 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Keyboard should hide when focus on no input client. 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&no_input_client_1); 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(WillHideKeyboard()); 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Wait for hide keyboard to finish. 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->Run(); 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(keyboard_container->IsVisible()); 4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class KeyboardControllerAnimationTest : public KeyboardControllerTest, 4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public KeyboardControllerObserver { 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) KeyboardControllerAnimationTest() {} 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~KeyboardControllerAnimationTest() {} 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void SetUp() OVERRIDE { 4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We cannot short-circuit animations for this test. 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) KeyboardControllerTest::SetUp(); 4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) keyboard_container()->SetBounds(root_bounds); 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) root_window()->AddChild(keyboard_container()); 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->AddObserver(this); 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void TearDown() OVERRIDE { 4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->RemoveObserver(this); 4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) KeyboardControllerTest::TearDown(); 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected: 4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // KeyboardControllerObserver overrides 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE { 4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notified_bounds_ = new_bounds; 4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& notified_bounds() { return notified_bounds_; } 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* keyboard_container() { 4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return controller()->GetContainerWindow(); 4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* keyboard_window() { 4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return proxy()->GetKeyboardWindow(); 4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect notified_bounds_; 4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); 4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests virtual keyboard has correct show and hide animation. 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::Layer* layer = keyboard_container()->layer(); 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShowKeyboard(); 4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Keyboard container and window should immediately become visible before 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // animation starts. 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container()->IsVisible()); 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_window()->IsVisible()); 4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) float show_start_opacity = layer->opacity(); 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Transform transform; 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) transform.Translate(0, keyboard_window()->bounds().height()); 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(transform, layer->transform()); 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(gfx::Rect(), notified_bounds()); 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunAnimationForLayer(layer); 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container()->IsVisible()); 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_window()->IsVisible()); 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) float show_end_opacity = layer->opacity(); 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_LT(show_start_opacity, show_end_opacity); 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(gfx::Transform(), layer->transform()); 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // KeyboardController should notify the bounds of keyboard window to its 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // observers after show animation finished. 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(keyboard_window()->bounds(), notified_bounds()); 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Directly hide keyboard without delay. 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container()->IsVisible()); 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container()->layer()->visible()); 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_window()->IsVisible()); 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) float hide_start_opacity = layer->opacity(); 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // KeyboardController should notify the bounds of keyboard window to its 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // observers before hide animation starts. 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(gfx::Rect(), notified_bounds()); 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunAnimationForLayer(layer); 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(keyboard_container()->IsVisible()); 4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(keyboard_container()->layer()->visible()); 5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(keyboard_window()->IsVisible()); 5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) float hide_end_opacity = layer->opacity(); 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_GT(hide_start_opacity, hide_end_opacity); 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(transform, layer->transform()); 5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(gfx::Rect(), notified_bounds()); 5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Show keyboard during keyboard hide animation should abort the hide animation 5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and the keyboard should animate in. 5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Test for crbug.com/333284. 5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { 5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::Layer* layer = keyboard_container()->layer(); 5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShowKeyboard(); 5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunAnimationForLayer(layer); 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); 5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Before hide animation finishes, show keyboard again. 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShowKeyboard(); 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunAnimationForLayer(layer); 5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_container()->IsVisible()); 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(keyboard_window()->IsVisible()); 5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(1.0, layer->opacity()); 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(gfx::Transform(), layer->transform()); 523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 524c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class KeyboardControllerUsabilityTest : public KeyboardControllerTest { 5261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 5271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) KeyboardControllerUsabilityTest() {} 5281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~KeyboardControllerUsabilityTest() {} 5291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void SetUp() OVERRIDE { 5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch( 532f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) switches::kKeyboardUsabilityExperiment); 5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) KeyboardControllerTest::SetUp(); 5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 5351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 5371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); 5381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 5391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { 5411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const gfx::Rect& root_bounds = root_window()->bounds(); 5421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 543effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); 544effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); 5451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* keyboard_container(controller()->GetContainerWindow()); 5471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) keyboard_container->SetBounds(root_bounds); 5481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) root_window()->AddChild(keyboard_container); 5491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&input_client); 5511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 5521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFocus(&no_input_client); 5541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Keyboard should not hide itself after lost focus. 5551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(keyboard_container->IsVisible()); 5561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(WillHideKeyboard()); 5571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace keyboard 560