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

Side by Side Diff: panels/panel_test.cc

Issue 6902072: wm: Update a lot of code to use structs from geometry.h. (Closed) Base URL: ssh://gitrw.chromium.org:9222/window_manager.git@master
Patch Set: move override-redirect stacking and visibility into Window Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <gflags/gflags.h> 5 #include <gflags/gflags.h>
6 #include <gtest/gtest.h> 6 #include <gtest/gtest.h>
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "window_manager/compositor/compositor.h" 10 #include "window_manager/compositor/compositor.h"
(...skipping 20 matching lines...) Expand all
31 protected: 31 protected:
32 virtual void SetUp() { 32 virtual void SetUp() {
33 BasicWindowManagerTest::SetUp(); 33 BasicWindowManagerTest::SetUp();
34 panel_manager_ = wm_->panel_manager_.get(); 34 panel_manager_ = wm_->panel_manager_.get();
35 } 35 }
36 36
37 PanelManager* panel_manager_; // instance belonging to |wm_| 37 PanelManager* panel_manager_; // instance belonging to |wm_|
38 }; 38 };
39 39
40 TEST_F(PanelTest, InputWindows) { 40 TEST_F(PanelTest, InputWindows) {
41 XWindow titlebar_xid = CreatePanelTitlebarWindow(200, 20); 41 XWindow titlebar_xid = CreatePanelTitlebarWindow(Size(200, 20));
42 XConnection::WindowGeometry geometry; 42 XConnection::WindowGeometry geometry;
43 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry)); 43 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry));
44 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry); 44 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry);
45 MockXConnection::WindowInfo* titlebar_info = 45 MockXConnection::WindowInfo* titlebar_info =
46 xconn_->GetWindowInfoOrDie(titlebar_xid); 46 xconn_->GetWindowInfoOrDie(titlebar_xid);
47 47
48 XWindow content_xid = CreatePanelContentWindow(200, 400, titlebar_xid); 48 XWindow content_xid = CreatePanelContentWindow(Size(200, 400), titlebar_xid);
49 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry)); 49 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry));
50 Window content_win(wm_.get(), content_xid, false, geometry); 50 Window content_win(wm_.get(), content_xid, false, geometry);
51 MockXConnection::WindowInfo* content_info = 51 MockXConnection::WindowInfo* content_info =
52 xconn_->GetWindowInfoOrDie(content_xid); 52 xconn_->GetWindowInfoOrDie(content_xid);
53 53
54 // Create a panel. 54 // Create a panel.
55 Panel panel(panel_manager_, &content_win, &titlebar_win, true); 55 Panel panel(panel_manager_, &content_win, &titlebar_win, true);
56 panel.SetResizable(true); 56 panel.SetResizable(true);
57 panel.Move(0, 0, 0); 57 panel.Move(Point(0, 0), 0);
58 58
59 // Restack the panel and check that its titlebar is stacked above the 59 // Restack the panel and check that its titlebar is stacked above the
60 // content window, and that the content window is above all of the input 60 // content window, and that the content window is above all of the input
61 // windows used for resizing. 61 // windows used for resizing.
62 panel.StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_BAR); 62 panel.StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_BAR);
63 EXPECT_LT(xconn_->stacked_xids().GetIndex(titlebar_xid), 63 EXPECT_LT(xconn_->stacked_xids().GetIndex(titlebar_xid),
64 xconn_->stacked_xids().GetIndex(content_xid)); 64 xconn_->stacked_xids().GetIndex(content_xid));
65 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid), 65 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid),
66 xconn_->stacked_xids().GetIndex(panel.top_input_xid_)); 66 xconn_->stacked_xids().GetIndex(panel.top_input_xid_));
67 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid), 67 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid), 148 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid),
149 xconn_->stacked_xids().GetIndex(panel.left_input_xid_)); 149 xconn_->stacked_xids().GetIndex(panel.left_input_xid_));
150 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid), 150 EXPECT_LT(xconn_->stacked_xids().GetIndex(content_xid),
151 xconn_->stacked_xids().GetIndex(panel.right_input_xid_)); 151 xconn_->stacked_xids().GetIndex(panel.right_input_xid_));
152 } 152 }
153 153
154 TEST_F(PanelTest, Resize) { 154 TEST_F(PanelTest, Resize) {
155 int orig_width = 200; 155 int orig_width = 200;
156 int orig_titlebar_height = 20; 156 int orig_titlebar_height = 20;
157 XWindow titlebar_xid = 157 XWindow titlebar_xid =
158 CreatePanelTitlebarWindow(orig_width, orig_titlebar_height); 158 CreatePanelTitlebarWindow(Size(orig_width, orig_titlebar_height));
159 XConnection::WindowGeometry geometry; 159 XConnection::WindowGeometry geometry;
160 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry)); 160 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry));
161 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry); 161 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry);
162 MockXConnection::WindowInfo* titlebar_info = 162 MockXConnection::WindowInfo* titlebar_info =
163 xconn_->GetWindowInfoOrDie(titlebar_xid); 163 xconn_->GetWindowInfoOrDie(titlebar_xid);
164 164
165 int orig_content_height = 400; 165 int orig_content_height = 400;
166 XWindow content_xid = CreatePanelContentWindow( 166 XWindow content_xid = CreatePanelContentWindow(
167 orig_width, orig_content_height, titlebar_xid); 167 Size(orig_width, orig_content_height), titlebar_xid);
168 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry)); 168 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry));
169 Window content_win(wm_.get(), content_xid, false, geometry); 169 Window content_win(wm_.get(), content_xid, false, geometry);
170 MockXConnection::WindowInfo* content_info = 170 MockXConnection::WindowInfo* content_info =
171 xconn_->GetWindowInfoOrDie(content_xid); 171 xconn_->GetWindowInfoOrDie(content_xid);
172 172
173 // Create a panel. 173 // Create a panel.
174 Panel panel(panel_manager_, &content_win, &titlebar_win, true); 174 Panel panel(panel_manager_, &content_win, &titlebar_win, true);
175 panel.SetResizable(true); 175 panel.SetResizable(true);
176 panel.Move(0, 0, 0); 176 panel.Move(Point(0, 0), 0);
177 177
178 // Check that one of the panel's resize handles has an asynchronous grab 178 // Check that one of the panel's resize handles has an asynchronous grab
179 // installed on the first mouse button. 179 // installed on the first mouse button.
180 MockXConnection::WindowInfo* handle_info = 180 MockXConnection::WindowInfo* handle_info =
181 xconn_->GetWindowInfoOrDie(panel.top_left_input_xid_); 181 xconn_->GetWindowInfoOrDie(panel.top_left_input_xid_);
182 EXPECT_TRUE(handle_info->button_is_grabbed(1)); 182 EXPECT_TRUE(handle_info->button_is_grabbed(1));
183 EXPECT_EQ(ButtonPressMask | ButtonReleaseMask | PointerMotionMask, 183 EXPECT_EQ(ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
184 handle_info->button_grabs[1].event_mask); 184 handle_info->button_grabs[1].event_mask);
185 EXPECT_FALSE(handle_info->button_grabs[1].synchronous); 185 EXPECT_FALSE(handle_info->button_grabs[1].synchronous);
186 186
187 // Pretend like the top left handle was clicked and a pointer grab was 187 // Pretend like the top left handle was clicked and a pointer grab was
188 // automatically installed. 188 // automatically installed.
189 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_); 189 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_);
190 panel.HandleInputWindowButtonPress( 190 panel.HandleInputWindowButtonPress(
191 panel.top_left_input_xid_, 191 panel.top_left_input_xid_, Point(0, 0), 1, CurrentTime);
192 0, 0, // relative x, y
193 1, // button
194 CurrentTime);
195 192
196 // Pretend like the second button is pressed and the first button is 193 // Pretend like the second button is pressed and the first button is
197 // released. We should explicitly ungrab the pointer when we see the 194 // released. We should explicitly ungrab the pointer when we see the
198 // first button get released; X will only automatically remove the 195 // first button get released; X will only automatically remove the
199 // pointer grab when *all* buttons are released. 196 // pointer grab when *all* buttons are released.
200 panel.HandleInputWindowButtonPress( 197 panel.HandleInputWindowButtonPress(
201 panel.top_left_input_xid_, 0, 0, 2, CurrentTime); 198 panel.top_left_input_xid_, Point(0, 0), 2, CurrentTime);
202 panel.HandleInputWindowButtonRelease( 199 panel.HandleInputWindowButtonRelease(
203 panel.top_left_input_xid_, 0, 0, 1, CurrentTime); 200 panel.top_left_input_xid_, Point(0, 0), 1, CurrentTime);
204 EXPECT_EQ(0, xconn_->pointer_grab_xid()); 201 EXPECT_EQ(0, xconn_->pointer_grab_xid());
205 202
206 // Release the second button too, not that it really matters to us. 203 // Release the second button too, not that it really matters to us.
207 panel.HandleInputWindowButtonRelease( 204 panel.HandleInputWindowButtonRelease(
208 panel.top_left_input_xid_, 0, 0, 2, CurrentTime); 205 panel.top_left_input_xid_, Point(0, 0), 2, CurrentTime);
209 206
210 // Check that the panel's dimensions are unchanged. 207 // Check that the panel's dimensions are unchanged.
211 EXPECT_EQ(orig_width, titlebar_info->bounds.width); 208 EXPECT_EQ(orig_width, titlebar_info->bounds.width);
212 EXPECT_EQ(orig_titlebar_height, titlebar_info->bounds.height); 209 EXPECT_EQ(orig_titlebar_height, titlebar_info->bounds.height);
213 EXPECT_EQ(orig_width, content_info->bounds.width); 210 EXPECT_EQ(orig_width, content_info->bounds.width);
214 EXPECT_EQ(orig_content_height, content_info->bounds.height); 211 EXPECT_EQ(orig_content_height, content_info->bounds.height);
215 212
216 int initial_x = titlebar_info->bounds.x; 213 int initial_x = titlebar_info->bounds.x;
217 EXPECT_EQ(initial_x, content_info->bounds.x); 214 EXPECT_EQ(initial_x, content_info->bounds.x);
218 int initial_titlebar_y = titlebar_info->bounds.y; 215 int initial_titlebar_y = titlebar_info->bounds.y;
219 EXPECT_EQ(initial_titlebar_y + titlebar_info->bounds.height, 216 EXPECT_EQ(initial_titlebar_y + titlebar_info->bounds.height,
220 content_info->bounds.y); 217 content_info->bounds.y);
221 218
222 // Now start a second resize using the upper-left handle. Drag a few 219 // Now start a second resize using the upper-left handle. Drag a few
223 // pixels up and to the left and then let go of the button. 220 // pixels up and to the left and then let go of the button.
224 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_); 221 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_);
225 panel.HandleInputWindowButtonPress( 222 panel.HandleInputWindowButtonPress(
226 panel.top_left_input_xid_, 0, 0, 1, CurrentTime); 223 panel.top_left_input_xid_, Point(0, 0), 1, CurrentTime);
227 EXPECT_EQ(panel.top_left_input_xid_, xconn_->pointer_grab_xid()); 224 EXPECT_EQ(panel.top_left_input_xid_, xconn_->pointer_grab_xid());
228 panel.HandleInputWindowPointerMotion(panel.top_left_input_xid_, -2, -4); 225 panel.HandleInputWindowPointerMotion(
226 panel.top_left_input_xid_, Point(-2, -4));
229 xconn_->set_pointer_grab_xid(None); 227 xconn_->set_pointer_grab_xid(None);
230 panel.HandleInputWindowButtonRelease( 228 panel.HandleInputWindowButtonRelease(
231 panel.top_left_input_xid_, -5, -6, 1, CurrentTime); 229 panel.top_left_input_xid_, Point(-5, -6), 1, CurrentTime);
232 230
233 // The titlebar should be offset by the drag and made a bit wider. 231 // The titlebar should be offset by the drag and made a bit wider.
234 EXPECT_EQ(initial_x - 5, titlebar_info->bounds.x); 232 EXPECT_EQ(initial_x - 5, titlebar_info->bounds.x);
235 EXPECT_EQ(initial_titlebar_y - 6, titlebar_info->bounds.y); 233 EXPECT_EQ(initial_titlebar_y - 6, titlebar_info->bounds.y);
236 EXPECT_EQ(orig_width + 5, titlebar_info->bounds.width); 234 EXPECT_EQ(orig_width + 5, titlebar_info->bounds.width);
237 EXPECT_EQ(orig_titlebar_height, titlebar_info->bounds.height); 235 EXPECT_EQ(orig_titlebar_height, titlebar_info->bounds.height);
238 236
239 // The panel should move along with its titlebar, and it should get wider 237 // The panel should move along with its titlebar, and it should get wider
240 // and taller by the amount of the drag. 238 // and taller by the amount of the drag.
241 EXPECT_EQ(initial_x - 5, content_info->bounds.x); 239 EXPECT_EQ(initial_x - 5, content_info->bounds.x);
242 EXPECT_EQ(titlebar_info->bounds.y + titlebar_info->bounds.height, 240 EXPECT_EQ(titlebar_info->bounds.y + titlebar_info->bounds.height,
243 content_info->bounds.y); 241 content_info->bounds.y);
244 EXPECT_EQ(orig_width + 5, content_info->bounds.width); 242 EXPECT_EQ(orig_width + 5, content_info->bounds.width);
245 EXPECT_EQ(orig_content_height + 6, content_info->bounds.height); 243 EXPECT_EQ(orig_content_height + 6, content_info->bounds.height);
246 } 244 }
247 245
248 // Test that the _CHROME_STATE property is updated correctly to reflect the 246 // Test that the _CHROME_STATE property is updated correctly to reflect the
249 // panel's expanded/collapsed state. 247 // panel's expanded/collapsed state.
250 TEST_F(PanelTest, ChromeState) { 248 TEST_F(PanelTest, ChromeState) {
251 XAtom state_atom = xconn_->GetAtomOrDie("_CHROME_STATE"); 249 XAtom state_atom = xconn_->GetAtomOrDie("_CHROME_STATE");
252 XAtom collapsed_atom = xconn_->GetAtomOrDie("_CHROME_STATE_COLLAPSED_PANEL"); 250 XAtom collapsed_atom = xconn_->GetAtomOrDie("_CHROME_STATE_COLLAPSED_PANEL");
253 251
254 // Create a collapsed panel. 252 // Create a collapsed panel.
255 XWindow titlebar_xid = CreatePanelTitlebarWindow(200, 20); 253 XWindow titlebar_xid = CreatePanelTitlebarWindow(Size(200, 20));
256 XConnection::WindowGeometry geometry; 254 XConnection::WindowGeometry geometry;
257 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry)); 255 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry));
258 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry); 256 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry);
259 new_panels_should_be_expanded_ = false; 257 new_panels_should_be_expanded_ = false;
260 new_panels_should_take_focus_ = false; 258 new_panels_should_take_focus_ = false;
261 XWindow content_xid = CreatePanelContentWindow(200, 400, titlebar_xid); 259 XWindow content_xid = CreatePanelContentWindow(Size(200, 400), titlebar_xid);
262 MockXConnection::WindowInfo* content_info = 260 MockXConnection::WindowInfo* content_info =
263 xconn_->GetWindowInfoOrDie(content_xid); 261 xconn_->GetWindowInfoOrDie(content_xid);
264 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry)); 262 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry));
265 Window content_win(wm_.get(), content_xid, false, geometry); 263 Window content_win(wm_.get(), content_xid, false, geometry);
266 Panel panel(panel_manager_, &content_win, &titlebar_win, false); 264 Panel panel(panel_manager_, &content_win, &titlebar_win, false);
267 panel.Move(0, 0, 0); 265 panel.Move(Point(0, 0), 0);
268 266
269 // The panel's content window should have have a collapsed state in 267 // The panel's content window should have have a collapsed state in
270 // _CHROME_STATE initially (since we told it to start collapsed). 268 // _CHROME_STATE initially (since we told it to start collapsed).
271 EXPECT_FALSE(panel.is_expanded()); 269 EXPECT_FALSE(panel.is_expanded());
272 vector<int> values; 270 vector<int> values;
273 ASSERT_TRUE(xconn_->GetIntArrayProperty(content_xid, state_atom, &values)); 271 ASSERT_TRUE(xconn_->GetIntArrayProperty(content_xid, state_atom, &values));
274 ASSERT_EQ(1, values.size()); 272 ASSERT_EQ(1, values.size());
275 EXPECT_EQ(collapsed_atom, values[0]); 273 EXPECT_EQ(collapsed_atom, values[0]);
276 274
277 // We should also send a message to the panel telling it about the 275 // We should also send a message to the panel telling it about the
(...skipping 24 matching lines...) Expand all
302 panel.SetExpandedState(false); 300 panel.SetExpandedState(false);
303 values.clear(); 301 values.clear();
304 ASSERT_TRUE(xconn_->GetIntArrayProperty(content_xid, state_atom, &values)); 302 ASSERT_TRUE(xconn_->GetIntArrayProperty(content_xid, state_atom, &values));
305 ASSERT_EQ(1, values.size()); 303 ASSERT_EQ(1, values.size());
306 EXPECT_EQ(collapsed_atom, values[0]); 304 EXPECT_EQ(collapsed_atom, values[0]);
307 } 305 }
308 306
309 // Test that we're able to hide panels' shadows. 307 // Test that we're able to hide panels' shadows.
310 TEST_F(PanelTest, Shadows) { 308 TEST_F(PanelTest, Shadows) {
311 // Create a collapsed panel. 309 // Create a collapsed panel.
312 XWindow titlebar_xid = CreatePanelTitlebarWindow(200, 20); 310 XWindow titlebar_xid = CreatePanelTitlebarWindow(Size(200, 20));
313 ASSERT_TRUE(xconn_->MapWindow(titlebar_xid)); 311 ASSERT_TRUE(xconn_->MapWindow(titlebar_xid));
314 XConnection::WindowGeometry geometry; 312 XConnection::WindowGeometry geometry;
315 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry)); 313 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry));
316 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry); 314 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry);
317 titlebar_win.HandleMapNotify(); 315 titlebar_win.HandleMapNotify();
318 316
319 new_panels_should_be_expanded_ = false; 317 new_panels_should_be_expanded_ = false;
320 new_panels_should_take_focus_ = false; 318 new_panels_should_take_focus_ = false;
321 XWindow content_xid = CreatePanelContentWindow(200, 400, titlebar_xid); 319 XWindow content_xid = CreatePanelContentWindow(Size(200, 400), titlebar_xid);
322 ASSERT_TRUE(xconn_->MapWindow(content_xid)); 320 ASSERT_TRUE(xconn_->MapWindow(content_xid));
323 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry)); 321 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry));
324 Window content_win(wm_.get(), content_xid, false, geometry); 322 Window content_win(wm_.get(), content_xid, false, geometry);
325 content_win.HandleMapNotify(); 323 content_win.HandleMapNotify();
326 324
327 Panel panel(panel_manager_, &content_win, &titlebar_win, true); 325 Panel panel(panel_manager_, &content_win, &titlebar_win, true);
328 panel.Move(0, 0, 0); 326 panel.Move(Point(0, 0), 0);
329 327
330 // Check that Panel's constructor enabled shadows for both windows. 328 // Check that Panel's constructor enabled shadows for both windows.
331 ASSERT_TRUE(titlebar_win.shadow() != NULL); 329 ASSERT_TRUE(titlebar_win.shadow() != NULL);
332 ASSERT_TRUE(content_win.shadow() != NULL); 330 ASSERT_TRUE(content_win.shadow() != NULL);
333 331
334 // Both the titlebar and content windows' shadows should be visible 332 // Both the titlebar and content windows' shadows should be visible
335 // initially. 333 // initially.
336 EXPECT_TRUE(titlebar_win.shadow()->is_shown()); 334 EXPECT_TRUE(titlebar_win.shadow()->is_shown());
337 EXPECT_TRUE(content_win.shadow()->is_shown()); 335 EXPECT_TRUE(content_win.shadow()->is_shown());
338 EXPECT_DOUBLE_EQ(1.0, titlebar_win.shadow()->opacity()); 336 EXPECT_DOUBLE_EQ(1.0, titlebar_win.shadow()->opacity());
339 EXPECT_DOUBLE_EQ(1.0, content_win.shadow()->opacity()); 337 EXPECT_DOUBLE_EQ(1.0, content_win.shadow()->opacity());
340 338
341 // Now tell the panel to hide the content shadow. 339 // Now tell the panel to hide the content shadow.
342 panel.SetShadowOpacity(0, 0); 340 panel.SetShadowOpacity(0, 0);
343 EXPECT_TRUE(titlebar_win.shadow()->is_shown()); 341 EXPECT_TRUE(titlebar_win.shadow()->is_shown());
344 EXPECT_TRUE(content_win.shadow()->is_shown()); 342 EXPECT_TRUE(content_win.shadow()->is_shown());
345 EXPECT_DOUBLE_EQ(0.0, titlebar_win.shadow()->opacity()); 343 EXPECT_DOUBLE_EQ(0.0, titlebar_win.shadow()->opacity());
346 EXPECT_DOUBLE_EQ(0.0, content_win.shadow()->opacity()); 344 EXPECT_DOUBLE_EQ(0.0, content_win.shadow()->opacity());
347 } 345 }
348 346
349 // Test that we don't let panels get smaller than the minimal allowed size. 347 // Test that we don't let panels get smaller than the minimal allowed size.
350 TEST_F(PanelTest, SizeLimits) { 348 TEST_F(PanelTest, SizeLimits) {
351 // Create a panel with a really small (20x20) content window. 349 // Create a panel with a really small (20x20) content window.
352 XWindow titlebar_xid = CreatePanelTitlebarWindow(200, 20); 350 XWindow titlebar_xid = CreatePanelTitlebarWindow(Size(200, 20));
353 XConnection::WindowGeometry geometry; 351 XConnection::WindowGeometry geometry;
354 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry)); 352 ASSERT_TRUE(xconn_->GetWindowGeometry(titlebar_xid, &geometry));
355 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry); 353 Window titlebar_win(wm_.get(), titlebar_xid, false, geometry);
356 XWindow content_xid = CreatePanelContentWindow(20, 20, titlebar_xid); 354 XWindow content_xid = CreatePanelContentWindow(Size(20, 20), titlebar_xid);
357 MockXConnection::WindowInfo* content_info = 355 MockXConnection::WindowInfo* content_info =
358 xconn_->GetWindowInfoOrDie(content_xid); 356 xconn_->GetWindowInfoOrDie(content_xid);
359 content_info->size_hints.min_size.reset(150, 100); 357 content_info->size_hints.min_size.reset(150, 100);
360 content_info->size_hints.max_size.reset(300, 250); 358 content_info->size_hints.max_size.reset(300, 250);
361 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry)); 359 ASSERT_TRUE(xconn_->GetWindowGeometry(content_xid, &geometry));
362 Window content_win(wm_.get(), content_xid, false, geometry); 360 Window content_win(wm_.get(), content_xid, false, geometry);
363 361
364 // The content window should've been resized to the minimum size. 362 // The content window should've been resized to the minimum size.
365 Panel panel(panel_manager_, &content_win, &titlebar_win, true); 363 Panel panel(panel_manager_, &content_win, &titlebar_win, true);
366 EXPECT_EQ(content_info->size_hints.min_size.width, 364 EXPECT_EQ(content_info->size_hints.min_size.width,
367 content_win.client_width()); 365 content_win.client_width());
368 EXPECT_EQ(content_info->size_hints.min_size.height, 366 EXPECT_EQ(content_info->size_hints.min_size.height,
369 content_win.client_height()); 367 content_win.client_height());
370 368
371 // Drag the upper-left resize handle down and to the right. 369 // Drag the upper-left resize handle down and to the right.
372 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_); 370 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_);
373 panel.HandleInputWindowButtonPress( 371 panel.HandleInputWindowButtonPress(
374 panel.top_left_input_xid_, 0, 0, 1, CurrentTime); 372 panel.top_left_input_xid_, Point(0, 0), 1, CurrentTime);
375 panel.HandleInputWindowPointerMotion(panel.top_left_input_xid_, 5, 5); 373 panel.HandleInputWindowPointerMotion(panel.top_left_input_xid_, Point(5, 5));
376 xconn_->set_pointer_grab_xid(None); 374 xconn_->set_pointer_grab_xid(None);
377 panel.HandleInputWindowButtonRelease( 375 panel.HandleInputWindowButtonRelease(
378 panel.top_left_input_xid_, 5, 5, 1, CurrentTime); 376 panel.top_left_input_xid_, Point(5, 5), 1, CurrentTime);
379 377
380 // The content window size should be unchanged, since we tried to make it 378 // The content window size should be unchanged, since we tried to make it
381 // smaller while it was already at the minimum. 379 // smaller while it was already at the minimum.
382 EXPECT_EQ(content_info->size_hints.min_size.width, 380 EXPECT_EQ(content_info->size_hints.min_size.width,
383 content_win.client_width()); 381 content_win.client_width());
384 EXPECT_EQ(content_info->size_hints.min_size.height, 382 EXPECT_EQ(content_info->size_hints.min_size.height,
385 content_win.client_height()); 383 content_win.client_height());
386 384
387 // Now drag the handle up and to the left and check that we restrict the 385 // Now drag the handle up and to the left and check that we restrict the
388 // content window to the max size. 386 // content window to the max size.
389 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_); 387 xconn_->set_pointer_grab_xid(panel.top_left_input_xid_);
390 panel.HandleInputWindowButtonPress( 388 panel.HandleInputWindowButtonPress(
391 panel.top_left_input_xid_, 0, 0, 1, CurrentTime); 389 panel.top_left_input_xid_, Point(0, 0), 1, CurrentTime);
392 panel.HandleInputWindowPointerMotion(panel.top_left_input_xid_, -300, -300); 390 panel.HandleInputWindowPointerMotion(
391 panel.top_left_input_xid_, Point(-300, -300));
393 xconn_->set_pointer_grab_xid(None); 392 xconn_->set_pointer_grab_xid(None);
394 panel.HandleInputWindowButtonRelease( 393 panel.HandleInputWindowButtonRelease(
395 panel.top_left_input_xid_, -300, -300, 1, CurrentTime); 394 panel.top_left_input_xid_, Point(-300, -300), 1, CurrentTime);
396 EXPECT_EQ(content_info->size_hints.max_size.width, 395 EXPECT_EQ(content_info->size_hints.max_size.width,
397 content_win.client_width()); 396 content_win.client_width());
398 EXPECT_EQ(content_info->size_hints.max_size.height, 397 EXPECT_EQ(content_info->size_hints.max_size.height,
399 content_win.client_height()); 398 content_win.client_height());
400 399
401 // Now tell the panel to make the content window bigger or smaller (this 400 // Now tell the panel to make the content window bigger or smaller (this
402 // is the path that gets taken when we get a ConfigureRequest). These 401 // is the path that gets taken when we get a ConfigureRequest). These
403 // requests should be capped as well. 402 // requests should be capped as well.
404 panel.ResizeContent(500, 500, GRAVITY_SOUTHEAST, true); 403 panel.ResizeContent(Size(500, 500), GRAVITY_SOUTHEAST, true);
405 EXPECT_EQ(content_info->size_hints.max_size.width, 404 EXPECT_EQ(content_info->size_hints.max_size.width,
406 content_win.client_width()); 405 content_win.client_width());
407 EXPECT_EQ(content_info->size_hints.max_size.height, 406 EXPECT_EQ(content_info->size_hints.max_size.height,
408 content_win.client_height()); 407 content_win.client_height());
409 panel.ResizeContent(50, 50, GRAVITY_SOUTHEAST, true); 408 panel.ResizeContent(Size(50, 50), GRAVITY_SOUTHEAST, true);
410 EXPECT_EQ(content_info->size_hints.min_size.width, 409 EXPECT_EQ(content_info->size_hints.min_size.width,
411 content_win.client_width()); 410 content_win.client_width());
412 EXPECT_EQ(content_info->size_hints.min_size.height, 411 EXPECT_EQ(content_info->size_hints.min_size.height,
413 content_win.client_height()); 412 content_win.client_height());
414 } 413 }
415 414
416 // Check that the resize input windows get configured correctly depending 415 // Check that the resize input windows get configured correctly depending
417 // on the the panel's user-resizable parameter. 416 // on the the panel's user-resizable parameter.
418 TEST_F(PanelTest, ResizeParameter) { 417 TEST_F(PanelTest, ResizeParameter) {
419 // If we create a panel that's only vertically-resizable, the top input 418 // If we create a panel that's only vertically-resizable, the top input
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // separator between a panel's titlebar and content windows. 472 // separator between a panel's titlebar and content windows.
474 TEST_F(PanelTest, SeparatorShadow) { 473 TEST_F(PanelTest, SeparatorShadow) {
475 const int kWidth = 200; 474 const int kWidth = 200;
476 const int kTitlebarHeight = 20; 475 const int kTitlebarHeight = 20;
477 const int kContentHeight = 300; 476 const int kContentHeight = 300;
478 MockCompositor::StageActor* stage = compositor_->GetDefaultStage(); 477 MockCompositor::StageActor* stage = compositor_->GetDefaultStage();
479 Panel* panel = CreatePanel(kWidth, kTitlebarHeight, kContentHeight); 478 Panel* panel = CreatePanel(kWidth, kTitlebarHeight, kContentHeight);
480 479
481 // Check that the separator shadow is scaled across the top of the 480 // Check that the separator shadow is scaled across the top of the
482 // content window. 481 // content window.
483 panel->Move(0, 0, 0); 482 panel->Move(Point(0, 0), 0);
484 EXPECT_EQ(panel->content_win_->composited_x(), 483 EXPECT_EQ(panel->content_win_->composited_x(),
485 panel->separator_shadow_->x()); 484 panel->separator_shadow_->x());
486 EXPECT_EQ(panel->content_win_->composited_y(), 485 EXPECT_EQ(panel->content_win_->composited_y(),
487 panel->separator_shadow_->y()); 486 panel->separator_shadow_->y());
488 EXPECT_EQ(panel->content_win_->client_width(), 487 EXPECT_EQ(panel->content_win_->client_width(),
489 panel->separator_shadow_->width()); 488 panel->separator_shadow_->width());
490 EXPECT_EQ(0, panel->separator_shadow_->height()); 489 EXPECT_EQ(0, panel->separator_shadow_->height());
491 490
492 // When we move the panel, the shadow should get moved along with it. 491 // When we move the panel, the shadow should get moved along with it.
493 panel->Move(50, 100, 0); 492 panel->Move(Point(50, 100), 0);
494 EXPECT_EQ(panel->content_win_->composited_x(), 493 EXPECT_EQ(panel->content_win_->composited_x(),
495 panel->separator_shadow_->x()); 494 panel->separator_shadow_->x());
496 EXPECT_EQ(panel->content_win_->composited_y(), 495 EXPECT_EQ(panel->content_win_->composited_y(),
497 panel->separator_shadow_->y()); 496 panel->separator_shadow_->y());
498 EXPECT_EQ(panel->content_win_->client_width(), 497 EXPECT_EQ(panel->content_win_->client_width(),
499 panel->separator_shadow_->width()); 498 panel->separator_shadow_->width());
500 EXPECT_EQ(0, panel->separator_shadow_->height()); 499 EXPECT_EQ(0, panel->separator_shadow_->height());
501 500
502 // Check that the separator shadow is stacked between the titlebar and 501 // Check that the separator shadow is stacked between the titlebar and
503 // the content. 502 // the content.
504 panel->StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_BAR); 503 panel->StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_BAR);
505 EXPECT_LT(stage->GetStackingIndex(panel->titlebar_win_->actor()), 504 EXPECT_LT(stage->GetStackingIndex(panel->titlebar_win_->actor()),
506 stage->GetStackingIndex(panel->separator_shadow_->group())); 505 stage->GetStackingIndex(panel->separator_shadow_->group()));
507 EXPECT_LT(stage->GetStackingIndex(panel->separator_shadow_->group()), 506 EXPECT_LT(stage->GetStackingIndex(panel->separator_shadow_->group()),
508 stage->GetStackingIndex(panel->content_win_->actor())); 507 stage->GetStackingIndex(panel->content_win_->actor()));
509 508
510 // The shadow should get restacked along with the panel. 509 // The shadow should get restacked along with the panel.
511 panel->StackAtTopOfLayer(StackingManager::LAYER_DRAGGED_PANEL); 510 panel->StackAtTopOfLayer(StackingManager::LAYER_DRAGGED_PANEL);
512 EXPECT_LT(stage->GetStackingIndex(panel->titlebar_win_->actor()), 511 EXPECT_LT(stage->GetStackingIndex(panel->titlebar_win_->actor()),
513 stage->GetStackingIndex(panel->separator_shadow_->group())); 512 stage->GetStackingIndex(panel->separator_shadow_->group()));
514 EXPECT_LT(stage->GetStackingIndex(panel->separator_shadow_->group()), 513 EXPECT_LT(stage->GetStackingIndex(panel->separator_shadow_->group()),
515 stage->GetStackingIndex(panel->content_win_->actor())); 514 stage->GetStackingIndex(panel->content_win_->actor()));
516 515
517 // Check that the shadow is moved correctly in response to resizes where 516 // Check that the shadow is moved correctly in response to resizes where
518 // a corner other than the top left one is fixed. 517 // a corner other than the top left one is fixed.
519 int new_width = 100; 518 int new_width = 100;
520 panel->ResizeContent(new_width, 200, GRAVITY_SOUTHEAST, true); 519 panel->ResizeContent(Size(new_width, 200), GRAVITY_SOUTHEAST, true);
521 EXPECT_EQ(panel->content_win_->composited_x(), 520 EXPECT_EQ(panel->content_win_->composited_x(),
522 panel->separator_shadow_->x()); 521 panel->separator_shadow_->x());
523 EXPECT_EQ(panel->content_win_->composited_y(), 522 EXPECT_EQ(panel->content_win_->composited_y(),
524 panel->separator_shadow_->y()); 523 panel->separator_shadow_->y());
525 EXPECT_EQ(panel->content_win_->client_width(), 524 EXPECT_EQ(panel->content_win_->client_width(),
526 panel->separator_shadow_->width()); 525 panel->separator_shadow_->width());
527 EXPECT_EQ(0, panel->separator_shadow_->height()); 526 EXPECT_EQ(0, panel->separator_shadow_->height());
528 527
529 // When we get a request to move a panel while it's fullscreen, we store 528 // When we get a request to move a panel while it's fullscreen, we store
530 // the requested position and apply it after the panel is unfullscreened. 529 // the requested position and apply it after the panel is unfullscreened.
531 // Check that the shadow gets moved to the stored position too. 530 // Check that the shadow gets moved to the stored position too.
532 panel->SetFullscreenState(true); 531 panel->SetFullscreenState(true);
533 panel->Move(20, 30, 0); 532 panel->Move(Point(20, 30), 0);
534 panel->SetFullscreenState(false); 533 panel->SetFullscreenState(false);
535 534
536 // First double-check that the content window got moved to the requested 535 // First double-check that the content window got moved to the requested
537 // position. 536 // position.
538 ASSERT_EQ(20 - new_width, panel->content_win_->composited_x()); 537 ASSERT_EQ(20 - new_width, panel->content_win_->composited_x());
539 ASSERT_EQ(30 + kTitlebarHeight, panel->content_win_->composited_y()); 538 ASSERT_EQ(30 + kTitlebarHeight, panel->content_win_->composited_y());
540 539
541 // Now check the shadow. 540 // Now check the shadow.
542 EXPECT_EQ(panel->content_win_->composited_x(), 541 EXPECT_EQ(panel->content_win_->composited_x(),
543 panel->separator_shadow_->x()); 542 panel->separator_shadow_->x());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 // Create a panel and move it off the left edge of the screen. 588 // Create a panel and move it off the left edge of the screen.
590 static const int kPanelWidth = 200; 589 static const int kPanelWidth = 200;
591 static const int kTitlebarHeight = 20; 590 static const int kTitlebarHeight = 20;
592 static const int kContentHeight = 600; 591 static const int kContentHeight = 600;
593 Panel* panel = CreatePanel(kPanelWidth, kTitlebarHeight, kContentHeight); 592 Panel* panel = CreatePanel(kPanelWidth, kTitlebarHeight, kContentHeight);
594 panel->MoveX(-300 - kPanelWidth, 0); 593 panel->MoveX(-300 - kPanelWidth, 0);
595 594
596 static const int kTransientWidth = 400; 595 static const int kTransientWidth = 400;
597 static const int kTransientHeight = 300; 596 static const int kTransientHeight = 300;
598 XWindow transient_xid = 597 XWindow transient_xid =
599 CreateBasicWindow(0, 0, kTransientWidth, kTransientHeight); 598 CreateBasicWindow(Rect(0, 0, kTransientWidth, kTransientHeight));
600 xconn_->GetWindowInfoOrDie(transient_xid)->transient_for = 599 xconn_->GetWindowInfoOrDie(transient_xid)->transient_for =
601 panel->content_xid(); 600 panel->content_xid();
602 SendInitialEventsForWindow(transient_xid); 601 SendInitialEventsForWindow(transient_xid);
603 602
604 MockXConnection::WindowInfo* transient_info = 603 MockXConnection::WindowInfo* transient_info =
605 xconn_->GetWindowInfoOrDie(transient_xid); 604 xconn_->GetWindowInfoOrDie(transient_xid);
606 EXPECT_EQ(0, transient_info->bounds.x); 605 EXPECT_EQ(0, transient_info->bounds.x);
607 EXPECT_EQ(wm_->height() - (kContentHeight + kTransientHeight) / 2, 606 EXPECT_EQ(wm_->height() - (kContentHeight + kTransientHeight) / 2,
608 transient_info->bounds.y); 607 transient_info->bounds.y);
609 } 608 }
610 609
611 } // namespace window_manager 610 } // namespace window_manager
612 611
613 int main(int argc, char** argv) { 612 int main(int argc, char** argv) {
614 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); 613 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr);
615 } 614 }
OLDNEW
« no previous file with comments | « panels/panel_manager_test.cc ('k') | pointer_position_watcher.h » ('j') | window.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698