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

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc

Issue 1900443002: Removes aura dependencies from WindowPositioner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nuke GetWorkAreaForWindowInParent and fix windows Created 4 years, 8 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 (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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/wm/window_resizer.h" 10 #include "ash/wm/window_resizer.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 20
21 #if defined(USE_AURA) 21 #if defined(USE_AURA)
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #endif 23 #endif
24 24
25 namespace { 25 namespace {
26 26
27 class TestScreen : public gfx::Screen { 27 class TestScreen : public gfx::Screen {
28 public: 28 public:
29 TestScreen() {} 29 TestScreen() : previous_screen_(gfx::Screen::GetScreen()) {
30 ~TestScreen() override {} 30 gfx::Screen::SetScreenInstance(this);
31 }
32 ~TestScreen() override { gfx::Screen::SetScreenInstance(previous_screen_); }
33
34 // Sets the index of the display returned from GetDisplayNearestWindow().
35 // Only used on aura.
36 void set_index_of_display_nearest_window(int index) {
37 index_of_display_nearest_window_ = index;
38 }
31 39
32 // Overridden from gfx::Screen: 40 // Overridden from gfx::Screen:
33 gfx::Point GetCursorScreenPoint() override { 41 gfx::Point GetCursorScreenPoint() override {
34 NOTREACHED(); 42 NOTREACHED();
35 return gfx::Point(); 43 return gfx::Point();
36 } 44 }
37 45
38 gfx::NativeWindow GetWindowUnderCursor() override { 46 gfx::NativeWindow GetWindowUnderCursor() override {
39 NOTREACHED(); 47 NOTREACHED();
40 return NULL; 48 return NULL;
41 } 49 }
42 50
43 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { 51 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
44 NOTREACHED(); 52 NOTREACHED();
45 return NULL; 53 return NULL;
46 } 54 }
47 55
48 int GetNumDisplays() const override { return displays_.size(); } 56 int GetNumDisplays() const override { return displays_.size(); }
49 57
50 std::vector<gfx::Display> GetAllDisplays() const override { 58 std::vector<gfx::Display> GetAllDisplays() const override {
51 return displays_; 59 return displays_;
52 } 60 }
53 61
54 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { 62 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override {
55 #if defined(USE_AURA) 63 #if defined(USE_AURA)
56 return GetDisplayMatching(view->GetBoundsInScreen()); 64 return displays_[index_of_display_nearest_window_];
57 #else 65 #else
58 NOTREACHED(); 66 NOTREACHED();
59 return gfx::Display(); 67 return gfx::Display();
60 #endif 68 #endif
61 } 69 }
62 70
63 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { 71 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override {
64 NOTREACHED(); 72 NOTREACHED();
65 return gfx::Display(); 73 return gfx::Display();
66 } 74 }
(...skipping 21 matching lines...) Expand all
88 void RemoveObserver(gfx::DisplayObserver* observer) override { NOTREACHED(); } 96 void RemoveObserver(gfx::DisplayObserver* observer) override { NOTREACHED(); }
89 97
90 void AddDisplay(const gfx::Rect& bounds, 98 void AddDisplay(const gfx::Rect& bounds,
91 const gfx::Rect& work_area) { 99 const gfx::Rect& work_area) {
92 gfx::Display display(displays_.size(), bounds); 100 gfx::Display display(displays_.size(), bounds);
93 display.set_work_area(work_area); 101 display.set_work_area(work_area);
94 displays_.push_back(display); 102 displays_.push_back(display);
95 } 103 }
96 104
97 private: 105 private:
106 gfx::Screen* previous_screen_;
107 size_t index_of_display_nearest_window_ = 0u;
98 std::vector<gfx::Display> displays_; 108 std::vector<gfx::Display> displays_;
99 109
100 DISALLOW_COPY_AND_ASSIGN(TestScreen); 110 DISALLOW_COPY_AND_ASSIGN(TestScreen);
101 }; 111 };
102 112
103 class TestTargetDisplayProvider : public WindowSizer::TargetDisplayProvider { 113 class TestTargetDisplayProvider : public WindowSizer::TargetDisplayProvider {
104 public: 114 public:
105 TestTargetDisplayProvider() {} 115 TestTargetDisplayProvider() {}
106 ~TestTargetDisplayProvider() override {} 116 ~TestTargetDisplayProvider() override {}
107 117
108 gfx::Display GetTargetDisplay(const gfx::Screen* screen, 118 gfx::Display GetTargetDisplay(const gfx::Screen* screen,
109 const gfx::Rect& bounds) const override { 119 const gfx::Rect& bounds) const override {
110 // On ash, the bounds is used as a indicator to specify 120 // On ash, the bounds is used as a indicator to specify
111 // the target display. 121 // the target display.
112 return screen->GetDisplayMatching(bounds); 122 return screen->GetDisplayMatching(bounds);
113 } 123 }
114 124
115 private: 125 private:
116 DISALLOW_COPY_AND_ASSIGN(TestTargetDisplayProvider); 126 DISALLOW_COPY_AND_ASSIGN(TestTargetDisplayProvider);
117 }; 127 };
118 128
119 } // namespace 129 } // namespace
120 130
121 TestStateProvider::TestStateProvider(): 131 TestStateProvider::TestStateProvider()
122 has_persistent_data_(false), 132 : has_persistent_data_(false),
123 persistent_show_state_(ui::SHOW_STATE_DEFAULT), 133 persistent_show_state_(ui::SHOW_STATE_DEFAULT),
124 has_last_active_data_(false), 134 has_last_active_data_(false),
125 last_active_show_state_(ui::SHOW_STATE_DEFAULT) { 135 last_active_show_state_(ui::SHOW_STATE_DEFAULT) {}
126 }
127 136
128 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds, 137 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds,
129 const gfx::Rect& work_area, 138 const gfx::Rect& work_area,
130 ui::WindowShowState show_state, 139 ui::WindowShowState show_state,
131 bool has_persistent_data) { 140 bool has_persistent_data) {
132 persistent_bounds_ = bounds; 141 persistent_bounds_ = bounds;
133 persistent_work_area_ = work_area; 142 persistent_work_area_ = work_area;
134 persistent_show_state_ = show_state; 143 persistent_show_state_ = show_state;
135 has_persistent_data_ = has_persistent_data; 144 has_persistent_data_ = has_persistent_data;
136 } 145 }
(...skipping 24 matching lines...) Expand all
161 DCHECK(show_state); 170 DCHECK(show_state);
162 *bounds = last_active_bounds_; 171 *bounds = last_active_bounds_;
163 if (*show_state == ui::SHOW_STATE_DEFAULT) 172 if (*show_state == ui::SHOW_STATE_DEFAULT)
164 *show_state = last_active_show_state_; 173 *show_state = last_active_show_state_;
165 return has_last_active_data_; 174 return has_last_active_data_;
166 } 175 }
167 176
168 int kWindowTilePixels = WindowSizer::kWindowTilePixels; 177 int kWindowTilePixels = WindowSizer::kWindowTilePixels;
169 178
170 // The window sizer commonly used test functions. 179 // The window sizer commonly used test functions.
171 void GetWindowBoundsAndShowState( 180 void GetWindowBoundsAndShowState(const gfx::Rect& monitor1_bounds,
172 const gfx::Rect& monitor1_bounds, 181 const gfx::Rect& monitor1_work_area,
173 const gfx::Rect& monitor1_work_area, 182 const gfx::Rect& monitor2_bounds,
174 const gfx::Rect& monitor2_bounds, 183 const gfx::Rect& bounds,
175 const gfx::Rect& bounds, 184 const gfx::Rect& work_area,
176 const gfx::Rect& work_area, 185 ui::WindowShowState show_state_persisted,
177 ui::WindowShowState show_state_persisted, 186 ui::WindowShowState show_state_last,
178 ui::WindowShowState show_state_last, 187 Source source,
179 Source source, 188 const Browser* browser,
180 const Browser* browser, 189 const gfx::Rect& passed_in,
181 const gfx::Rect& passed_in, 190 size_t display_index,
182 gfx::Rect* out_bounds, 191 gfx::Rect* out_bounds,
183 ui::WindowShowState* out_show_state) { 192 ui::WindowShowState* out_show_state) {
184 DCHECK(out_show_state); 193 DCHECK(out_show_state);
185 TestScreen test_screen; 194 TestScreen test_screen;
186 test_screen.AddDisplay(monitor1_bounds, monitor1_work_area); 195 test_screen.AddDisplay(monitor1_bounds, monitor1_work_area);
187 if (!monitor2_bounds.IsEmpty()) 196 if (!monitor2_bounds.IsEmpty())
188 test_screen.AddDisplay(monitor2_bounds, monitor2_bounds); 197 test_screen.AddDisplay(monitor2_bounds, monitor2_bounds);
198 test_screen.set_index_of_display_nearest_window(display_index);
189 std::unique_ptr<TestStateProvider> sp(new TestStateProvider); 199 std::unique_ptr<TestStateProvider> sp(new TestStateProvider);
190 if (source == PERSISTED || source == BOTH) 200 if (source == PERSISTED || source == BOTH)
191 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); 201 sp->SetPersistentState(bounds, work_area, show_state_persisted, true);
192 if (source == LAST_ACTIVE || source == BOTH) 202 if (source == LAST_ACTIVE || source == BOTH)
193 sp->SetLastActiveState(bounds, show_state_last, true); 203 sp->SetLastActiveState(bounds, show_state_last, true);
194 std::unique_ptr<WindowSizer::TargetDisplayProvider> tdp( 204 std::unique_ptr<WindowSizer::TargetDisplayProvider> tdp(
195 new TestTargetDisplayProvider); 205 new TestTargetDisplayProvider);
196 206
197 WindowSizer sizer(std::move(sp), std::move(tdp), &test_screen, browser); 207 WindowSizer sizer(std::move(sp), std::move(tdp), &test_screen, browser);
198 sizer.DetermineWindowBoundsAndShowState(passed_in, 208 sizer.DetermineWindowBoundsAndShowState(passed_in,
199 out_bounds, 209 out_bounds,
200 out_show_state); 210 out_show_state);
201 } 211 }
202
203 void GetWindowBounds(const gfx::Rect& monitor1_bounds, 212 void GetWindowBounds(const gfx::Rect& monitor1_bounds,
204 const gfx::Rect& monitor1_work_area, 213 const gfx::Rect& monitor1_work_area,
205 const gfx::Rect& monitor2_bounds, 214 const gfx::Rect& monitor2_bounds,
206 const gfx::Rect& bounds, 215 const gfx::Rect& bounds,
207 const gfx::Rect& work_area, 216 const gfx::Rect& work_area,
208 Source source, 217 Source source,
209 const Browser* browser, 218 const Browser* browser,
210 const gfx::Rect& passed_in, 219 const gfx::Rect& passed_in,
211 gfx::Rect* out_bounds) { 220 gfx::Rect* out_bounds) {
212 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; 221 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT;
213 GetWindowBoundsAndShowState( 222 GetWindowBoundsAndShowState(
214 monitor1_bounds, monitor1_work_area, monitor2_bounds, bounds, work_area, 223 monitor1_bounds, monitor1_work_area, monitor2_bounds, bounds, work_area,
215 ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_DEFAULT, source, browser, 224 ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_DEFAULT, source, browser,
216 passed_in, out_bounds, &out_show_state); 225 passed_in, 0u, out_bounds, &out_show_state);
217 } 226 }
218 227
219 ui::WindowShowState GetWindowShowState( 228 ui::WindowShowState GetWindowShowState(
220 ui::WindowShowState show_state_persisted, 229 ui::WindowShowState show_state_persisted,
221 ui::WindowShowState show_state_last, 230 ui::WindowShowState show_state_last,
222 Source source, 231 Source source,
223 const Browser* browser, 232 const Browser* browser,
224 const gfx::Rect& bounds, 233 const gfx::Rect& bounds,
225 const gfx::Rect& display_config) { 234 const gfx::Rect& display_config) {
226 TestScreen test_screen; 235 TestScreen test_screen;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 { // Check that a window which hangs out of the screen get moved back in. 456 { // Check that a window which hangs out of the screen get moved back in.
448 gfx::Rect window_bounds; 457 gfx::Rect window_bounds;
449 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), 458 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(),
450 gfx::Rect(), DEFAULT, NULL, 459 gfx::Rect(), DEFAULT, NULL,
451 gfx::Rect(1020, 700, 100, 100), &window_bounds); 460 gfx::Rect(1020, 700, 100, 100), &window_bounds);
452 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); 461 EXPECT_EQ("924,668 100x100", window_bounds.ToString());
453 } 462 }
454 } 463 }
455 464
456 #endif // defined(OS_MACOSX) 465 #endif // defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_sizer/window_sizer_common_unittest.h ('k') | ui/platform_window/win/win_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698