| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/wm/always_on_top_controller.h" | 5 #include "ash/common/wm/always_on_top_controller.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" |
| 7 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/common/wm/workspace/workspace_layout_manager.h" | 9 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 9 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" | 10 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" |
| 10 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/aura/wm_window_aura.h" | |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "ui/keyboard/keyboard_controller.h" | 16 #include "ui/keyboard/keyboard_controller.h" |
| 17 #include "ui/keyboard/keyboard_switches.h" | 17 #include "ui/keyboard/keyboard_switches.h" |
| 18 #include "ui/keyboard/keyboard_ui.h" | 18 #include "ui/keyboard/keyboard_ui.h" |
| 19 #include "ui/keyboard/keyboard_util.h" | 19 #include "ui/keyboard/keyboard_util.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 class VirtualKeyboardAlwaysOnTopControllerTest : public AshTestBase { | 24 class VirtualKeyboardAlwaysOnTopControllerTest : public AshTestBase { |
| 25 public: | 25 public: |
| 26 VirtualKeyboardAlwaysOnTopControllerTest() {} | 26 VirtualKeyboardAlwaysOnTopControllerTest() {} |
| 27 ~VirtualKeyboardAlwaysOnTopControllerTest() override {} | 27 ~VirtualKeyboardAlwaysOnTopControllerTest() override {} |
| 28 | 28 |
| 29 void SetUp() override { | 29 void SetUp() override { |
| 30 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 30 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 31 keyboard::switches::kEnableVirtualKeyboard); | 31 keyboard::switches::kEnableVirtualKeyboard); |
| 32 test::AshTestBase::SetUp(); | 32 test::AshTestBase::SetUp(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardAlwaysOnTopControllerTest); | 36 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardAlwaysOnTopControllerTest); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class TestLayoutManager : public WorkspaceLayoutManager { | 39 class TestLayoutManager : public WorkspaceLayoutManager { |
| 40 public: | 40 public: |
| 41 explicit TestLayoutManager(wm::WmWindow* window) | 41 explicit TestLayoutManager(WmWindow* window) |
| 42 : WorkspaceLayoutManager(window, nullptr), | 42 : WorkspaceLayoutManager(window, nullptr), |
| 43 keyboard_bounds_changed_(false) {} | 43 keyboard_bounds_changed_(false) {} |
| 44 | 44 |
| 45 ~TestLayoutManager() override {} | 45 ~TestLayoutManager() override {} |
| 46 | 46 |
| 47 void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override { | 47 void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override { |
| 48 keyboard_bounds_changed_ = true; | 48 keyboard_bounds_changed_ = true; |
| 49 WorkspaceLayoutManager::OnKeyboardBoundsChanging(bounds); | 49 WorkspaceLayoutManager::OnKeyboardBoundsChanging(bounds); |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool keyboard_bounds_changed() const { return keyboard_bounds_changed_; } | 52 bool keyboard_bounds_changed() const { return keyboard_bounds_changed_; } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 bool keyboard_bounds_changed_; | 55 bool keyboard_bounds_changed_; |
| 56 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); | 56 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Verifies that the always on top controller is notified of keyboard bounds | 59 // Verifies that the always on top controller is notified of keyboard bounds |
| 60 // changing events. | 60 // changing events. |
| 61 TEST_F(VirtualKeyboardAlwaysOnTopControllerTest, NotifyKeyboardBoundsChanged) { | 61 TEST_F(VirtualKeyboardAlwaysOnTopControllerTest, NotifyKeyboardBoundsChanged) { |
| 62 keyboard::KeyboardController* keyboard_controller = | 62 keyboard::KeyboardController* keyboard_controller = |
| 63 keyboard::KeyboardController::GetInstance(); | 63 keyboard::KeyboardController::GetInstance(); |
| 64 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 64 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 65 aura::Window* always_on_top_container = | 65 aura::Window* always_on_top_container = |
| 66 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer); | 66 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer); |
| 67 // Install test layout manager. | 67 // Install test layout manager. |
| 68 TestLayoutManager* manager = | 68 TestLayoutManager* manager = |
| 69 new TestLayoutManager(wm::WmWindowAura::Get(always_on_top_container)); | 69 new TestLayoutManager(WmWindowAura::Get(always_on_top_container)); |
| 70 RootWindowController* controller = Shell::GetPrimaryRootWindowController(); | 70 RootWindowController* controller = Shell::GetPrimaryRootWindowController(); |
| 71 AlwaysOnTopController* always_on_top_controller = | 71 AlwaysOnTopController* always_on_top_controller = |
| 72 controller->always_on_top_controller(); | 72 controller->always_on_top_controller(); |
| 73 always_on_top_controller->SetLayoutManagerForTest(base::WrapUnique(manager)); | 73 always_on_top_controller->SetLayoutManagerForTest(base::WrapUnique(manager)); |
| 74 // Activate keyboard. This triggers keyboard listeners to be registered. | 74 // Activate keyboard. This triggers keyboard listeners to be registered. |
| 75 controller->ActivateKeyboard(keyboard_controller); | 75 controller->ActivateKeyboard(keyboard_controller); |
| 76 | 76 |
| 77 // Mock a keyboard appearing. | 77 // Mock a keyboard appearing. |
| 78 aura::Window* keyboard_container = | 78 aura::Window* keyboard_container = |
| 79 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); | 79 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
| 80 ASSERT_TRUE(keyboard_container); | 80 ASSERT_TRUE(keyboard_container); |
| 81 keyboard_container->Show(); | 81 keyboard_container->Show(); |
| 82 aura::Window* keyboard_window = | 82 aura::Window* keyboard_window = |
| 83 keyboard_controller->ui()->GetKeyboardWindow(); | 83 keyboard_controller->ui()->GetKeyboardWindow(); |
| 84 keyboard_container->AddChild(keyboard_window); | 84 keyboard_container->AddChild(keyboard_window); |
| 85 keyboard_window->set_owned_by_parent(false); | 85 keyboard_window->set_owned_by_parent(false); |
| 86 const int kKeyboardHeight = 200; | 86 const int kKeyboardHeight = 200; |
| 87 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds( | 87 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 88 root_window->bounds(), kKeyboardHeight); | 88 root_window->bounds(), kKeyboardHeight); |
| 89 keyboard_window->SetBounds(keyboard_bounds); | 89 keyboard_window->SetBounds(keyboard_bounds); |
| 90 keyboard_window->Show(); | 90 keyboard_window->Show(); |
| 91 keyboard_controller->NotifyKeyboardBoundsChanging(keyboard_bounds); | 91 keyboard_controller->NotifyKeyboardBoundsChanging(keyboard_bounds); |
| 92 // Verify that test manager was notified of bounds change. | 92 // Verify that test manager was notified of bounds change. |
| 93 ASSERT_TRUE(manager->keyboard_bounds_changed()); | 93 ASSERT_TRUE(manager->keyboard_bounds_changed()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace test | 96 } // namespace test |
| 97 } // namespace ash | 97 } // namespace ash |
| OLD | NEW |