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

Side by Side Diff: ash/root_window_controller_unittest.cc

Issue 22465007: Whitelist virtual keyboard container to process events at login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit tests for virtual keyboard container Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/root_window_controller.h" 5 #include "ash/root_window_controller.h"
6 6
7 #include "ash/session_state_delegate.h" 7 #include "ash/session_state_delegate.h"
8 #include "ash/shelf/shelf_layout_manager.h" 8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/system/tray/system_tray_delegate.h" 11 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/system_modal_container_layout_manager.h" 13 #include "ash/wm/system_modal_container_layout_manager.h"
14 #include "ash/wm/window_properties.h" 14 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
16 #include "base/command_line.h"
16 #include "ui/aura/client/focus_change_observer.h" 17 #include "ui/aura/client/focus_change_observer.h"
17 #include "ui/aura/client/focus_client.h" 18 #include "ui/aura/client/focus_client.h"
18 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
19 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/event_generator.h" 21 #include "ui/aura/test/event_generator.h"
21 #include "ui/aura/test/test_window_delegate.h" 22 #include "ui/aura/test/test_window_delegate.h"
22 #include "ui/aura/test/test_windows.h" 23 #include "ui/aura/test/test_windows.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #include "ui/aura/window_tracker.h" 25 #include "ui/aura/window_tracker.h"
26 #include "ui/keyboard/keyboard_switches.h"
25 #include "ui/views/controls/menu/menu_controller.h" 27 #include "ui/views/controls/menu/menu_controller.h"
26 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h" 29 #include "ui/views/widget/widget_delegate.h"
28 30
29 using aura::Window; 31 using aura::Window;
30 using views::Widget; 32 using views::Widget;
31 33
32 namespace ash { 34 namespace ash {
33 namespace { 35 namespace {
34 36
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 aura::Window* lost_focus) OVERRIDE { 75 aura::Window* lost_focus) OVERRIDE {
74 if (window_ == lost_focus) 76 if (window_ == lost_focus)
75 delete window_; 77 delete window_;
76 } 78 }
77 79
78 aura::Window* window_; 80 aura::Window* window_;
79 81
80 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); 82 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
81 }; 83 };
82 84
85 class ClickTestWindow : public views::WidgetDelegateView {
86 public:
87 ClickTestWindow() : mouse_presses_(0) {}
88 virtual ~ClickTestWindow() {}
89
90 // Overridden from views::WidgetDelegate:
91 virtual views::View* GetContentsView() OVERRIDE {
92 return this;
93 }
94
95 aura::Window* CreateTestWindowWithParent(aura::Window* parent) {
96 DCHECK(parent);
97 views::Widget* widget = Widget::CreateWindowWithParent(this, parent);
98 return widget->GetNativeView();
99 }
100
101 // Overridden from views::View:
102 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
103 mouse_presses_++;
104 return false;
105 }
106
107 int mouse_presses() const { return mouse_presses_; }
James Cook 2013/08/08 17:29:44 nit: blank line after this
bshe 2013/08/08 19:39:24 Done.
108 private:
109 int mouse_presses_;
110
111 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow);
112 };
113
83 } // namespace 114 } // namespace
84 115
85 namespace test { 116 namespace test {
86 117
87 class RootWindowControllerTest : public test::AshTestBase { 118 class RootWindowControllerTest : public test::AshTestBase {
88 public: 119 public:
89 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { 120 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
90 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 121 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
91 NULL, CurrentContext(), bounds); 122 NULL, CurrentContext(), bounds);
92 widget->Show(); 123 widget->Show();
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 ++block_reason) { 497 ++block_reason) {
467 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); 498 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
468 lock_window->Focus(); 499 lock_window->Focus();
469 EXPECT_TRUE(lock_window->HasFocus()); 500 EXPECT_TRUE(lock_window->HasFocus());
470 session_window->Focus(); 501 session_window->Focus();
471 EXPECT_FALSE(session_window->HasFocus()); 502 EXPECT_FALSE(session_window->HasFocus());
472 UnblockUserSession(); 503 UnblockUserSession();
473 } 504 }
474 } 505 }
475 506
507 class VirtualKeyboardRootWindowControllerTest : public test::AshTestBase {
508 public:
509 virtual void SetUp() OVERRIDE {
510 CommandLine::ForCurrentProcess()->AppendSwitch(
511 keyboard::switches::kEnableVirtualKeyboard);
512 test::AshTestBase::SetUp();
513 }
oshima 2013/08/08 17:19:29 nit: DISALLOW_COPY_AND_ASSIGN
bshe 2013/08/08 19:37:02 Done.
514 };
515
516 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
517 // events at blocked user session.
518 TEST_F(VirtualKeyboardRootWindowControllerTest,
519 ClickVirtualKeyboardInBlockedWindow) {
520 UpdateDisplay("600x600");
oshima 2013/08/08 17:19:29 do you need to change the size of the display for
bshe 2013/08/08 19:37:02 No. I was just following the above example. It is
521 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
oshima 2013/08/08 17:19:29 GetPrimaryRootWindow is static
bshe 2013/08/08 19:37:02 Done.
522 aura::Window* vk_container = Shell::GetContainer(root_window,
James Cook 2013/08/08 17:29:44 no abbreviations: vk_container -> keyboard_contain
bshe 2013/08/08 19:39:24 Done.
523 internal::kShellWindowId_VirtualKeyboardContainer);
524 CHECK(vk_container);
James Cook 2013/08/08 17:29:44 optional nit: ASSERT_TRUE ?
bshe 2013/08/08 19:39:24 Done.
525 vk_container->Show();
526
527 ClickTestWindow* main_delegate = new ClickTestWindow();
528 scoped_ptr<aura::Window> vk_window(
James Cook 2013/08/08 17:29:44 vk_window -> keyboard_window or similar
bshe 2013/08/08 19:39:24 Done.
529 main_delegate->CreateTestWindowWithParent(vk_container));
530 vk_container->layout_manager()->OnWindowResized();
531 vk_window->Show();
532 aura::test::EventGenerator event_generator(root_window,
533 vk_window.get());
534 event_generator.ClickLeftButton();
535 int expected_mouse_presses = 1;
536 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses());
537
538 for (int block_reason = FIRST_BLOCK_REASON;
539 block_reason < NUMBER_OF_BLOCK_REASONS;
540 ++block_reason) {
541 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
542 event_generator.ClickLeftButton();
543 expected_mouse_presses++;
544 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses());
545 UnblockUserSession();
546 }
547 }
548
476 } // namespace test 549 } // namespace test
477 } // namespace ash 550 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698