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

Side by Side Diff: ash/wm/panels/panel_window_resizer_unittest.cc

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase fix Created 7 years, 3 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
« no previous file with comments | « ash/wm/panels/panel_window_resizer.cc ('k') | ash/wm/property_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/wm/panels/panel_window_resizer.h" 5 #include "ash/wm/panels/panel_window_resizer.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h" 8 #include "ash/launcher/launcher_model.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_types.h" 11 #include "ash/shelf/shelf_types.h"
12 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/cursor_manager_test_api.h" 16 #include "ash/test/cursor_manager_test_api.h"
17 #include "ash/test/shell_test_api.h" 17 #include "ash/test/shell_test_api.h"
18 #include "ash/test/test_launcher_delegate.h" 18 #include "ash/test/test_launcher_delegate.h"
19 #include "ash/wm/drag_window_resizer.h" 19 #include "ash/wm/drag_window_resizer.h"
20 #include "ash/wm/panels/panel_layout_manager.h" 20 #include "ash/wm/panels/panel_layout_manager.h"
21 #include "ash/wm/window_settings.h" 21 #include "ash/wm/window_state.h"
22 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
24 #include "ui/base/hit_test.h" 24 #include "ui/base/hit_test.h"
25 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/ui_base_types.h" 26 #include "ui/base/ui_base_types.h"
27 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
28 28
29 namespace ash { 29 namespace ash {
30 namespace internal { 30 namespace internal {
31 31
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 void DragRevert() { 93 void DragRevert() {
94 resizer_->RevertDrag(); 94 resizer_->RevertDrag();
95 resizer_.reset(); 95 resizer_.reset();
96 } 96 }
97 97
98 // Test dragging the panel slightly, then detaching, and then reattaching 98 // Test dragging the panel slightly, then detaching, and then reattaching
99 // dragging out by the vector (dx, dy). 99 // dragging out by the vector (dx, dy).
100 void DetachReattachTest(aura::Window* window, int dx, int dy) { 100 void DetachReattachTest(aura::Window* window, int dx, int dy) {
101 EXPECT_TRUE(wm::GetWindowSettings(window)->panel_attached()); 101 wm::WindowState* window_state = wm::GetWindowState(window);
102 EXPECT_TRUE(window_state->panel_attached());
102 aura::RootWindow* root_window = window->GetRootWindow(); 103 aura::RootWindow* root_window = window->GetRootWindow();
103 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 104 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
104 DragStart(window); 105 DragStart(window);
105 gfx::Rect initial_bounds = window->GetBoundsInScreen(); 106 gfx::Rect initial_bounds = window->GetBoundsInScreen();
106 107
107 // Drag the panel slightly. The window should still be snapped to the 108 // Drag the panel slightly. The window should still be snapped to the
108 // launcher. 109 // launcher.
109 DragMove(dx * 5, dy * 5); 110 DragMove(dx * 5, dy * 5);
110 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); 111 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
111 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); 112 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y());
112 113
113 // Drag further out and the window should now move to the cursor. 114 // Drag further out and the window should now move to the cursor.
114 DragMove(dx * 100, dy * 100); 115 DragMove(dx * 100, dy * 100);
115 EXPECT_EQ(initial_bounds.x() + dx * 100, window->GetBoundsInScreen().x()); 116 EXPECT_EQ(initial_bounds.x() + dx * 100, window->GetBoundsInScreen().x());
116 EXPECT_EQ(initial_bounds.y() + dy * 100, window->GetBoundsInScreen().y()); 117 EXPECT_EQ(initial_bounds.y() + dy * 100, window->GetBoundsInScreen().y());
117 118
118 // The panel should be detached when the drag completes. 119 // The panel should be detached when the drag completes.
119 DragEnd(); 120 DragEnd();
120 121
121 EXPECT_FALSE(wm::GetWindowSettings(window)->panel_attached()); 122 EXPECT_FALSE(window_state->panel_attached());
122 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 123 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
123 window->parent()->id()); 124 window->parent()->id());
124 EXPECT_EQ(root_window, window->GetRootWindow()); 125 EXPECT_EQ(root_window, window->GetRootWindow());
125 126
126 DragStart(window); 127 DragStart(window);
127 // Drag the panel down. 128 // Drag the panel down.
128 DragMove(dx * -95, dy * -95); 129 DragMove(dx * -95, dy * -95);
129 // Release the mouse and the panel should be reattached. 130 // Release the mouse and the panel should be reattached.
130 DragEnd(); 131 DragEnd();
131 132
132 // The panel should be reattached and have snapped to the launcher. 133 // The panel should be reattached and have snapped to the launcher.
133 EXPECT_TRUE(wm::GetWindowSettings(window)->panel_attached()); 134 EXPECT_TRUE(window_state->panel_attached());
134 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); 135 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
135 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); 136 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y());
136 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 137 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
137 } 138 }
138 139
139 void TestWindowOrder(const std::vector<aura::Window*>& window_order) { 140 void TestWindowOrder(const std::vector<aura::Window*>& window_order) {
140 int panel_index = model_->FirstPanelIndex(); 141 int panel_index = model_->FirstPanelIndex();
141 EXPECT_EQ((int)(panel_index + window_order.size()), model_->item_count()); 142 EXPECT_EQ((int)(panel_index + window_order.size()), model_->item_count());
142 for (std::vector<aura::Window*>::const_iterator iter = 143 for (std::vector<aura::Window*>::const_iterator iter =
143 window_order.begin(); iter != window_order.end(); 144 window_order.begin(); iter != window_order.end();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 scoped_ptr<aura::Window> window( 284 scoped_ptr<aura::Window> window(
284 CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 285 CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
285 gfx::Rect initial_bounds = window->GetBoundsInScreen(); 286 gfx::Rect initial_bounds = window->GetBoundsInScreen();
286 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 287 EXPECT_EQ(root_windows[0], window->GetRootWindow());
287 DragStart(window.get()); 288 DragStart(window.get());
288 DragMove(0, -100); 289 DragMove(0, -100);
289 DragEnd(); 290 DragEnd();
290 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 291 EXPECT_EQ(root_windows[0], window->GetRootWindow());
291 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); 292 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
292 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y()); 293 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
293 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 294 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
294 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 295 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
295 window->parent()->id()); 296 window->parent()->id());
296 297
297 DragStart(window.get()); 298 DragStart(window.get());
298 DragMove(500, 0); 299 DragMove(500, 0);
299 DragEnd(); 300 DragEnd();
300 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 301 EXPECT_EQ(root_windows[1], window->GetRootWindow());
301 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x()); 302 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
302 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y()); 303 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
303 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 304 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
304 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 305 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
305 window->parent()->id()); 306 window->parent()->id());
306 } 307 }
307 308
308 TEST_F(PanelWindowResizerTest, DetachAcrossDisplays) { 309 TEST_F(PanelWindowResizerTest, DetachAcrossDisplays) {
309 if (!SupportsMultipleDisplays()) 310 if (!SupportsMultipleDisplays())
310 return; 311 return;
311 312
312 UpdateDisplay("600x400,600x400"); 313 UpdateDisplay("600x400,600x400");
313 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 314 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
314 scoped_ptr<aura::Window> window( 315 scoped_ptr<aura::Window> window(
315 CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 316 CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
316 gfx::Rect initial_bounds = window->GetBoundsInScreen(); 317 gfx::Rect initial_bounds = window->GetBoundsInScreen();
317 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 318 EXPECT_EQ(root_windows[0], window->GetRootWindow());
318 DragStart(window.get()); 319 DragStart(window.get());
319 DragMove(500, -100); 320 DragMove(500, -100);
320 DragEnd(); 321 DragEnd();
321 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 322 EXPECT_EQ(root_windows[1], window->GetRootWindow());
322 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x()); 323 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
323 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y()); 324 EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
324 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 325 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
325 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 326 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
326 window->parent()->id()); 327 window->parent()->id());
327 } 328 }
328 329
329 TEST_F(PanelWindowResizerTest, DetachThenAttachToSecondDisplay) { 330 TEST_F(PanelWindowResizerTest, DetachThenAttachToSecondDisplay) {
330 if (!SupportsMultipleDisplays()) 331 if (!SupportsMultipleDisplays())
331 return; 332 return;
332 333
333 UpdateDisplay("600x400,600x600"); 334 UpdateDisplay("600x400,600x600");
334 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
335 scoped_ptr<aura::Window> window( 336 scoped_ptr<aura::Window> window(
336 CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 337 CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
337 gfx::Rect initial_bounds = window->GetBoundsInScreen(); 338 gfx::Rect initial_bounds = window->GetBoundsInScreen();
338 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 339 EXPECT_EQ(root_windows[0], window->GetRootWindow());
339 340
340 // Detach the window. 341 // Detach the window.
341 DragStart(window.get()); 342 DragStart(window.get());
342 DragMove(0, -100); 343 DragMove(0, -100);
343 DragEnd(); 344 DragEnd();
344 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 345 EXPECT_EQ(root_windows[0], window->GetRootWindow());
345 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 346 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
346 347
347 // Drag the window just above the other display's launcher. 348 // Drag the window just above the other display's launcher.
348 DragStart(window.get()); 349 DragStart(window.get());
349 DragMove(500, 295); 350 DragMove(500, 295);
350 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x()); 351 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
351 352
352 // Should stick to other launcher. 353 // Should stick to other launcher.
353 EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y()); 354 EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y());
354 DragEnd(); 355 DragEnd();
355 356
356 // When dropped should move to second display's panel container. 357 // When dropped should move to second display's panel container.
357 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 358 EXPECT_EQ(root_windows[1], window->GetRootWindow());
358 EXPECT_TRUE(wm::GetWindowSettings(window.get())->panel_attached()); 359 EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
359 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 360 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
360 } 361 }
361 362
362 TEST_F(PanelWindowResizerTest, AttachToSecondDisplay) { 363 TEST_F(PanelWindowResizerTest, AttachToSecondDisplay) {
363 if (!SupportsMultipleDisplays()) 364 if (!SupportsMultipleDisplays())
364 return; 365 return;
365 366
366 UpdateDisplay("600x400,600x600"); 367 UpdateDisplay("600x400,600x600");
367 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 368 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
368 scoped_ptr<aura::Window> window( 369 scoped_ptr<aura::Window> window(
369 CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 370 CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
370 gfx::Rect initial_bounds = window->GetBoundsInScreen(); 371 gfx::Rect initial_bounds = window->GetBoundsInScreen();
371 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 372 EXPECT_EQ(root_windows[0], window->GetRootWindow());
372 373
373 // Drag the window just above the other display's launcher. 374 // Drag the window just above the other display's launcher.
374 DragStart(window.get()); 375 DragStart(window.get());
375 DragMove(500, 195); 376 DragMove(500, 195);
376 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x()); 377 EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
377 378
378 // Should stick to other launcher. 379 // Should stick to other launcher.
379 EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y()); 380 EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y());
380 DragEnd(); 381 DragEnd();
381 382
382 // When dropped should move to second display's panel container. 383 // When dropped should move to second display's panel container.
383 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 384 EXPECT_EQ(root_windows[1], window->GetRootWindow());
384 EXPECT_TRUE(wm::GetWindowSettings(window.get())->panel_attached()); 385 EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
385 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 386 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
386 } 387 }
387 388
388 TEST_F(PanelWindowResizerTest, RevertDragRestoresAttachment) { 389 TEST_F(PanelWindowResizerTest, RevertDragRestoresAttachment) {
389 scoped_ptr<aura::Window> window( 390 scoped_ptr<aura::Window> window(
390 CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 391 CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
391 EXPECT_TRUE(wm::GetWindowSettings(window.get())->panel_attached()); 392 EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
392 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 393 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
393 DragStart(window.get()); 394 DragStart(window.get());
394 DragMove(0, -100); 395 DragMove(0, -100);
395 DragRevert(); 396 DragRevert();
396 EXPECT_TRUE(wm::GetWindowSettings(window.get())->panel_attached()); 397 EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
397 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id()); 398 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
398 399
399 // Detach panel. 400 // Detach panel.
400 DragStart(window.get()); 401 DragStart(window.get());
401 DragMove(0, -100); 402 DragMove(0, -100);
402 DragEnd(); 403 DragEnd();
403 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 404 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
404 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 405 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
405 window->parent()->id()); 406 window->parent()->id());
406 407
407 // Drag back to launcher. 408 // Drag back to launcher.
408 DragStart(window.get()); 409 DragStart(window.get());
409 DragMove(0, 100); 410 DragMove(0, 100);
410 411
411 // When the drag is reverted it should remain detached. 412 // When the drag is reverted it should remain detached.
412 DragRevert(); 413 DragRevert();
413 EXPECT_FALSE(wm::GetWindowSettings(window.get())->panel_attached()); 414 EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
414 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 415 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
415 window->parent()->id()); 416 window->parent()->id());
416 } 417 }
417 418
418 TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) { 419 TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) {
419 scoped_ptr<aura::Window> window(CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 420 scoped_ptr<aura::Window> window(CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
420 DragStart(window.get()); 421 DragStart(window.get());
421 DragMove(0, -100); 422 DragMove(0, -100);
422 DragEnd(); 423 DragEnd();
423 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, 424 EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
(...skipping 24 matching lines...) Expand all
448 ash::Shell* shell = ash::Shell::GetInstance(); 449 ash::Shell* shell = ash::Shell::GetInstance();
449 shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, shell->GetPrimaryRootWindow()); 450 shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, shell->GetPrimaryRootWindow());
450 DragAlongShelfReorder(0, -1); 451 DragAlongShelfReorder(0, -1);
451 } 452 }
452 453
453 INSTANTIATE_TEST_CASE_P(LtrRtl, PanelWindowResizerTextDirectionTest, 454 INSTANTIATE_TEST_CASE_P(LtrRtl, PanelWindowResizerTextDirectionTest,
454 testing::Bool()); 455 testing::Bool());
455 456
456 } // namespace internal 457 } // namespace internal
457 } // namespace ash 458 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panels/panel_window_resizer.cc ('k') | ash/wm/property_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698