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/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/focus_client.h" | 10 #include "ui/aura/client/focus_client.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 186 |
187 void ShowKeyboard() { | 187 void ShowKeyboard() { |
188 ui::DummyTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); | 188 ui::DummyTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
189 SetFocus(&test_text_input_client); | 189 SetFocus(&test_text_input_client); |
190 } | 190 } |
191 | 191 |
192 protected: | 192 protected: |
193 void SetFocus(ui::TextInputClient* client) { | 193 void SetFocus(ui::TextInputClient* client) { |
194 ui::InputMethod* input_method = proxy()->GetInputMethod(); | 194 ui::InputMethod* input_method = proxy()->GetInputMethod(); |
195 input_method->SetFocusedTextInputClient(client); | 195 input_method->SetFocusedTextInputClient(client); |
196 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) | 196 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { |
197 input_method->ShowImeIfNeeded(); | 197 input_method->ShowImeIfNeeded(); |
198 if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { | |
199 // Set initial bounds for test keyboard window. | |
200 gfx::Rect window_bounds = controller()->GetContainerWindow()->bounds(); | |
oshima
2014/04/23 16:14:08
you're doing this in muliple places. Can you add a
bshe
2014/04/23 16:39:07
Done.
| |
201 proxy_->GetKeyboardWindow()->SetBounds(gfx::Rect( | |
202 window_bounds.x(), | |
203 window_bounds.y() + window_bounds.height() - 100, | |
204 window_bounds.width(), | |
205 100)); | |
206 } | |
207 } | |
198 } | 208 } |
199 | 209 |
200 bool WillHideKeyboard() { | 210 bool WillHideKeyboard() { |
201 return controller_->WillHideKeyboard(); | 211 return controller_->WillHideKeyboard(); |
202 } | 212 } |
203 | 213 |
204 base::MessageLoopForUI message_loop_; | 214 base::MessageLoopForUI message_loop_; |
205 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 215 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
206 scoped_ptr<TestFocusController> focus_controller_; | 216 scoped_ptr<TestFocusController> focus_controller_; |
207 | 217 |
208 private: | 218 private: |
209 KeyboardControllerProxy* proxy_; | 219 KeyboardControllerProxy* proxy_; |
210 scoped_ptr<KeyboardController> controller_; | 220 scoped_ptr<KeyboardController> controller_; |
211 | 221 |
212 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 222 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
213 }; | 223 }; |
214 | 224 |
215 TEST_F(KeyboardControllerTest, KeyboardSize) { | 225 TEST_F(KeyboardControllerTest, KeyboardSize) { |
216 aura::Window* container(controller()->GetContainerWindow()); | 226 aura::Window* container(controller()->GetContainerWindow()); |
217 gfx::Rect bounds(0, 0, 100, 100); | 227 aura::Window* keyboard(proxy()->GetKeyboardWindow()); |
218 container->SetBounds(bounds); | 228 container->SetBounds(gfx::Rect(0, 0, 200, 100)); |
219 | 229 |
220 const gfx::Rect& before_bounds = proxy()->GetKeyboardWindow()->bounds(); | 230 container->AddChild(keyboard); |
231 const gfx::Rect& before_bounds = keyboard->bounds(); | |
232 // The initial keyboard should be positioned at the bottom of container and | |
233 // has 0 height. | |
234 ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds); | |
235 | |
221 gfx::Rect new_bounds( | 236 gfx::Rect new_bounds( |
222 before_bounds.x(), before_bounds.y(), | 237 before_bounds.x(), before_bounds.y() - 50, |
223 before_bounds.width() / 2, before_bounds.height() / 2); | 238 before_bounds.width(), 50); |
224 | 239 |
225 // The KeyboardController's LayoutManager shouldn't let this happen | 240 keyboard->SetBounds(new_bounds); |
226 proxy()->GetKeyboardWindow()->SetBounds(new_bounds); | 241 ASSERT_EQ(new_bounds, keyboard->bounds()); |
227 ASSERT_EQ(before_bounds, proxy()->GetKeyboardWindow()->bounds()); | 242 |
243 // Mock a screen rotation. | |
244 container->SetBounds(gfx::Rect(0, 0, 100, 200)); | |
245 // The above call should resize keyboard to new width while keeping the old | |
246 // height. | |
247 ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds()); | |
228 } | 248 } |
229 | 249 |
230 // Tests that tapping/clicking inside the keyboard does not give it focus. | 250 // Tests that tapping/clicking inside the keyboard does not give it focus. |
231 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 251 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
232 const gfx::Rect& root_bounds = root_window()->bounds(); | 252 const gfx::Rect& root_bounds = root_window()->bounds(); |
233 aura::test::EventCountDelegate delegate; | 253 aura::test::EventCountDelegate delegate; |
234 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 254 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
235 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 255 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
236 window->SetBounds(root_bounds); | 256 window->SetBounds(root_bounds); |
237 root_window()->AddChild(window.get()); | 257 root_window()->AddChild(window.get()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 406 |
387 // Keyboard should hide when focus on no input client. | 407 // Keyboard should hide when focus on no input client. |
388 SetFocus(&no_input_client_1); | 408 SetFocus(&no_input_client_1); |
389 EXPECT_TRUE(WillHideKeyboard()); | 409 EXPECT_TRUE(WillHideKeyboard()); |
390 | 410 |
391 // Wait for hide keyboard to finish. | 411 // Wait for hide keyboard to finish. |
392 base::MessageLoop::current()->Run(); | 412 base::MessageLoop::current()->Run(); |
393 EXPECT_FALSE(keyboard_container->IsVisible()); | 413 EXPECT_FALSE(keyboard_container->IsVisible()); |
394 } | 414 } |
395 | 415 |
396 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { | |
397 aura::Window* keyboard_container = controller()->GetContainerWindow(); | |
398 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | |
399 keyboard_container->SetBounds(gfx::Rect(800, 600)); | |
400 keyboard_container->AddChild(keyboard_window); | |
401 | |
402 int original_height = keyboard_window->bounds().height(); | |
403 | |
404 // Resizes from contents when flag is unset. | |
405 keyboard_window->SetBounds(gfx::Rect(100, 80)); | |
406 EXPECT_EQ(original_height, keyboard_window->bounds().height()); | |
407 | |
408 // Resizes from contents when flag is set. | |
409 proxy()->set_resizing_from_contents(true); | |
410 keyboard_window->SetBounds(gfx::Rect(100, 80)); | |
411 EXPECT_EQ(80, keyboard_window->bounds().height()); | |
412 | |
413 // Resizes from container when flag is set. | |
414 keyboard_container->SetBounds(gfx::Rect(400, 300)); | |
415 EXPECT_EQ(80, keyboard_window->bounds().height()); | |
416 | |
417 // Resizes from container when flag is unset. | |
418 proxy()->set_resizing_from_contents(false); | |
419 keyboard_container->SetBounds(gfx::Rect(800, 600)); | |
420 EXPECT_EQ(original_height, keyboard_window->bounds().height()); | |
421 } | |
422 | |
423 class KeyboardControllerAnimationTest : public KeyboardControllerTest, | 416 class KeyboardControllerAnimationTest : public KeyboardControllerTest, |
424 public KeyboardControllerObserver { | 417 public KeyboardControllerObserver { |
425 public: | 418 public: |
426 KeyboardControllerAnimationTest() {} | 419 KeyboardControllerAnimationTest() {} |
427 virtual ~KeyboardControllerAnimationTest() {} | 420 virtual ~KeyboardControllerAnimationTest() {} |
428 | 421 |
429 virtual void SetUp() OVERRIDE { | 422 virtual void SetUp() OVERRIDE { |
430 // We cannot short-circuit animations for this test. | 423 // We cannot short-circuit animations for this test. |
431 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 424 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
432 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 425 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 SetFocus(&input_client); | 550 SetFocus(&input_client); |
558 EXPECT_TRUE(keyboard_container->IsVisible()); | 551 EXPECT_TRUE(keyboard_container->IsVisible()); |
559 | 552 |
560 SetFocus(&no_input_client); | 553 SetFocus(&no_input_client); |
561 // Keyboard should not hide itself after lost focus. | 554 // Keyboard should not hide itself after lost focus. |
562 EXPECT_TRUE(keyboard_container->IsVisible()); | 555 EXPECT_TRUE(keyboard_container->IsVisible()); |
563 EXPECT_FALSE(WillHideKeyboard()); | 556 EXPECT_FALSE(WillHideKeyboard()); |
564 } | 557 } |
565 | 558 |
566 } // namespace keyboard | 559 } // namespace keyboard |
OLD | NEW |