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

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

Issue 9689027: MonitorManager to manage multiple monitors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: crash fix Created 8 years, 9 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
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/shelf_layout_manager.h" 5 #include "ash/wm/shelf_layout_manager.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.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 "ui/aura/env.h"
12 #include "ui/aura/monitor.h"
13 #include "ui/aura/monitor_manager.h"
11 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
12 #include "ui/aura/screen_aura.h"
13 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
14 #include "ui/base/animation/animation_container_element.h" 16 #include "ui/base/animation/animation_container_element.h"
15 #include "ui/gfx/compositor/layer_animator.h" 17 #include "ui/gfx/compositor/layer_animator.h"
16 #include "ui/gfx/compositor/layer.h" 18 #include "ui/gfx/compositor/layer.h"
19 #include "ui/gfx/screen.h"
17 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
18 21
19 namespace ash { 22 namespace ash {
20 namespace internal { 23 namespace internal {
21 24
22 namespace { 25 namespace {
23 26
24 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { 27 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
25 ui::AnimationContainerElement* element = 28 ui::AnimationContainerElement* element =
26 static_cast<ui::AnimationContainerElement*>( 29 static_cast<ui::AnimationContainerElement*>(
(...skipping 16 matching lines...) Expand all
43 #define MAYBE_SetVisible FAILS_SetVisible 46 #define MAYBE_SetVisible FAILS_SetVisible
44 #else 47 #else
45 #define MAYBE_SetVisible SetVisible 48 #define MAYBE_SetVisible SetVisible
46 #endif 49 #endif
47 // Makes sure SetVisible updates work area and widget appropriately. 50 // Makes sure SetVisible updates work area and widget appropriately.
48 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { 51 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
49 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 52 ShelfLayoutManager* shelf = GetShelfLayoutManager();
50 // Force an initial layout. 53 // Force an initial layout.
51 shelf->LayoutShelf(); 54 shelf->LayoutShelf();
52 ASSERT_TRUE(shelf->visible()); 55 ASSERT_TRUE(shelf->visible());
53 56 const aura::MonitorManager* manager =
54 const aura::ScreenAura* screen = Shell::GetRootWindow()->screen(); 57 aura::Env::GetInstance()->monitor_manager();
55 ASSERT_TRUE(screen); 58 const aura::Monitor* monitor =
59 manager->GetMonitorNearestWindow(Shell::GetRootWindow());
60 ASSERT_TRUE(monitor);
56 // Bottom inset should be the max of widget heights. 61 // Bottom inset should be the max of widget heights.
57 EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom()); 62 EXPECT_EQ(shelf->max_height(), monitor->work_area_insets().bottom());
58 63
59 // Hide the shelf. 64 // Hide the shelf.
60 shelf->SetVisible(false); 65 shelf->SetVisible(false);
61 // Run the animation to completion. 66 // Run the animation to completion.
62 StepWidgetLayerAnimatorToEnd(shelf->launcher()); 67 StepWidgetLayerAnimatorToEnd(shelf->launcher());
63 StepWidgetLayerAnimatorToEnd(shelf->status()); 68 StepWidgetLayerAnimatorToEnd(shelf->status());
64 EXPECT_FALSE(shelf->visible()); 69 EXPECT_FALSE(shelf->visible());
65 EXPECT_EQ(0, screen->work_area_insets().bottom()); 70 EXPECT_EQ(0, monitor->work_area_insets().bottom());
66 71
67 // Make sure the bounds of the two widgets changed. 72 // Make sure the bounds of the two widgets changed.
68 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), 73 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(),
69 gfx::Screen::GetPrimaryMonitorBounds().bottom()); 74 gfx::Screen::GetPrimaryMonitorBounds().bottom());
70 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), 75 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
71 gfx::Screen::GetPrimaryMonitorBounds().bottom()); 76 gfx::Screen::GetPrimaryMonitorBounds().bottom());
72 77
73 // And show it again. 78 // And show it again.
74 shelf->SetVisible(true); 79 shelf->SetVisible(true);
75 // Run the animation to completion. 80 // Run the animation to completion.
76 StepWidgetLayerAnimatorToEnd(shelf->launcher()); 81 StepWidgetLayerAnimatorToEnd(shelf->launcher());
77 StepWidgetLayerAnimatorToEnd(shelf->status()); 82 StepWidgetLayerAnimatorToEnd(shelf->status());
78 EXPECT_TRUE(shelf->visible()); 83 EXPECT_TRUE(shelf->visible());
79 EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom()); 84 EXPECT_EQ(shelf->max_height(), monitor->work_area_insets().bottom());
80 85
81 // Make sure the bounds of the two widgets changed. 86 // Make sure the bounds of the two widgets changed.
82 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds()); 87 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds());
83 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - 88 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() -
84 shelf->max_height(); 89 shelf->max_height();
85 EXPECT_EQ(launcher_bounds.y(), 90 EXPECT_EQ(launcher_bounds.y(),
86 bottom + (shelf->max_height() - launcher_bounds.height()) / 2); 91 bottom + (shelf->max_height() - launcher_bounds.height()) / 2);
87 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds()); 92 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds());
88 EXPECT_EQ(status_bounds.y(), 93 EXPECT_EQ(status_bounds.y(),
89 bottom + shelf->max_height() - status_bounds.height()); 94 bottom + shelf->max_height() - status_bounds.height());
90 } 95 }
91 96
92 // Makes sure LayoutShelf invoked while animating cleans things up. 97 // Makes sure LayoutShelf invoked while animating cleans things up.
93 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { 98 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
94 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 99 ShelfLayoutManager* shelf = GetShelfLayoutManager();
95 // Force an initial layout. 100 // Force an initial layout.
96 shelf->LayoutShelf(); 101 shelf->LayoutShelf();
97 ASSERT_TRUE(shelf->visible()); 102 ASSERT_TRUE(shelf->visible());
98 103
99 const aura::ScreenAura* screen = Shell::GetRootWindow()->screen(); 104 const aura::MonitorManager* manager =
105 aura::Env::GetInstance()->monitor_manager();
106 const aura::Monitor* monitor =
107 manager->GetMonitorNearestWindow(Shell::GetRootWindow());
100 108
101 // Hide the shelf. 109 // Hide the shelf.
102 shelf->SetVisible(false); 110 shelf->SetVisible(false);
103 shelf->LayoutShelf(); 111 shelf->LayoutShelf();
104 EXPECT_FALSE(shelf->visible()); 112 EXPECT_FALSE(shelf->visible());
105 EXPECT_FALSE(shelf->visible()); 113 EXPECT_FALSE(shelf->visible());
106 EXPECT_EQ(0, screen->work_area_insets().bottom()); 114 EXPECT_EQ(0, monitor->work_area_insets().bottom());
107 // Make sure the bounds of the two widgets changed. 115 // Make sure the bounds of the two widgets changed.
108 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), 116 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(),
109 gfx::Screen::GetPrimaryMonitorBounds().bottom()); 117 gfx::Screen::GetPrimaryMonitorBounds().bottom());
110 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), 118 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(),
111 gfx::Screen::GetPrimaryMonitorBounds().bottom()); 119 gfx::Screen::GetPrimaryMonitorBounds().bottom());
112 } 120 }
113 121
114 // Makes sure the launcher is initially sized correctly. 122 // Makes sure the launcher is initially sized correctly.
115 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { 123 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) {
116 Launcher* launcher = Shell::GetInstance()->launcher(); 124 Launcher* launcher = Shell::GetInstance()->launcher();
(...skipping 25 matching lines...) Expand all
142 views::Widget* widget = new views::Widget; 150 views::Widget* widget = new views::Widget;
143 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 151 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
144 params.bounds = gfx::Rect(0, 0, 200, 200); 152 params.bounds = gfx::Rect(0, 0, 200, 200);
145 // Widget is now owned by the parent window. 153 // Widget is now owned by the parent window.
146 widget->Init(params); 154 widget->Init(params);
147 widget->SetFullscreen(true); 155 widget->SetFullscreen(true);
148 } 156 }
149 157
150 } // namespace internal 158 } // namespace internal
151 } // namespace ash 159 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698