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

Side by Side Diff: ash/wm/always_on_top_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698