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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/aura/client/focus_client.h" | 10 #include "ui/aura/client/focus_client.h" |
10 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
11 #include "ui/aura/test/aura_test_helper.h" | 12 #include "ui/aura/test/aura_test_helper.h" |
12 #include "ui/aura/test/event_generator.h" | 13 #include "ui/aura/test/event_generator.h" |
13 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
15 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
16 #include "ui/base/ime/input_method_factory.h" | 17 #include "ui/base/ime/input_method_factory.h" |
17 #include "ui/base/ime/text_input_client.h" | 18 #include "ui/base/ime/text_input_client.h" |
18 #include "ui/compositor/layer_type.h" | 19 #include "ui/compositor/layer_type.h" |
19 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
20 #include "ui/keyboard/keyboard_controller.h" | 21 #include "ui/keyboard/keyboard_controller.h" |
21 #include "ui/keyboard/keyboard_controller_proxy.h" | 22 #include "ui/keyboard/keyboard_controller_proxy.h" |
23 #include "ui/keyboard/keyboard_switches.h" | |
22 | 24 |
23 namespace keyboard { | 25 namespace keyboard { |
24 namespace { | 26 namespace { |
25 | 27 |
26 // An event handler that focuses a window when it is clicked/touched on. This is | 28 // An event handler that focuses a window when it is clicked/touched on. This is |
27 // used to match the focus manger behaviour in ash and views. | 29 // used to match the focus manger behaviour in ash and views. |
28 class TestFocusController : public ui::EventHandler { | 30 class TestFocusController : public ui::EventHandler { |
29 public: | 31 public: |
30 explicit TestFocusController(aura::RootWindow* root) | 32 explicit TestFocusController(aura::RootWindow* root) |
31 : root_(root) { | 33 : root_(root) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 | 182 |
181 aura::Window* window_; | 183 aura::Window* window_; |
182 | 184 |
183 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); | 185 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); |
184 }; | 186 }; |
185 | 187 |
186 } // namespace | 188 } // namespace |
187 | 189 |
188 class KeyboardControllerTest : public testing::Test { | 190 class KeyboardControllerTest : public testing::Test { |
189 public: | 191 public: |
190 KeyboardControllerTest() {} | 192 KeyboardControllerTest() : command_line_(CommandLine::NO_PROGRAM) {} |
191 virtual ~KeyboardControllerTest() {} | 193 virtual ~KeyboardControllerTest() {} |
192 | 194 |
193 virtual void SetUp() OVERRIDE { | 195 virtual void SetUp() OVERRIDE { |
194 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 196 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
195 aura_test_helper_->SetUp(); | 197 aura_test_helper_->SetUp(); |
196 ui::SetUpInputMethodFactoryForTesting(); | 198 ui::SetUpInputMethodFactoryForTesting(); |
197 focus_controller_.reset(new TestFocusController(root_window())); | 199 focus_controller_.reset(new TestFocusController(root_window())); |
198 proxy_ = new TestKeyboardControllerProxy(); | 200 proxy_ = new TestKeyboardControllerProxy(); |
199 controller_.reset(new KeyboardController(proxy_)); | 201 controller_.reset(new KeyboardController(proxy_)); |
200 } | 202 } |
201 | 203 |
202 virtual void TearDown() OVERRIDE { | 204 virtual void TearDown() OVERRIDE { |
203 focus_controller_.reset(); | 205 focus_controller_.reset(); |
204 aura_test_helper_->TearDown(); | 206 aura_test_helper_->TearDown(); |
205 } | 207 } |
206 | 208 |
207 aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } | 209 aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } |
208 KeyboardControllerProxy* proxy() { return proxy_; } | 210 KeyboardControllerProxy* proxy() { return proxy_; } |
209 KeyboardController* controller() { return controller_.get(); } | 211 KeyboardController* controller() { return controller_.get(); } |
210 | 212 |
213 void AppendSwitch(const std::string& switch_string) { | |
214 command_line_.AppendSwitch(switch_string); | |
215 controller_->set_command_line_for_testing(&command_line_); | |
sadrul
2013/10/24 01:21:01
You don't do this.
For this kind of tests, where
bshe
2013/10/24 03:35:36
eh. I followed the pattern that is used in desktop
| |
216 } | |
217 | |
211 void ShowKeyboard() { | 218 void ShowKeyboard() { |
212 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); | 219 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
213 controller_->OnTextInputStateChanged(&test_text_input_client); | 220 controller_->OnTextInputStateChanged(&test_text_input_client); |
214 } | 221 } |
215 | 222 |
216 protected: | 223 protected: |
217 bool WillHideKeyboard() { | 224 bool WillHideKeyboard() { |
218 return controller_->WillHideKeyboard(); | 225 return controller_->WillHideKeyboard(); |
219 } | 226 } |
220 | 227 |
221 base::MessageLoopForUI message_loop_; | 228 base::MessageLoopForUI message_loop_; |
222 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 229 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
223 scoped_ptr<TestFocusController> focus_controller_; | 230 scoped_ptr<TestFocusController> focus_controller_; |
224 | 231 |
225 private: | 232 private: |
233 // Custom command line passed to KeyboardController by AppendSwitch(). | |
234 CommandLine command_line_; | |
235 | |
226 KeyboardControllerProxy* proxy_; | 236 KeyboardControllerProxy* proxy_; |
227 scoped_ptr<KeyboardController> controller_; | 237 scoped_ptr<KeyboardController> controller_; |
228 | 238 |
229 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 239 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
230 }; | 240 }; |
231 | 241 |
232 TEST_F(KeyboardControllerTest, KeyboardSize) { | 242 TEST_F(KeyboardControllerTest, KeyboardSize) { |
233 aura::Window* container(controller()->GetContainerWindow()); | 243 aura::Window* container(controller()->GetContainerWindow()); |
234 gfx::Rect bounds(0, 0, 100, 100); | 244 gfx::Rect bounds(0, 0, 100, 100); |
235 container->SetBounds(bounds); | 245 container->SetBounds(bounds); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 // Schedule to hide keyboard. | 332 // Schedule to hide keyboard. |
323 input_method->SetFocusedTextInputClient(&no_input_client_1); | 333 input_method->SetFocusedTextInputClient(&no_input_client_1); |
324 EXPECT_TRUE(WillHideKeyboard()); | 334 EXPECT_TRUE(WillHideKeyboard()); |
325 // Cancel keyboard hide. | 335 // Cancel keyboard hide. |
326 input_method->SetFocusedTextInputClient(&input_client_2); | 336 input_method->SetFocusedTextInputClient(&input_client_2); |
327 | 337 |
328 EXPECT_FALSE(WillHideKeyboard()); | 338 EXPECT_FALSE(WillHideKeyboard()); |
329 EXPECT_TRUE(keyboard_container->IsVisible()); | 339 EXPECT_TRUE(keyboard_container->IsVisible()); |
330 } | 340 } |
331 | 341 |
342 TEST_F(KeyboardControllerTest, KeyboardAlwaysVisibleInKeyboardUsabilityTest) { | |
343 const gfx::Rect& root_bounds = root_window()->bounds(); | |
344 | |
345 AppendSwitch(switches::kKeyboardUsabilityTest); | |
346 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
347 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | |
348 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | |
349 input_method->SetFocusedTextInputClient(&input_client); | |
350 | |
351 aura::Window* keyboard_container(controller()->GetContainerWindow()); | |
352 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | |
353 new KeyboardContainerObserver(keyboard_container)); | |
354 keyboard_container->SetBounds(root_bounds); | |
355 root_window()->AddChild(keyboard_container); | |
356 | |
357 EXPECT_TRUE(keyboard_container->IsVisible()); | |
358 | |
359 input_method->SetFocusedTextInputClient(&no_input_client); | |
360 // Keyboard should not hide itself after lost focus. | |
361 EXPECT_TRUE(keyboard_container->IsVisible()); | |
362 EXPECT_FALSE(WillHideKeyboard()); | |
363 } | |
364 | |
332 } // namespace keyboard | 365 } // namespace keyboard |
OLD | NEW |