Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | |
| 5 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/client/focus_client.h" | 9 #include "ui/aura/client/focus_client.h" |
| 9 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| 10 #include "ui/aura/test/aura_test_helper.h" | 11 #include "ui/aura/test/aura_test_helper.h" |
| 11 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/base/ime/input_method.h" | 15 #include "ui/base/ime/input_method.h" |
| 15 #include "ui/base/ime/input_method_factory.h" | 16 #include "ui/base/ime/input_method_factory.h" |
| 16 #include "ui/base/ime/text_input_client.h" | 17 #include "ui/base/ime/text_input_client.h" |
| 17 #include "ui/compositor/layer_type.h" | 18 #include "ui/compositor/layer_type.h" |
| 18 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 19 #include "ui/keyboard/keyboard_controller.h" | 20 #include "ui/keyboard/keyboard_controller.h" |
| 20 #include "ui/keyboard/keyboard_controller_proxy.h" | 21 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 21 | 22 |
| 22 namespace keyboard { | 23 namespace keyboard { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 26 void StopWait() { | |
| 27 base::MessageLoop::current()->Quit(); | |
| 28 } | |
| 29 | |
| 30 void WaitKeyboardHideToFinish() { | |
| 31 base::MessageLoop::current()->PostDelayedTask( | |
| 32 FROM_HERE, | |
| 33 base::Bind(&StopWait), | |
| 34 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | |
| 35 base::MessageLoop::current()->Run(); | |
| 36 } | |
| 37 | |
| 25 // An event handler that focuses a window when it is clicked/touched on. This is | 38 // An event handler that focuses a window when it is clicked/touched on. This is |
| 26 // used to match the focus manger behaviour in ash and views. | 39 // used to match the focus manger behaviour in ash and views. |
| 27 class TestFocusController : public ui::EventHandler { | 40 class TestFocusController : public ui::EventHandler { |
| 28 public: | 41 public: |
| 29 explicit TestFocusController(aura::RootWindow* root) | 42 explicit TestFocusController(aura::RootWindow* root) |
| 30 : root_(root) { | 43 : root_(root) { |
| 31 root_->AddPreTargetHandler(this); | 44 root_->AddPreTargetHandler(this); |
| 32 } | 45 } |
| 33 | 46 |
| 34 virtual ~TestFocusController() { | 47 virtual ~TestFocusController() { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 aura::test::EventCountDelegate delegate; | 276 aura::test::EventCountDelegate delegate; |
| 264 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 277 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 265 window->Init(ui::LAYER_NOT_DRAWN); | 278 window->Init(ui::LAYER_NOT_DRAWN); |
| 266 window->SetBounds(root_bounds); | 279 window->SetBounds(root_bounds); |
| 267 root_window()->AddChild(window.get()); | 280 root_window()->AddChild(window.get()); |
| 268 window->Show(); | 281 window->Show(); |
| 269 window->Focus(); | 282 window->Focus(); |
| 270 | 283 |
| 271 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); | 284 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); |
| 272 ui::InputMethod* input_method = proxy->GetInputMethod(); | 285 ui::InputMethod* input_method = proxy->GetInputMethod(); |
| 273 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 286 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 274 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 287 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 275 input_method->SetFocusedTextInputClient(&input_client); | 288 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 289 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | |
| 290 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 276 | 291 |
| 277 KeyboardController controller(proxy); | 292 KeyboardController controller(proxy); |
| 278 | 293 |
| 279 scoped_ptr<aura::Window> keyboard_container(controller.GetContainerWindow()); | 294 scoped_ptr<aura::Window> keyboard_container(controller.GetContainerWindow()); |
| 280 keyboard_container->SetBounds(root_bounds); | 295 keyboard_container->SetBounds(root_bounds); |
| 281 root_window()->AddChild(keyboard_container.get()); | 296 root_window()->AddChild(keyboard_container.get()); |
| 282 | 297 |
| 283 EXPECT_TRUE(keyboard_container->IsVisible()); | 298 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 284 | 299 |
| 285 input_method->SetFocusedTextInputClient(&no_input_client); | 300 input_method->SetFocusedTextInputClient(&no_input_client_0); |
| 301 // Keyboard should not immediately hide itself. | |
|
kevers
2013/08/26 15:50:18
Probably worth noting in the comment why the keybo
bshe
2013/08/26 18:39:17
Done.
| |
| 302 EXPECT_TRUE(keyboard_container->IsVisible()); | |
| 303 WaitKeyboardHideToFinish(); | |
| 286 EXPECT_FALSE(keyboard_container->IsVisible()); | 304 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 287 | 305 |
| 288 input_method->SetFocusedTextInputClient(&input_client); | 306 input_method->SetFocusedTextInputClient(&input_client_0); |
| 307 EXPECT_TRUE(keyboard_container->IsVisible()); | |
| 308 | |
| 309 // Schedule to hide keyboard. | |
| 310 input_method->SetFocusedTextInputClient(&no_input_client_1); | |
| 311 // Cancel keyboard hide. | |
| 312 input_method->SetFocusedTextInputClient(&input_client_1); | |
| 313 | |
| 314 WaitKeyboardHideToFinish(); | |
| 289 EXPECT_TRUE(keyboard_container->IsVisible()); | 315 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 290 } | 316 } |
| 291 | 317 |
| 292 } // namespace keyboard | 318 } // namespace keyboard |
| OLD | NEW |