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" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (!visible) | 159 if (!visible) |
160 run_loop_->QuitWhenIdle(); | 160 run_loop_->QuitWhenIdle(); |
161 } | 161 } |
162 | 162 |
163 aura::Window* window_; | 163 aura::Window* window_; |
164 base::RunLoop* const run_loop_; | 164 base::RunLoop* const run_loop_; |
165 | 165 |
166 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); | 166 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); |
167 }; | 167 }; |
168 | 168 |
| 169 class TestKeyboardLayoutDelegate : public KeyboardLayoutDelegate { |
| 170 public: |
| 171 TestKeyboardLayoutDelegate() {} |
| 172 ~TestKeyboardLayoutDelegate() override {} |
| 173 |
| 174 // Overridden from keyboard::KeyboardLayoutDelegate |
| 175 void MoveKeyboardToAnotherDisplayIfNeeded(int64_t /* display_id */) override { |
| 176 } |
| 177 |
| 178 private: |
| 179 DISALLOW_COPY_AND_ASSIGN(TestKeyboardLayoutDelegate); |
| 180 }; |
| 181 |
169 } // namespace | 182 } // namespace |
170 | 183 |
171 class KeyboardControllerTest : public testing::Test, | 184 class KeyboardControllerTest : public testing::Test, |
172 public KeyboardControllerObserver { | 185 public KeyboardControllerObserver { |
173 public: | 186 public: |
174 KeyboardControllerTest() | 187 KeyboardControllerTest() |
175 : number_of_calls_(0), ui_(nullptr), keyboard_closed_(false) {} | 188 : number_of_calls_(0), ui_(nullptr), keyboard_closed_(false) {} |
176 ~KeyboardControllerTest() override {} | 189 ~KeyboardControllerTest() override {} |
177 | 190 |
178 void SetUp() override { | 191 void SetUp() override { |
179 // The ContextFactory must exist before any Compositors are created. | 192 // The ContextFactory must exist before any Compositors are created. |
180 bool enable_pixel_output = false; | 193 bool enable_pixel_output = false; |
181 ui::ContextFactory* context_factory = | 194 ui::ContextFactory* context_factory = |
182 ui::InitializeContextFactoryForTests(enable_pixel_output); | 195 ui::InitializeContextFactoryForTests(enable_pixel_output); |
183 | 196 |
184 ui::SetUpInputMethodFactoryForTesting(); | 197 ui::SetUpInputMethodFactoryForTesting(); |
185 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 198 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
186 aura_test_helper_->SetUp(context_factory); | 199 aura_test_helper_->SetUp(context_factory); |
187 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 200 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
188 focus_controller_.reset(new TestFocusController(root_window())); | 201 focus_controller_.reset(new TestFocusController(root_window())); |
189 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); | 202 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); |
190 controller_.reset(new KeyboardController(ui_)); | 203 layout_delegate_.reset(new TestKeyboardLayoutDelegate()); |
| 204 controller_.reset(new KeyboardController(ui_, layout_delegate_.get())); |
191 controller()->AddObserver(this); | 205 controller()->AddObserver(this); |
192 } | 206 } |
193 | 207 |
194 void TearDown() override { | 208 void TearDown() override { |
195 if (controller()) | 209 if (controller()) |
196 controller()->RemoveObserver(this); | 210 controller()->RemoveObserver(this); |
197 controller_.reset(); | 211 controller_.reset(); |
198 focus_controller_.reset(); | 212 focus_controller_.reset(); |
199 aura_test_helper_->TearDown(); | 213 aura_test_helper_->TearDown(); |
200 ui::TerminateContextFactoryForTests(); | 214 ui::TerminateContextFactoryForTests(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 void ResetController() { controller_.reset(); } | 273 void ResetController() { controller_.reset(); } |
260 | 274 |
261 base::MessageLoopForUI message_loop_; | 275 base::MessageLoopForUI message_loop_; |
262 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 276 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
263 std::unique_ptr<TestFocusController> focus_controller_; | 277 std::unique_ptr<TestFocusController> focus_controller_; |
264 | 278 |
265 private: | 279 private: |
266 int number_of_calls_; | 280 int number_of_calls_; |
267 gfx::Rect notified_bounds_; | 281 gfx::Rect notified_bounds_; |
268 KeyboardUI* ui_; | 282 KeyboardUI* ui_; |
| 283 std::unique_ptr<KeyboardLayoutDelegate> layout_delegate_; |
269 std::unique_ptr<KeyboardController> controller_; | 284 std::unique_ptr<KeyboardController> controller_; |
270 std::unique_ptr<ui::TextInputClient> test_text_input_client_; | 285 std::unique_ptr<ui::TextInputClient> test_text_input_client_; |
271 bool keyboard_closed_; | 286 bool keyboard_closed_; |
272 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 287 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
273 }; | 288 }; |
274 | 289 |
275 TEST_F(KeyboardControllerTest, KeyboardSize) { | 290 TEST_F(KeyboardControllerTest, KeyboardSize) { |
276 aura::Window* container(controller()->GetContainerWindow()); | 291 aura::Window* container(controller()->GetContainerWindow()); |
277 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 292 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
278 gfx::Rect screen_bounds = root_window()->bounds(); | 293 gfx::Rect screen_bounds = root_window()->bounds(); |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 gfx::Rect new_bounds(0, 0, 1280, 800); | 697 gfx::Rect new_bounds(0, 0, 1280, 800); |
683 ASSERT_NE(new_bounds, root_window()->bounds()); | 698 ASSERT_NE(new_bounds, root_window()->bounds()); |
684 EXPECT_EQ(1, number_of_calls()); | 699 EXPECT_EQ(1, number_of_calls()); |
685 root_window()->SetBounds(new_bounds); | 700 root_window()->SetBounds(new_bounds); |
686 EXPECT_EQ(2, number_of_calls()); | 701 EXPECT_EQ(2, number_of_calls()); |
687 MockRotateScreen(); | 702 MockRotateScreen(); |
688 EXPECT_EQ(3, number_of_calls()); | 703 EXPECT_EQ(3, number_of_calls()); |
689 } | 704 } |
690 | 705 |
691 } // namespace keyboard | 706 } // namespace keyboard |
OLD | NEW |