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
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura_shell/shelf_layout_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/screen_aura.h"
#include "ui/aura/window.h"
#include "ui/aura_shell/launcher/launcher.h"
#include "ui/aura_shell/shell.h"
#include "ui/aura_shell/shell_window_ids.h"
#include "ui/aura_shell/test/aura_shell_test_base.h"
#include "ui/base/animation/animation_container_element.h"
#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/views/widget/widget.h"
namespace aura_shell {
namespace internal {
namespace {
void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
ui::AnimationContainerElement* element =
static_cast<ui::AnimationContainerElement*>(
widget->GetNativeView()->layer()->GetAnimator());
element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
}
ShelfLayoutManager* GetShelfLayoutManager() {
aura::Window* window = aura_shell::Shell::GetInstance()->GetContainer(
aura_shell::internal::kShellWindowId_LauncherContainer);
return static_cast<ShelfLayoutManager*>(window->layout_manager());
}
} // namespace
typedef aura_shell::test::AuraShellTestBase ShelfLayoutManagerTest;
// Makes sure SetVisible updates work area and widget appropriately.
TEST_F(ShelfLayoutManagerTest, SetVisible) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
// Force an initial layout.
shelf->LayoutShelf();
ASSERT_TRUE(shelf->visible());
aura::ScreenAura* screen = aura::RootWindow::GetInstance()->screen();
ASSERT_TRUE(screen);
// Bottom inset should be the max of widget heights.
EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom());
// Hide the shelf.
shelf->SetVisible(false);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf->launcher());
StepWidgetLayerAnimatorToEnd(shelf->status());
EXPECT_FALSE(shelf->visible());
EXPECT_EQ(0, screen->work_area_insets().bottom());
// Make sure the bounds of the two widgets changed.
EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryMonitorBounds().bottom());
EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryMonitorBounds().bottom());
// And show it again.
shelf->SetVisible(true);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf->launcher());
StepWidgetLayerAnimatorToEnd(shelf->status());
EXPECT_TRUE(shelf->visible());
EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom());
// Make sure the bounds of the two widgets changed.
gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds());
int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() -
shelf->max_height();
EXPECT_EQ(launcher_bounds.y(),
bottom + (shelf->max_height() - launcher_bounds.height()) / 2);
gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds());
EXPECT_EQ(status_bounds.y(),
bottom + (shelf->max_height() - status_bounds.height()) / 2);
}
// Makes sure LayoutShelf invoked while animating cleans things up.
TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
// Force an initial layout.
shelf->LayoutShelf();
ASSERT_TRUE(shelf->visible());
aura::ScreenAura* screen = aura::RootWindow::GetInstance()->screen();
// Hide the shelf.
shelf->SetVisible(false);
shelf->LayoutShelf();
EXPECT_FALSE(shelf->visible());
EXPECT_FALSE(shelf->visible());
EXPECT_EQ(0, screen->work_area_insets().bottom());
// Make sure the bounds of the two widgets changed.
EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryMonitorBounds().bottom());
EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryMonitorBounds().bottom());
}
// Makes sure the launcher is initially sized correctly.
TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) {
Launcher* launcher = Shell::GetInstance()->launcher();
ASSERT_TRUE(launcher);
ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager();
ASSERT_TRUE(shelf_layout_manager);
ASSERT_TRUE(shelf_layout_manager->status());
int status_width =
shelf_layout_manager->status()->GetWindowScreenBounds().width();
// Test only makes sense if the status is > 0, which is better be.
EXPECT_GT(status_width, 0);
EXPECT_EQ(status_width, launcher->GetStatusWidth());
}
// Makes sure the launcher is sized when the status area changes size.
TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) {
Launcher* launcher = Shell::GetInstance()->launcher();
ASSERT_TRUE(launcher);
ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager();
ASSERT_TRUE(shelf_layout_manager);
ASSERT_TRUE(shelf_layout_manager->status());
shelf_layout_manager->status()->SetBounds(gfx::Rect(0, 0, 200, 200));
EXPECT_EQ(200, launcher->GetStatusWidth());
}
} // namespace internal
} // namespace aura_shell
|