1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
ash / accessibility / ui / accessibility_panel_layout_manager_unittest.cc [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accessibility/ui/accessibility_panel_layout_manager.h"
#include <memory>
#include "ash/accessibility/magnifier/docked_magnifier_controller.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {
// Shorten the name for better line wrapping.
constexpr int kDefaultPanelHeight =
AccessibilityPanelLayoutManager::kDefaultPanelHeight;
AccessibilityPanelLayoutManager* GetLayoutManager() {
aura::Window* container =
Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_AccessibilityPanelContainer);
return static_cast<AccessibilityPanelLayoutManager*>(
container->layout_manager());
}
// Simulates Chrome creating the ChromeVoxPanel widget.
std::unique_ptr<views::Widget> CreateChromeVoxPanel() {
std::unique_ptr<views::Widget> widget = std::make_unique<views::Widget>();
views::Widget::InitParams params(
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET,
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
aura::Window* root_window = Shell::GetPrimaryRootWindow();
params.parent = Shell::GetContainer(
root_window, kShellWindowId_AccessibilityPanelContainer);
params.activatable = views::Widget::InitParams::Activatable::kNo;
params.bounds = gfx::Rect(0, 0, root_window->bounds().width(),
root_window->bounds().height());
widget->Init(std::move(params));
return widget;
}
using AccessibilityPanelLayoutManagerTest = AshTestBase;
TEST_F(AccessibilityPanelLayoutManagerTest, Basics) {
AccessibilityPanelLayoutManager* layout_manager = GetLayoutManager();
ASSERT_TRUE(layout_manager);
// The layout manager doesn't track anything at startup.
EXPECT_FALSE(layout_manager->panel_window_for_test());
// Simulate chrome creating the ChromeVox widget. The layout manager starts
// managing it.
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
EXPECT_EQ(widget->GetNativeWindow(), layout_manager->panel_window_for_test());
// The layout manager doesn't track anything after the widget closes.
widget.reset();
EXPECT_FALSE(layout_manager->panel_window_for_test());
}
TEST_F(AccessibilityPanelLayoutManagerTest, Shutdown) {
// Simulate chrome creating the ChromeVox widget.
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
// Don't close the window.
widget.release();
// Ash should not crash if the window is still open at shutdown.
}
TEST_F(AccessibilityPanelLayoutManagerTest, PanelFullscreen) {
AccessibilityPanelLayoutManager* layout_manager = GetLayoutManager();
display::Screen* screen = display::Screen::GetScreen();
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
layout_manager->SetPanelBounds(gfx::Rect(0, 0, 0, kDefaultPanelHeight),
AccessibilityPanelState::FULL_WIDTH);
gfx::Rect expected_work_area = screen->GetPrimaryDisplay().work_area();
// When the panel is fullscreen it fills the display and clears the
// work area.
layout_manager->SetPanelBounds(gfx::Rect(),
AccessibilityPanelState::FULLSCREEN);
EXPECT_EQ(widget->GetNativeWindow()->bounds(),
screen->GetPrimaryDisplay().bounds());
EXPECT_EQ(screen->GetPrimaryDisplay().work_area().y(), 0);
// Restoring the panel to default size restores the bounds and sets
// the work area.
layout_manager->SetPanelBounds(gfx::Rect(0, 0, 0, kDefaultPanelHeight),
AccessibilityPanelState::FULL_WIDTH);
gfx::Rect expected_bounds(0, 0, screen->GetPrimaryDisplay().bounds().width(),
kDefaultPanelHeight);
EXPECT_EQ(widget->GetNativeWindow()->bounds(), expected_bounds);
EXPECT_EQ(screen->GetPrimaryDisplay().work_area(), expected_work_area);
}
TEST_F(AccessibilityPanelLayoutManagerTest, SetBounds) {
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
gfx::Rect bounds(0, 0, 100, 100);
GetLayoutManager()->SetPanelBounds(bounds, AccessibilityPanelState::BOUNDED);
EXPECT_EQ(widget->GetNativeWindow()->bounds(), bounds);
}
TEST_F(AccessibilityPanelLayoutManagerTest, DisplayBoundsChange) {
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
GetLayoutManager()->SetPanelBounds(gfx::Rect(0, 0, 0, kDefaultPanelHeight),
AccessibilityPanelState::FULL_WIDTH);
// When the display resolution changes the panel still sits at the top of the
// screen.
UpdateDisplay("1200x700,1300x800");
display::Screen* screen = display::Screen::GetScreen();
gfx::Rect expected_bounds(0, 0, screen->GetPrimaryDisplay().bounds().width(),
kDefaultPanelHeight);
EXPECT_EQ(widget->GetNativeWindow()->bounds(), expected_bounds);
gfx::Rect expected_work_area = screen->GetPrimaryDisplay().bounds();
expected_work_area.Inset(gfx::Insets::TLBR(
kDefaultPanelHeight, 0, ShelfConfig::Get()->shelf_size(), 0));
EXPECT_EQ(screen->GetPrimaryDisplay().work_area(), expected_work_area);
}
TEST_F(AccessibilityPanelLayoutManagerTest, DockedMagnifierEnabled) {
auto* docked_magnifier_controller =
Shell::Get()->docked_magnifier_controller();
std::unique_ptr<views::Widget> widget = CreateChromeVoxPanel();
widget->Show();
GetLayoutManager()->SetPanelBounds(gfx::Rect(0, 0, 0, kDefaultPanelHeight),
AccessibilityPanelState::FULL_WIDTH);
// When Docked Magnifier is enabled, panel sits right below, and work area
// sits below the panel.
docked_magnifier_controller->SetEnabled(true);
int magnifier_height = docked_magnifier_controller->GetTotalMagnifierHeight();
display::Screen* screen = display::Screen::GetScreen();
gfx::Rect expected_bounds(0, magnifier_height,
screen->GetPrimaryDisplay().bounds().width(),
kDefaultPanelHeight);
EXPECT_EQ(widget->GetNativeWindow()->bounds(), expected_bounds);
gfx::Rect expected_work_area = screen->GetPrimaryDisplay().bounds();
expected_work_area.Inset(
gfx::Insets::TLBR(magnifier_height + kDefaultPanelHeight, 0,
ShelfConfig::Get()->shelf_size(), 0));
EXPECT_EQ(screen->GetPrimaryDisplay().work_area(), expected_work_area);
}
} // namespace
} // namespace ash