| OLD | NEW |
| 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 Loading... |
| 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_; } |
| 108 |
| 109 private: |
| 110 int mouse_presses_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow); |
| 113 }; |
| 114 |
| 83 } // namespace | 115 } // namespace |
| 84 | 116 |
| 85 namespace test { | 117 namespace test { |
| 86 | 118 |
| 87 class RootWindowControllerTest : public test::AshTestBase { | 119 class RootWindowControllerTest : public test::AshTestBase { |
| 88 public: | 120 public: |
| 89 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { | 121 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 90 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 122 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 91 NULL, CurrentContext(), bounds); | 123 NULL, CurrentContext(), bounds); |
| 92 widget->Show(); | 124 widget->Show(); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 ++block_reason) { | 498 ++block_reason) { |
| 467 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 499 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 468 lock_window->Focus(); | 500 lock_window->Focus(); |
| 469 EXPECT_TRUE(lock_window->HasFocus()); | 501 EXPECT_TRUE(lock_window->HasFocus()); |
| 470 session_window->Focus(); | 502 session_window->Focus(); |
| 471 EXPECT_FALSE(session_window->HasFocus()); | 503 EXPECT_FALSE(session_window->HasFocus()); |
| 472 UnblockUserSession(); | 504 UnblockUserSession(); |
| 473 } | 505 } |
| 474 } | 506 } |
| 475 | 507 |
| 508 class VirtualKeyboardRootWindowControllerTest : public test::AshTestBase { |
| 509 public: |
| 510 VirtualKeyboardRootWindowControllerTest() {}; |
| 511 virtual ~VirtualKeyboardRootWindowControllerTest() {}; |
| 512 |
| 513 virtual void SetUp() OVERRIDE { |
| 514 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 515 keyboard::switches::kEnableVirtualKeyboard); |
| 516 test::AshTestBase::SetUp(); |
| 517 } |
| 518 |
| 519 private: |
| 520 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 521 }; |
| 522 |
| 523 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 524 // events at blocked user session. |
| 525 TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 526 ClickVirtualKeyboardInBlockedWindow) { |
| 527 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 528 aura::Window* keyboard_container = Shell::GetContainer(root_window, |
| 529 internal::kShellWindowId_VirtualKeyboardContainer); |
| 530 ASSERT_TRUE(keyboard_container); |
| 531 keyboard_container->Show(); |
| 532 |
| 533 ClickTestWindow* main_delegate = new ClickTestWindow(); |
| 534 scoped_ptr<aura::Window> keyboard_window( |
| 535 main_delegate->CreateTestWindowWithParent(keyboard_container)); |
| 536 keyboard_container->layout_manager()->OnWindowResized(); |
| 537 keyboard_window->Show(); |
| 538 aura::test::EventGenerator event_generator(root_window, |
| 539 keyboard_window.get()); |
| 540 event_generator.ClickLeftButton(); |
| 541 int expected_mouse_presses = 1; |
| 542 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); |
| 543 |
| 544 for (int block_reason = FIRST_BLOCK_REASON; |
| 545 block_reason < NUMBER_OF_BLOCK_REASONS; |
| 546 ++block_reason) { |
| 547 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 548 event_generator.ClickLeftButton(); |
| 549 expected_mouse_presses++; |
| 550 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); |
| 551 UnblockUserSession(); |
| 552 } |
| 553 } |
| 554 |
| 476 } // namespace test | 555 } // namespace test |
| 477 } // namespace ash | 556 } // namespace ash |
| OLD | NEW |