OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/wm/window_positioner.h" | 5 #include "ash/common/wm/window_positioner.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/common/material_design/material_design_controller.h" | |
10 #include "ash/common/scoped_root_window_for_new_windows.h" | 9 #include "ash/common/scoped_root_window_for_new_windows.h" |
11 #include "ash/common/wm/window_positioner.h" | 10 #include "ash/common/wm/window_positioner.h" |
12 #include "ash/common/wm/window_state.h" | 11 #include "ash/common/wm/window_state.h" |
13 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
14 #include "ash/common/wm_window.h" | 13 #include "ash/common/wm_window.h" |
15 #include "ash/shell.h" | 14 #include "ash/shell.h" |
16 #include "ash/shell/toplevel_window.h" | 15 #include "ash/shell/toplevel_window.h" |
17 #include "ash/test/ash_md_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
18 #include "ash/test/test_shell_delegate.h" | 17 #include "ash/test/test_shell_delegate.h" |
19 #include "ash/wm/window_state_aura.h" | 18 #include "ash/wm/window_state_aura.h" |
20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
21 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
22 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
23 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
24 | 23 |
25 namespace ash { | 24 namespace ash { |
26 | 25 |
27 using WindowPositionerTest = test::AshMDTestBase; | 26 using WindowPositionerTest = test::AshTestBase; |
28 | 27 |
29 INSTANTIATE_TEST_CASE_P( | 28 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { |
30 /* prefix intentionally left blank due to only one parameterization */, | |
31 WindowPositionerTest, | |
32 testing::Values(MaterialDesignController::NON_MATERIAL, | |
33 MaterialDesignController::MATERIAL_NORMAL, | |
34 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | |
35 | |
36 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { | |
37 const int height_offset = GetMdMaximizedWindowHeightOffset(); | |
38 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit | 29 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit |
39 // a new window gets maximized. | 30 // a new window gets maximized. |
40 UpdateDisplay("400x400,500x500"); | 31 UpdateDisplay("400x400,500x500"); |
41 ScopedRootWindowForNewWindows root_for_new_windows( | 32 ScopedRootWindowForNewWindows root_for_new_windows( |
42 WmShell::Get()->GetAllRootWindows()[1]); | 33 WmShell::Get()->GetAllRootWindows()[1]); |
43 shell::ToplevelWindow::CreateParams params; | 34 shell::ToplevelWindow::CreateParams params; |
44 params.can_resize = true; | 35 params.can_resize = true; |
45 params.can_maximize = true; | 36 params.can_maximize = true; |
46 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); | 37 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); |
47 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(), | 38 EXPECT_EQ(gfx::Rect(400, 0, 500, 452).ToString(), |
48 widget->GetWindowBoundsInScreen().ToString()); | 39 widget->GetWindowBoundsInScreen().ToString()); |
49 } | 40 } |
50 | 41 |
51 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { | 42 TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { |
52 UpdateDisplay("400x400,1400x900"); | 43 UpdateDisplay("400x400,1400x900"); |
53 WmWindow* second_root_window = WmShell::Get()->GetAllRootWindows()[1]; | 44 WmWindow* second_root_window = WmShell::Get()->GetAllRootWindows()[1]; |
54 ScopedRootWindowForNewWindows root_for_new_windows(second_root_window); | 45 ScopedRootWindowForNewWindows root_for_new_windows(second_root_window); |
55 shell::ToplevelWindow::CreateParams params; | 46 shell::ToplevelWindow::CreateParams params; |
56 params.can_resize = true; | 47 params.can_resize = true; |
57 params.can_maximize = true; | 48 params.can_maximize = true; |
58 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); | 49 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); |
59 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); | 50 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); |
60 | 51 |
61 // The window should be in the 2nd display with the default size. | 52 // The window should be in the 2nd display with the default size. |
62 EXPECT_EQ("300x300", bounds.size().ToString()); | 53 EXPECT_EQ("300x300", bounds.size().ToString()); |
63 EXPECT_TRUE( | 54 EXPECT_TRUE( |
64 second_root_window->GetDisplayNearestWindow().bounds().Contains(bounds)); | 55 second_root_window->GetDisplayNearestWindow().bounds().Contains(bounds)); |
65 } | 56 } |
66 | 57 |
67 // Tests that second window inherits first window's maximized state as well as | 58 // Tests that second window inherits first window's maximized state as well as |
68 // its restore bounds. | 59 // its restore bounds. |
69 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) { | 60 TEST_F(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) { |
70 const int height_offset = GetMdMaximizedWindowHeightOffset(); | |
71 UpdateDisplay("1400x900"); | 61 UpdateDisplay("1400x900"); |
72 shell::ToplevelWindow::CreateParams params; | 62 shell::ToplevelWindow::CreateParams params; |
73 params.can_resize = true; | 63 params.can_resize = true; |
74 params.can_maximize = true; | 64 params.can_maximize = true; |
75 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); | 65 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); |
76 gfx::Rect bounds = widget1->GetWindowBoundsInScreen(); | 66 gfx::Rect bounds = widget1->GetWindowBoundsInScreen(); |
77 | 67 |
78 // The window should have default size. | 68 // The window should have default size. |
79 EXPECT_FALSE(widget1->IsMaximized()); | 69 EXPECT_FALSE(widget1->IsMaximized()); |
80 EXPECT_EQ("300x300", bounds.size().ToString()); | 70 EXPECT_EQ("300x300", bounds.size().ToString()); |
81 widget1->Maximize(); | 71 widget1->Maximize(); |
82 | 72 |
83 // The window should be maximized. | 73 // The window should be maximized. |
84 bounds = widget1->GetWindowBoundsInScreen(); | 74 bounds = widget1->GetWindowBoundsInScreen(); |
85 EXPECT_TRUE(widget1->IsMaximized()); | 75 EXPECT_TRUE(widget1->IsMaximized()); |
86 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), | 76 EXPECT_EQ(gfx::Rect(0, 0, 1400, 852).ToString(), bounds.ToString()); |
87 bounds.ToString()); | |
88 | 77 |
89 // Create another window | 78 // Create another window |
90 views::Widget* widget2 = shell::ToplevelWindow::CreateToplevelWindow(params); | 79 views::Widget* widget2 = shell::ToplevelWindow::CreateToplevelWindow(params); |
91 | 80 |
92 // The second window should be maximized. | 81 // The second window should be maximized. |
93 bounds = widget2->GetWindowBoundsInScreen(); | 82 bounds = widget2->GetWindowBoundsInScreen(); |
94 EXPECT_TRUE(widget2->IsMaximized()); | 83 EXPECT_TRUE(widget2->IsMaximized()); |
95 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), | 84 EXPECT_EQ(gfx::Rect(0, 0, 1400, 852).ToString(), bounds.ToString()); |
96 bounds.ToString()); | |
97 | 85 |
98 widget2->Restore(); | 86 widget2->Restore(); |
99 // Second window's restored size should be set to default size. | 87 // Second window's restored size should be set to default size. |
100 bounds = widget2->GetWindowBoundsInScreen(); | 88 bounds = widget2->GetWindowBoundsInScreen(); |
101 EXPECT_EQ("300x300", bounds.size().ToString()); | 89 EXPECT_EQ("300x300", bounds.size().ToString()); |
102 } | 90 } |
103 | 91 |
104 namespace { | 92 namespace { |
105 | 93 |
106 // A WidgetDelegate that returns the out of display saved bounds. | 94 // A WidgetDelegate that returns the out of display saved bounds. |
(...skipping 15 matching lines...) Expand all Loading... |
122 } | 110 } |
123 | 111 |
124 private: | 112 private: |
125 views::Widget* widget_; | 113 views::Widget* widget_; |
126 | 114 |
127 DISALLOW_COPY_AND_ASSIGN(OutOfDisplayDelegate); | 115 DISALLOW_COPY_AND_ASSIGN(OutOfDisplayDelegate); |
128 }; | 116 }; |
129 | 117 |
130 } // namespace | 118 } // namespace |
131 | 119 |
132 TEST_P(WindowPositionerTest, EnsureMinimumVisibility) { | 120 TEST_F(WindowPositionerTest, EnsureMinimumVisibility) { |
133 UpdateDisplay("400x400"); | 121 UpdateDisplay("400x400"); |
134 views::Widget* widget = new views::Widget(); | 122 views::Widget* widget = new views::Widget(); |
135 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 123 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
136 params.delegate = new OutOfDisplayDelegate(widget); | 124 params.delegate = new OutOfDisplayDelegate(widget); |
137 params.context = Shell::GetPrimaryRootWindow(); | 125 params.context = Shell::GetPrimaryRootWindow(); |
138 widget->Init(params); | 126 widget->Init(params); |
139 widget->SetBounds(gfx::Rect(450, 10, 100, 100)); | 127 widget->SetBounds(gfx::Rect(450, 10, 100, 100)); |
140 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); | 128 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); |
141 widget->Show(); | 129 widget->Show(); |
142 // Make sure the bounds is adjusted to be inside the work area. | 130 // Make sure the bounds is adjusted to be inside the work area. |
143 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString()); | 131 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString()); |
144 widget->CloseNow(); | 132 widget->CloseNow(); |
145 } | 133 } |
146 | 134 |
147 // In general case on first run the browser window will be maximized only for | 135 // In general case on first run the browser window will be maximized only for |
148 // low resolution screens (width < 1366). In case of big screens the browser is | 136 // low resolution screens (width < 1366). In case of big screens the browser is |
149 // opened being not maximized. To enforce maximization for all screen | 137 // opened being not maximized. To enforce maximization for all screen |
150 // resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun" | 138 // resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun" |
151 // policy. In the following tests we check if the window will be opened in | 139 // policy. In the following tests we check if the window will be opened in |
152 // maximized mode for low and high resolution when this policy is set. | 140 // maximized mode for low and high resolution when this policy is set. |
153 TEST_P(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) { | 141 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) { |
154 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; | 142 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; |
155 // Set resolution to 1466x300. | 143 // Set resolution to 1466x300. |
156 const std::string resolution = base::IntToString(width) + "x300"; | 144 const std::string resolution = base::IntToString(width) + "x300"; |
157 UpdateDisplay(resolution); | 145 UpdateDisplay(resolution); |
158 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. | 146 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. |
159 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; | 147 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; |
160 | 148 |
161 test::TestShellDelegate* const delegate = | 149 test::TestShellDelegate* const delegate = |
162 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); | 150 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); |
163 delegate->SetForceMaximizeOnFirstRun(true); | 151 delegate->SetForceMaximizeOnFirstRun(true); |
164 | 152 |
165 WindowPositioner::GetBoundsAndShowStateForNewWindow( | 153 WindowPositioner::GetBoundsAndShowStateForNewWindow( |
166 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); | 154 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); |
167 | 155 |
168 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); | 156 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); |
169 } | 157 } |
170 | 158 |
171 // For detail see description of FirstRunMaximizeWindowHighResloution. | 159 // For detail see description of FirstRunMaximizeWindowHighResloution. |
172 TEST_P(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) { | 160 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) { |
173 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100; | 161 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100; |
174 // Set resolution to 1266x300. | 162 // Set resolution to 1266x300. |
175 const std::string resolution = base::IntToString(width) + "x300"; | 163 const std::string resolution = base::IntToString(width) + "x300"; |
176 UpdateDisplay(resolution); | 164 UpdateDisplay(resolution); |
177 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. | 165 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. |
178 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; | 166 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; |
179 | 167 |
180 test::TestShellDelegate* const delegate = | 168 test::TestShellDelegate* const delegate = |
181 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); | 169 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); |
182 delegate->SetForceMaximizeOnFirstRun(true); | 170 delegate->SetForceMaximizeOnFirstRun(true); |
183 | 171 |
184 WindowPositioner::GetBoundsAndShowStateForNewWindow( | 172 WindowPositioner::GetBoundsAndShowStateForNewWindow( |
185 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); | 173 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); |
186 | 174 |
187 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); | 175 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); |
188 } | 176 } |
189 | 177 |
190 TEST_P(WindowPositionerTest, IgnoreFullscreenInAutoRearrange) { | 178 TEST_F(WindowPositionerTest, IgnoreFullscreenInAutoRearrange) { |
191 // Set bigger than 1366 so that the new window is opened in normal state. | 179 // Set bigger than 1366 so that the new window is opened in normal state. |
192 UpdateDisplay("1400x800"); | 180 UpdateDisplay("1400x800"); |
193 | 181 |
194 // 1st window mimics fullscreen browser window behavior. | 182 // 1st window mimics fullscreen browser window behavior. |
195 shell::ToplevelWindow::CreateParams params; | 183 shell::ToplevelWindow::CreateParams params; |
196 params.can_resize = true; | 184 params.can_resize = true; |
197 params.can_maximize = true; | 185 params.can_maximize = true; |
198 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); | 186 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); |
199 wm::WindowState* managed_state = | 187 wm::WindowState* managed_state = |
200 wm::GetWindowState(widget1->GetNativeWindow()); | 188 wm::GetWindowState(widget1->GetNativeWindow()); |
(...skipping 13 matching lines...) Expand all Loading... |
214 widget1->SetFullscreen(false); | 202 widget1->SetFullscreen(false); |
215 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); | 203 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); |
216 | 204 |
217 // Closing 2nd widget triggers the rearrange logic but the 1st | 205 // Closing 2nd widget triggers the rearrange logic but the 1st |
218 // widget should stay in the current size. | 206 // widget should stay in the current size. |
219 widget2->CloseNow(); | 207 widget2->CloseNow(); |
220 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); | 208 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); |
221 } | 209 } |
222 | 210 |
223 } // namespace ash | 211 } // namespace ash |
OLD | NEW |