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 "ui/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/aura/client/focus_client.h" | 15 #include "ui/aura/client/focus_client.h" |
16 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
17 #include "ui/aura/test/aura_test_helper.h" | 17 #include "ui/aura/test/aura_test_helper.h" |
18 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
21 #include "ui/base/ime/dummy_text_input_client.h" | 21 #include "ui/base/ime/dummy_text_input_client.h" |
22 #include "ui/base/ime/input_method.h" | 22 #include "ui/base/ime/input_method.h" |
23 #include "ui/base/ime/input_method_factory.h" | 23 #include "ui/base/ime/input_method_factory.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 private: | 205 private: |
206 DISALLOW_COPY_AND_ASSIGN(TestKeyboardLayoutDelegate); | 206 DISALLOW_COPY_AND_ASSIGN(TestKeyboardLayoutDelegate); |
207 }; | 207 }; |
208 | 208 |
209 } // namespace | 209 } // namespace |
210 | 210 |
211 class KeyboardControllerTest : public testing::Test, | 211 class KeyboardControllerTest : public testing::Test, |
212 public KeyboardControllerObserver { | 212 public KeyboardControllerObserver { |
213 public: | 213 public: |
214 KeyboardControllerTest() | 214 KeyboardControllerTest() |
215 : number_of_calls_(0), ui_(nullptr), keyboard_closed_(false) {} | 215 : scoped_task_environment_( |
| 216 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 217 number_of_calls_(0), |
| 218 ui_(nullptr), |
| 219 keyboard_closed_(false) {} |
216 ~KeyboardControllerTest() override {} | 220 ~KeyboardControllerTest() override {} |
217 | 221 |
218 void SetUp() override { | 222 void SetUp() override { |
219 // The ContextFactory must exist before any Compositors are created. | 223 // The ContextFactory must exist before any Compositors are created. |
220 bool enable_pixel_output = false; | 224 bool enable_pixel_output = false; |
221 ui::ContextFactory* context_factory = nullptr; | 225 ui::ContextFactory* context_factory = nullptr; |
222 ui::ContextFactoryPrivate* context_factory_private = nullptr; | 226 ui::ContextFactoryPrivate* context_factory_private = nullptr; |
223 | 227 |
224 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, | 228 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, |
225 &context_factory_private); | 229 &context_factory_private); |
226 | 230 |
227 ui::SetUpInputMethodFactoryForTesting(); | 231 ui::SetUpInputMethodFactoryForTesting(); |
228 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 232 aura_test_helper_.reset(new aura::test::AuraTestHelper()); |
229 aura_test_helper_->SetUp(context_factory, context_factory_private); | 233 aura_test_helper_->SetUp(context_factory, context_factory_private); |
230 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 234 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
231 focus_controller_.reset(new TestFocusController(root_window())); | 235 focus_controller_.reset(new TestFocusController(root_window())); |
232 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); | 236 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); |
233 layout_delegate_.reset(new TestKeyboardLayoutDelegate()); | 237 layout_delegate_.reset(new TestKeyboardLayoutDelegate()); |
234 controller_.reset(new KeyboardController(ui_, layout_delegate_.get())); | 238 controller_.reset(new KeyboardController(ui_, layout_delegate_.get())); |
235 controller()->AddObserver(this); | 239 controller()->AddObserver(this); |
236 } | 240 } |
237 | 241 |
238 void TearDown() override { | 242 void TearDown() override { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 bool ShouldEnableInsets(aura::Window* window) { | 299 bool ShouldEnableInsets(aura::Window* window) { |
296 aura::Window* keyboard_window = ui_->GetKeyboardWindow(); | 300 aura::Window* keyboard_window = ui_->GetKeyboardWindow(); |
297 return (keyboard_window->GetRootWindow() == window->GetRootWindow() && | 301 return (keyboard_window->GetRootWindow() == window->GetRootWindow() && |
298 keyboard::IsKeyboardOverscrollEnabled() && | 302 keyboard::IsKeyboardOverscrollEnabled() && |
299 keyboard_window->IsVisible() && | 303 keyboard_window->IsVisible() && |
300 controller_->keyboard_visible()); | 304 controller_->keyboard_visible()); |
301 } | 305 } |
302 | 306 |
303 void ResetController() { controller_.reset(); } | 307 void ResetController() { controller_.reset(); } |
304 | 308 |
305 base::MessageLoopForUI message_loop_; | 309 base::test::ScopedTaskEnvironment scoped_task_environment_; |
306 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 310 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
307 std::unique_ptr<TestFocusController> focus_controller_; | 311 std::unique_ptr<TestFocusController> focus_controller_; |
308 | 312 |
309 private: | 313 private: |
310 int number_of_calls_; | 314 int number_of_calls_; |
311 gfx::Rect notified_bounds_; | 315 gfx::Rect notified_bounds_; |
312 KeyboardUI* ui_; | 316 KeyboardUI* ui_; |
313 std::unique_ptr<KeyboardLayoutDelegate> layout_delegate_; | 317 std::unique_ptr<KeyboardLayoutDelegate> layout_delegate_; |
314 std::unique_ptr<KeyboardController> controller_; | 318 std::unique_ptr<KeyboardController> controller_; |
315 std::unique_ptr<ui::TextInputClient> test_text_input_client_; | 319 std::unique_ptr<ui::TextInputClient> test_text_input_client_; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 gfx::Rect new_bounds(0, 0, 1280, 800); | 760 gfx::Rect new_bounds(0, 0, 1280, 800); |
757 ASSERT_NE(new_bounds, root_window()->bounds()); | 761 ASSERT_NE(new_bounds, root_window()->bounds()); |
758 EXPECT_EQ(1, number_of_calls()); | 762 EXPECT_EQ(1, number_of_calls()); |
759 root_window()->SetBounds(new_bounds); | 763 root_window()->SetBounds(new_bounds); |
760 EXPECT_EQ(2, number_of_calls()); | 764 EXPECT_EQ(2, number_of_calls()); |
761 MockRotateScreen(); | 765 MockRotateScreen(); |
762 EXPECT_EQ(3, number_of_calls()); | 766 EXPECT_EQ(3, number_of_calls()); |
763 } | 767 } |
764 | 768 |
765 } // namespace keyboard | 769 } // namespace keyboard |
OLD | NEW |