Use active window if on current workspace for fullscreen mode.
[chromium-blink-merge.git] / ash / wm / overview / window_selector_unittest.cc
blobc200c381d318f38fce16cc24602a02bb1d066537
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/drag_drop/drag_drop_controller.h"
6 #include "ash/root_window_controller.h"
7 #include "ash/screen_util.h"
8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/shelf_test_api.h"
13 #include "ash/test/shelf_view_test_api.h"
14 #include "ash/test/shell_test_api.h"
15 #include "ash/test/test_shelf_delegate.h"
16 #include "ash/wm/mru_window_tracker.h"
17 #include "ash/wm/overview/window_selector.h"
18 #include "ash/wm/overview/window_selector_controller.h"
19 #include "ash/wm/window_state.h"
20 #include "ash/wm/window_util.h"
21 #include "base/basictypes.h"
22 #include "base/compiler_specific.h"
23 #include "base/memory/scoped_vector.h"
24 #include "base/run_loop.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "ui/aura/client/activation_delegate.h"
27 #include "ui/aura/client/aura_constants.h"
28 #include "ui/aura/client/cursor_client.h"
29 #include "ui/aura/client/focus_client.h"
30 #include "ui/aura/test/event_generator.h"
31 #include "ui/aura/test/test_window_delegate.h"
32 #include "ui/aura/test/test_windows.h"
33 #include "ui/aura/window.h"
34 #include "ui/aura/window_event_dispatcher.h"
35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
36 #include "ui/gfx/rect_conversions.h"
37 #include "ui/gfx/transform.h"
38 #include "ui/views/corewm/window_util.h"
40 namespace ash {
41 namespace internal {
43 namespace {
45 class NonActivatableActivationDelegate
46 : public aura::client::ActivationDelegate {
47 public:
48 virtual bool ShouldActivate() const OVERRIDE {
49 return false;
53 bool IsWindowAbove(aura::Window* w1, aura::Window* w2) {
54 aura::Window* parent = w1->parent();
55 DCHECK_EQ(parent, w2->parent());
56 for (aura::Window::Windows::const_iterator iter = parent->children().begin();
57 iter != parent->children().end(); ++iter) {
58 if (*iter == w1)
59 return false;
60 if (*iter == w2)
61 return true;
63 NOTREACHED();
64 return false;
67 aura::Window* GetWindowByName(aura::Window* container,
68 const std::string& name) {
69 aura::Window* window = NULL;
70 for (aura::Window::Windows::const_iterator iter =
71 container->children().begin(); iter != container->children().end();
72 ++iter) {
73 if ((*iter)->name() == name) {
74 // The name should be unique.
75 DCHECK(!window);
76 window = *iter;
79 return window;
82 // Returns the copy of |window| created for overview. It is found using the
83 // window name which should be the same as the source window's name with a
84 // special suffix, and in the same container as the source window.
85 aura::Window* GetCopyWindow(aura::Window* window) {
86 aura::Window* copy_window = NULL;
87 std::string copy_name = window->name() + " (Copy)";
88 std::vector<aura::Window*> containers(
89 Shell::GetContainersFromAllRootWindows(window->parent()->id(), NULL));
90 for (std::vector<aura::Window*>::iterator iter = containers.begin();
91 iter != containers.end(); ++iter) {
92 aura::Window* found = GetWindowByName(*iter, copy_name);
93 if (found) {
94 // There should only be one copy window.
95 DCHECK(!copy_window);
96 copy_window = found;
99 return copy_window;
102 void CancelDrag(DragDropController* controller, bool* canceled) {
103 if (controller->IsDragDropInProgress()) {
104 *canceled = true;
105 controller->DragCancel();
109 } // namespace
111 class WindowSelectorTest : public test::AshTestBase {
112 public:
113 WindowSelectorTest() {}
114 virtual ~WindowSelectorTest() {}
116 virtual void SetUp() OVERRIDE {
117 test::AshTestBase::SetUp();
118 ASSERT_TRUE(test::TestShelfDelegate::instance());
120 shelf_view_test_.reset(new test::ShelfViewTestAPI(
121 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view()));
122 shelf_view_test_->SetAnimationDuration(1);
125 aura::Window* CreateWindow(const gfx::Rect& bounds) {
126 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds);
129 aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) {
130 aura::Window* window = CreateWindow(bounds);
131 aura::client::SetActivationDelegate(window,
132 &non_activatable_activation_delegate_);
133 EXPECT_FALSE(ash::wm::CanActivateWindow(window));
134 return window;
137 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) {
138 aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
139 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, bounds);
140 test::TestShelfDelegate::instance()->AddShelfItem(window);
141 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
142 return window;
145 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) {
146 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1);
147 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2);
148 return window1_bounds.Intersects(window2_bounds);
151 void ToggleOverview() {
152 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview();
155 void Cycle(WindowSelector::Direction direction) {
156 ash::Shell::GetInstance()->window_selector_controller()->
157 HandleCycleWindow(direction);
160 void StopCycling() {
161 ash::Shell::GetInstance()->window_selector_controller()->window_selector_->
162 SelectWindow();
165 void FireOverviewStartTimer() {
166 // Calls the method to start overview mode which is normally called by the
167 // timer. The timer will still fire and call this method triggering the
168 // DCHECK that overview mode was not already started, except that we call
169 // StopCycling before the timer has a chance to fire.
170 ash::Shell::GetInstance()->window_selector_controller()->window_selector_->
171 StartOverview();
174 gfx::Transform GetTransformRelativeTo(gfx::PointF origin,
175 const gfx::Transform& transform) {
176 gfx::Transform t;
177 t.Translate(origin.x(), origin.y());
178 t.PreconcatTransform(transform);
179 t.Translate(-origin.x(), -origin.y());
180 return t;
183 gfx::RectF GetTransformedBounds(aura::Window* window) {
184 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
185 window->parent(), window->layer()->bounds()));
186 gfx::Transform transform(GetTransformRelativeTo(bounds.origin(),
187 window->layer()->transform()));
188 transform.TransformRect(&bounds);
189 return bounds;
192 gfx::RectF GetTransformedTargetBounds(aura::Window* window) {
193 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
194 window->parent(), window->layer()->GetTargetBounds()));
195 gfx::Transform transform(GetTransformRelativeTo(bounds.origin(),
196 window->layer()->GetTargetTransform()));
197 transform.TransformRect(&bounds);
198 return bounds;
201 gfx::RectF GetTransformedBoundsInRootWindow(aura::Window* window) {
202 gfx::RectF bounds = gfx::Rect(window->bounds().size());
203 aura::Window* root = window->GetRootWindow();
204 CHECK(window->layer());
205 CHECK(root->layer());
206 gfx::Transform transform;
207 if (!window->layer()->GetTargetTransformRelativeTo(root->layer(),
208 &transform)) {
209 return gfx::RectF();
211 transform.TransformRect(&bounds);
212 return bounds;
215 void ClickWindow(aura::Window* window) {
216 aura::test::EventGenerator event_generator(window->GetRootWindow(), window);
217 gfx::RectF target = GetTransformedBounds(window);
218 event_generator.ClickLeftButton();
221 bool IsSelecting() {
222 return ash::Shell::GetInstance()->window_selector_controller()->
223 IsSelecting();
226 aura::Window* GetFocusedWindow() {
227 return aura::client::GetFocusClient(
228 Shell::GetPrimaryRootWindow())->GetFocusedWindow();
231 test::ShelfViewTestAPI* shelf_view_test() {
232 return shelf_view_test_.get();
235 private:
236 aura::test::TestWindowDelegate delegate_;
237 NonActivatableActivationDelegate non_activatable_activation_delegate_;
238 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
240 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
243 // Tests entering overview mode with two windows and selecting one.
244 TEST_F(WindowSelectorTest, Basic) {
245 gfx::Rect bounds(0, 0, 400, 400);
246 aura::Window* root_window = Shell::GetPrimaryRootWindow();
247 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
248 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
249 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
250 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
251 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
252 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
253 wm::ActivateWindow(window2.get());
254 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
255 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
256 EXPECT_EQ(window2.get(), GetFocusedWindow());
257 // Hide the cursor before entering overview to test that it will be shown.
258 aura::client::GetCursorClient(root_window)->HideCursor();
260 // In overview mode the windows should no longer overlap and focus should
261 // be removed from the window.
262 ToggleOverview();
263 EXPECT_EQ(NULL, GetFocusedWindow());
264 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
265 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get()));
266 // Panels 1 and 2 should still be overlapping being in a single selector
267 // item.
268 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
270 // The cursor should be visible and locked as a pointer
271 EXPECT_EQ(ui::kCursorPointer,
272 root_window->GetDispatcher()->host()->last_cursor().native_type());
273 EXPECT_TRUE(aura::client::GetCursorClient(root_window)->IsCursorLocked());
274 EXPECT_TRUE(aura::client::GetCursorClient(root_window)->IsCursorVisible());
276 // Clicking window 1 should activate it.
277 ClickWindow(window1.get());
278 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
279 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
280 EXPECT_EQ(window1.get(), GetFocusedWindow());
282 // Cursor should have been unlocked.
283 EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked());
286 // Tests entering overview mode with two windows and selecting one.
287 TEST_F(WindowSelectorTest, FullscreenWindow) {
288 gfx::Rect bounds(0, 0, 400, 400);
289 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
290 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
291 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
292 wm::ActivateWindow(window1.get());
294 wm::GetWindowState(window1.get())->ToggleFullscreen();
295 // The panel is hidden in fullscreen mode.
296 EXPECT_FALSE(panel1->IsVisible());
297 EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
299 // Enter overview and select the fullscreen window.
300 ToggleOverview();
302 // The panel becomes temporarily visible for the overview.
303 EXPECT_TRUE(panel1->IsVisible());
304 ClickWindow(window1.get());
306 // The window is still fullscreen as it was selected. The panel should again
307 // be hidden.
308 EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
309 EXPECT_FALSE(panel1->IsVisible());
311 // Entering overview and selecting another window, the previous window remains
312 // fullscreen.
313 // TODO(flackr): Currently the panel remains hidden, but should become visible
314 // again.
315 ToggleOverview();
316 ClickWindow(window2.get());
317 EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
319 // Verify that selecting the panel will make it visible.
320 // TODO(flackr): Click on panel rather than cycle to it when
321 // clicking on panels is fixed, see http://crbug.com/339834.
322 Cycle(WindowSelector::FORWARD);
323 Cycle(WindowSelector::FORWARD);
324 StopCycling();
325 EXPECT_TRUE(wm::GetWindowState(panel1.get())->IsActive());
326 EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
327 EXPECT_TRUE(panel1->IsVisible());
330 // Tests that the shelf dimming state is removed while in overview and restored
331 // on exiting overview.
332 TEST_F(WindowSelectorTest, OverviewUndimsShelf) {
333 gfx::Rect bounds(0, 0, 400, 400);
334 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
335 wm::WindowState* window_state = wm::GetWindowState(window1.get());
336 window_state->Maximize();
337 ash::ShelfWidget* shelf = Shell::GetPrimaryRootWindowController()->shelf();
338 EXPECT_TRUE(shelf->GetDimsShelf());
339 ToggleOverview();
340 EXPECT_FALSE(shelf->GetDimsShelf());
341 ToggleOverview();
342 EXPECT_TRUE(shelf->GetDimsShelf());
345 // Tests that beginning window selection hides the app list.
346 TEST_F(WindowSelectorTest, SelectingHidesAppList) {
347 gfx::Rect bounds(0, 0, 400, 400);
348 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
349 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
350 Shell::GetInstance()->ToggleAppList(NULL);
351 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
352 ToggleOverview();
353 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
354 ToggleOverview();
356 // The app list uses an animation to fade out. If it is toggled on immediately
357 // after being removed the old widget is re-used and it does not gain focus.
358 // When running under normal circumstances this shouldn't be possible, but
359 // it is in a test without letting the message loop run.
360 RunAllPendingInMessageLoop();
362 Shell::GetInstance()->ToggleAppList(NULL);
363 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
364 Cycle(WindowSelector::FORWARD);
365 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
366 StopCycling();
369 // Tests that a minimized window's visibility and layer visibility is correctly
370 // changed when entering overview and restored when leaving overview mode.
371 TEST_F(WindowSelectorTest, MinimizedWindowVisibility) {
372 gfx::Rect bounds(0, 0, 400, 400);
373 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
374 wm::WindowState* window_state = wm::GetWindowState(window1.get());
375 window_state->Minimize();
376 EXPECT_FALSE(window1->IsVisible());
377 EXPECT_FALSE(window1->layer()->GetTargetVisibility());
379 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
380 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
381 ToggleOverview();
382 EXPECT_TRUE(window1->IsVisible());
383 EXPECT_TRUE(window1->layer()->GetTargetVisibility());
386 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
387 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
388 ToggleOverview();
389 EXPECT_FALSE(window1->IsVisible());
390 EXPECT_FALSE(window1->layer()->GetTargetVisibility());
394 // Tests that a bounds change during overview is corrected for.
395 TEST_F(WindowSelectorTest, BoundsChangeDuringOverview) {
396 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 400, 400)));
397 ToggleOverview();
398 gfx::Rect overview_bounds =
399 ToEnclosingRect(GetTransformedTargetBounds(window.get()));
400 window->SetBounds(gfx::Rect(200, 0, 200, 200));
401 gfx::Rect new_overview_bounds =
402 ToEnclosingRect(GetTransformedTargetBounds(window.get()));
403 EXPECT_EQ(overview_bounds.x(), new_overview_bounds.x());
404 EXPECT_EQ(overview_bounds.y(), new_overview_bounds.y());
405 EXPECT_EQ(overview_bounds.width(), new_overview_bounds.width());
406 EXPECT_EQ(overview_bounds.height(), new_overview_bounds.height());
407 ToggleOverview();
410 // Tests entering overview mode with three windows and cycling through them.
411 TEST_F(WindowSelectorTest, BasicCycle) {
412 gfx::Rect bounds(0, 0, 400, 400);
413 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
414 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
415 scoped_ptr<aura::Window> window3(CreateWindow(bounds));
416 wm::ActivateWindow(window3.get());
417 wm::ActivateWindow(window2.get());
418 wm::ActivateWindow(window1.get());
419 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
420 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
421 EXPECT_FALSE(wm::IsActiveWindow(window3.get()));
423 Cycle(WindowSelector::FORWARD);
424 EXPECT_TRUE(IsSelecting());
425 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
427 Cycle(WindowSelector::FORWARD);
428 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
430 StopCycling();
431 EXPECT_FALSE(IsSelecting());
432 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
433 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
434 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
437 // Tests that cycling through windows preserves the window stacking order.
438 TEST_F(WindowSelectorTest, CyclePreservesStackingOrder) {
439 gfx::Rect bounds(0, 0, 400, 400);
440 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
441 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
442 scoped_ptr<aura::Window> window3(CreateWindow(bounds));
443 wm::ActivateWindow(window3.get());
444 wm::ActivateWindow(window2.get());
445 wm::ActivateWindow(window1.get());
446 // Window order from top to bottom is 1, 2, 3.
447 EXPECT_TRUE(IsWindowAbove(window1.get(), window2.get()));
448 EXPECT_TRUE(IsWindowAbove(window2.get(), window3.get()));
450 // On window 2.
451 Cycle(WindowSelector::FORWARD);
452 EXPECT_TRUE(IsWindowAbove(window2.get(), window1.get()));
453 EXPECT_TRUE(IsWindowAbove(window1.get(), window3.get()));
455 // On window 3.
456 Cycle(WindowSelector::FORWARD);
457 EXPECT_TRUE(IsWindowAbove(window3.get(), window1.get()));
458 EXPECT_TRUE(IsWindowAbove(window1.get(), window2.get()));
460 // Back on window 1.
461 Cycle(WindowSelector::FORWARD);
462 EXPECT_TRUE(IsWindowAbove(window1.get(), window2.get()));
463 EXPECT_TRUE(IsWindowAbove(window2.get(), window3.get()));
464 StopCycling();
467 // Tests that cycling through windows shows and minimizes windows as they
468 // are passed.
469 TEST_F(WindowSelectorTest, CyclePreservesMinimization) {
470 gfx::Rect bounds(0, 0, 400, 400);
471 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
472 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
473 wm::ActivateWindow(window2.get());
474 wm::GetWindowState(window2.get())->Minimize();
475 wm::ActivateWindow(window1.get());
476 EXPECT_TRUE(wm::IsWindowMinimized(window2.get()));
478 // On window 2.
479 Cycle(WindowSelector::FORWARD);
480 EXPECT_FALSE(wm::IsWindowMinimized(window2.get()));
482 // Back on window 1.
483 Cycle(WindowSelector::FORWARD);
484 EXPECT_TRUE(wm::IsWindowMinimized(window2.get()));
486 StopCycling();
487 EXPECT_TRUE(wm::IsWindowMinimized(window2.get()));
490 // Tests beginning cycling while in overview mode.
491 TEST_F(WindowSelectorTest, OverviewTransitionToCycle) {
492 gfx::Rect bounds(0, 0, 400, 400);
493 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
494 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
495 wm::ActivateWindow(window2.get());
496 wm::ActivateWindow(window1.get());
498 ToggleOverview();
499 Cycle(WindowSelector::FORWARD);
500 StopCycling();
502 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
503 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
504 EXPECT_EQ(window2.get(), GetFocusedWindow());
507 // Tests cycles between panel and normal windows.
508 TEST_F(WindowSelectorTest, CyclePanels) {
509 gfx::Rect bounds(0, 0, 400, 400);
510 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
511 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
512 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
513 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
514 wm::ActivateWindow(window2.get());
515 wm::ActivateWindow(window1.get());
516 wm::ActivateWindow(panel2.get());
517 wm::ActivateWindow(panel1.get());
518 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
520 // Cycling once should select window1 since the panels are grouped into a
521 // single selectable item.
522 Cycle(WindowSelector::FORWARD);
523 StopCycling();
524 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
526 // Cycling again should select the most recently used panel.
527 Cycle(WindowSelector::FORWARD);
528 StopCycling();
529 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
532 // Tests the visibility of panel windows during cycling.
533 TEST_F(WindowSelectorTest, CyclePanelVisibility) {
534 gfx::Rect bounds(0, 0, 400, 400);
535 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
536 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
537 wm::ActivateWindow(panel1.get());
538 wm::ActivateWindow(window1.get());
540 Cycle(WindowSelector::FORWARD);
541 FireOverviewStartTimer();
542 EXPECT_EQ(1.0f, panel1->layer()->GetTargetOpacity());
543 StopCycling();
546 // Tests cycles between panel and normal windows.
547 TEST_F(WindowSelectorTest, CyclePanelsDestroyed) {
548 gfx::Rect bounds(0, 0, 400, 400);
549 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
550 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
551 scoped_ptr<aura::Window> window3(CreateWindow(bounds));
552 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
553 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
554 wm::ActivateWindow(window3.get());
555 wm::ActivateWindow(panel2.get());
556 wm::ActivateWindow(panel1.get());
557 wm::ActivateWindow(window2.get());
558 wm::ActivateWindow(window1.get());
559 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
561 // Cycling once highlights window2.
562 Cycle(WindowSelector::FORWARD);
563 // All panels are destroyed.
564 panel1.reset();
565 panel2.reset();
566 // Cycling again should now select window3.
567 Cycle(WindowSelector::FORWARD);
568 StopCycling();
569 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
572 // Tests cycles between panel and normal windows.
573 TEST_F(WindowSelectorTest, CycleMruPanelDestroyed) {
574 gfx::Rect bounds(0, 0, 400, 400);
575 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
576 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
577 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
578 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
579 wm::ActivateWindow(panel2.get());
580 wm::ActivateWindow(panel1.get());
581 wm::ActivateWindow(window2.get());
582 wm::ActivateWindow(window1.get());
583 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
585 // Cycling once highlights window2.
586 Cycle(WindowSelector::FORWARD);
587 // Panel 1 is the next item as the MRU panel, removing it should make panel 2
588 // the next window to be selected.
589 panel1.reset();
590 // Cycling again should now select window3.
591 Cycle(WindowSelector::FORWARD);
592 StopCycling();
593 EXPECT_TRUE(wm::IsActiveWindow(panel2.get()));
596 // Tests that a newly created window aborts overview.
597 TEST_F(WindowSelectorTest, NewWindowCancelsOveriew) {
598 gfx::Rect bounds(0, 0, 400, 400);
599 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
600 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
601 ToggleOverview();
602 EXPECT_TRUE(IsSelecting());
604 // A window being created should exit overview mode.
605 scoped_ptr<aura::Window> window3(CreateWindow(bounds));
606 EXPECT_FALSE(IsSelecting());
609 // Tests that a window activation exits overview mode.
610 TEST_F(WindowSelectorTest, ActivationCancelsOveriew) {
611 gfx::Rect bounds(0, 0, 400, 400);
612 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
613 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
614 window2->Focus();
615 ToggleOverview();
616 EXPECT_TRUE(IsSelecting());
618 // A window being activated should exit overview mode.
619 window1->Focus();
620 EXPECT_FALSE(IsSelecting());
622 // window1 should be focused after exiting even though window2 was focused on
623 // entering overview because we exited due to an activation.
624 EXPECT_EQ(window1.get(), GetFocusedWindow());
627 // Verifies that overview mode only begins after a delay when cycling.
628 TEST_F(WindowSelectorTest, CycleOverviewDelay) {
629 gfx::Rect bounds(0, 0, 400, 400);
630 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
631 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
632 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
634 // When cycling first starts, the windows will still be overlapping.
635 Cycle(WindowSelector::FORWARD);
636 EXPECT_TRUE(IsSelecting());
637 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
639 // Once the overview timer fires, the windows should no longer overlap.
640 FireOverviewStartTimer();
641 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
642 StopCycling();
645 // Tests that exiting overview mode without selecting a window restores focus
646 // to the previously focused window.
647 TEST_F(WindowSelectorTest, CancelRestoresFocus) {
648 gfx::Rect bounds(0, 0, 400, 400);
649 scoped_ptr<aura::Window> window(CreateWindow(bounds));
650 wm::ActivateWindow(window.get());
651 EXPECT_EQ(window.get(), GetFocusedWindow());
653 // In overview mode, focus should be removed.
654 ToggleOverview();
655 EXPECT_EQ(NULL, GetFocusedWindow());
657 // If canceling overview mode, focus should be restored.
658 ToggleOverview();
659 EXPECT_EQ(window.get(), GetFocusedWindow());
662 // Tests that overview mode is exited if the last remaining window is destroyed.
663 TEST_F(WindowSelectorTest, LastWindowDestroyed) {
664 gfx::Rect bounds(0, 0, 400, 400);
665 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
666 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
667 ToggleOverview();
669 window1.reset();
670 window2.reset();
671 EXPECT_FALSE(IsSelecting());
674 // Tests that entering overview mode restores a window to its original
675 // target location.
676 TEST_F(WindowSelectorTest, QuickReentryRestoresInitialTransform) {
677 gfx::Rect bounds(0, 0, 400, 400);
678 scoped_ptr<aura::Window> window(CreateWindow(bounds));
679 gfx::Rect initial_bounds = ToEnclosingRect(
680 GetTransformedBounds(window.get()));
681 ToggleOverview();
682 // Quickly exit and reenter overview mode. The window should still be
683 // animating when we reenter. We cannot short circuit animations for this but
684 // we also don't have to wait for them to complete.
686 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
687 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
688 ToggleOverview();
689 ToggleOverview();
691 EXPECT_NE(initial_bounds, ToEnclosingRect(
692 GetTransformedTargetBounds(window.get())));
693 ToggleOverview();
694 EXPECT_FALSE(IsSelecting());
695 EXPECT_EQ(initial_bounds, ToEnclosingRect(
696 GetTransformedTargetBounds(window.get())));
699 // Tests that non-activatable windows are hidden when entering overview mode.
700 TEST_F(WindowSelectorTest, NonActivatableWindowsHidden) {
701 gfx::Rect bounds(0, 0, 400, 400);
702 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
703 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
704 scoped_ptr<aura::Window> non_activatable_window(
705 CreateNonActivatableWindow(Shell::GetPrimaryRootWindow()->bounds()));
706 EXPECT_TRUE(non_activatable_window->IsVisible());
707 ToggleOverview();
708 EXPECT_FALSE(non_activatable_window->IsVisible());
709 ToggleOverview();
710 EXPECT_TRUE(non_activatable_window->IsVisible());
712 // Test that a window behind the fullscreen non-activatable window can be
713 // clicked.
714 non_activatable_window->parent()->StackChildAtTop(
715 non_activatable_window.get());
716 ToggleOverview();
717 ClickWindow(window1.get());
718 EXPECT_FALSE(IsSelecting());
719 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
722 // Tests that windows with modal child windows are transformed with the modal
723 // child even though not activatable themselves.
724 TEST_F(WindowSelectorTest, ModalChild) {
725 gfx::Rect bounds(0, 0, 400, 400);
726 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
727 scoped_ptr<aura::Window> child1(CreateWindow(bounds));
728 child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
729 views::corewm::AddTransientChild(window1.get(), child1.get());
730 EXPECT_EQ(window1->parent(), child1->parent());
731 ToggleOverview();
732 EXPECT_TRUE(window1->IsVisible());
733 EXPECT_TRUE(child1->IsVisible());
734 EXPECT_EQ(ToEnclosingRect(GetTransformedTargetBounds(child1.get())),
735 ToEnclosingRect(GetTransformedTargetBounds(window1.get())));
736 ToggleOverview();
739 // Tests that clicking a modal window's parent activates the modal window in
740 // overview.
741 TEST_F(WindowSelectorTest, ClickModalWindowParent) {
742 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 180, 180)));
743 scoped_ptr<aura::Window> child1(CreateWindow(gfx::Rect(200, 0, 180, 180)));
744 child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
745 views::corewm::AddTransientChild(window1.get(), child1.get());
746 EXPECT_FALSE(WindowsOverlapping(window1.get(), child1.get()));
747 EXPECT_EQ(window1->parent(), child1->parent());
748 ToggleOverview();
749 // Given that their relative positions are preserved, the windows should still
750 // not overlap.
751 EXPECT_FALSE(WindowsOverlapping(window1.get(), child1.get()));
752 ClickWindow(window1.get());
753 EXPECT_FALSE(IsSelecting());
755 // Clicking on window1 should activate child1.
756 EXPECT_TRUE(wm::IsActiveWindow(child1.get()));
759 // Tests that windows remain on the display they are currently on in overview
760 // mode.
761 TEST_F(WindowSelectorTest, MultipleDisplays) {
762 if (!SupportsMultipleDisplays())
763 return;
765 UpdateDisplay("600x400,600x400");
766 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
767 gfx::Rect bounds1(0, 0, 400, 400);
768 gfx::Rect bounds2(650, 0, 400, 400);
770 scoped_ptr<aura::Window> window1(CreateWindow(bounds1));
771 scoped_ptr<aura::Window> window2(CreateWindow(bounds1));
772 scoped_ptr<aura::Window> window3(CreateWindow(bounds2));
773 scoped_ptr<aura::Window> window4(CreateWindow(bounds2));
774 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds1));
775 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds1));
776 scoped_ptr<aura::Window> panel3(CreatePanelWindow(bounds2));
777 scoped_ptr<aura::Window> panel4(CreatePanelWindow(bounds2));
778 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
779 EXPECT_EQ(root_windows[0], window2->GetRootWindow());
780 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
781 EXPECT_EQ(root_windows[1], window4->GetRootWindow());
783 EXPECT_EQ(root_windows[0], panel1->GetRootWindow());
784 EXPECT_EQ(root_windows[0], panel2->GetRootWindow());
785 EXPECT_EQ(root_windows[1], panel3->GetRootWindow());
786 EXPECT_EQ(root_windows[1], panel4->GetRootWindow());
788 // In overview mode, each window remains in the same root window.
789 ToggleOverview();
790 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
791 EXPECT_EQ(root_windows[0], window2->GetRootWindow());
792 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
793 EXPECT_EQ(root_windows[1], window4->GetRootWindow());
794 EXPECT_EQ(root_windows[0], panel1->GetRootWindow());
795 EXPECT_EQ(root_windows[0], panel2->GetRootWindow());
796 EXPECT_EQ(root_windows[1], panel3->GetRootWindow());
797 EXPECT_EQ(root_windows[1], panel4->GetRootWindow());
799 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
800 ToEnclosingRect(GetTransformedTargetBounds(window1.get()))));
801 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
802 ToEnclosingRect(GetTransformedTargetBounds(window2.get()))));
803 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
804 ToEnclosingRect(GetTransformedTargetBounds(window3.get()))));
805 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
806 ToEnclosingRect(GetTransformedTargetBounds(window4.get()))));
808 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
809 ToEnclosingRect(GetTransformedTargetBounds(panel1.get()))));
810 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
811 ToEnclosingRect(GetTransformedTargetBounds(panel2.get()))));
812 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
813 ToEnclosingRect(GetTransformedTargetBounds(panel3.get()))));
814 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
815 ToEnclosingRect(GetTransformedTargetBounds(panel4.get()))));
816 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
817 EXPECT_TRUE(WindowsOverlapping(panel3.get(), panel4.get()));
818 EXPECT_FALSE(WindowsOverlapping(panel1.get(), panel3.get()));
821 // Verifies that the single display overview used during alt tab cycling uses
822 // the display of the selected window by default.
823 TEST_F(WindowSelectorTest, CycleOverviewUsesCurrentDisplay) {
824 if (!SupportsMultipleDisplays())
825 return;
827 UpdateDisplay("400x400,400x400");
828 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
830 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100)));
831 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(450, 0, 100, 100)));
832 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
833 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
834 wm::ActivateWindow(window2.get());
835 wm::ActivateWindow(window1.get());
836 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
838 Cycle(WindowSelector::FORWARD);
839 FireOverviewStartTimer();
841 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
842 ToEnclosingRect(GetTransformedTargetBounds(window1.get()))));
843 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
844 ToEnclosingRect(GetTransformedTargetBounds(window2.get()))));
845 StopCycling();
848 // Verifies that the windows being shown on another display are copied.
849 TEST_F(WindowSelectorTest, CycleMultipleDisplaysCopiesWindows) {
850 if (!SupportsMultipleDisplays())
851 return;
853 UpdateDisplay("400x400,400x400");
854 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
856 gfx::Rect root1_rect(0, 0, 100, 100);
857 gfx::Rect root2_rect(450, 0, 100, 100);
858 scoped_ptr<aura::Window> unmoved1(CreateWindow(root2_rect));
859 scoped_ptr<aura::Window> unmoved2(CreateWindow(root2_rect));
860 scoped_ptr<aura::Window> moved1_trans_parent(CreateWindow(root1_rect));
861 scoped_ptr<aura::Window> moved1(CreateWindow(root1_rect));
862 unmoved1->SetName("unmoved1");
863 unmoved2->SetName("unmoved2");
864 moved1->SetName("moved1");
865 moved1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
866 views::corewm::AddTransientChild(moved1_trans_parent.get(), moved1.get());
867 moved1_trans_parent->SetName("moved1_trans_parent");
869 EXPECT_EQ(root_windows[0], moved1->GetRootWindow());
870 EXPECT_EQ(root_windows[0], moved1_trans_parent->GetRootWindow());
871 EXPECT_EQ(root_windows[1], unmoved1->GetRootWindow());
872 EXPECT_EQ(root_windows[1], unmoved2->GetRootWindow());
873 wm::ActivateWindow(unmoved2.get());
874 wm::ActivateWindow(unmoved1.get());
876 Cycle(WindowSelector::FORWARD);
877 FireOverviewStartTimer();
879 // All windows are moved to second root window.
880 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
881 ToEnclosingRect(GetTransformedTargetBounds(unmoved1.get()))));
882 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
883 ToEnclosingRect(GetTransformedTargetBounds(unmoved2.get()))));
884 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
885 ToEnclosingRect(GetTransformedTargetBounds(moved1.get()))));
886 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
887 ToEnclosingRect(GetTransformedTargetBounds(moved1_trans_parent.get()))));
889 // unmoved1 and unmoved2 were already on the correct display and should not
890 // have been copied.
891 EXPECT_TRUE(!GetCopyWindow(unmoved1.get()));
892 EXPECT_TRUE(!GetCopyWindow(unmoved2.get()));
894 // moved1 and its transient parent moved1_trans_parent should have also been
895 // copied for displaying on root_windows[1].
896 aura::Window* copy1 = GetCopyWindow(moved1.get());
897 aura::Window* copy1_trans_parent = GetCopyWindow(moved1_trans_parent.get());
898 ASSERT_FALSE(!copy1);
899 ASSERT_FALSE(!copy1_trans_parent);
901 // Verify that the bounds and transform of the copy match the original window
902 // but that it is on the other root window.
903 EXPECT_EQ(root_windows[1], copy1->GetRootWindow());
904 EXPECT_EQ(moved1->GetBoundsInScreen().ToString(),
905 copy1->GetBoundsInScreen().ToString());
906 EXPECT_EQ(moved1->layer()->GetTargetTransform().ToString(),
907 copy1->layer()->GetTargetTransform().ToString());
908 StopCycling();
910 // After cycling the copy windows should have been destroyed.
911 RunAllPendingInMessageLoop();
912 EXPECT_TRUE(!GetCopyWindow(moved1.get()));
913 EXPECT_TRUE(!GetCopyWindow(moved1_trans_parent.get()));
916 // Tests that beginning to cycle from overview mode moves windows to the
917 // active display.
918 TEST_F(WindowSelectorTest, MultipleDisplaysOverviewTransitionToCycle) {
919 if (!SupportsMultipleDisplays())
920 return;
922 UpdateDisplay("400x400,400x400");
923 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
925 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100)));
926 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(450, 0, 100, 100)));
927 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
928 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
929 wm::ActivateWindow(window2.get());
930 wm::ActivateWindow(window1.get());
932 ToggleOverview();
933 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
934 ToEnclosingRect(GetTransformedTargetBounds(window1.get()))));
935 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(
936 ToEnclosingRect(GetTransformedTargetBounds(window2.get()))));
938 Cycle(WindowSelector::FORWARD);
939 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
940 ToEnclosingRect(GetTransformedTargetBounds(window1.get()))));
941 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains(
942 ToEnclosingRect(GetTransformedTargetBounds(window2.get()))));
943 StopCycling();
946 // Tests that a bounds change during overview is corrected for.
947 TEST_F(WindowSelectorTest, BoundsChangeDuringCycleOnOtherDisplay) {
948 if (!SupportsMultipleDisplays())
949 return;
951 UpdateDisplay("400x400,400x400");
952 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
954 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100)));
955 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(450, 0, 100, 100)));
956 scoped_ptr<aura::Window> window3(CreateWindow(gfx::Rect(450, 0, 100, 100)));
957 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
958 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
959 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
960 wm::ActivateWindow(window1.get());
961 wm::ActivateWindow(window2.get());
962 wm::ActivateWindow(window3.get());
964 Cycle(WindowSelector::FORWARD);
965 FireOverviewStartTimer();
967 gfx::Rect overview_bounds(
968 ToEnclosingRect(GetTransformedTargetBounds(window1.get())));
969 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains(overview_bounds));
971 // Change the position and size of window1 (being displayed on the second
972 // root window) and it should remain within the same bounds.
973 window1->SetBounds(gfx::Rect(100, 0, 200, 200));
974 gfx::Rect new_overview_bounds =
975 ToEnclosingRect(GetTransformedTargetBounds(window1.get()));
976 EXPECT_EQ(overview_bounds.x(), new_overview_bounds.x());
977 EXPECT_EQ(overview_bounds.y(), new_overview_bounds.y());
978 EXPECT_EQ(overview_bounds.width(), new_overview_bounds.width());
979 EXPECT_EQ(overview_bounds.height(), new_overview_bounds.height());
980 StopCycling();
983 // Tests shutting down during overview.
984 TEST_F(WindowSelectorTest, Shutdown) {
985 gfx::Rect bounds(0, 0, 400, 400);
986 // These windows will be deleted when the test exits and the Shell instance
987 // is shut down.
988 aura::Window* window1(CreateWindow(bounds));
989 aura::Window* window2(CreateWindow(bounds));
990 aura::Window* window3(CreatePanelWindow(bounds));
991 aura::Window* window4(CreatePanelWindow(bounds));
993 wm::ActivateWindow(window4);
994 wm::ActivateWindow(window3);
995 wm::ActivateWindow(window2);
996 wm::ActivateWindow(window1);
998 ToggleOverview();
1001 // Tests removing a display during overview.
1002 TEST_F(WindowSelectorTest, RemoveDisplay) {
1003 if (!SupportsMultipleDisplays())
1004 return;
1006 UpdateDisplay("400x400,400x400");
1007 gfx::Rect bounds1(0, 0, 100, 100);
1008 gfx::Rect bounds2(450, 0, 100, 100);
1009 scoped_ptr<aura::Window> window1(CreateWindow(bounds1));
1010 scoped_ptr<aura::Window> window2(CreateWindow(bounds2));
1011 scoped_ptr<aura::Window> window3(CreatePanelWindow(bounds1));
1012 scoped_ptr<aura::Window> window4(CreatePanelWindow(bounds2));
1014 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1015 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
1016 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
1017 EXPECT_EQ(root_windows[0], window3->GetRootWindow());
1018 EXPECT_EQ(root_windows[1], window4->GetRootWindow());
1020 wm::ActivateWindow(window4.get());
1021 wm::ActivateWindow(window3.get());
1022 wm::ActivateWindow(window2.get());
1023 wm::ActivateWindow(window1.get());
1025 ToggleOverview();
1026 EXPECT_TRUE(IsSelecting());
1027 UpdateDisplay("400x400");
1028 EXPECT_FALSE(IsSelecting());
1031 // Tests starting overview during a drag and drop tracking operation.
1032 // TODO(flackr): Fix memory corruption crash when running locally (not failing
1033 // on bots). See http://crbug.com/342528.
1034 TEST_F(WindowSelectorTest, DISABLED_DragDropInProgress) {
1035 bool drag_canceled_by_test = false;
1036 gfx::Rect bounds(0, 0, 400, 400);
1037 scoped_ptr<aura::Window> window(CreateWindow(bounds));
1038 test::ShellTestApi shell_test_api(Shell::GetInstance());
1039 ash::internal::DragDropController* drag_drop_controller =
1040 shell_test_api.drag_drop_controller();
1041 ui::OSExchangeData data;
1042 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
1043 base::Bind(&WindowSelectorTest::ToggleOverview,
1044 base::Unretained(this)));
1045 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
1046 base::Bind(&CancelDrag, drag_drop_controller, &drag_canceled_by_test));
1047 data.SetString(base::UTF8ToUTF16("I am being dragged"));
1048 drag_drop_controller->StartDragAndDrop(data, window->GetRootWindow(),
1049 window.get(), gfx::Point(5, 5), ui::DragDropTypes::DRAG_MOVE,
1050 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
1051 RunAllPendingInMessageLoop();
1052 EXPECT_FALSE(drag_canceled_by_test);
1053 ASSERT_TRUE(IsSelecting());
1054 RunAllPendingInMessageLoop();
1057 TEST_F(WindowSelectorTest, HitTestingInOverview) {
1058 gfx::Rect window_bounds(20, 10, 200, 300);
1059 aura::Window* root_window = Shell::GetPrimaryRootWindow();
1060 scoped_ptr<aura::Window> window1(CreateWindow(window_bounds));
1061 scoped_ptr<aura::Window> window2(CreateWindow(window_bounds));
1063 ToggleOverview();
1064 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1.get());
1065 gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2.get());
1066 EXPECT_NE(bounds1.ToString(), bounds2.ToString());
1068 ui::EventTarget* root_target = root_window;
1069 ui::EventTargeter* targeter = root_target->GetEventTargeter();
1070 aura::Window* windows[] = { window1.get(), window2.get() };
1071 for (size_t w = 0; w < arraysize(windows); ++w) {
1072 gfx::RectF bounds = GetTransformedBoundsInRootWindow(windows[w]);
1073 gfx::Point points[] = {
1074 gfx::Point(bounds.x(), bounds.y()),
1075 gfx::Point(bounds.right() - 1, bounds.y()),
1076 gfx::Point(bounds.x(), bounds.bottom() - 1),
1077 gfx::Point(bounds.right() - 1, bounds.bottom() - 1),
1080 for (size_t p = 0; p < arraysize(points); ++p) {
1081 ui::MouseEvent event(ui::ET_MOUSE_MOVED, points[p], points[p],
1082 ui::EF_NONE, ui::EF_NONE);
1083 EXPECT_EQ(windows[w],
1084 targeter->FindTargetForEvent(root_target, &event));
1089 } // namespace internal
1090 } // namespace ash