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

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

Issue 2067223003: Parameterize Ash unittests to pass with material design enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address trybot failures Created 4 years, 6 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
OLDNEW
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"
9 #include "ash/common/wm/window_positioner.h" 10 #include "ash/common/wm/window_positioner.h"
10 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/shell/toplevel_window.h" 13 #include "ash/shell/toplevel_window.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_md_test_base.h"
14 #include "ash/test/test_shell_delegate.h" 15 #include "ash/test/test_shell_delegate.h"
15 #include "ash/wm/window_state_aura.h" 16 #include "ash/wm/window_state_aura.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
21 22
22 namespace ash { 23 namespace ash {
23 24
24 typedef test::AshTestBase WindowPositionerTest; 25 using WindowPositionerTest = test::AshMDTestBase;
25 26
26 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { 27 // Note: First argument is optional and intentionally left blank.
28 // (it's a prefix for the generated test cases)
29 INSTANTIATE_TEST_CASE_P(
30 ,
31 WindowPositionerTest,
32 testing::Values(MaterialDesignController::NON_MATERIAL,
33 MaterialDesignController::MATERIAL_NORMAL,
34 MaterialDesignController::MATERIAL_EXPERIMENTAL));
35
36 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) {
27 if (!SupportsMultipleDisplays()) 37 if (!SupportsMultipleDisplays())
28 return; 38 return;
39 const int height_offset = GetMdMaximizedWindowHeightOffset();
29 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit 40 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit
30 // a new window gets maximized. 41 // a new window gets maximized.
31 UpdateDisplay("400x400,500x500"); 42 UpdateDisplay("400x400,500x500");
32 Shell::GetInstance()->set_target_root_window( 43 Shell::GetInstance()->set_target_root_window(
33 Shell::GetAllRootWindows()[1]); 44 Shell::GetAllRootWindows()[1]);
34 shell::ToplevelWindow::CreateParams params; 45 shell::ToplevelWindow::CreateParams params;
35 params.can_resize = true; 46 params.can_resize = true;
36 params.can_maximize = true; 47 params.can_maximize = true;
37 views::Widget* widget = 48 views::Widget* widget =
38 shell::ToplevelWindow::CreateToplevelWindow(params); 49 shell::ToplevelWindow::CreateToplevelWindow(params);
39 EXPECT_EQ("400,0 500x453", widget->GetWindowBoundsInScreen().ToString()); 50 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(),
51 widget->GetWindowBoundsInScreen().ToString());
40 } 52 }
41 53
42 TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { 54 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) {
43 if (!SupportsMultipleDisplays()) 55 if (!SupportsMultipleDisplays())
44 return; 56 return;
45 #if defined(OS_WIN) 57 #if defined(OS_WIN)
46 ash::WindowPositioner::SetMaximizeFirstWindow(true); 58 ash::WindowPositioner::SetMaximizeFirstWindow(true);
47 #endif 59 #endif
48 UpdateDisplay("400x400,1400x900"); 60 UpdateDisplay("400x400,1400x900");
49 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; 61 aura::Window* second_root_window = Shell::GetAllRootWindows()[1];
50 Shell::GetInstance()->set_target_root_window( 62 Shell::GetInstance()->set_target_root_window(
51 second_root_window); 63 second_root_window);
52 shell::ToplevelWindow::CreateParams params; 64 shell::ToplevelWindow::CreateParams params;
53 params.can_resize = true; 65 params.can_resize = true;
54 params.can_maximize = true; 66 params.can_maximize = true;
55 views::Widget* widget = 67 views::Widget* widget =
56 shell::ToplevelWindow::CreateToplevelWindow(params); 68 shell::ToplevelWindow::CreateToplevelWindow(params);
57 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); 69 gfx::Rect bounds = widget->GetWindowBoundsInScreen();
58 #if defined(OS_WIN) 70 #if defined(OS_WIN)
59 EXPECT_TRUE(widget->IsMaximized()); 71 EXPECT_TRUE(widget->IsMaximized());
60 #else 72 #else
61 // The window should be in the 2nd display with the default size. 73 // The window should be in the 2nd display with the default size.
62 EXPECT_EQ("300x300", bounds.size().ToString()); 74 EXPECT_EQ("300x300", bounds.size().ToString());
63 #endif 75 #endif
64 EXPECT_TRUE(display::Screen::GetScreen() 76 EXPECT_TRUE(display::Screen::GetScreen()
65 ->GetDisplayNearestWindow(second_root_window) 77 ->GetDisplayNearestWindow(second_root_window)
66 .bounds() 78 .bounds()
67 .Contains(bounds)); 79 .Contains(bounds));
68 } 80 }
69 81
70 // Tests that second window inherits first window's maximized state as well as 82 // Tests that second window inherits first window's maximized state as well as
71 // its restore bounds. 83 // its restore bounds.
72 #if defined(OS_WIN) && !defined(USE_ASH)
73 // TODO(msw): Broken on Windows. http://crbug.com/584038 84 // TODO(msw): Broken on Windows. http://crbug.com/584038
74 #define MAYBE_SecondMaximizedWindowHasProperRestoreSize \ 85 #if defined(OS_CHROMEOS)
75 DISABLED_SecondMaximizedWindowHasProperRestoreSize 86 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) {
76 #else 87 const int height_offset = GetMdMaximizedWindowHeightOffset();
77 #define MAYBE_SecondMaximizedWindowHasProperRestoreSize \
78 SecondMaximizedWindowHasProperRestoreSize
79 #endif
80 TEST_F(WindowPositionerTest, MAYBE_SecondMaximizedWindowHasProperRestoreSize) {
81 #if defined(OS_WIN)
82 ash::WindowPositioner::SetMaximizeFirstWindow(true);
83 #endif
84 UpdateDisplay("1400x900"); 88 UpdateDisplay("1400x900");
85 shell::ToplevelWindow::CreateParams params; 89 shell::ToplevelWindow::CreateParams params;
86 params.can_resize = true; 90 params.can_resize = true;
87 params.can_maximize = true; 91 params.can_maximize = true;
88 views::Widget* widget1 = 92 views::Widget* widget1 =
89 shell::ToplevelWindow::CreateToplevelWindow(params); 93 shell::ToplevelWindow::CreateToplevelWindow(params);
90 gfx::Rect bounds = widget1->GetWindowBoundsInScreen(); 94 gfx::Rect bounds = widget1->GetWindowBoundsInScreen();
91 95
92 #if !defined(OS_WIN)
93 // The window should have default size. 96 // The window should have default size.
94 EXPECT_FALSE(widget1->IsMaximized()); 97 EXPECT_FALSE(widget1->IsMaximized());
95 EXPECT_EQ("300x300", bounds.size().ToString()); 98 EXPECT_EQ("300x300", bounds.size().ToString());
96 widget1->Maximize(); 99 widget1->Maximize();
97 #endif 100
98 // The window should be maximized. 101 // The window should be maximized.
99 bounds = widget1->GetWindowBoundsInScreen(); 102 bounds = widget1->GetWindowBoundsInScreen();
100 EXPECT_TRUE(widget1->IsMaximized()); 103 EXPECT_TRUE(widget1->IsMaximized());
101 EXPECT_EQ("0,0 1400x853", bounds.ToString()); 104 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(),
105 bounds.ToString());
102 106
103 // Create another window 107 // Create another window
104 views::Widget* widget2 = 108 views::Widget* widget2 =
105 shell::ToplevelWindow::CreateToplevelWindow(params); 109 shell::ToplevelWindow::CreateToplevelWindow(params);
106 110
107 // The second window should be maximized. 111 // The second window should be maximized.
108 bounds = widget2->GetWindowBoundsInScreen(); 112 bounds = widget2->GetWindowBoundsInScreen();
109 EXPECT_TRUE(widget2->IsMaximized()); 113 EXPECT_TRUE(widget2->IsMaximized());
110 EXPECT_EQ("0,0 1400x853", bounds.ToString()); 114 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(),
115 bounds.ToString());
111 116
112 widget2->Restore(); 117 widget2->Restore();
113 // Second window's restored size should be set to default size. 118 // Second window's restored size should be set to default size.
114 bounds = widget2->GetWindowBoundsInScreen(); 119 bounds = widget2->GetWindowBoundsInScreen();
115 EXPECT_EQ("300x300", bounds.size().ToString()); 120 EXPECT_EQ("300x300", bounds.size().ToString());
116 } 121 }
122 #endif // defined(OS_CHROMEOS)
117 123
118 namespace { 124 namespace {
119 125
120 // A WidgetDelegate that returns the out of display saved bounds. 126 // A WidgetDelegate that returns the out of display saved bounds.
121 class OutOfDisplayDelegate : public views::WidgetDelegate { 127 class OutOfDisplayDelegate : public views::WidgetDelegate {
122 public: 128 public:
123 explicit OutOfDisplayDelegate(views::Widget* widget) : widget_(widget) {} 129 explicit OutOfDisplayDelegate(views::Widget* widget) : widget_(widget) {}
124 ~OutOfDisplayDelegate() override {} 130 ~OutOfDisplayDelegate() override {}
125 131
126 // Overridden from WidgetDelegate: 132 // Overridden from WidgetDelegate:
127 void DeleteDelegate() override { delete this; } 133 void DeleteDelegate() override { delete this; }
128 views::Widget* GetWidget() override { return widget_; } 134 views::Widget* GetWidget() override { return widget_; }
129 const views::Widget* GetWidget() const override { return widget_; } 135 const views::Widget* GetWidget() const override { return widget_; }
130 bool GetSavedWindowPlacement(const views::Widget* widget, 136 bool GetSavedWindowPlacement(const views::Widget* widget,
131 gfx::Rect* bounds, 137 gfx::Rect* bounds,
132 ui::WindowShowState* show_state) const override { 138 ui::WindowShowState* show_state) const override {
133 bounds->SetRect(450, 10, 100, 100); 139 bounds->SetRect(450, 10, 100, 100);
134 *show_state = ui::SHOW_STATE_NORMAL; 140 *show_state = ui::SHOW_STATE_NORMAL;
135 return true; 141 return true;
136 } 142 }
137 143
138 private: 144 private:
139 views::Widget* widget_; 145 views::Widget* widget_;
140 146
141 DISALLOW_COPY_AND_ASSIGN(OutOfDisplayDelegate); 147 DISALLOW_COPY_AND_ASSIGN(OutOfDisplayDelegate);
142 }; 148 };
143 149
144 } // namespace 150 } // namespace
145 151
146 TEST_F(WindowPositionerTest, EnsureMinimumVisibility) { 152 TEST_P(WindowPositionerTest, EnsureMinimumVisibility) {
147 if (!SupportsHostWindowResize()) 153 if (!SupportsHostWindowResize())
148 return; 154 return;
149 155
150 UpdateDisplay("400x400"); 156 UpdateDisplay("400x400");
151 views::Widget* widget = new views::Widget(); 157 views::Widget* widget = new views::Widget();
152 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 158 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
153 params.delegate = new OutOfDisplayDelegate(widget); 159 params.delegate = new OutOfDisplayDelegate(widget);
154 params.context = Shell::GetPrimaryRootWindow(); 160 params.context = Shell::GetPrimaryRootWindow();
155 widget->Init(params); 161 widget->Init(params);
156 widget->SetBounds(gfx::Rect(450,10, 100, 100)); 162 widget->SetBounds(gfx::Rect(450,10, 100, 100));
157 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); 163 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true);
158 widget->Show(); 164 widget->Show();
159 // Make sure the bounds is adjusted to be inside the work area. 165 // Make sure the bounds is adjusted to be inside the work area.
160 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString()); 166 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString());
161 widget->CloseNow(); 167 widget->CloseNow();
162 } 168 }
163 169
164 // In general case on first run the browser window will be maximized only for 170 // In general case on first run the browser window will be maximized only for
165 // low resolution screens (width < 1366). In case of big screens the browser is 171 // low resolution screens (width < 1366). In case of big screens the browser is
166 // opened being not maximized. To enforce maximization for all screen 172 // opened being not maximized. To enforce maximization for all screen
167 // resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun" 173 // resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun"
168 // policy. In the following tests we check if the window will be opened in 174 // policy. In the following tests we check if the window will be opened in
169 // maximized mode for low and high resolution when this policy is set. 175 // maximized mode for low and high resolution when this policy is set.
170 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) { 176 TEST_P(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) {
171 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; 177 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
172 // Set resolution to 1466x300. 178 // Set resolution to 1466x300.
173 const std::string resolution = base::IntToString(width) + "x300"; 179 const std::string resolution = base::IntToString(width) + "x300";
174 UpdateDisplay(resolution); 180 UpdateDisplay(resolution);
175 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. 181 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds.
176 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; 182 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT;
177 183
178 test::TestShellDelegate* const delegate = 184 test::TestShellDelegate* const delegate =
179 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate()); 185 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate());
180 delegate->SetForceMaximizeOnFirstRun(true); 186 delegate->SetForceMaximizeOnFirstRun(true);
181 187
182 WindowPositioner::GetBoundsAndShowStateForNewWindow( 188 WindowPositioner::GetBoundsAndShowStateForNewWindow(
183 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); 189 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out);
184 190
185 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); 191 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED);
186 } 192 }
187 193
188 // For detail see description of FirstRunMaximizeWindowHighResloution. 194 // For detail see description of FirstRunMaximizeWindowHighResloution.
189 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) { 195 TEST_P(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) {
190 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100; 196 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100;
191 // Set resolution to 1266x300. 197 // Set resolution to 1266x300.
192 const std::string resolution = base::IntToString(width) + "x300"; 198 const std::string resolution = base::IntToString(width) + "x300";
193 UpdateDisplay(resolution); 199 UpdateDisplay(resolution);
194 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. 200 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds.
195 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; 201 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT;
196 202
197 test::TestShellDelegate* const delegate = 203 test::TestShellDelegate* const delegate =
198 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate()); 204 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate());
199 delegate->SetForceMaximizeOnFirstRun(true); 205 delegate->SetForceMaximizeOnFirstRun(true);
200 206
201 WindowPositioner::GetBoundsAndShowStateForNewWindow( 207 WindowPositioner::GetBoundsAndShowStateForNewWindow(
202 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out); 208 nullptr, false, ui::SHOW_STATE_DEFAULT, &bounds_in_out, &show_state_out);
203 209
204 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); 210 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED);
205 } 211 }
206 212
207 TEST_F(WindowPositionerTest, IgnoreFullscreenInAutoRearrange) { 213 TEST_P(WindowPositionerTest, IgnoreFullscreenInAutoRearrange) {
208 if (!SupportsHostWindowResize()) 214 if (!SupportsHostWindowResize())
209 return; 215 return;
210 // Set bigger than 1366 so that the new window is opened in normal state. 216 // Set bigger than 1366 so that the new window is opened in normal state.
211 UpdateDisplay("1400x800"); 217 UpdateDisplay("1400x800");
212 218
213 // 1st window mimics fullscreen browser window behavior. 219 // 1st window mimics fullscreen browser window behavior.
214 shell::ToplevelWindow::CreateParams params; 220 shell::ToplevelWindow::CreateParams params;
215 params.can_resize = true; 221 params.can_resize = true;
216 params.can_maximize = true; 222 params.can_maximize = true;
217 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); 223 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params);
(...skipping 15 matching lines...) Expand all
233 widget1->SetFullscreen(false); 239 widget1->SetFullscreen(false);
234 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); 240 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString());
235 241
236 // Closing 2nd widget triggers the rearrange logic but the 1st 242 // Closing 2nd widget triggers the rearrange logic but the 1st
237 // widget should stay in the current size. 243 // widget should stay in the current size.
238 widget2->CloseNow(); 244 widget2->CloseNow();
239 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); 245 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString());
240 } 246 }
241 247
242 } // namespace ash 248 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698