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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
// Copyright (c) 2012 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 "ash/wm/shelf_layout_manager.h"
#include "ash/focus_cycler.h"
#include "ash/launcher/launcher.h"
#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/tray/system_tray.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/display_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/base/animation/animation_container_element.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
namespace ash {
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 = Shell::GetContainer(
Shell::GetPrimaryRootWindow(),
internal::kShellWindowId_LauncherContainer);
return static_cast<ShelfLayoutManager*>(window->layout_manager());
}
} // namespace
class ShelfLayoutManagerTest : public ash::test::AshTestBase {
public:
ShelfLayoutManagerTest() {}
void SetState(ShelfLayoutManager* shelf,
ShelfLayoutManager::VisibilityState state) {
shelf->SetState(state);
}
void UpdateAutoHideStateNow() {
GetShelfLayoutManager()->UpdateAutoHideStateNow();
}
aura::Window* CreateTestWindow() {
aura::Window* window = new aura::Window(NULL);
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_TEXTURED);
aura::Window* parent = Shell::GetContainer(
Shell::GetPrimaryRootWindow(),
internal::kShellWindowId_DefaultContainer);
window->SetParent(parent);
return window;
}
private:
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest);
};
// Fails on Mac only. Need to be implemented. http://crbug.com/111279.
#if defined(OS_MACOSX)
#define MAYBE_SetVisible FAILS_SetVisible
#else
#define MAYBE_SetVisible SetVisible
#endif
// Makes sure SetVisible updates work area and widget appropriately.
TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
// Force an initial layout.
shelf->LayoutShelf();
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
gfx::Rect status_bounds(shelf->status()->GetWindowScreenBounds());
gfx::Rect launcher_bounds(shelf->launcher_widget()->GetWindowScreenBounds());
int shelf_height = shelf->GetIdealBounds().height();
const aura::DisplayManager* manager =
aura::Env::GetInstance()->display_manager();
const gfx::Display& display =
manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
// Bottom inset should be the max of widget heights.
EXPECT_EQ(shelf_height,
display.bounds().bottom() - display.work_area().bottom());
// Hide the shelf.
SetState(shelf, ShelfLayoutManager::HIDDEN);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf->launcher_widget());
StepWidgetLayerAnimatorToEnd(shelf->status());
EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
EXPECT_EQ(0,
display.bounds().bottom() - display.work_area().bottom());
// Make sure the bounds of the two widgets changed.
EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryDisplay().bounds().bottom());
EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryDisplay().bounds().bottom());
// And show it again.
SetState(shelf, ShelfLayoutManager::VISIBLE);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf->launcher_widget());
StepWidgetLayerAnimatorToEnd(shelf->status());
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
EXPECT_EQ(shelf_height,
display.bounds().bottom() - display.work_area().bottom());
// Make sure the bounds of the two widgets changed.
launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds();
int bottom = gfx::Screen::GetPrimaryDisplay().bounds().bottom() -
shelf_height;
EXPECT_EQ(launcher_bounds.y(),
bottom + (shelf->GetIdealBounds().height() -
launcher_bounds.height()) / 2);
status_bounds = shelf->status()->GetNativeView()->bounds();
EXPECT_EQ(status_bounds.y(),
bottom + shelf_height - status_bounds.height());
}
// Makes sure LayoutShelf invoked while animating cleans things up.
TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
// Force an initial layout.
shelf->LayoutShelf();
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
const aura::DisplayManager* manager =
aura::Env::GetInstance()->display_manager();
const gfx::Display& display =
manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
// Hide the shelf.
SetState(shelf, ShelfLayoutManager::HIDDEN);
shelf->LayoutShelf();
EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom());
// Make sure the bounds of the two widgets changed.
EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryDisplay().bounds().bottom());
EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
gfx::Screen::GetPrimaryDisplay().bounds().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->status_size().width());
}
// 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->status_size().width());
}
// Verifies when the shell is deleted with a full screen window we don't
// crash. This test is here as originally the crash was in ShelfLayoutManager.
TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
// Widget is now owned by the parent window.
widget->Init(params);
widget->SetFullscreen(true);
}
// Various assertions around auto-hide.
TEST_F(ShelfLayoutManagerTest, AutoHide) {
aura::RootWindow* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator generator(root, root);
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
// Widget is now owned by the parent window.
widget->Init(params);
widget->Maximize();
widget->Show();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
// LayoutShelf() forces the animation to completion, at which point the
// launcher should go off the screen.
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->launcher_widget()->GetWindowScreenBounds().y());
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
gfx::Screen::GetDisplayNearestWindow(root).work_area().bottom());
// Move the mouse to the bottom of the screen.
generator.MoveMouseTo(0, root->bounds().bottom() - 1);
// Shelf should be shown again (but it shouldn't have changed the work area).
SetState(shelf, ShelfLayoutManager::AUTO_HIDE);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(),
shelf->launcher_widget()->GetWindowScreenBounds().y());
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
gfx::Screen::GetDisplayNearestWindow(root).work_area().bottom());
// Move mouse back up.
generator.MoveMouseTo(0, 0);
SetState(shelf, ShelfLayoutManager::AUTO_HIDE);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->launcher_widget()->GetWindowScreenBounds().y());
// Drag mouse to bottom of screen.
generator.PressLeftButton();
generator.MoveMouseTo(0, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.ReleaseLeftButton();
generator.MoveMouseTo(1, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
generator.PressLeftButton();
generator.MoveMouseTo(1, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
}
// Assertions around the lock screen showing.
TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
// Since ShelfLayoutManager queries for mouse location, move the mouse so
// it isn't over the shelf.
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
// Widget is now owned by the parent window.
widget->Init(params);
widget->Maximize();
widget->Show();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
aura::RootWindow* root = Shell::GetPrimaryRootWindow();
// LayoutShelf() forces the animation to completion, at which point the
// launcher should go off the screen.
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->launcher_widget()->GetWindowScreenBounds().y());
aura::Window* lock_container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(),
internal::kShellWindowId_LockScreenContainer);
views::Widget* lock_widget = new views::Widget;
views::Widget::InitParams lock_params(
views::Widget::InitParams::TYPE_WINDOW);
lock_params.bounds = gfx::Rect(0, 0, 200, 200);
lock_params.parent = lock_container;
// Widget is now owned by the parent window.
lock_widget->Init(lock_params);
lock_widget->Maximize();
lock_widget->Show();
// Lock the screen.
Shell::GetInstance()->delegate()->LockScreen();
shelf->UpdateVisibilityState();
// Showing a widget in the lock screen should force the shelf to be visibile.
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
Shell::GetInstance()->delegate()->UnlockScreen();
shelf->UpdateVisibilityState();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
}
// Assertions around SetAutoHideBehavior.
TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
// Since ShelfLayoutManager queries for mouse location, move the mouse so
// it isn't over the shelf.
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
// Widget is now owned by the parent window.
widget->Init(params);
widget->Show();
aura::Window* window = widget->GetNativeWindow();
gfx::Rect display_bounds(
gfx::Screen::GetDisplayNearestWindow(window).bounds());
EXPECT_EQ(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->GetMaximizedWindowBounds(window).bottom());
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->GetMaximizedWindowBounds(window).bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT);
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
EXPECT_EQ(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->GetMaximizedWindowBounds(window).bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
EXPECT_GT(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize,
shelf->GetMaximizedWindowBounds(window).bottom());
widget->Maximize();
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
}
// Verifies the shelf is visible when status/launcher is focused.
TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrLauncherFocused) {
// Since ShelfLayoutManager queries for mouse location, move the mouse so
// it isn't over the shelf.
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
// Widget is now owned by the parent window.
widget->Init(params);
widget->Show();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
// Focus the launcher. Have to go through the focus cycler as normal focus
// requests to it do nothing.
shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
widget->Activate();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
// Trying to activate the status should fail, since we only allow activating
// it when the user is using the keyboard (i.e. through FocusCycler).
shelf->status()->Activate();
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
}
// Makes sure shelf will be visible when app list opens as shelf is in VISIBLE
// state,and toggling app list won't change shelf visibility state.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
shelf->LayoutShelf();
shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT);
// Create a normal unmaximized windowm shelf should be visible.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
// Toggle app list to show, and the shelf stays visible.
shell->ToggleAppList();
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
// Toggle app list to hide, and the shelf stays visible.
shell->ToggleAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
}
// Makes sure shelf will be shown with AUTO_HIDE_SHOWN state when app list opens
// as shelf is in AUTO_HIDE state, and toggling app list won't change shelf
// visibility state.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
shelf->LayoutShelf();
shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT);
// Create a window and show it in maximized state.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window->Show();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
// Toggle app list to show.
shell->ToggleAppList();
// The shelf's auto hide state won't be changed until the timer fires, so
// calling shell->UpdateShelfVisibility() is kind of manually helping it to
// update the state.
shell->UpdateShelfVisibility();
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state());
// Toggle app list to hide.
shell->ToggleAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
}
// Makes sure shelf will be hidden when app list opens as shelf is in HIDDEN
// state, and toggling app list won't change shelf visibility state.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
// For shelf to be visible, app list is not open in initial state.
shelf->LayoutShelf();
// Create a window and make it full screen.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window->Show();
// App list and shelf is not shown.
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
// Toggle app list to show.
shell->ToggleAppList();
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
// Toggle app list to hide.
shell->ToggleAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
}
// Tests SHELF_ALIGNMENT_LEFT and SHELF_ALIGNMENT_RIGHT.
TEST_F(ShelfLayoutManagerTest, SetAlignment) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
// Force an initial layout.
shelf->LayoutShelf();
EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
gfx::Rect launcher_bounds(shelf->launcher_widget()->GetWindowScreenBounds());
const aura::DisplayManager* manager =
aura::Env::GetInstance()->display_manager();
gfx::Display display =
manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_GE(
launcher_bounds.width(),
shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(SHELF_ALIGNMENT_LEFT,
Shell::GetInstance()->system_tray()->shelf_alignment());
gfx::Rect status_bounds(shelf->status()->GetWindowScreenBounds());
EXPECT_GE(status_bounds.width(),
shelf->status()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().right());
EXPECT_EQ(display.bounds().x(), launcher_bounds.x());
EXPECT_EQ(display.bounds().y(), launcher_bounds.y());
EXPECT_EQ(display.bounds().height(), launcher_bounds.height());
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
launcher_bounds = shelf->launcher_widget()->GetWindowScreenBounds();
display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_GE(
launcher_bounds.width(),
shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(SHELF_ALIGNMENT_RIGHT,
Shell::GetInstance()->system_tray()->shelf_alignment());
status_bounds = gfx::Rect(shelf->status()->GetWindowScreenBounds());
EXPECT_GE(status_bounds.width(),
shelf->status()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().left());
EXPECT_EQ(display.work_area().right(), launcher_bounds.x());
EXPECT_EQ(display.bounds().y(), launcher_bounds.y());
EXPECT_EQ(display.bounds().height(), launcher_bounds.height());
}
} // namespace internal
} // namespace ash
|