OLD | NEW |
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 "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" |
6 | 6 |
7 #include "ash/wm/window_resizer.h" | 7 #include "ash/wm/window_resizer.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 display.set_work_area(work_area); | 105 display.set_work_area(work_area); |
106 displays_.push_back(display); | 106 displays_.push_back(display); |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 std::vector<gfx::Display> displays_; | 110 std::vector<gfx::Display> displays_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(TestScreen); | 112 DISALLOW_COPY_AND_ASSIGN(TestScreen); |
113 }; | 113 }; |
114 | 114 |
| 115 class TestTargetDisplayProvider : public WindowSizer::TargetDisplayProvider { |
| 116 public: |
| 117 TestTargetDisplayProvider() {} |
| 118 virtual ~TestTargetDisplayProvider() {} |
| 119 |
| 120 virtual gfx::Display GetTargetDisplay( |
| 121 const gfx::Screen* screen, |
| 122 const gfx::Rect& bounds) const OVERRIDE { |
| 123 // On ash, the bounds is used as a indicator to specify |
| 124 // the target display. |
| 125 return screen->GetDisplayMatching(bounds); |
| 126 } |
| 127 |
| 128 private: |
| 129 DISALLOW_COPY_AND_ASSIGN(TestTargetDisplayProvider); |
| 130 }; |
| 131 |
115 } // namespace | 132 } // namespace |
116 | 133 |
117 TestStateProvider::TestStateProvider(): | 134 TestStateProvider::TestStateProvider(): |
118 has_persistent_data_(false), | 135 has_persistent_data_(false), |
119 persistent_show_state_(ui::SHOW_STATE_DEFAULT), | 136 persistent_show_state_(ui::SHOW_STATE_DEFAULT), |
120 has_last_active_data_(false), | 137 has_last_active_data_(false), |
121 last_active_show_state_(ui::SHOW_STATE_DEFAULT) { | 138 last_active_show_state_(ui::SHOW_STATE_DEFAULT) { |
122 } | 139 } |
123 | 140 |
124 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds, | 141 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 Source source, | 192 Source source, |
176 const Browser* browser, | 193 const Browser* browser, |
177 const gfx::Rect& passed_in, | 194 const gfx::Rect& passed_in, |
178 gfx::Rect* out_bounds, | 195 gfx::Rect* out_bounds, |
179 ui::WindowShowState* out_show_state) { | 196 ui::WindowShowState* out_show_state) { |
180 DCHECK(out_show_state); | 197 DCHECK(out_show_state); |
181 TestScreen test_screen; | 198 TestScreen test_screen; |
182 test_screen.AddDisplay(monitor1_bounds, monitor1_work_area); | 199 test_screen.AddDisplay(monitor1_bounds, monitor1_work_area); |
183 if (!monitor2_bounds.IsEmpty()) | 200 if (!monitor2_bounds.IsEmpty()) |
184 test_screen.AddDisplay(monitor2_bounds, monitor2_bounds); | 201 test_screen.AddDisplay(monitor2_bounds, monitor2_bounds); |
185 TestStateProvider* sp = new TestStateProvider; | 202 scoped_ptr<TestStateProvider> sp(new TestStateProvider); |
186 if (source == PERSISTED || source == BOTH) | 203 if (source == PERSISTED || source == BOTH) |
187 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); | 204 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); |
188 if (source == LAST_ACTIVE || source == BOTH) | 205 if (source == LAST_ACTIVE || source == BOTH) |
189 sp->SetLastActiveState(bounds, show_state_last, true); | 206 sp->SetLastActiveState(bounds, show_state_last, true); |
| 207 scoped_ptr<WindowSizer::TargetDisplayProvider> tdp( |
| 208 new TestTargetDisplayProvider); |
190 | 209 |
191 WindowSizer sizer(sp, &test_screen, browser); | 210 WindowSizer sizer(sp.PassAs<WindowSizer::StateProvider>(), |
| 211 tdp.Pass(), &test_screen, browser); |
192 sizer.DetermineWindowBoundsAndShowState(passed_in, | 212 sizer.DetermineWindowBoundsAndShowState(passed_in, |
193 out_bounds, | 213 out_bounds, |
194 out_show_state); | 214 out_show_state); |
195 } | 215 } |
196 | 216 |
197 void GetWindowBounds(const gfx::Rect& monitor1_bounds, | 217 void GetWindowBounds(const gfx::Rect& monitor1_bounds, |
198 const gfx::Rect& monitor1_work_area, | 218 const gfx::Rect& monitor1_work_area, |
199 const gfx::Rect& monitor2_bounds, | 219 const gfx::Rect& monitor2_bounds, |
200 const gfx::Rect& bounds, | 220 const gfx::Rect& bounds, |
201 const gfx::Rect& work_area, | 221 const gfx::Rect& work_area, |
(...skipping 11 matching lines...) Expand all Loading... |
213 ui::WindowShowState GetWindowShowState( | 233 ui::WindowShowState GetWindowShowState( |
214 ui::WindowShowState show_state_persisted, | 234 ui::WindowShowState show_state_persisted, |
215 ui::WindowShowState show_state_last, | 235 ui::WindowShowState show_state_last, |
216 Source source, | 236 Source source, |
217 const Browser* browser, | 237 const Browser* browser, |
218 const gfx::Rect& display_config) { | 238 const gfx::Rect& display_config) { |
219 gfx::Rect bounds = display_config; | 239 gfx::Rect bounds = display_config; |
220 gfx::Rect work_area = display_config; | 240 gfx::Rect work_area = display_config; |
221 TestScreen test_screen; | 241 TestScreen test_screen; |
222 test_screen.AddDisplay(display_config, display_config); | 242 test_screen.AddDisplay(display_config, display_config); |
223 TestStateProvider* sp = new TestStateProvider; | 243 scoped_ptr<TestStateProvider> sp(new TestStateProvider); |
224 if (source == PERSISTED || source == BOTH) | 244 if (source == PERSISTED || source == BOTH) |
225 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); | 245 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); |
226 if (source == LAST_ACTIVE || source == BOTH) | 246 if (source == LAST_ACTIVE || source == BOTH) |
227 sp->SetLastActiveState(bounds, show_state_last, true); | 247 sp->SetLastActiveState(bounds, show_state_last, true); |
| 248 scoped_ptr<WindowSizer::TargetDisplayProvider> tdp( |
| 249 new TestTargetDisplayProvider); |
228 | 250 |
229 WindowSizer sizer(sp, &test_screen, browser); | 251 WindowSizer sizer(sp.PassAs<WindowSizer::StateProvider>(), |
| 252 tdp.Pass(), &test_screen, browser); |
230 | 253 |
231 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; | 254 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; |
232 gfx::Rect out_bounds; | 255 gfx::Rect out_bounds; |
233 sizer.DetermineWindowBoundsAndShowState( | 256 sizer.DetermineWindowBoundsAndShowState( |
234 gfx::Rect(), | 257 gfx::Rect(), |
235 &out_bounds, | 258 &out_bounds, |
236 &out_show_state); | 259 &out_show_state); |
237 return out_show_state; | 260 return out_show_state; |
238 } | 261 } |
239 | 262 |
240 #if !defined(OS_MACOSX) | 263 #if !defined(OS_MACOSX) |
241 TEST(WindowSizerTestCommon, PersistedWindowOffscreenWithNonAggressiveRepositioni
ng) { | 264 TEST(WindowSizerTestCommon, |
| 265 PersistedWindowOffscreenWithNonAggressiveRepositioning) { |
242 { // off the left but the minimum visibility condition is barely satisfied | 266 { // off the left but the minimum visibility condition is barely satisfied |
243 // without relocaiton. | 267 // without relocaiton. |
244 gfx::Rect initial_bounds(-470, 50, 500, 400); | 268 gfx::Rect initial_bounds(-470, 50, 500, 400); |
245 | 269 |
246 gfx::Rect window_bounds; | 270 gfx::Rect window_bounds; |
247 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), | 271 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), |
248 initial_bounds, gfx::Rect(), PERSISTED, | 272 initial_bounds, gfx::Rect(), PERSISTED, |
249 NULL, gfx::Rect(), &window_bounds); | 273 NULL, gfx::Rect(), &window_bounds); |
250 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); | 274 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
251 } | 275 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 { // Check that a window which hangs out of the screen get moved back in. | 463 { // Check that a window which hangs out of the screen get moved back in. |
440 gfx::Rect window_bounds; | 464 gfx::Rect window_bounds; |
441 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), | 465 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), |
442 gfx::Rect(), DEFAULT, NULL, | 466 gfx::Rect(), DEFAULT, NULL, |
443 gfx::Rect(1020, 700, 100, 100), &window_bounds); | 467 gfx::Rect(1020, 700, 100, 100), &window_bounds); |
444 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); | 468 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
445 } | 469 } |
446 } | 470 } |
447 | 471 |
448 #endif // defined(OS_MACOSX) | 472 #endif // defined(OS_MACOSX) |
OLD | NEW |