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

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

Issue 25111002: Only show virtual keyboard on primary root window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a TODO Created 7 years, 2 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/keyboard/keyboard_controller.cc ('k') | no next file » | 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/aura/client/focus_client.h" 9 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 scoped_ptr<TestFocusController> focus_controller_; 220 scoped_ptr<TestFocusController> focus_controller_;
221 221
222 private: 222 private:
223 KeyboardControllerProxy* proxy_; 223 KeyboardControllerProxy* proxy_;
224 scoped_ptr<KeyboardController> controller_; 224 scoped_ptr<KeyboardController> controller_;
225 225
226 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); 226 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest);
227 }; 227 };
228 228
229 TEST_F(KeyboardControllerTest, KeyboardSize) { 229 TEST_F(KeyboardControllerTest, KeyboardSize) {
230 scoped_ptr<aura::Window> container(controller()->GetContainerWindow()); 230 aura::Window* container(controller()->GetContainerWindow());
231 gfx::Rect bounds(0, 0, 100, 100); 231 gfx::Rect bounds(0, 0, 100, 100);
232 container->SetBounds(bounds); 232 container->SetBounds(bounds);
233 233
234 const gfx::Rect& before_bounds = proxy()->GetKeyboardWindow()->bounds(); 234 const gfx::Rect& before_bounds = proxy()->GetKeyboardWindow()->bounds();
235 gfx::Rect new_bounds( 235 gfx::Rect new_bounds(
236 before_bounds.x(), before_bounds.y(), 236 before_bounds.x(), before_bounds.y(),
237 before_bounds.width() / 2, before_bounds.height() / 2); 237 before_bounds.width() / 2, before_bounds.height() / 2);
238 238
239 // The KeyboardController's LayoutManager shouldn't let this happen 239 // The KeyboardController's LayoutManager shouldn't let this happen
240 proxy()->GetKeyboardWindow()->SetBounds(new_bounds); 240 proxy()->GetKeyboardWindow()->SetBounds(new_bounds);
241 ASSERT_EQ(before_bounds, proxy()->GetKeyboardWindow()->bounds()); 241 ASSERT_EQ(before_bounds, proxy()->GetKeyboardWindow()->bounds());
242 } 242 }
243 243
244 // Tests that tapping/clicking inside the keyboard does not give it focus. 244 // Tests that tapping/clicking inside the keyboard does not give it focus.
245 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { 245 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
246 const gfx::Rect& root_bounds = root_window()->bounds(); 246 const gfx::Rect& root_bounds = root_window()->bounds();
247 aura::test::EventCountDelegate delegate; 247 aura::test::EventCountDelegate delegate;
248 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); 248 scoped_ptr<aura::Window> window(new aura::Window(&delegate));
249 window->Init(ui::LAYER_NOT_DRAWN); 249 window->Init(ui::LAYER_NOT_DRAWN);
250 window->SetBounds(root_bounds); 250 window->SetBounds(root_bounds);
251 root_window()->AddChild(window.get()); 251 root_window()->AddChild(window.get());
252 window->Show(); 252 window->Show();
253 window->Focus(); 253 window->Focus();
254 254
255 scoped_ptr<aura::Window> keyboard_container( 255 aura::Window* keyboard_container(controller()->GetContainerWindow());
256 controller()->GetContainerWindow());
257 keyboard_container->SetBounds(root_bounds); 256 keyboard_container->SetBounds(root_bounds);
258 257
259 root_window()->AddChild(keyboard_container.get()); 258 root_window()->AddChild(keyboard_container);
260 keyboard_container->Show(); 259 keyboard_container->Show();
261 260
262 ShowKeyboard(); 261 ShowKeyboard();
263 262
264 EXPECT_TRUE(window->IsVisible()); 263 EXPECT_TRUE(window->IsVisible());
265 EXPECT_TRUE(keyboard_container->IsVisible()); 264 EXPECT_TRUE(keyboard_container->IsVisible());
266 EXPECT_TRUE(window->HasFocus()); 265 EXPECT_TRUE(window->HasFocus());
267 EXPECT_FALSE(keyboard_container->HasFocus()); 266 EXPECT_FALSE(keyboard_container->HasFocus());
268 267
269 // Click on the keyboard. Make sure the keyboard receives the event, but does 268 // Click on the keyboard. Make sure the keyboard receives the event, but does
(...skipping 20 matching lines...) Expand all
290 const gfx::Rect& root_bounds = root_window()->bounds(); 289 const gfx::Rect& root_bounds = root_window()->bounds();
291 290
292 ui::InputMethod* input_method = proxy()->GetInputMethod(); 291 ui::InputMethod* input_method = proxy()->GetInputMethod();
293 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); 292 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
294 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); 293 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
295 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); 294 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
296 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); 295 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
297 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); 296 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
298 input_method->SetFocusedTextInputClient(&input_client_0); 297 input_method->SetFocusedTextInputClient(&input_client_0);
299 298
300 scoped_ptr<aura::Window> keyboard_container( 299 aura::Window* keyboard_container(controller()->GetContainerWindow());
301 controller()->GetContainerWindow());
302 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( 300 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
303 new KeyboardContainerObserver(keyboard_container.get())); 301 new KeyboardContainerObserver(keyboard_container));
304 keyboard_container->SetBounds(root_bounds); 302 keyboard_container->SetBounds(root_bounds);
305 root_window()->AddChild(keyboard_container.get()); 303 root_window()->AddChild(keyboard_container);
306 304
307 EXPECT_TRUE(keyboard_container->IsVisible()); 305 EXPECT_TRUE(keyboard_container->IsVisible());
308 306
309 input_method->SetFocusedTextInputClient(&no_input_client_0); 307 input_method->SetFocusedTextInputClient(&no_input_client_0);
310 // Keyboard should not immediately hide itself. It is delayed to avoid layout 308 // Keyboard should not immediately hide itself. It is delayed to avoid layout
311 // flicker when the focus of input field quickly change. 309 // flicker when the focus of input field quickly change.
312 EXPECT_TRUE(keyboard_container->IsVisible()); 310 EXPECT_TRUE(keyboard_container->IsVisible());
313 EXPECT_TRUE(WillHideKeyboard()); 311 EXPECT_TRUE(WillHideKeyboard());
314 // Wait for hide keyboard to finish. 312 // Wait for hide keyboard to finish.
315 base::MessageLoop::current()->Run(); 313 base::MessageLoop::current()->Run();
316 EXPECT_FALSE(keyboard_container->IsVisible()); 314 EXPECT_FALSE(keyboard_container->IsVisible());
317 315
318 input_method->SetFocusedTextInputClient(&input_client_1); 316 input_method->SetFocusedTextInputClient(&input_client_1);
319 EXPECT_TRUE(keyboard_container->IsVisible()); 317 EXPECT_TRUE(keyboard_container->IsVisible());
320 318
321 // Schedule to hide keyboard. 319 // Schedule to hide keyboard.
322 input_method->SetFocusedTextInputClient(&no_input_client_1); 320 input_method->SetFocusedTextInputClient(&no_input_client_1);
323 EXPECT_TRUE(WillHideKeyboard()); 321 EXPECT_TRUE(WillHideKeyboard());
324 // Cancel keyboard hide. 322 // Cancel keyboard hide.
325 input_method->SetFocusedTextInputClient(&input_client_2); 323 input_method->SetFocusedTextInputClient(&input_client_2);
326 324
327 EXPECT_FALSE(WillHideKeyboard()); 325 EXPECT_FALSE(WillHideKeyboard());
328 EXPECT_TRUE(keyboard_container->IsVisible()); 326 EXPECT_TRUE(keyboard_container->IsVisible());
329 } 327 }
330 328
331 } // namespace keyboard 329 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698