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

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

Issue 10174037: Implement a callout widget for the active panel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase? Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/panel_layout_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/panel_layout_manager.h" 5 #include "ash/wm/panel_layout_manager.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/test_launcher_delegate.h" 12 #include "ash/test/test_launcher_delegate.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/test/test_windows.h" 18 #include "ui/aura/test/test_windows.h"
19 #include "ui/aura/test/test_window_delegate.h" 19 #include "ui/views/widget/widget.h"
20 20
21 namespace ash { 21 namespace ash {
22 22
23 namespace { 23 namespace internal {
24 24
25 aura::Window* GetPanelContainer() { 25 using aura::test::WindowIsAbove;
26 return Shell::GetInstance()->GetContainer(
27 ash::internal::kShellWindowId_PanelContainer);
28 }
29 26
30 class PanelLayoutManagerTest : public ash::test::AshTestBase { 27 class PanelLayoutManagerTest : public ash::test::AshTestBase {
31 public: 28 public:
32 PanelLayoutManagerTest() {} 29 PanelLayoutManagerTest() {}
33 virtual ~PanelLayoutManagerTest() {} 30 virtual ~PanelLayoutManagerTest() {}
34 31
35 virtual void SetUp() OVERRIDE { 32 virtual void SetUp() OVERRIDE {
36 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kAuraPanelManager); 33 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kAuraPanelManager);
37 ash::test::AshTestBase::SetUp(); 34 ash::test::AshTestBase::SetUp();
38 ASSERT_TRUE(ash::test::TestLauncherDelegate::instance()); 35 ASSERT_TRUE(ash::test::TestLauncherDelegate::instance());
39 } 36 }
40 37
38 aura::Window* CreateNormalWindow() {
39 return aura::test::CreateTestWindowWithBounds(gfx::Rect(), NULL);
40 }
41
41 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { 42 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) {
42 aura::Window* window = CreateTestWindowWithDelegateAndType( 43 aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType(
43 &window_delegate_, 44 NULL,
44 aura::client::WINDOW_TYPE_PANEL, 45 aura::client::WINDOW_TYPE_PANEL,
45 0, 46 0,
46 bounds, 47 bounds,
47 NULL /* parent should automatically become GetPanelContainer */); 48 NULL /* parent should automatically become GetPanelContainer */);
48 ash::test::TestLauncherDelegate* launcher_delegate = 49 ash::test::TestLauncherDelegate* launcher_delegate =
49 ash::test::TestLauncherDelegate::instance(); 50 ash::test::TestLauncherDelegate::instance();
50 launcher_delegate->AddLauncherItem(window); 51 launcher_delegate->AddLauncherItem(window);
51 return window; 52 return window;
52 } 53 }
53 54
55 aura::Window* GetPanelContainer() {
56 return Shell::GetInstance()->GetContainer(
57 ash::internal::kShellWindowId_PanelContainer);
58 }
59
60 void GetCalloutWidget(views::Widget** widget) {
61 PanelLayoutManager* manager =
62 static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager());
63 ASSERT_TRUE(manager);
64 ASSERT_TRUE(manager->callout_widget());
65 *widget = manager->callout_widget();
66 }
67
68 // TODO(dcheng): This should be const, but GetScreenBoundsOfItemIconForWindow
69 // takes a non-const Window. We can probably fix that.
70 void IsPanelAboveLauncherIcon(aura::Window* panel) {
71 Launcher* launcher = Shell::GetInstance()->launcher();
72 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel);
73 ASSERT_FALSE(icon_bounds.IsEmpty());
74
75 gfx::Rect window_bounds = panel->GetBoundsInRootWindow();
76
77 // 1-pixel tolerance--since we center panels over their icons, panels with
78 // odd pixel widths won't be perfectly lined up with even pixel width
79 // launcher icons.
80 EXPECT_NEAR(icon_bounds.CenterPoint().x(),
81 window_bounds.CenterPoint().x(),
82 1);
83 EXPECT_EQ(launcher->widget()->GetWindowScreenBounds().y(),
84 window_bounds.bottom());
85 }
86
87 void IsCalloutAbovePanel(aura::Window* panel) {
88 // Flush the message loop, since callout updates use a delayed task.
89 MessageLoop::current()->RunAllPending();
90 views::Widget* widget = NULL;
91 GetCalloutWidget(&widget);
92 EXPECT_TRUE(widget->IsVisible());
93 EXPECT_EQ(panel->GetBoundsInRootWindow().bottom(),
94 widget->GetWindowScreenBounds().y());
95 EXPECT_NEAR(panel->GetBoundsInRootWindow().CenterPoint().x(),
96 widget->GetWindowScreenBounds().CenterPoint().x(),
97 1);
98 }
99
100 bool IsCalloutVisible() {
101 views::Widget* widget = NULL;
102 GetCalloutWidget(&widget);
103 return widget->IsVisible();
104 }
105
54 private: 106 private:
55 aura::test::TestWindowDelegate window_delegate_;
56
57 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); 107 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest);
58 }; 108 };
59 109
60 // TODO(dcheng): This should be const, but GetScreenBoundsOfItemIconForWindow
61 // takes a non-const Window. We can probably fix that.
62 void IsPanelAboveLauncherIcon(aura::Window* panel) {
63 Launcher* launcher = Shell::GetInstance()->launcher();
64 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel);
65 ASSERT_FALSE(icon_bounds.IsEmpty());
66
67 gfx::Rect window_bounds = panel->GetBoundsInRootWindow();
68
69 // 1-pixel tolerance--since we center panels over their icons, panels with odd
70 // pixel widths won't be perfectly lined up with even pixel width launcher
71 // icons.
72 EXPECT_NEAR(
73 window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1);
74 EXPECT_EQ(window_bounds.bottom(), icon_bounds.y());
75 }
76
77 } // namespace
78
79 // Tests that a created panel window is successfully added to the panel 110 // Tests that a created panel window is successfully added to the panel
80 // layout manager. 111 // layout manager.
81 TEST_F(PanelLayoutManagerTest, AddOnePanel) { 112 TEST_F(PanelLayoutManagerTest, AddOnePanel) {
82 gfx::Rect bounds(0, 0, 201, 201); 113 gfx::Rect bounds(0, 0, 201, 201);
83 scoped_ptr<aura::Window> window(CreatePanelWindow(bounds)); 114 scoped_ptr<aura::Window> window(CreatePanelWindow(bounds));
84 EXPECT_EQ(GetPanelContainer(), window->parent()); 115 EXPECT_EQ(GetPanelContainer(), window->parent());
85 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); 116 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get()));
86 } 117 }
87 118
88 // Tests interactions between multiple panels 119 // Tests interactions between multiple panels
(...skipping 14 matching lines...) Expand all
103 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); 134 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get()));
104 } 135 }
105 136
106 TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) { 137 TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) {
107 gfx::Rect bounds(0, 0, 201, 201); 138 gfx::Rect bounds(0, 0, 201, 201);
108 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); 139 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
109 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); 140 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
110 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); 141 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
111 142
112 // Default stacking order. 143 // Default stacking order.
113 ASSERT_EQ(3u, GetPanelContainer()->children().size()); 144 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get()));
114 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); 145 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get()));
115 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]);
116 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]);
117 146
118 // Changing the active window should update the stacking order. 147 // Changing the active window should update the stacking order.
119 wm::ActivateWindow(w1.get()); 148 wm::ActivateWindow(w1.get());
120 ASSERT_EQ(3u, GetPanelContainer()->children().size()); 149 EXPECT_TRUE(WindowIsAbove(w1.get(), w2.get()));
121 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); 150 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get()));
122 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]);
123 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[2]);
124 151
125 wm::ActivateWindow(w2.get()); 152 wm::ActivateWindow(w2.get());
126 ASSERT_EQ(3u, GetPanelContainer()->children().size()); 153 EXPECT_TRUE(WindowIsAbove(w1.get(), w3.get()));
127 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); 154 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get()));
128 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[1]); 155 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get()));
129 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[2]);
130 156
131 wm::ActivateWindow(w3.get()); 157 wm::ActivateWindow(w3.get());
132 ASSERT_EQ(3u, GetPanelContainer()->children().size()); 158 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get()));
133 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); 159 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get()));
134 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); 160 }
135 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); 161
162 TEST_F(PanelLayoutManagerTest, MultiplePanelCallout) {
163 gfx::Rect bounds(0, 0, 200, 200);
164 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
165 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
166 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
167 scoped_ptr<aura::Window> w4(CreateNormalWindow());
168 EXPECT_FALSE(IsCalloutVisible());
169 wm::ActivateWindow(w1.get());
170 EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w1.get()));
171 wm::ActivateWindow(w2.get());
172 EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w2.get()));
173 wm::ActivateWindow(w3.get());
174 EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w3.get()));
175 wm::ActivateWindow(w4.get());
176 EXPECT_FALSE(IsCalloutVisible());
177 wm::ActivateWindow(w3.get());
178 EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w3.get()));
179 w3.reset();
180 EXPECT_FALSE(IsCalloutVisible());
181
136 } 182 }
137 183
138 // Tests removing panels. 184 // Tests removing panels.
139 TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) { 185 TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) {
140 gfx::Rect bounds(0, 0, 201, 201); 186 gfx::Rect bounds(0, 0, 201, 201);
141 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); 187 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
142 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); 188 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
143 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); 189 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
144 190
191 // At this point, windows should be stacked with 1 < 2 < 3
145 wm::ActivateWindow(w1.get()); 192 wm::ActivateWindow(w1.get());
193 // Now, windows should be stacked 1 > 2 > 3
146 w1.reset(); 194 w1.reset();
147 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); 195 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get()));
148 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); 196 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get()));
149 ASSERT_EQ(2u, GetPanelContainer()->children().size()); 197 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get()));
150 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]);
151 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]);
152 } 198 }
153 199
154 TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { 200 TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) {
155 gfx::Rect bounds(0, 0, 201, 201); 201 gfx::Rect bounds(0, 0, 201, 201);
156 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); 202 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
157 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); 203 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
158 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); 204 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
159 205
206 // At this point, windows should be stacked with 1 < 2 < 3
160 wm::ActivateWindow(w2.get()); 207 wm::ActivateWindow(w2.get());
208 // Windows should be stacked 1 < 2 > 3
161 w2.reset(); 209 w2.reset();
162 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); 210 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get()));
163 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); 211 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get()));
164 ASSERT_EQ(2u, GetPanelContainer()->children().size()); 212 EXPECT_TRUE(WindowIsAbove(w3.get(), w1.get()));
165 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]);
166 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[1]);
167 } 213 }
168 214
169 TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { 215 TEST_F(PanelLayoutManagerTest, RemoveRightPanel) {
170 gfx::Rect bounds(0, 0, 201, 201); 216 gfx::Rect bounds(0, 0, 201, 201);
171 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); 217 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
172 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); 218 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
173 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); 219 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
174 220
221 // At this point, windows should be stacked with 1 < 2 < 3
175 wm::ActivateWindow(w3.get()); 222 wm::ActivateWindow(w3.get());
223 // Order shouldn't change.
176 w3.reset(); 224 w3.reset();
177 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); 225 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get()));
178 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); 226 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get()));
179 ASSERT_EQ(2u, GetPanelContainer()->children().size()); 227 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get()));
180 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]);
181 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]);
182 } 228 }
183 229
184 TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { 230 TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) {
185 gfx::Rect bounds(0, 0, 201, 201); 231 gfx::Rect bounds(0, 0, 201, 201);
186 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); 232 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds));
187 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); 233 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds));
188 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); 234 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds));
189 235
236 // At this point, windows should be stacked with 1 < 2 < 3
190 wm::ActivateWindow(w2.get()); 237 wm::ActivateWindow(w2.get());
238 // Windows should be stacked 1 < 2 > 3
191 w1.reset(); 239 w1.reset();
192 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); 240 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get()));
193 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); 241 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get()));
194 ASSERT_EQ(2u, GetPanelContainer()->children().size()); 242 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get()));
195 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]);
196 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]);
197 } 243 }
198 244
245 } // namespace internal
246
199 } // namespace ash 247 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panel_layout_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698