| 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/client/focus_client.h" | 8 #include "ui/aura/client/focus_client.h" |
| 9 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
| 10 #include "ui/aura/test/aura_test_helper.h" | 10 #include "ui/aura/test/aura_test_helper.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 if (event->type() == ui::ET_MOUSE_PRESSED || | 42 if (event->type() == ui::ET_MOUSE_PRESSED || |
| 43 event->type() == ui::ET_TOUCH_PRESSED) { | 43 event->type() == ui::ET_TOUCH_PRESSED) { |
| 44 aura::client::GetFocusClient(target)->FocusWindow(target); | 44 aura::client::GetFocusClient(target)->FocusWindow(target); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 aura::Window* root_; | 48 aura::Window* root_; |
| 49 DISALLOW_COPY_AND_ASSIGN(TestFocusController); | 49 DISALLOW_COPY_AND_ASSIGN(TestFocusController); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class KeyboardControllerTest : public testing::Test { | |
| 53 public: | |
| 54 KeyboardControllerTest() {} | |
| 55 virtual ~KeyboardControllerTest() {} | |
| 56 | |
| 57 virtual void SetUp() OVERRIDE { | |
| 58 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | |
| 59 aura_test_helper_->SetUp(); | |
| 60 ui::SetUpInputMethodFactoryForTesting(); | |
| 61 focus_controller_.reset(new TestFocusController(root_window())); | |
| 62 } | |
| 63 | |
| 64 virtual void TearDown() OVERRIDE { | |
| 65 aura_test_helper_->TearDown(); | |
| 66 } | |
| 67 | |
| 68 aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } | |
| 69 | |
| 70 protected: | |
| 71 base::MessageLoopForUI message_loop_; | |
| 72 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | |
| 73 scoped_ptr<TestFocusController> focus_controller_; | |
| 74 | |
| 75 private: | |
| 76 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | |
| 77 }; | |
| 78 | |
| 79 class TestKeyboardControllerProxy : public KeyboardControllerProxy { | 52 class TestKeyboardControllerProxy : public KeyboardControllerProxy { |
| 80 public: | 53 public: |
| 81 TestKeyboardControllerProxy() | 54 TestKeyboardControllerProxy() |
| 82 : window_(new aura::Window(&delegate_)), | 55 : window_(new aura::Window(&delegate_)), |
| 83 input_method_(ui::CreateInputMethod(NULL, | 56 input_method_(ui::CreateInputMethod(NULL, |
| 84 gfx::kNullAcceleratedWidget)) { | 57 gfx::kNullAcceleratedWidget)) { |
| 85 window_->Init(ui::LAYER_NOT_DRAWN); | 58 window_->Init(ui::LAYER_NOT_DRAWN); |
| 86 window_->set_owned_by_parent(false); | 59 window_->set_owned_by_parent(false); |
| 87 } | 60 } |
| 88 | 61 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 base::i18n::TextDirection direction) OVERRIDE { return false; } | 142 base::i18n::TextDirection direction) OVERRIDE { return false; } |
| 170 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE {} | 143 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE {} |
| 171 | 144 |
| 172 ui::TextInputType type_; | 145 ui::TextInputType type_; |
| 173 | 146 |
| 174 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); | 147 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); |
| 175 }; | 148 }; |
| 176 | 149 |
| 177 } // namespace | 150 } // namespace |
| 178 | 151 |
| 152 class KeyboardControllerTest : public testing::Test { |
| 153 public: |
| 154 KeyboardControllerTest() {} |
| 155 virtual ~KeyboardControllerTest() {} |
| 156 |
| 157 virtual void SetUp() OVERRIDE { |
| 158 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
| 159 aura_test_helper_->SetUp(); |
| 160 ui::SetUpInputMethodFactoryForTesting(); |
| 161 focus_controller_.reset(new TestFocusController(root_window())); |
| 162 } |
| 163 |
| 164 virtual void TearDown() OVERRIDE { |
| 165 aura_test_helper_->TearDown(); |
| 166 } |
| 167 |
| 168 aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } |
| 169 |
| 170 void ShowKeyboard(KeyboardController* controller) { |
| 171 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 172 controller->OnTextInputStateChanged(&test_text_input_client); |
| 173 } |
| 174 |
| 175 protected: |
| 176 base::MessageLoopForUI message_loop_; |
| 177 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 178 scoped_ptr<TestFocusController> focus_controller_; |
| 179 |
| 180 private: |
| 181 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
| 182 }; |
| 183 |
| 179 TEST_F(KeyboardControllerTest, KeyboardSize) { | 184 TEST_F(KeyboardControllerTest, KeyboardSize) { |
| 180 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); | 185 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); |
| 181 KeyboardController controller(proxy); | 186 KeyboardController controller(proxy); |
| 182 | 187 |
| 183 scoped_ptr<aura::Window> container(controller.GetContainerWindow()); | 188 scoped_ptr<aura::Window> container(controller.GetContainerWindow()); |
| 184 gfx::Rect bounds(0, 0, 100, 100); | 189 gfx::Rect bounds(0, 0, 100, 100); |
| 185 container->SetBounds(bounds); | 190 container->SetBounds(bounds); |
| 186 | 191 |
| 187 const gfx::Rect& before_bounds = proxy->GetKeyboardWindow()->bounds(); | 192 const gfx::Rect& before_bounds = proxy->GetKeyboardWindow()->bounds(); |
| 188 gfx::Rect new_bounds( | 193 gfx::Rect new_bounds( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 207 | 212 |
| 208 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); | 213 KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); |
| 209 KeyboardController controller(proxy); | 214 KeyboardController controller(proxy); |
| 210 | 215 |
| 211 scoped_ptr<aura::Window> keyboard_container(controller.GetContainerWindow()); | 216 scoped_ptr<aura::Window> keyboard_container(controller.GetContainerWindow()); |
| 212 keyboard_container->SetBounds(root_bounds); | 217 keyboard_container->SetBounds(root_bounds); |
| 213 | 218 |
| 214 root_window()->AddChild(keyboard_container.get()); | 219 root_window()->AddChild(keyboard_container.get()); |
| 215 keyboard_container->Show(); | 220 keyboard_container->Show(); |
| 216 | 221 |
| 217 root_window()->StackChildAtTop(keyboard_container.get()); | 222 ShowKeyboard(&controller); |
| 223 |
| 218 EXPECT_TRUE(window->IsVisible()); | 224 EXPECT_TRUE(window->IsVisible()); |
| 219 EXPECT_TRUE(keyboard_container->IsVisible()); | 225 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 220 EXPECT_TRUE(window->HasFocus()); | 226 EXPECT_TRUE(window->HasFocus()); |
| 221 EXPECT_FALSE(keyboard_container->HasFocus()); | 227 EXPECT_FALSE(keyboard_container->HasFocus()); |
| 222 | 228 |
| 223 // Click on the keyboard. Make sure the keyboard receives the event, but does | 229 // Click on the keyboard. Make sure the keyboard receives the event, but does |
| 224 // not get focus. | 230 // not get focus. |
| 225 EventObserver observer; | 231 EventObserver observer; |
| 226 keyboard_container->AddPreTargetHandler(&observer); | 232 keyboard_container->AddPreTargetHandler(&observer); |
| 227 | 233 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 EXPECT_TRUE(keyboard_container->IsVisible()); | 271 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 266 | 272 |
| 267 input_method->SetFocusedTextInputClient(&no_input_client); | 273 input_method->SetFocusedTextInputClient(&no_input_client); |
| 268 EXPECT_FALSE(keyboard_container->IsVisible()); | 274 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 269 | 275 |
| 270 input_method->SetFocusedTextInputClient(&input_client); | 276 input_method->SetFocusedTextInputClient(&input_client); |
| 271 EXPECT_TRUE(keyboard_container->IsVisible()); | 277 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 272 } | 278 } |
| 273 | 279 |
| 274 } // namespace keyboard | 280 } // namespace keyboard |
| OLD | NEW |