1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/wm/workspace_controller.h"
9 #include "ash/ash_switches.h"
10 #include "ash/root_window_controller.h"
11 #include "ash/screen_util.h"
12 #include "ash/shelf/shelf_layout_manager.h"
13 #include "ash/shelf/shelf_widget.h"
14 #include "ash/shell.h"
15 #include "ash/shell_window_ids.h"
16 #include "ash/system/status_area_widget.h"
17 #include "ash/test/ash_test_base.h"
18 #include "ash/test/shell_test_api.h"
19 #include "ash/test/test_shelf_delegate.h"
20 #include "ash/wm/panels/panel_layout_manager.h"
21 #include "ash/wm/window_state.h"
22 #include "ash/wm/window_util.h"
23 #include "ash/wm/workspace/workspace_window_resizer.h"
24 #include "base/command_line.h"
25 #include "base/strings/string_number_conversions.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/test/event_generator.h"
28 #include "ui/aura/test/test_window_delegate.h"
29 #include "ui/aura/test/test_windows.h"
30 #include "ui/aura/window.h"
31 #include "ui/aura/window_event_dispatcher.h"
32 #include "ui/base/hit_test.h"
33 #include "ui/base/ui_base_types.h"
34 #include "ui/compositor/layer.h"
35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
36 #include "ui/events/event_utils.h"
37 #include "ui/gfx/screen.h"
38 #include "ui/views/widget/widget.h"
39 #include "ui/wm/core/window_animations.h"
40 #include "ui/wm/core/window_util.h"
46 // Returns a string containing the names of all the children of |window| (in
47 // order). Each entry is separated by a space.
48 std::string
GetWindowNames(const aura::Window
* window
) {
50 for (size_t i
= 0; i
< window
->children().size(); ++i
) {
53 result
+= window
->children()[i
]->name();
58 // Returns a string containing the names of windows corresponding to each of the
59 // child layers of |window|'s layer. Any layers that don't correspond to a child
60 // Window of |window| are ignored. The result is ordered based on the layer
62 std::string
GetLayerNames(const aura::Window
* window
) {
63 typedef std::map
<const ui::Layer
*, std::string
> LayerToWindowNameMap
;
64 LayerToWindowNameMap window_names
;
65 for (size_t i
= 0; i
< window
->children().size(); ++i
) {
66 window_names
[window
->children()[i
]->layer()] =
67 window
->children()[i
]->name();
71 const std::vector
<ui::Layer
*>& layers(window
->layer()->children());
72 for (size_t i
= 0; i
< layers
.size(); ++i
) {
73 LayerToWindowNameMap::iterator layer_i
=
74 window_names
.find(layers
[i
]);
75 if (layer_i
!= window_names
.end()) {
78 result
+= layer_i
->second
;
84 class WorkspaceControllerTest
: public test::AshTestBase
{
86 WorkspaceControllerTest() {}
87 virtual ~WorkspaceControllerTest() {}
89 aura::Window
* CreateTestWindowUnparented() {
90 aura::Window
* window
= new aura::Window(NULL
);
91 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
92 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
93 window
->Init(aura::WINDOW_LAYER_TEXTURED
);
97 aura::Window
* CreateTestWindow() {
98 aura::Window
* window
= new aura::Window(NULL
);
99 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
100 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
101 window
->Init(aura::WINDOW_LAYER_TEXTURED
);
102 ParentWindowInPrimaryRootWindow(window
);
106 aura::Window
* CreateBrowserLikeWindow(const gfx::Rect
& bounds
) {
107 aura::Window
* window
= CreateTestWindow();
108 window
->SetBounds(bounds
);
109 wm::WindowState
* window_state
= wm::GetWindowState(window
);
110 window_state
->set_window_position_managed(true);
115 aura::Window
* CreatePopupLikeWindow(const gfx::Rect
& bounds
) {
116 aura::Window
* window
= CreateTestWindowInShellWithBounds(bounds
);
121 aura::Window
* CreateTestPanel(aura::WindowDelegate
* delegate
,
122 const gfx::Rect
& bounds
) {
123 aura::Window
* window
= CreateTestWindowInShellWithDelegateAndType(
125 ui::wm::WINDOW_TYPE_PANEL
,
128 test::TestShelfDelegate
* shelf_delegate
=
129 test::TestShelfDelegate::instance();
130 shelf_delegate
->AddShelfItem(window
);
131 PanelLayoutManager
* manager
= static_cast<PanelLayoutManager
*>(
132 Shell::GetContainer(window
->GetRootWindow(),
133 kShellWindowId_PanelContainer
)->layout_manager());
138 aura::Window
* GetDesktop() {
139 return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
140 kShellWindowId_DefaultContainer
);
143 gfx::Rect
GetFullscreenBounds(aura::Window
* window
) {
144 return Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds();
147 ShelfWidget
* shelf_widget() {
148 return Shell::GetPrimaryRootWindowController()->shelf();
151 ShelfLayoutManager
* shelf_layout_manager() {
152 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
155 bool GetWindowOverlapsShelf() {
156 return shelf_layout_manager()->window_overlaps_shelf();
160 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest
);
163 // Assertions around adding a normal window.
164 TEST_F(WorkspaceControllerTest
, AddNormalWindowWhenEmpty
) {
165 scoped_ptr
<Window
> w1(CreateTestWindow());
166 w1
->SetBounds(gfx::Rect(0, 0, 250, 251));
168 wm::WindowState
* window_state
= wm::GetWindowState(w1
.get());
170 EXPECT_FALSE(window_state
->HasRestoreBounds());
174 EXPECT_FALSE(window_state
->HasRestoreBounds());
176 ASSERT_TRUE(w1
->layer() != NULL
);
177 EXPECT_TRUE(w1
->layer()->visible());
179 EXPECT_EQ("0,0 250x251", w1
->bounds().ToString());
181 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
184 // Assertions around maximizing/unmaximizing.
185 TEST_F(WorkspaceControllerTest
, SingleMaximizeWindow
) {
186 scoped_ptr
<Window
> w1(CreateTestWindow());
187 w1
->SetBounds(gfx::Rect(0, 0, 250, 251));
190 wm::ActivateWindow(w1
.get());
192 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
194 ASSERT_TRUE(w1
->layer() != NULL
);
195 EXPECT_TRUE(w1
->layer()->visible());
197 EXPECT_EQ("0,0 250x251", w1
->bounds().ToString());
199 // Maximize the window.
200 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
202 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
204 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
205 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w1
.get()).width(),
206 w1
->bounds().width());
207 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w1
.get()).height(),
208 w1
->bounds().height());
210 // Restore the window.
211 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
213 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
214 EXPECT_EQ("0,0 250x251", w1
->bounds().ToString());
217 // Assertions around two windows and toggling one to be fullscreen.
218 TEST_F(WorkspaceControllerTest
, FullscreenWithNormalWindow
) {
219 scoped_ptr
<Window
> w1(CreateTestWindow());
220 scoped_ptr
<Window
> w2(CreateTestWindow());
221 w1
->SetBounds(gfx::Rect(0, 0, 250, 251));
224 ASSERT_TRUE(w1
->layer() != NULL
);
225 EXPECT_TRUE(w1
->layer()->visible());
227 w2
->SetBounds(gfx::Rect(0, 0, 50, 51));
228 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
230 wm::ActivateWindow(w2
.get());
232 // Both windows should be in the same workspace.
233 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
234 EXPECT_EQ(w2
.get(), GetDesktop()->children()[1]);
237 ScreenUtil::GetMaximizedWindowBoundsInParent(w1
.get()));
238 EXPECT_EQ(work_area
.width(), w2
->bounds().width());
239 EXPECT_EQ(work_area
.height(), w2
->bounds().height());
241 // Restore w2, which should then go back to one workspace.
242 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
243 EXPECT_EQ(50, w2
->bounds().width());
244 EXPECT_EQ(51, w2
->bounds().height());
245 EXPECT_TRUE(wm::IsActiveWindow(w2
.get()));
248 // Makes sure requests to change the bounds of a normal window go through.
249 TEST_F(WorkspaceControllerTest
, ChangeBoundsOfNormalWindow
) {
250 scoped_ptr
<Window
> w1(CreateTestWindow());
253 // Setting the bounds should go through since the window is in the normal
255 w1
->SetBounds(gfx::Rect(0, 0, 200, 500));
256 EXPECT_EQ(200, w1
->bounds().width());
257 EXPECT_EQ(500, w1
->bounds().height());
260 // Verifies the bounds is not altered when showing and grid is enabled.
261 TEST_F(WorkspaceControllerTest
, SnapToGrid
) {
262 scoped_ptr
<Window
> w1(CreateTestWindowUnparented());
263 w1
->SetBounds(gfx::Rect(1, 6, 25, 30));
264 ParentWindowInPrimaryRootWindow(w1
.get());
265 // We are not aligning this anymore this way. When the window gets shown
266 // the window is expected to be handled differently, but this cannot be
267 // tested with this test. So the result of this test should be that the
268 // bounds are exactly as passed in.
269 EXPECT_EQ("1,6 25x30", w1
->bounds().ToString());
272 // Assertions around a fullscreen window.
273 TEST_F(WorkspaceControllerTest
, SingleFullscreenWindow
) {
274 scoped_ptr
<Window
> w1(CreateTestWindow());
275 w1
->SetBounds(gfx::Rect(0, 0, 250, 251));
276 // Make the window fullscreen.
277 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
279 wm::ActivateWindow(w1
.get());
281 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
282 EXPECT_EQ(GetFullscreenBounds(w1
.get()).width(), w1
->bounds().width());
283 EXPECT_EQ(GetFullscreenBounds(w1
.get()).height(), w1
->bounds().height());
285 // Restore the window. Use SHOW_STATE_DEFAULT as that is what we'll end up
286 // with when using views::Widget.
287 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_DEFAULT
);
288 EXPECT_EQ("0,0 250x251", w1
->bounds().ToString());
290 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
291 EXPECT_EQ(250, w1
->bounds().width());
292 EXPECT_EQ(251, w1
->bounds().height());
294 // Back to fullscreen.
295 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
296 EXPECT_EQ(w1
.get(), GetDesktop()->children()[0]);
297 EXPECT_EQ(GetFullscreenBounds(w1
.get()).width(), w1
->bounds().width());
298 EXPECT_EQ(GetFullscreenBounds(w1
.get()).height(), w1
->bounds().height());
299 wm::WindowState
* window_state
= wm::GetWindowState(w1
.get());
301 ASSERT_TRUE(window_state
->HasRestoreBounds());
302 EXPECT_EQ("0,0 250x251", window_state
->GetRestoreBoundsInScreen().ToString());
305 // Assertions around minimizing a single window.
306 TEST_F(WorkspaceControllerTest
, MinimizeSingleWindow
) {
307 scoped_ptr
<Window
> w1(CreateTestWindow());
311 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
312 EXPECT_FALSE(w1
->layer()->IsDrawn());
313 EXPECT_TRUE(w1
->layer()->GetTargetTransform().IsIdentity());
317 EXPECT_TRUE(wm::GetWindowState(w1
.get())->IsNormalStateType());
318 EXPECT_TRUE(w1
->layer()->IsDrawn());
321 // Assertions around minimizing a fullscreen window.
322 TEST_F(WorkspaceControllerTest
, MinimizeFullscreenWindow
) {
323 // Two windows, w1 normal, w2 fullscreen.
324 scoped_ptr
<Window
> w1(CreateTestWindow());
325 scoped_ptr
<Window
> w2(CreateTestWindow());
327 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
330 wm::WindowState
* w1_state
= wm::GetWindowState(w1
.get());
331 wm::WindowState
* w2_state
= wm::GetWindowState(w2
.get());
333 w2_state
->Activate();
336 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
337 EXPECT_TRUE(w1
->layer()->IsDrawn());
338 EXPECT_FALSE(w2
->layer()->IsDrawn());
340 // Show the window, which should trigger unminimizing.
342 w2_state
->Activate();
344 EXPECT_TRUE(w2_state
->IsFullscreen());
345 EXPECT_TRUE(w1
->layer()->IsDrawn());
346 EXPECT_TRUE(w2
->layer()->IsDrawn());
348 // Minimize the window, which should hide the window.
349 EXPECT_TRUE(w2_state
->IsActive());
350 w2_state
->Minimize();
351 EXPECT_FALSE(w2_state
->IsActive());
352 EXPECT_FALSE(w2
->layer()->IsDrawn());
353 EXPECT_TRUE(w1_state
->IsActive());
354 EXPECT_EQ(w2
.get(), GetDesktop()->children()[0]);
355 EXPECT_EQ(w1
.get(), GetDesktop()->children()[1]);
357 // Make the window normal.
358 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
359 // Setting back to normal doesn't change the activation.
360 EXPECT_FALSE(w2_state
->IsActive());
361 EXPECT_TRUE(w1_state
->IsActive());
362 EXPECT_EQ(w2
.get(), GetDesktop()->children()[0]);
363 EXPECT_EQ(w1
.get(), GetDesktop()->children()[1]);
364 EXPECT_TRUE(w2
->layer()->IsDrawn());
367 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly
369 TEST_F(WorkspaceControllerTest
, ShelfStateUpdated
) {
370 // Since ShelfLayoutManager queries for mouse location, move the mouse so
371 // it isn't over the shelf.
372 aura::test::EventGenerator
generator(
373 Shell::GetPrimaryRootWindow(), gfx::Point());
374 generator
.MoveMouseTo(0, 0);
376 scoped_ptr
<Window
> w1(CreateTestWindow());
377 const gfx::Rect
w1_bounds(0, 1, 101, 102);
378 ShelfLayoutManager
* shelf
= shelf_layout_manager();
379 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
380 const gfx::Rect
touches_shelf_bounds(
381 0, shelf
->GetIdealBounds().y() - 10, 101, 102);
382 // Move |w1| to overlap the shelf.
383 w1
->SetBounds(touches_shelf_bounds
);
384 EXPECT_FALSE(GetWindowOverlapsShelf());
386 // A visible ignored window should not trigger the overlap.
387 scoped_ptr
<Window
> w_ignored(CreateTestWindow());
388 w_ignored
->SetBounds(touches_shelf_bounds
);
389 wm::GetWindowState(&(*w_ignored
))->set_ignored_by_shelf(true);
391 EXPECT_FALSE(GetWindowOverlapsShelf());
393 // Make it visible, since visible shelf overlaps should be true.
395 EXPECT_TRUE(GetWindowOverlapsShelf());
397 wm::ActivateWindow(w1
.get());
398 w1
->SetBounds(w1_bounds
);
400 wm::ActivateWindow(w1
.get());
402 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
404 // Maximize the window.
405 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
406 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
407 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
410 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
411 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
412 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
415 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
416 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
419 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
420 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
421 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
422 EXPECT_FALSE(GetWindowOverlapsShelf());
424 // Move window so it obscures shelf.
425 w1
->SetBounds(touches_shelf_bounds
);
426 EXPECT_TRUE(GetWindowOverlapsShelf());
429 w1
->SetBounds(w1_bounds
);
430 EXPECT_FALSE(GetWindowOverlapsShelf());
433 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
434 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
435 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
438 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
439 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
441 // Since the restore from minimize will restore to the pre-minimize
442 // state (tested elsewhere), we abandon the current size and restore
443 // rect and set them to the window.
444 wm::WindowState
* window_state
= wm::GetWindowState(w1
.get());
446 gfx::Rect restore
= window_state
->GetRestoreBoundsInScreen();
447 EXPECT_EQ("0,0 800x597", w1
->bounds().ToString());
448 EXPECT_EQ("0,1 101x102", restore
.ToString());
449 window_state
->ClearRestoreBounds();
450 w1
->SetBounds(restore
);
453 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
454 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
455 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
457 // Create another window, maximized.
458 scoped_ptr
<Window
> w2(CreateTestWindow());
459 w2
->SetBounds(gfx::Rect(10, 11, 250, 251));
460 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
462 wm::ActivateWindow(w2
.get());
463 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
464 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
465 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
466 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(
467 w2
->parent()).ToString(),
468 w2
->bounds().ToString());
471 wm::ActivateWindow(w1
.get());
472 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
473 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
474 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(
475 w2
->parent()).ToString(),
476 w2
->bounds().ToString());
479 wm::ActivateWindow(w2
.get());
480 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
481 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
482 EXPECT_EQ("0,1 101x102", w1
->bounds().ToString());
483 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w2
.get()).ToString(),
484 w2
->bounds().ToString());
486 // Turn off auto-hide, switch back to w2 (maximized) and verify overlap.
487 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
488 wm::ActivateWindow(w2
.get());
489 EXPECT_FALSE(GetWindowOverlapsShelf());
491 // Move w1 to overlap shelf, it shouldn't change window overlaps shelf since
492 // the window isn't in the visible workspace.
493 w1
->SetBounds(touches_shelf_bounds
);
494 EXPECT_FALSE(GetWindowOverlapsShelf());
496 // Activate w1. Although w1 is visible, the overlap state is still false since
498 wm::ActivateWindow(w1
.get());
499 EXPECT_FALSE(GetWindowOverlapsShelf());
502 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
503 EXPECT_TRUE(GetWindowOverlapsShelf());
506 // Verifies going from maximized to minimized sets the right state for painting
507 // the background of the launcher.
508 TEST_F(WorkspaceControllerTest
, MinimizeResetsVisibility
) {
509 scoped_ptr
<Window
> w1(CreateTestWindow());
511 wm::ActivateWindow(w1
.get());
512 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
513 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, shelf_widget()->GetBackgroundType());
515 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
516 EXPECT_EQ(SHELF_VISIBLE
,
517 shelf_layout_manager()->visibility_state());
518 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, shelf_widget()->GetBackgroundType());
521 // Verifies window visibility during various workspace changes.
522 TEST_F(WorkspaceControllerTest
, VisibilityTests
) {
523 scoped_ptr
<Window
> w1(CreateTestWindow());
525 EXPECT_TRUE(w1
->IsVisible());
526 EXPECT_EQ(1.0f
, w1
->layer()->GetCombinedOpacity());
528 // Create another window, activate it and make it fullscreen.
529 scoped_ptr
<Window
> w2(CreateTestWindow());
531 wm::ActivateWindow(w2
.get());
532 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
533 EXPECT_TRUE(w2
->IsVisible());
534 EXPECT_EQ(1.0f
, w2
->layer()->GetCombinedOpacity());
535 EXPECT_TRUE(w1
->IsVisible());
537 // Switch to w1. |w1| should be visible on top of |w2|.
538 wm::ActivateWindow(w1
.get());
539 EXPECT_TRUE(w1
->IsVisible());
540 EXPECT_EQ(1.0f
, w1
->layer()->GetCombinedOpacity());
541 EXPECT_TRUE(w2
->IsVisible());
543 // Switch back to |w2|.
544 wm::ActivateWindow(w2
.get());
545 EXPECT_TRUE(w2
->IsVisible());
546 EXPECT_EQ(1.0f
, w2
->layer()->GetCombinedOpacity());
547 EXPECT_TRUE(w1
->IsVisible());
549 // Restore |w2|, both windows should be visible.
550 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
551 EXPECT_TRUE(w1
->IsVisible());
552 EXPECT_EQ(1.0f
, w1
->layer()->GetCombinedOpacity());
553 EXPECT_TRUE(w2
->IsVisible());
554 EXPECT_EQ(1.0f
, w2
->layer()->GetCombinedOpacity());
556 // Make |w2| fullscreen again, then close it.
557 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
559 EXPECT_FALSE(w2
->IsVisible());
560 EXPECT_EQ(1.0f
, w1
->layer()->GetCombinedOpacity());
561 EXPECT_TRUE(w1
->IsVisible());
563 // Create |w2| and maximize it.
564 w2
.reset(CreateTestWindow());
566 wm::ActivateWindow(w2
.get());
567 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
568 EXPECT_TRUE(w2
->IsVisible());
569 EXPECT_EQ(1.0f
, w2
->layer()->GetCombinedOpacity());
570 EXPECT_TRUE(w1
->IsVisible());
574 EXPECT_EQ(1.0f
, w1
->layer()->GetCombinedOpacity());
575 EXPECT_TRUE(w1
->IsVisible());
578 // Verifies windows that are offscreen don't move when switching workspaces.
579 TEST_F(WorkspaceControllerTest
, DontMoveOnSwitch
) {
580 aura::test::EventGenerator
generator(
581 Shell::GetPrimaryRootWindow(), gfx::Point());
582 generator
.MoveMouseTo(0, 0);
584 scoped_ptr
<Window
> w1(CreateTestWindow());
585 ShelfLayoutManager
* shelf
= shelf_layout_manager();
586 const gfx::Rect
touches_shelf_bounds(
587 0, shelf
->GetIdealBounds().y() - 10, 101, 102);
588 // Move |w1| to overlap the shelf.
589 w1
->SetBounds(touches_shelf_bounds
);
591 wm::ActivateWindow(w1
.get());
593 // Create another window and maximize it.
594 scoped_ptr
<Window
> w2(CreateTestWindow());
595 w2
->SetBounds(gfx::Rect(10, 11, 250, 251));
596 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
598 wm::ActivateWindow(w2
.get());
601 wm::ActivateWindow(w1
.get());
602 EXPECT_EQ(touches_shelf_bounds
.ToString(), w1
->bounds().ToString());
605 // Verifies that windows that are completely offscreen move when switching
607 TEST_F(WorkspaceControllerTest
, MoveOnSwitch
) {
608 aura::test::EventGenerator
generator(
609 Shell::GetPrimaryRootWindow(), gfx::Point());
610 generator
.MoveMouseTo(0, 0);
612 scoped_ptr
<Window
> w1(CreateTestWindow());
613 ShelfLayoutManager
* shelf
= shelf_layout_manager();
614 const gfx::Rect
w1_bounds(0, shelf
->GetIdealBounds().y(), 100, 200);
615 // Move |w1| so that the top edge is the same as the top edge of the shelf.
616 w1
->SetBounds(w1_bounds
);
618 wm::ActivateWindow(w1
.get());
619 EXPECT_EQ(w1_bounds
.ToString(), w1
->bounds().ToString());
621 // Create another window and maximize it.
622 scoped_ptr
<Window
> w2(CreateTestWindow());
623 w2
->SetBounds(gfx::Rect(10, 11, 250, 251));
624 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
626 wm::ActivateWindow(w2
.get());
628 // Increase the size of the WorkAreaInsets. This would make |w1| fall
629 // completely out of the display work area.
631 Shell::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets();
632 insets
.Set(0, 0, insets
.bottom() + 30, 0);
633 Shell::GetInstance()->SetDisplayWorkAreaInsets(w1
.get(), insets
);
635 // Switch to w1. The window should have moved.
636 wm::ActivateWindow(w1
.get());
637 EXPECT_NE(w1_bounds
.ToString(), w1
->bounds().ToString());
642 // WindowDelegate used by DontCrashOnChangeAndActivate.
643 class DontCrashOnChangeAndActivateDelegate
644 : public aura::test::TestWindowDelegate
{
646 DontCrashOnChangeAndActivateDelegate() : window_(NULL
) {}
648 void set_window(aura::Window
* window
) { window_
= window
; }
650 // WindowDelegate overrides:
651 virtual void OnBoundsChanged(const gfx::Rect
& old_bounds
,
652 const gfx::Rect
& new_bounds
) OVERRIDE
{
654 wm::ActivateWindow(window_
);
660 aura::Window
* window_
;
662 DISALLOW_COPY_AND_ASSIGN(DontCrashOnChangeAndActivateDelegate
);
667 // Exercises possible crash in W2. Here's the sequence:
668 // . minimize a maximized window.
669 // . remove the window (which happens when switching displays).
670 // . add the window back.
671 // . show the window and during the bounds change activate it.
672 TEST_F(WorkspaceControllerTest
, DontCrashOnChangeAndActivate
) {
674 ShelfLayoutManager
* shelf
= shelf_layout_manager();
675 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
677 DontCrashOnChangeAndActivateDelegate delegate
;
678 scoped_ptr
<Window
> w1(CreateTestWindowInShellWithDelegate(
679 &delegate
, 1000, gfx::Rect(10, 11, 250, 251)));
682 wm::WindowState
* w1_state
= wm::GetWindowState(w1
.get());
683 w1_state
->Activate();
684 w1_state
->Maximize();
685 w1_state
->Minimize();
687 w1
->parent()->RemoveChild(w1
.get());
689 // Do this so that when we Show() the window a resize occurs and we make the
691 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
693 ParentWindowInPrimaryRootWindow(w1
.get());
694 delegate
.set_window(w1
.get());
698 // Verifies a window with a transient parent not managed by workspace works.
699 TEST_F(WorkspaceControllerTest
, TransientParent
) {
700 // Normal window with no transient parent.
701 scoped_ptr
<Window
> w2(CreateTestWindow());
702 w2
->SetBounds(gfx::Rect(10, 11, 250, 251));
704 wm::ActivateWindow(w2
.get());
706 // Window with a transient parent. We set the transient parent to the root,
707 // which would never happen but is enough to exercise the bug.
708 scoped_ptr
<Window
> w1(CreateTestWindowUnparented());
709 ::wm::AddTransientChild(
710 Shell::GetInstance()->GetPrimaryRootWindow(), w1
.get());
711 w1
->SetBounds(gfx::Rect(10, 11, 250, 251));
712 ParentWindowInPrimaryRootWindow(w1
.get());
714 wm::ActivateWindow(w1
.get());
716 // The window with the transient parent should get added to the same parent as
717 // the normal window.
718 EXPECT_EQ(w2
->parent(), w1
->parent());
721 // Test the placement of newly created windows.
722 TEST_F(WorkspaceControllerTest
, BasicAutoPlacingOnCreate
) {
723 if (!SupportsHostWindowResize())
725 UpdateDisplay("1600x1200");
726 // Creating a popup handler here to make sure it does not interfere with the
728 gfx::Rect
source_browser_bounds(16, 32, 640, 320);
729 scoped_ptr
<aura::Window
> browser_window(CreateBrowserLikeWindow(
730 source_browser_bounds
));
732 // Creating a popup to make sure it does not interfere with the positioning.
733 scoped_ptr
<aura::Window
> browser_popup(CreatePopupLikeWindow(
734 gfx::Rect(16, 32, 128, 256)));
736 browser_window
->Show();
737 browser_popup
->Show();
739 { // With a shown window it's size should get returned.
740 scoped_ptr
<aura::Window
> new_browser_window(CreateBrowserLikeWindow(
741 source_browser_bounds
));
742 // The position should be right flush.
743 EXPECT_EQ("960,32 640x320", new_browser_window
->bounds().ToString());
746 { // With the window shown - but more on the right side then on the left
747 // side (and partially out of the screen), it should default to the other
748 // side and inside the screen.
749 gfx::Rect
source_browser_bounds(gfx::Rect(1000, 600, 640, 320));
750 browser_window
->SetBounds(source_browser_bounds
);
752 scoped_ptr
<aura::Window
> new_browser_window(CreateBrowserLikeWindow(
753 source_browser_bounds
));
754 // The position should be left & bottom flush.
755 EXPECT_EQ("0,600 640x320", new_browser_window
->bounds().ToString());
757 // If the other window was already beyond the point to get right flush
758 // it will remain where it is.
759 EXPECT_EQ("1000,600 640x320", browser_window
->bounds().ToString());
762 { // Make sure that popups do not get changed.
763 scoped_ptr
<aura::Window
> new_popup_window(CreatePopupLikeWindow(
764 gfx::Rect(50, 100, 300, 150)));
765 EXPECT_EQ("50,100 300x150", new_popup_window
->bounds().ToString());
768 browser_window
->Hide();
769 { // If a window is there but not shown the default should be centered.
770 scoped_ptr
<aura::Window
> new_browser_window(CreateBrowserLikeWindow(
771 gfx::Rect(50, 100, 300, 150)));
772 EXPECT_EQ("650,100 300x150", new_browser_window
->bounds().ToString());
776 // Test that adding a second window shifts both the first window and its
778 TEST_F(WorkspaceControllerTest
, AutoPlacingMovesTransientChild
) {
779 // Create an auto-positioned window.
780 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
781 gfx::Rect desktop_area
= window1
->parent()->bounds();
782 wm::GetWindowState(window1
.get())->set_window_position_managed(true);
783 // Hide and then show |window1| to trigger auto-positioning logic.
785 window1
->SetBounds(gfx::Rect(16, 32, 300, 300));
788 // |window1| should be horizontally centered.
789 int x_window1
= (desktop_area
.width() - 300) / 2;
790 EXPECT_EQ(base::IntToString(x_window1
) + ",32 300x300",
791 window1
->bounds().ToString());
793 // Create a |child| window and make it a transient child of |window1|.
794 scoped_ptr
<Window
> child(CreateTestWindowUnparented());
795 ::wm::AddTransientChild(window1
.get(), child
.get());
796 const int x_child
= x_window1
+ 50;
797 child
->SetBounds(gfx::Rect(x_child
, 20, 200, 200));
798 ParentWindowInPrimaryRootWindow(child
.get());
800 wm::ActivateWindow(child
.get());
802 // The |child| should be where it was created.
803 EXPECT_EQ(base::IntToString(x_child
) + ",20 200x200",
804 child
->bounds().ToString());
806 // Create and show a second window forcing the first window and its child to
808 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
809 wm::GetWindowState(window2
.get())->set_window_position_managed(true);
810 // Hide and then show |window2| to trigger auto-positioning logic.
812 window2
->SetBounds(gfx::Rect(32, 48, 250, 250));
815 // Check that both |window1| and |child| have moved left.
816 EXPECT_EQ("0,32 300x300", window1
->bounds().ToString());
817 int x
= x_child
- x_window1
;
818 EXPECT_EQ(base::IntToString(x
) + ",20 200x200", child
->bounds().ToString());
819 // Check that |window2| has moved right.
820 x
= desktop_area
.width() - window2
->bounds().width();
821 EXPECT_EQ(base::IntToString(x
) + ",48 250x250", window2
->bounds().ToString());
824 // Test the basic auto placement of one and or two windows in a "simulated
825 // session" of sequential window operations.
826 TEST_F(WorkspaceControllerTest
, BasicAutoPlacingOnShowHide
) {
827 // Test 1: In case there is no manageable window, no window should shift.
829 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
830 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
831 gfx::Rect desktop_area
= window1
->parent()->bounds();
833 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
834 // Trigger the auto window placement function by making it visible.
835 // Note that the bounds are getting changed while it is invisible.
837 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
840 // Check the initial position of the windows is unchanged.
841 EXPECT_EQ("16,32 640x320", window1
->bounds().ToString());
842 EXPECT_EQ("32,48 256x512", window2
->bounds().ToString());
844 // Remove the second window and make sure that the first window
845 // does NOT get centered.
847 EXPECT_EQ("16,32 640x320", window1
->bounds().ToString());
849 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
850 // Test 2: Set up two managed windows and check their auto positioning.
851 window1_state
->set_window_position_managed(true);
853 scoped_ptr
<aura::Window
> window3(CreateTestWindowInShellWithId(2));
854 wm::GetWindowState(window3
.get())->set_window_position_managed(true);
855 // To avoid any auto window manager changes due to SetBounds, the window
856 // gets first hidden and then shown again.
858 window3
->SetBounds(gfx::Rect(32, 48, 256, 512));
860 // |window1| should be flush left and |window3| flush right.
861 EXPECT_EQ("0,32 640x320", window1
->bounds().ToString());
862 EXPECT_EQ(base::IntToString(
863 desktop_area
.width() - window3
->bounds().width()) +
864 ",48 256x512", window3
->bounds().ToString());
866 // After removing |window3|, |window1| should be centered again.
870 (desktop_area
.width() - window1
->bounds().width()) / 2) +
871 ",32 640x320", window1
->bounds().ToString());
873 // Test 3: Set up a manageable and a non manageable window and check
875 scoped_ptr
<aura::Window
> window4(CreateTestWindowInShellWithId(3));
876 // To avoid any auto window manager changes due to SetBounds, the window
877 // gets first hidden and then shown again.
879 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
880 window4
->SetBounds(gfx::Rect(32, 48, 256, 512));
882 // |window1| should be centered and |window4| untouched.
885 (desktop_area
.width() - window1
->bounds().width()) / 2) +
886 ",32 640x320", window1
->bounds().ToString());
887 EXPECT_EQ("32,48 256x512", window4
->bounds().ToString());
889 // Test4: A single manageable window should get centered.
891 window1_state
->set_bounds_changed_by_user(false);
892 // Trigger the auto window placement function by showing (and hiding) it.
895 // |window1| should be centered.
898 (desktop_area
.width() - window1
->bounds().width()) / 2) +
899 ",32 640x320", window1
->bounds().ToString());
902 // Test the proper usage of user window movement interaction.
903 TEST_F(WorkspaceControllerTest
, TestUserMovedWindowRepositioning
) {
904 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
905 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
906 gfx::Rect desktop_area
= window1
->parent()->bounds();
907 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
908 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
911 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
912 wm::WindowState
* window2_state
= wm::GetWindowState(window2
.get());
914 window1_state
->set_window_position_managed(true);
915 window2_state
->set_window_position_managed(true);
916 EXPECT_FALSE(window1_state
->bounds_changed_by_user());
917 EXPECT_FALSE(window2_state
->bounds_changed_by_user());
919 // Check that the current location gets preserved if the user has
920 // positioned it previously.
921 window1_state
->set_bounds_changed_by_user(true);
923 EXPECT_EQ("16,32 640x320", window1
->bounds().ToString());
924 // Flag should be still set.
925 EXPECT_TRUE(window1_state
->bounds_changed_by_user());
926 EXPECT_FALSE(window2_state
->bounds_changed_by_user());
928 // Turn on the second window and make sure that both windows are now
929 // positionable again (user movement cleared).
932 // |window1| should be flush left and |window2| flush right.
933 EXPECT_EQ("0,32 640x320", window1
->bounds().ToString());
935 base::IntToString(desktop_area
.width() - window2
->bounds().width()) +
936 ",48 256x512", window2
->bounds().ToString());
937 // FLag should now be reset.
938 EXPECT_FALSE(window1_state
->bounds_changed_by_user());
939 EXPECT_FALSE(window2_state
->bounds_changed_by_user());
941 // Going back to one shown window should keep the state.
942 window1_state
->set_bounds_changed_by_user(true);
944 EXPECT_EQ("0,32 640x320", window1
->bounds().ToString());
945 EXPECT_TRUE(window1_state
->bounds_changed_by_user());
948 // Test if the single window will be restored at original position.
949 TEST_F(WorkspaceControllerTest
, TestSingleWindowsRestoredBounds
) {
950 scoped_ptr
<aura::Window
> window1(
951 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
952 scoped_ptr
<aura::Window
> window2(
953 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100)));
954 scoped_ptr
<aura::Window
> window3(
955 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100)));
959 wm::GetWindowState(window1
.get())->set_window_position_managed(true);
960 wm::GetWindowState(window2
.get())->set_window_position_managed(true);
961 wm::GetWindowState(window3
.get())->set_window_position_managed(true);
964 wm::ActivateWindow(window1
.get());
966 wm::ActivateWindow(window2
.get());
968 wm::ActivateWindow(window3
.get());
969 EXPECT_EQ(0, window1
->bounds().x());
970 EXPECT_EQ(window2
->GetRootWindow()->bounds().right(),
971 window2
->bounds().right());
972 EXPECT_EQ(0, window3
->bounds().x());
975 EXPECT_EQ(window2
->GetRootWindow()->bounds().right(),
976 window2
->bounds().right());
977 EXPECT_EQ(0, window3
->bounds().x());
979 // Being a single window will retore the original location.
981 wm::ActivateWindow(window2
.get());
982 EXPECT_EQ("110,110 100x100", window2
->bounds().ToString());
984 // Showing the 3rd will push the 2nd window left.
986 wm::ActivateWindow(window3
.get());
987 EXPECT_EQ(0, window2
->bounds().x());
988 EXPECT_EQ(window3
->GetRootWindow()->bounds().right(),
989 window3
->bounds().right());
991 // Being a single window will retore the original location.
993 EXPECT_EQ("120,120 100x100", window3
->bounds().ToString());
996 // Test that user placed windows go back to their user placement after the user
997 // closes all other windows.
998 TEST_F(WorkspaceControllerTest
, TestUserHandledWindowRestore
) {
999 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1000 gfx::Rect user_pos
= gfx::Rect(16, 42, 640, 320);
1001 window1
->SetBounds(user_pos
);
1002 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1004 window1_state
->SetPreAutoManageWindowBounds(user_pos
);
1005 gfx::Rect desktop_area
= window1
->parent()->bounds();
1007 // Create a second window to let the auto manager kick in.
1008 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1009 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
1012 wm::GetWindowState(window1
.get())->set_window_position_managed(true);
1013 wm::GetWindowState(window2
.get())->set_window_position_managed(true);
1015 EXPECT_EQ(user_pos
.ToString(), window1
->bounds().ToString());
1018 // |window1| should be flush left and |window2| flush right.
1019 EXPECT_EQ("0," + base::IntToString(user_pos
.y()) +
1020 " 640x320", window1
->bounds().ToString());
1022 base::IntToString(desktop_area
.width() - window2
->bounds().width()) +
1023 ",48 256x512", window2
->bounds().ToString());
1026 // After the other window get hidden the window has to move back to the
1027 // previous position and the bounds should still be set and unchanged.
1028 EXPECT_EQ(user_pos
.ToString(), window1
->bounds().ToString());
1029 ASSERT_TRUE(window1_state
->pre_auto_manage_window_bounds());
1030 EXPECT_EQ(user_pos
.ToString(),
1031 window1_state
->pre_auto_manage_window_bounds()->ToString());
1034 // Solo window should be restored to the bounds where a user moved to.
1035 TEST_F(WorkspaceControllerTest
, TestRestoreToUserModifiedBounds
) {
1036 if (!SupportsHostWindowResize())
1039 UpdateDisplay("400x300");
1040 gfx::Rect
default_bounds(10, 0, 100, 100);
1041 scoped_ptr
<aura::Window
> window1(
1042 CreateTestWindowInShellWithBounds(default_bounds
));
1043 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1045 window1_state
->set_window_position_managed(true);
1047 // First window is centered.
1048 EXPECT_EQ("150,0 100x100", window1
->bounds().ToString());
1049 scoped_ptr
<aura::Window
> window2(
1050 CreateTestWindowInShellWithBounds(default_bounds
));
1051 wm::WindowState
* window2_state
= wm::GetWindowState(window2
.get());
1053 window2_state
->set_window_position_managed(true);
1056 // Auto positioning pushes windows to each sides.
1057 EXPECT_EQ("0,0 100x100", window1
->bounds().ToString());
1058 EXPECT_EQ("300,0 100x100", window2
->bounds().ToString());
1061 // Restores to the center.
1062 EXPECT_EQ("150,0 100x100", window1
->bounds().ToString());
1064 // A user moved the window.
1065 scoped_ptr
<WindowResizer
> resizer(CreateWindowResizer(
1069 aura::client::WINDOW_MOVE_SOURCE_MOUSE
).release());
1070 gfx::Point location
= resizer
->GetInitialLocation();
1071 location
.Offset(-50, 0);
1072 resizer
->Drag(location
, 0);
1073 resizer
->CompleteDrag();
1075 window1_state
->set_bounds_changed_by_user(true);
1076 window1
->SetBounds(gfx::Rect(100, 0, 100, 100));
1079 EXPECT_EQ("0,0 100x100", window1
->bounds().ToString());
1080 EXPECT_EQ("300,0 100x100", window2
->bounds().ToString());
1082 // Window 1 should be restored to the user modified bounds.
1084 EXPECT_EQ("100,0 100x100", window1
->bounds().ToString());
1087 // Test that a window from normal to minimize will repos the remaining.
1088 TEST_F(WorkspaceControllerTest
, ToMinimizeRepositionsRemaining
) {
1089 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1090 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1091 window1_state
->set_window_position_managed(true);
1092 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
1093 gfx::Rect desktop_area
= window1
->parent()->bounds();
1095 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1096 wm::WindowState
* window2_state
= wm::GetWindowState(window2
.get());
1097 window2_state
->set_window_position_managed(true);
1098 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
1100 window1_state
->Minimize();
1102 // |window2| should be centered now.
1103 EXPECT_TRUE(window2
->IsVisible());
1104 EXPECT_TRUE(window2_state
->IsNormalStateType());
1105 EXPECT_EQ(base::IntToString(
1106 (desktop_area
.width() - window2
->bounds().width()) / 2) +
1107 ",48 256x512", window2
->bounds().ToString());
1109 window1_state
->Restore();
1110 // |window1| should be flush right and |window3| flush left.
1111 EXPECT_EQ(base::IntToString(
1112 desktop_area
.width() - window1
->bounds().width()) +
1113 ",32 640x320", window1
->bounds().ToString());
1114 EXPECT_EQ("0,48 256x512", window2
->bounds().ToString());
1117 // Test that minimizing an initially maximized window will repos the remaining.
1118 TEST_F(WorkspaceControllerTest
, MaxToMinRepositionsRemaining
) {
1119 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1120 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1121 window1_state
->set_window_position_managed(true);
1122 gfx::Rect desktop_area
= window1
->parent()->bounds();
1124 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1125 wm::WindowState
* window2_state
= wm::GetWindowState(window2
.get());
1126 window2_state
->set_window_position_managed(true);
1127 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
1129 window1_state
->Maximize();
1130 window1_state
->Minimize();
1132 // |window2| should be centered now.
1133 EXPECT_TRUE(window2
->IsVisible());
1134 EXPECT_TRUE(window2_state
->IsNormalStateType());
1135 EXPECT_EQ(base::IntToString(
1136 (desktop_area
.width() - window2
->bounds().width()) / 2) +
1137 ",48 256x512", window2
->bounds().ToString());
1140 // Test that nomral, maximize, minimizing will repos the remaining.
1141 TEST_F(WorkspaceControllerTest
, NormToMaxToMinRepositionsRemaining
) {
1142 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1143 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
1144 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1145 window1_state
->set_window_position_managed(true);
1146 gfx::Rect desktop_area
= window1
->parent()->bounds();
1148 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1149 wm::WindowState
* window2_state
= wm::GetWindowState(window2
.get());
1150 window2_state
->set_window_position_managed(true);
1151 window2
->SetBounds(gfx::Rect(32, 40, 256, 512));
1153 // Trigger the auto window placement function by showing (and hiding) it.
1157 // |window1| should be flush right and |window3| flush left.
1158 EXPECT_EQ(base::IntToString(
1159 desktop_area
.width() - window1
->bounds().width()) +
1160 ",32 640x320", window1
->bounds().ToString());
1161 EXPECT_EQ("0,40 256x512", window2
->bounds().ToString());
1163 window1_state
->Maximize();
1164 window1_state
->Minimize();
1166 // |window2| should be centered now.
1167 EXPECT_TRUE(window2
->IsVisible());
1168 EXPECT_TRUE(window2_state
->IsNormalStateType());
1169 EXPECT_EQ(base::IntToString(
1170 (desktop_area
.width() - window2
->bounds().width()) / 2) +
1171 ",40 256x512", window2
->bounds().ToString());
1174 // Test that nomral, maximize, normal will repos the remaining.
1175 TEST_F(WorkspaceControllerTest
, NormToMaxToNormRepositionsRemaining
) {
1176 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1177 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
1178 wm::WindowState
* window1_state
= wm::GetWindowState(window1
.get());
1179 window1_state
->set_window_position_managed(true);
1180 gfx::Rect desktop_area
= window1
->parent()->bounds();
1182 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1183 wm::GetWindowState(window2
.get())->set_window_position_managed(true);
1184 window2
->SetBounds(gfx::Rect(32, 40, 256, 512));
1186 // Trigger the auto window placement function by showing (and hiding) it.
1190 // |window1| should be flush right and |window3| flush left.
1191 EXPECT_EQ(base::IntToString(
1192 desktop_area
.width() - window1
->bounds().width()) +
1193 ",32 640x320", window1
->bounds().ToString());
1194 EXPECT_EQ("0,40 256x512", window2
->bounds().ToString());
1196 window1_state
->Maximize();
1197 window1_state
->Restore();
1199 // |window1| should be flush right and |window2| flush left.
1200 EXPECT_EQ(base::IntToString(
1201 desktop_area
.width() - window1
->bounds().width()) +
1202 ",32 640x320", window1
->bounds().ToString());
1203 EXPECT_EQ("0,40 256x512", window2
->bounds().ToString());
1206 // Test that animations are triggered.
1207 TEST_F(WorkspaceControllerTest
, AnimatedNormToMaxToNormRepositionsRemaining
) {
1208 ui::ScopedAnimationDurationScaleMode
normal_duration_mode(
1209 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
1210 scoped_ptr
<aura::Window
> window1(CreateTestWindowInShellWithId(0));
1212 window1
->SetBounds(gfx::Rect(16, 32, 640, 320));
1213 gfx::Rect desktop_area
= window1
->parent()->bounds();
1214 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(1));
1216 window2
->SetBounds(gfx::Rect(32, 48, 256, 512));
1218 wm::GetWindowState(window1
.get())->set_window_position_managed(true);
1219 wm::GetWindowState(window2
.get())->set_window_position_managed(true);
1220 // Make sure nothing is animating.
1221 window1
->layer()->GetAnimator()->StopAnimating();
1222 window2
->layer()->GetAnimator()->StopAnimating();
1225 // The second window should now animate.
1226 EXPECT_FALSE(window1
->layer()->GetAnimator()->is_animating());
1227 EXPECT_TRUE(window2
->layer()->GetAnimator()->is_animating());
1228 window2
->layer()->GetAnimator()->StopAnimating();
1231 EXPECT_TRUE(window1
->layer()->GetAnimator()->is_animating());
1232 EXPECT_TRUE(window2
->layer()->GetAnimator()->is_animating());
1234 window1
->layer()->GetAnimator()->StopAnimating();
1235 window2
->layer()->GetAnimator()->StopAnimating();
1236 // |window1| should be flush right and |window2| flush left.
1237 EXPECT_EQ(base::IntToString(
1238 desktop_area
.width() - window1
->bounds().width()) +
1239 ",32 640x320", window1
->bounds().ToString());
1240 EXPECT_EQ("0,48 256x512", window2
->bounds().ToString());
1243 // This tests simulates a browser and an app and verifies the ordering of the
1244 // windows and layers doesn't get out of sync as various operations occur. Its
1245 // really testing code in FocusController, but easier to simulate here. Just as
1246 // with a real browser the browser here has a transient child window
1247 // (corresponds to the status bubble).
1248 TEST_F(WorkspaceControllerTest
, VerifyLayerOrdering
) {
1249 scoped_ptr
<Window
> browser(aura::test::CreateTestWindowWithDelegate(
1250 NULL
, ui::wm::WINDOW_TYPE_NORMAL
, gfx::Rect(5, 6, 7, 8), NULL
));
1251 browser
->SetName("browser");
1252 ParentWindowInPrimaryRootWindow(browser
.get());
1254 wm::ActivateWindow(browser
.get());
1256 // |status_bubble| is made a transient child of |browser| and as a result
1257 // owned by |browser|.
1258 aura::test::TestWindowDelegate
* status_bubble_delegate
=
1259 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
1260 status_bubble_delegate
->set_can_focus(false);
1261 Window
* status_bubble
=
1262 aura::test::CreateTestWindowWithDelegate(status_bubble_delegate
,
1263 ui::wm::WINDOW_TYPE_POPUP
,
1264 gfx::Rect(5, 6, 7, 8),
1266 ::wm::AddTransientChild(browser
.get(), status_bubble
);
1267 ParentWindowInPrimaryRootWindow(status_bubble
);
1268 status_bubble
->SetName("status_bubble");
1270 scoped_ptr
<Window
> app(aura::test::CreateTestWindowWithDelegate(
1271 NULL
, ui::wm::WINDOW_TYPE_NORMAL
, gfx::Rect(5, 6, 7, 8), NULL
));
1272 app
->SetName("app");
1273 ParentWindowInPrimaryRootWindow(app
.get());
1275 aura::Window
* parent
= browser
->parent();
1278 wm::ActivateWindow(app
.get());
1279 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1281 // Minimize the app, focus should go the browser.
1282 app
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
1283 EXPECT_TRUE(wm::IsActiveWindow(browser
.get()));
1284 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1286 // Minimize the browser (neither windows are focused).
1287 browser
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
1288 EXPECT_FALSE(wm::IsActiveWindow(browser
.get()));
1289 EXPECT_FALSE(wm::IsActiveWindow(app
.get()));
1290 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1292 // Show the browser (which should restore it).
1294 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1296 // Activate the browser.
1297 ash::wm::ActivateWindow(browser
.get());
1298 EXPECT_TRUE(wm::IsActiveWindow(browser
.get()));
1299 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1301 // Restore the app. This differs from above code for |browser| as internally
1302 // the app code does this. Restoring this way or using Show() should not make
1304 app
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
1305 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1307 // Activate the app.
1308 ash::wm::ActivateWindow(app
.get());
1309 EXPECT_TRUE(wm::IsActiveWindow(app
.get()));
1310 EXPECT_EQ(GetWindowNames(parent
), GetLayerNames(parent
));
1315 // Used by DragMaximizedNonTrackedWindow to track how many times the window
1316 // hierarchy changes affecting the specified window.
1317 class DragMaximizedNonTrackedWindowObserver
1318 : public aura::WindowObserver
{
1320 DragMaximizedNonTrackedWindowObserver(aura::Window
* window
)
1325 // Number of times OnWindowHierarchyChanged() has been received.
1326 void clear_change_count() { change_count_
= 0; }
1327 int change_count() const {
1328 return change_count_
;
1331 // aura::WindowObserver overrides:
1332 // Counts number of times a window is reparented. Ignores reparenting into and
1333 // from a docked container which is expected when a tab is dragged.
1334 virtual void OnWindowHierarchyChanged(
1335 const HierarchyChangeParams
& params
) OVERRIDE
{
1336 if (params
.target
!= window_
||
1337 (params
.old_parent
->id() == kShellWindowId_DefaultContainer
&&
1338 params
.new_parent
->id() == kShellWindowId_DockedContainer
) ||
1339 (params
.old_parent
->id() == kShellWindowId_DockedContainer
&&
1340 params
.new_parent
->id() == kShellWindowId_DefaultContainer
)) {
1348 aura::Window
* window_
;
1350 DISALLOW_COPY_AND_ASSIGN(DragMaximizedNonTrackedWindowObserver
);
1355 // Verifies that a new maximized window becomes visible after its activation
1356 // is requested, even though it does not become activated because a system
1357 // modal window is active.
1358 TEST_F(WorkspaceControllerTest
, SwitchFromModal
) {
1359 scoped_ptr
<Window
> modal_window(CreateTestWindowUnparented());
1360 modal_window
->SetBounds(gfx::Rect(10, 11, 21, 22));
1361 modal_window
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_SYSTEM
);
1362 ParentWindowInPrimaryRootWindow(modal_window
.get());
1363 modal_window
->Show();
1364 wm::ActivateWindow(modal_window
.get());
1366 scoped_ptr
<Window
> maximized_window(CreateTestWindow());
1367 maximized_window
->SetProperty(
1368 aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1369 maximized_window
->Show();
1370 wm::ActivateWindow(maximized_window
.get());
1371 EXPECT_TRUE(maximized_window
->IsVisible());
1376 // Subclass of WorkspaceControllerTest that runs tests with docked windows
1377 // enabled and disabled.
1378 class WorkspaceControllerTestDragging
1379 : public WorkspaceControllerTest
,
1380 public testing::WithParamInterface
<bool> {
1382 WorkspaceControllerTestDragging() {}
1383 virtual ~WorkspaceControllerTestDragging() {}
1386 virtual void SetUp() OVERRIDE
{
1387 WorkspaceControllerTest::SetUp();
1388 if (!docked_windows_enabled()) {
1389 CommandLine::ForCurrentProcess()->AppendSwitch(
1390 ash::switches::kAshDisableDockedWindows
);
1394 bool docked_windows_enabled() const { return GetParam(); }
1397 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTestDragging
);
1402 // Verifies that when dragging a window over the shelf overlap is detected
1403 // during and after the drag.
1404 TEST_P(WorkspaceControllerTestDragging
, DragWindowOverlapShelf
) {
1405 aura::test::TestWindowDelegate delegate
;
1406 delegate
.set_window_component(HTCAPTION
);
1407 scoped_ptr
<Window
> w1(aura::test::CreateTestWindowWithDelegate(
1408 &delegate
, ui::wm::WINDOW_TYPE_NORMAL
, gfx::Rect(5, 5, 100, 50), NULL
));
1409 ParentWindowInPrimaryRootWindow(w1
.get());
1411 ShelfLayoutManager
* shelf
= shelf_layout_manager();
1412 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1414 // Drag near the shelf.
1415 aura::test::EventGenerator
generator(
1416 Shell::GetPrimaryRootWindow(), gfx::Point());
1417 generator
.MoveMouseTo(10, 10);
1418 generator
.PressLeftButton();
1419 generator
.MoveMouseTo(100, shelf
->GetIdealBounds().y() - 70);
1421 // Shelf should not be in overlapped state.
1422 EXPECT_FALSE(GetWindowOverlapsShelf());
1424 generator
.MoveMouseTo(100, shelf
->GetIdealBounds().y() - 20);
1426 // Shelf should detect overlap. Overlap state stays after mouse is released.
1427 EXPECT_TRUE(GetWindowOverlapsShelf());
1428 generator
.ReleaseLeftButton();
1429 EXPECT_TRUE(GetWindowOverlapsShelf());
1432 // Verifies that when dragging a window autohidden shelf stays hidden during
1433 // and after the drag.
1434 TEST_P(WorkspaceControllerTestDragging
, DragWindowKeepsShelfAutohidden
) {
1435 aura::test::TestWindowDelegate delegate
;
1436 delegate
.set_window_component(HTCAPTION
);
1437 scoped_ptr
<Window
> w1(aura::test::CreateTestWindowWithDelegate(
1438 &delegate
, ui::wm::WINDOW_TYPE_NORMAL
, gfx::Rect(5, 5, 100, 50), NULL
));
1439 ParentWindowInPrimaryRootWindow(w1
.get());
1441 ShelfLayoutManager
* shelf
= shelf_layout_manager();
1442 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1443 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1445 // Drag very little.
1446 aura::test::EventGenerator
generator(
1447 Shell::GetPrimaryRootWindow(), gfx::Point());
1448 generator
.MoveMouseTo(10, 10);
1449 generator
.PressLeftButton();
1450 generator
.MoveMouseTo(12, 12);
1452 // Shelf should be hidden during and after the drag.
1453 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1454 generator
.ReleaseLeftButton();
1455 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1458 INSTANTIATE_TEST_CASE_P(DockedOrNot
, WorkspaceControllerTestDragging
,
1461 // Verifies that events are targeted properly just outside the window edges.
1462 TEST_F(WorkspaceControllerTest
, WindowEdgeHitTest
) {
1463 aura::test::TestWindowDelegate d_first
, d_second
;
1464 scoped_ptr
<Window
> first(aura::test::CreateTestWindowWithDelegate(&d_first
,
1465 123, gfx::Rect(20, 10, 100, 50), NULL
));
1466 ParentWindowInPrimaryRootWindow(first
.get());
1469 scoped_ptr
<Window
> second(aura::test::CreateTestWindowWithDelegate(&d_second
,
1470 234, gfx::Rect(30, 40, 40, 10), NULL
));
1471 ParentWindowInPrimaryRootWindow(second
.get());
1474 ui::EventTarget
* root
= first
->GetRootWindow();
1475 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
1477 // The windows overlap, and |second| is on top of |first|. Events targeted
1478 // slightly outside the edges of the |second| window should still be targeted
1479 // to |second| to allow resizing the windows easily.
1481 const int kNumPoints
= 4;
1483 const char* direction
;
1484 gfx::Point location
;
1485 } points
[kNumPoints
] = {
1486 { "left", gfx::Point(28, 45) }, // outside the left edge.
1487 { "top", gfx::Point(50, 38) }, // outside the top edge.
1488 { "right", gfx::Point(72, 45) }, // outside the right edge.
1489 { "bottom", gfx::Point(50, 52) }, // outside the bottom edge.
1491 // Do two iterations, first without any transform on |second|, and the second
1492 // time after applying some transform on |second| so that it doesn't get
1494 for (int times
= 0; times
< 2; ++times
) {
1495 SCOPED_TRACE(times
== 0 ? "Without transform" : "With transform");
1496 aura::Window
* expected_target
= times
== 0 ? second
.get() : first
.get();
1497 for (int i
= 0; i
< kNumPoints
; ++i
) {
1498 SCOPED_TRACE(points
[i
].direction
);
1499 const gfx::Point
& location
= points
[i
].location
;
1500 ui::MouseEvent
mouse(ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
,
1502 ui::EventTarget
* target
= targeter
->FindTargetForEvent(root
, &mouse
);
1503 EXPECT_EQ(expected_target
, target
);
1505 ui::TouchEvent
touch(ui::ET_TOUCH_PRESSED
, location
, 0,
1506 ui::EventTimeForNow());
1507 target
= targeter
->FindTargetForEvent(root
, &touch
);
1508 EXPECT_EQ(expected_target
, target
);
1510 // Apply a transform on |second|. After the transform is applied, the window
1511 // should no longer be targeted.
1512 gfx::Transform transform
;
1513 transform
.Translate(70, 40);
1514 second
->SetTransform(transform
);
1518 // Verifies mouse event targeting just outside the window edges for panels.
1519 TEST_F(WorkspaceControllerTest
, WindowEdgeMouseHitTestPanel
) {
1520 aura::test::TestWindowDelegate delegate
;
1521 scoped_ptr
<Window
> window(CreateTestPanel(&delegate
,
1522 gfx::Rect(20, 10, 100, 50)));
1523 ui::EventTarget
* root
= window
->GetRootWindow();
1524 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
1525 const gfx::Rect bounds
= window
->bounds();
1526 const int kNumPoints
= 5;
1528 const char* direction
;
1529 gfx::Point location
;
1531 } points
[kNumPoints
] = {
1532 { "left", gfx::Point(bounds
.x() - 2, bounds
.y() + 10), true },
1533 { "top", gfx::Point(bounds
.x() + 10, bounds
.y() - 2), true },
1534 { "right", gfx::Point(bounds
.right() + 2, bounds
.y() + 10), true },
1535 { "bottom", gfx::Point(bounds
.x() + 10, bounds
.bottom() + 2), true },
1536 { "outside", gfx::Point(bounds
.x() + 10, bounds
.y() - 31), false },
1538 for (int i
= 0; i
< kNumPoints
; ++i
) {
1539 SCOPED_TRACE(points
[i
].direction
);
1540 const gfx::Point
& location
= points
[i
].location
;
1541 ui::MouseEvent
mouse(ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
,
1543 ui::EventTarget
* target
= targeter
->FindTargetForEvent(root
, &mouse
);
1544 if (points
[i
].is_target_hit
)
1545 EXPECT_EQ(window
.get(), target
);
1547 EXPECT_NE(window
.get(), target
);
1551 // Verifies touch event targeting just outside the window edges for panels.
1552 // The shelf is aligned to the bottom by default, and so touches just below
1553 // the bottom edge of the panel should not target the panel itself because
1554 // an AttachedPanelWindowTargeter is installed on the panel container.
1555 TEST_F(WorkspaceControllerTest
, WindowEdgeTouchHitTestPanel
) {
1556 aura::test::TestWindowDelegate delegate
;
1557 scoped_ptr
<Window
> window(CreateTestPanel(&delegate
,
1558 gfx::Rect(20, 10, 100, 50)));
1559 ui::EventTarget
* root
= window
->GetRootWindow();
1560 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
1561 const gfx::Rect bounds
= window
->bounds();
1562 const int kNumPoints
= 5;
1564 const char* direction
;
1565 gfx::Point location
;
1567 } points
[kNumPoints
] = {
1568 { "left", gfx::Point(bounds
.x() - 2, bounds
.y() + 10), true },
1569 { "top", gfx::Point(bounds
.x() + 10, bounds
.y() - 2), true },
1570 { "right", gfx::Point(bounds
.right() + 2, bounds
.y() + 10), true },
1571 { "bottom", gfx::Point(bounds
.x() + 10, bounds
.bottom() + 2), false },
1572 { "outside", gfx::Point(bounds
.x() + 10, bounds
.y() - 31), false },
1574 for (int i
= 0; i
< kNumPoints
; ++i
) {
1575 SCOPED_TRACE(points
[i
].direction
);
1576 const gfx::Point
& location
= points
[i
].location
;
1577 ui::TouchEvent
touch(ui::ET_TOUCH_PRESSED
, location
, 0,
1578 ui::EventTimeForNow());
1579 ui::EventTarget
* target
= targeter
->FindTargetForEvent(root
, &touch
);
1580 if (points
[i
].is_target_hit
)
1581 EXPECT_EQ(window
.get(), target
);
1583 EXPECT_NE(window
.get(), target
);
1587 // Verifies events targeting just outside the window edges for docked windows.
1588 TEST_F(WorkspaceControllerTest
, WindowEdgeHitTestDocked
) {
1589 if (!switches::UseDockedWindows())
1591 aura::test::TestWindowDelegate delegate
;
1592 // Make window smaller than the minimum docked area so that the window edges
1594 delegate
.set_maximum_size(gfx::Size(180, 200));
1595 scoped_ptr
<Window
> window(aura::test::CreateTestWindowWithDelegate(&delegate
,
1596 123, gfx::Rect(20, 10, 100, 50), NULL
));
1597 ParentWindowInPrimaryRootWindow(window
.get());
1598 aura::Window
* docked_container
= Shell::GetContainer(
1599 window
->GetRootWindow(), kShellWindowId_DockedContainer
);
1600 docked_container
->AddChild(window
.get());
1602 ui::EventTarget
* root
= window
->GetRootWindow();
1603 ui::EventTargeter
* targeter
= root
->GetEventTargeter();
1604 const gfx::Rect bounds
= window
->bounds();
1605 const int kNumPoints
= 5;
1607 const char* direction
;
1608 gfx::Point location
;
1610 } points
[kNumPoints
] = {
1611 { "left", gfx::Point(bounds
.x() - 2, bounds
.y() + 10), true },
1612 { "top", gfx::Point(bounds
.x() + 10, bounds
.y() - 2), true },
1613 { "right", gfx::Point(bounds
.right() + 2, bounds
.y() + 10), true },
1614 { "bottom", gfx::Point(bounds
.x() + 10, bounds
.bottom() + 2), true },
1615 { "outside", gfx::Point(bounds
.x() + 10, bounds
.y() - 31), false },
1617 for (int i
= 0; i
< kNumPoints
; ++i
) {
1618 SCOPED_TRACE(points
[i
].direction
);
1619 const gfx::Point
& location
= points
[i
].location
;
1620 ui::MouseEvent
mouse(ui::ET_MOUSE_MOVED
, location
, location
, ui::EF_NONE
,
1622 ui::EventTarget
* target
= targeter
->FindTargetForEvent(root
, &mouse
);
1623 if (points
[i
].is_target_hit
)
1624 EXPECT_EQ(window
.get(), target
);
1626 EXPECT_NE(window
.get(), target
);
1628 ui::TouchEvent
touch(ui::ET_TOUCH_PRESSED
, location
, 0,
1629 ui::EventTimeForNow());
1630 target
= targeter
->FindTargetForEvent(root
, &touch
);
1631 if (points
[i
].is_target_hit
)
1632 EXPECT_EQ(window
.get(), target
);
1634 EXPECT_NE(window
.get(), target
);