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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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 WindowSizer::TargetDisplayProvider* tdp = new TestTargetDisplayProvider; |
190 | 208 |
191 WindowSizer sizer(sp, &test_screen, browser); | 209 WindowSizer sizer(sp, tdp, &test_screen, browser); |
192 sizer.DetermineWindowBoundsAndShowState(passed_in, | 210 sizer.DetermineWindowBoundsAndShowState(passed_in, |
193 out_bounds, | 211 out_bounds, |
194 out_show_state); | 212 out_show_state); |
195 } | 213 } |
196 | 214 |
197 void GetWindowBounds(const gfx::Rect& monitor1_bounds, | 215 void GetWindowBounds(const gfx::Rect& monitor1_bounds, |
198 const gfx::Rect& monitor1_work_area, | 216 const gfx::Rect& monitor1_work_area, |
199 const gfx::Rect& monitor2_bounds, | 217 const gfx::Rect& monitor2_bounds, |
200 const gfx::Rect& bounds, | 218 const gfx::Rect& bounds, |
201 const gfx::Rect& work_area, | 219 const gfx::Rect& work_area, |
(...skipping 16 matching lines...) Expand all Loading... |
218 const gfx::Rect& display_config) { | 236 const gfx::Rect& display_config) { |
219 gfx::Rect bounds = display_config; | 237 gfx::Rect bounds = display_config; |
220 gfx::Rect work_area = display_config; | 238 gfx::Rect work_area = display_config; |
221 TestScreen test_screen; | 239 TestScreen test_screen; |
222 test_screen.AddDisplay(display_config, display_config); | 240 test_screen.AddDisplay(display_config, display_config); |
223 TestStateProvider* sp = new TestStateProvider; | 241 TestStateProvider* sp = new TestStateProvider; |
224 if (source == PERSISTED || source == BOTH) | 242 if (source == PERSISTED || source == BOTH) |
225 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); | 243 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); |
226 if (source == LAST_ACTIVE || source == BOTH) | 244 if (source == LAST_ACTIVE || source == BOTH) |
227 sp->SetLastActiveState(bounds, show_state_last, true); | 245 sp->SetLastActiveState(bounds, show_state_last, true); |
| 246 WindowSizer::TargetDisplayProvider* tdp = new TestTargetDisplayProvider; |
228 | 247 |
229 WindowSizer sizer(sp, &test_screen, browser); | 248 WindowSizer sizer(sp, tdp, &test_screen, browser); |
230 | 249 |
231 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; | 250 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; |
232 gfx::Rect out_bounds; | 251 gfx::Rect out_bounds; |
233 sizer.DetermineWindowBoundsAndShowState( | 252 sizer.DetermineWindowBoundsAndShowState( |
234 gfx::Rect(), | 253 gfx::Rect(), |
235 &out_bounds, | 254 &out_bounds, |
236 &out_show_state); | 255 &out_show_state); |
237 return out_show_state; | 256 return out_show_state; |
238 } | 257 } |
239 | 258 |
240 #if !defined(OS_MACOSX) | 259 #if !defined(OS_MACOSX) |
241 TEST(WindowSizerTestCommon, PersistedWindowOffscreenWithNonAggressiveRepositioni
ng) { | 260 TEST(WindowSizerTestCommon, |
| 261 PersistedWindowOffscreenWithNonAggressiveRepositioning) { |
242 { // off the left but the minimum visibility condition is barely satisfied | 262 { // off the left but the minimum visibility condition is barely satisfied |
243 // without relocaiton. | 263 // without relocaiton. |
244 gfx::Rect initial_bounds(-470, 50, 500, 400); | 264 gfx::Rect initial_bounds(-470, 50, 500, 400); |
245 | 265 |
246 gfx::Rect window_bounds; | 266 gfx::Rect window_bounds; |
247 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), | 267 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), |
248 initial_bounds, gfx::Rect(), PERSISTED, | 268 initial_bounds, gfx::Rect(), PERSISTED, |
249 NULL, gfx::Rect(), &window_bounds); | 269 NULL, gfx::Rect(), &window_bounds); |
250 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); | 270 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
251 } | 271 } |
(...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. | 459 { // Check that a window which hangs out of the screen get moved back in. |
440 gfx::Rect window_bounds; | 460 gfx::Rect window_bounds; |
441 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), | 461 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), |
442 gfx::Rect(), DEFAULT, NULL, | 462 gfx::Rect(), DEFAULT, NULL, |
443 gfx::Rect(1020, 700, 100, 100), &window_bounds); | 463 gfx::Rect(1020, 700, 100, 100), &window_bounds); |
444 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); | 464 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
445 } | 465 } |
446 } | 466 } |
447 | 467 |
448 #endif // defined(OS_MACOSX) | 468 #endif // defined(OS_MACOSX) |
OLD | NEW |