Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(990)

Side by Side Diff: ui/keyboard/keyboard_controller_unittest.cc

Issue 334573004: Fixes unittests with --enable-text-input-focus-manager flag enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed more unittests. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/ime/mock_input_method.cc ('k') | ui/wm/core/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/command_line.h" 8 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/layout_manager.h" 13 #include "ui/aura/layout_manager.h"
12 #include "ui/aura/test/aura_test_helper.h" 14 #include "ui/aura/test/aura_test_helper.h"
13 #include "ui/aura/test/event_generator.h" 15 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_window_delegate.h" 16 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/base/ime/dummy_text_input_client.h" 19 #include "ui/base/ime/dummy_text_input_client.h"
18 #include "ui/base/ime/input_method.h" 20 #include "ui/base/ime/input_method.h"
19 #include "ui/base/ime/input_method_factory.h" 21 #include "ui/base/ime/input_method_factory.h"
20 #include "ui/base/ime/text_input_client.h" 22 #include "ui/base/ime/text_input_client.h"
23 #include "ui/base/ime/text_input_focus_manager.h"
24 #include "ui/base/ui_base_switches_util.h"
21 #include "ui/compositor/compositor.h" 25 #include "ui/compositor/compositor.h"
22 #include "ui/compositor/layer_type.h" 26 #include "ui/compositor/layer_type.h"
23 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
24 #include "ui/compositor/test/context_factories_for_test.h" 28 #include "ui/compositor/test/context_factories_for_test.h"
25 #include "ui/compositor/test/layer_animator_test_controller.h" 29 #include "ui/compositor/test/layer_animator_test_controller.h"
26 #include "ui/gfx/rect.h" 30 #include "ui/gfx/geometry/rect.h"
27 #include "ui/keyboard/keyboard_controller.h"
28 #include "ui/keyboard/keyboard_controller_observer.h" 31 #include "ui/keyboard/keyboard_controller_observer.h"
29 #include "ui/keyboard/keyboard_controller_proxy.h" 32 #include "ui/keyboard/keyboard_controller_proxy.h"
30 #include "ui/keyboard/keyboard_switches.h" 33 #include "ui/keyboard/keyboard_switches.h"
31 #include "ui/keyboard/keyboard_util.h" 34 #include "ui/keyboard/keyboard_util.h"
32 #include "ui/wm/core/default_activation_client.h" 35 #include "ui/wm/core/default_activation_client.h"
33 36
34 namespace keyboard { 37 namespace keyboard {
35 namespace { 38 namespace {
36 39
37 // Steps a layer animation until it is completed. Animations must be enabled. 40 // Steps a layer animation until it is completed. Animations must be enabled.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 virtual void SetUp() OVERRIDE { 169 virtual void SetUp() OVERRIDE {
167 // The ContextFactory must exist before any Compositors are created. 170 // The ContextFactory must exist before any Compositors are created.
168 bool enable_pixel_output = false; 171 bool enable_pixel_output = false;
169 ui::ContextFactory* context_factory = 172 ui::ContextFactory* context_factory =
170 ui::InitializeContextFactoryForTests(enable_pixel_output); 173 ui::InitializeContextFactoryForTests(enable_pixel_output);
171 174
172 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 175 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
173 aura_test_helper_->SetUp(context_factory); 176 aura_test_helper_->SetUp(context_factory);
174 new wm::DefaultActivationClient(aura_test_helper_->root_window()); 177 new wm::DefaultActivationClient(aura_test_helper_->root_window());
175 ui::SetUpInputMethodFactoryForTesting(); 178 ui::SetUpInputMethodFactoryForTesting();
179 if (::switches::IsTextInputFocusManagerEnabled())
180 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL);
176 focus_controller_.reset(new TestFocusController(root_window())); 181 focus_controller_.reset(new TestFocusController(root_window()));
177 proxy_ = new TestKeyboardControllerProxy(); 182 proxy_ = new TestKeyboardControllerProxy();
178 controller_.reset(new KeyboardController(proxy_)); 183 controller_.reset(new KeyboardController(proxy_));
179 } 184 }
180 185
181 virtual void TearDown() OVERRIDE { 186 virtual void TearDown() OVERRIDE {
182 controller_.reset(); 187 controller_.reset();
183 focus_controller_.reset(); 188 focus_controller_.reset();
189 if (::switches::IsTextInputFocusManagerEnabled())
190 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL);
184 aura_test_helper_->TearDown(); 191 aura_test_helper_->TearDown();
185 ui::TerminateContextFactoryForTests(); 192 ui::TerminateContextFactoryForTests();
186 } 193 }
187 194
188 aura::Window* root_window() { return aura_test_helper_->root_window(); } 195 aura::Window* root_window() { return aura_test_helper_->root_window(); }
189 KeyboardControllerProxy* proxy() { return proxy_; } 196 KeyboardControllerProxy* proxy() { return proxy_; }
190 KeyboardController* controller() { return controller_.get(); } 197 KeyboardController* controller() { return controller_.get(); }
191 198
192 void ShowKeyboard() { 199 void ShowKeyboard() {
193 test_text_input_client_.reset( 200 test_text_input_client_.reset(
194 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); 201 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
195 SetFocus(test_text_input_client_.get()); 202 SetFocus(test_text_input_client_.get());
196 } 203 }
197 204
198 protected: 205 protected:
199 void SetFocus(ui::TextInputClient* client) { 206 void SetFocus(ui::TextInputClient* client) {
200 ui::InputMethod* input_method = proxy()->GetInputMethod(); 207 ui::InputMethod* input_method = proxy()->GetInputMethod();
201 input_method->SetFocusedTextInputClient(client); 208 if (::switches::IsTextInputFocusManagerEnabled()) {
209 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client);
210 input_method->OnTextInputTypeChanged(client);
211 } else {
212 input_method->SetFocusedTextInputClient(client);
213 }
202 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { 214 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
203 input_method->ShowImeIfNeeded(); 215 input_method->ShowImeIfNeeded();
204 if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { 216 if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
205 // Set initial bounds for test keyboard window. 217 // Set initial bounds for test keyboard window.
206 proxy_->GetKeyboardWindow()->SetBounds( 218 proxy_->GetKeyboardWindow()->SetBounds(
207 KeyboardBoundsFromWindowBounds( 219 KeyboardBoundsFromWindowBounds(
208 controller()->GetContainerWindow()->bounds(), 100)); 220 controller()->GetContainerWindow()->bounds(), 100));
209 } 221 }
210 } 222 }
211 } 223 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 332
321 // Make sure hit testing works correctly while the keyboard is visible. 333 // Make sure hit testing works correctly while the keyboard is visible.
322 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); 334 aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
323 ui::EventTarget* root = root_window(); 335 ui::EventTarget* root = root_window();
324 ui::EventTargeter* targeter = root->GetEventTargeter(); 336 ui::EventTargeter* targeter = root->GetEventTargeter();
325 gfx::Point location = keyboard_window->bounds().CenterPoint(); 337 gfx::Point location = keyboard_window->bounds().CenterPoint();
326 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, 338 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
327 ui::EF_NONE); 339 ui::EF_NONE);
328 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); 340 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1));
329 341
330
331 location.set_y(keyboard_window->bounds().y() - 5); 342 location.set_y(keyboard_window->bounds().y() - 5);
332 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, 343 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE,
333 ui::EF_NONE); 344 ui::EF_NONE);
334 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); 345 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2));
335 } 346 }
336 347
337 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { 348 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
338 const gfx::Rect& root_bounds = root_window()->bounds(); 349 const gfx::Rect& root_bounds = root_window()->bounds();
339 350
340 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); 351 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 SetFocus(&input_client); 564 SetFocus(&input_client);
554 EXPECT_TRUE(keyboard_container->IsVisible()); 565 EXPECT_TRUE(keyboard_container->IsVisible());
555 566
556 SetFocus(&no_input_client); 567 SetFocus(&no_input_client);
557 // Keyboard should not hide itself after lost focus. 568 // Keyboard should not hide itself after lost focus.
558 EXPECT_TRUE(keyboard_container->IsVisible()); 569 EXPECT_TRUE(keyboard_container->IsVisible());
559 EXPECT_FALSE(WillHideKeyboard()); 570 EXPECT_FALSE(WillHideKeyboard());
560 } 571 }
561 572
562 } // namespace keyboard 573 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/base/ime/mock_input_method.cc ('k') | ui/wm/core/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698