Permission message rules: Each rule must have >= 1 required permissions
[chromium-blink-merge.git] / ash / wm / always_on_top_controller_unittest.cc
blobf2db7e01663e6f7da5b85c096c9e5580bda83932
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
3 // found in the LICENSE file.
5 #include "ash/wm/always_on_top_controller.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/workspace/workspace_layout_manager.h"
12 #include "base/command_line.h"
13 #include "ui/keyboard/keyboard_controller.h"
14 #include "ui/keyboard/keyboard_controller_proxy.h"
15 #include "ui/keyboard/keyboard_switches.h"
16 #include "ui/keyboard/keyboard_util.h"
18 namespace ash {
19 namespace test {
21 class VirtualKeyboardAlwaysOnTopControllerTest : public AshTestBase {
22 public:
23 VirtualKeyboardAlwaysOnTopControllerTest() {}
24 ~VirtualKeyboardAlwaysOnTopControllerTest() override {}
26 void SetUp() override {
27 base::CommandLine::ForCurrentProcess()->AppendSwitch(
28 keyboard::switches::kEnableVirtualKeyboard);
29 test::AshTestBase::SetUp();
32 private:
33 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardAlwaysOnTopControllerTest);
36 class TestLayoutManager : public WorkspaceLayoutManager {
37 public:
38 explicit TestLayoutManager(aura::Window* window)
39 : WorkspaceLayoutManager(window), keyboard_bounds_changed_(false) {}
41 ~TestLayoutManager() override {}
43 void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override {
44 keyboard_bounds_changed_ = true;
45 WorkspaceLayoutManager::OnKeyboardBoundsChanging(bounds);
48 bool keyboard_bounds_changed() const { return keyboard_bounds_changed_; }
50 private:
51 bool keyboard_bounds_changed_;
52 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
55 // Verifies that the always on top controller is notified of keyboard bounds
56 // changing events.
57 TEST_F(VirtualKeyboardAlwaysOnTopControllerTest, NotifyKeyboardBoundsChanged) {
58 keyboard::KeyboardController* keyboard_controller =
59 keyboard::KeyboardController::GetInstance();
60 aura::Window* root_window = Shell::GetPrimaryRootWindow();
61 aura::Window* always_on_top_container =
62 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer);
63 // Install test layout manager.
64 TestLayoutManager* manager = new TestLayoutManager(always_on_top_container);
65 RootWindowController* controller = Shell::GetPrimaryRootWindowController();
66 AlwaysOnTopController* always_on_top_controller =
67 controller->always_on_top_controller();
68 always_on_top_controller->SetLayoutManagerForTest(manager);
69 // Activate keyboard. This triggers keyboard listeners to be registered.
70 controller->ActivateKeyboard(keyboard_controller);
72 // Mock a keyboard appearing.
73 aura::Window* keyboard_container =
74 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
75 ASSERT_TRUE(keyboard_container);
76 keyboard_container->Show();
77 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
78 aura::Window* keyboard_window = proxy->GetKeyboardWindow();
79 keyboard_container->AddChild(keyboard_window);
80 keyboard_window->set_owned_by_parent(false);
81 const int kKeyboardHeight = 200;
82 gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds(
83 root_window->bounds(), kKeyboardHeight);
84 keyboard_window->SetBounds(keyboard_bounds);
85 keyboard_window->Show();
86 keyboard_controller->NotifyKeyboardBoundsChanging(keyboard_bounds);
87 // Verify that test manager was notified of bounds change.
88 ASSERT_TRUE(manager->keyboard_bounds_changed());
91 } // namespace test
92 } // namespace ash