1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// found in the LICENSE file.
4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
5f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <algorithm>
6f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/accessibility_delegate.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/drag_drop/drag_drop_controller.h"
9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/root_window_controller.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/shell.h"
140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ash/shell_window_ids.h"
15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/test/ash_test_base.h"
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/test/shelf_test_api.h"
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/test/shelf_view_test_api.h"
18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/test/shell_test_api.h"
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/test/test_shelf_delegate.h"
20a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/mru_window_tracker.h"
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/wm/overview/window_grid.h"
22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/wm/overview/window_selector.h"
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/wm/overview/window_selector_controller.h"
240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ash/wm/overview/window_selector_item.h"
25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ash/wm/panels/panel_layout_manager.h"
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/window_state.h"
27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/window_util.h"
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h"
29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/basictypes.h"
30a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/compiler_specific.h"
31a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/memory/scoped_vector.h"
32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/run_loop.h"
33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/strings/string_piece.h"
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
3668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/aura/client/cursor_client.h"
37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ui/aura/client/focus_client.h"
38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/aura/test/test_window_delegate.h"
39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/aura/test/test_windows.h"
40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/aura/window.h"
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h"
435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h"
44a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/gfx/rect_conversions.h"
45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/gfx/transform.h"
460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/views/controls/label.h"
470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/views/widget/native_widget_aura.h"
48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h"
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_util.h"
50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_delegate.h"
51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace ash {
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace {
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class NonActivatableActivationDelegate
564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    : public aura::client::ActivationDelegate {
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual bool ShouldActivate() const OVERRIDE {
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return false;
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CancelDrag(DragDropController* controller, bool* canceled) {
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (controller->IsDragDropInProgress()) {
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    *canceled = true;
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    controller->DragCancel();
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace
714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class WindowSelectorTest : public test::AshTestBase {
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public:
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  WindowSelectorTest() {}
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual ~WindowSelectorTest() {}
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    test::AshTestBase::SetUp();
79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_TRUE(test::TestShelfDelegate::instance());
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    shelf_view_test_.reset(new test::ShelfViewTestAPI(
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view()));
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    shelf_view_test_->SetAnimationDuration(1);
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  aura::Window* CreateWindow(const gfx::Rect& bounds) {
874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds);
884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  aura::Window* CreateWindowWithId(const gfx::Rect& bounds, int id) {
9146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return CreateTestWindowInShellWithDelegate(&delegate_, id, bounds);
9246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) {
944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    aura::Window* window = CreateWindow(bounds);
954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    aura::client::SetActivationDelegate(window,
964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                        &non_activatable_activation_delegate_);
974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_FALSE(ash::wm::CanActivateWindow(window));
984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return window;
99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  aura::Window* CreatePanelWindow(const gfx::Rect& bounds) {
102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        NULL, ui::wm::WINDOW_TYPE_PANEL, 0, bounds);
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test::TestShelfDelegate::instance()->AddShelfItem(window);
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    shelf_view_test()->RunMessageLoopUntilAnimationsDone();
106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return window;
107d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::Widget* CreatePanelWindowWidget(const gfx::Rect& bounds) {
110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    views::Widget* widget = new views::Widget;
111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    views::Widget::InitParams params;
112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    params.bounds = bounds;
113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    params.type = views::Widget::InitParams::TYPE_PANEL;
114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget->Init(params);
116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget->Show();
117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    ParentWindowInPrimaryRootWindow(widget->GetNativeWindow());
118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return widget;
119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) {
122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    gfx::RectF window1_bounds = GetTransformedTargetBounds(window1);
123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    gfx::RectF window2_bounds = GetTransformedTargetBounds(window2);
124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return window1_bounds.Intersects(window2_bounds);
125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
127a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  void ToggleOverview() {
128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview();
129a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
130a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Transform GetTransformRelativeTo(gfx::PointF origin,
132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                        const gfx::Transform& transform) {
133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    gfx::Transform t;
134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    t.Translate(origin.x(), origin.y());
135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    t.PreconcatTransform(transform);
136d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    t.Translate(-origin.x(), -origin.y());
137d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return t;
138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
140a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  gfx::RectF GetTransformedBounds(aura::Window* window) {
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
142d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        window->parent(), window->layer()->bounds()));
143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    gfx::Transform transform(GetTransformRelativeTo(bounds.origin(),
144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        window->layer()->transform()));
145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    transform.TransformRect(&bounds);
146a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return bounds;
147a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
148a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
149a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  gfx::RectF GetTransformedTargetBounds(aura::Window* window) {
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        window->parent(), window->layer()->GetTargetBounds()));
152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    gfx::Transform transform(GetTransformRelativeTo(bounds.origin(),
153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        window->layer()->GetTargetTransform()));
154d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    transform.TransformRect(&bounds);
155a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return bounds;
156a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
157a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::RectF GetTransformedBoundsInRootWindow(aura::Window* window) {
159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    gfx::RectF bounds = gfx::Rect(window->bounds().size());
160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    aura::Window* root = window->GetRootWindow();
161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CHECK(window->layer());
162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CHECK(root->layer());
163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    gfx::Transform transform;
164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (!window->layer()->GetTargetTransformRelativeTo(root->layer(),
165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                       &transform)) {
166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return gfx::RectF();
167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    transform.TransformRect(&bounds);
169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return bounds;
170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
172a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  void ClickWindow(aura::Window* window) {
1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::test::EventGenerator event_generator(window->GetRootWindow(), window);
174a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    gfx::RectF target = GetTransformedBounds(window);
175a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    event_generator.ClickLeftButton();
176a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
177a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
17846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void SendKey(ui::KeyboardCode key) {
1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow());
18046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      event_generator.PressKey(key, 0);
18146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      event_generator.ReleaseKey(key, 0);
18246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
18346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
184ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  bool IsSelecting() {
185ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return ash::Shell::GetInstance()->window_selector_controller()->
186ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        IsSelecting();
187ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
188ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
189424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  aura::Window* GetFocusedWindow() {
190424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    return aura::client::GetFocusClient(
191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        Shell::GetPrimaryRootWindow())->GetFocusedWindow();
1920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
1930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
19446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) {
19546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return ash::Shell::GetInstance()->window_selector_controller()->
19646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        window_selector_->grid_list_[index]->window_list_.get();
1970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
1980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
19946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const aura::Window* GetSelectedWindow() {
20046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    WindowSelector* ws = ash::Shell::GetInstance()->
20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        window_selector_controller()->window_selector_.get();
20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return ws->grid_list_[ws->selected_grid_index_]->
20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        SelectedWindow()->SelectionWindow();
20446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
20546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool selection_widget_active() {
207116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    WindowSelector* ws = ash::Shell::GetInstance()->
208116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        window_selector_controller()->window_selector_.get();
209116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return ws->grid_list_[ws->selected_grid_index_]->is_selecting();
210116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
211116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
212116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool showing_filter_widget() {
213116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    WindowSelector* ws = ash::Shell::GetInstance()->
214116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        window_selector_controller()->window_selector_.get();
215116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return ws->text_filter_widget_->GetNativeWindow()->layer()->
216116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        GetTargetTransform().IsIdentity();
217116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
218116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
219f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::Widget* GetCloseButton(ash::WindowSelectorItem* window) {
220f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return window->close_button_.get();
221f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
222f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
223116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  views::Label* GetLabelView(ash::WindowSelectorItem* window) {
224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return window->window_label_view_;
225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Tests that a window is contained within a given WindowSelectorItem, and
228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // that both the window and its matching close button are within the same
229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // screen.
230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void IsWindowAndCloseButtonInScreen(aura::Window* window,
231116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                      WindowSelectorItem* window_item) {
232116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    aura::Window* root_window = window_item->GetRootWindow();
233116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    EXPECT_TRUE(window_item->Contains(window));
234116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    EXPECT_TRUE(root_window->GetBoundsInScreen().Contains(
235116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        ToEnclosingRect(GetTransformedTargetBounds(window))));
236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    EXPECT_TRUE(root_window->GetBoundsInScreen().Contains(
237116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        ToEnclosingRect(GetTransformedTargetBounds(
238116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            GetCloseButton(window_item)->GetNativeView()))));
239116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
240116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
241116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void FilterItems(const base::StringPiece& pattern) {
242116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    ash::Shell::GetInstance()->
243116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        window_selector_controller()->window_selector_.get()->
244116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            ContentsChanged(NULL, base::UTF8ToUTF16(pattern));
245d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
246d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
2478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  test::ShelfViewTestAPI* shelf_view_test() {
2488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return shelf_view_test_.get();
249424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  }
250424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
251116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  views::Widget* text_filter_widget() {
252116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return ash::Shell::GetInstance()->
253116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        window_selector_controller()->window_selector_.get()->
254116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            text_filter_widget_.get();
255116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
256116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
257a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) private:
2584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  aura::test::TestWindowDelegate delegate_;
2594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  NonActivatableActivationDelegate non_activatable_activation_delegate_;
2608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
261a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
262a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
263a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
264a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Tests that an a11y alert is sent on entering overview mode.
2665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuTEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) {
2675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  gfx::Rect bounds(0, 0, 400, 400);
2685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  AccessibilityDelegate* delegate =
2695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      ash::Shell::GetInstance()->accessibility_delegate();
2705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
2715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_NE(delegate->GetLastAccessibilityAlert(),
2725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu            A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
2735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ToggleOverview();
2745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(delegate->GetLastAccessibilityAlert(),
2755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu            A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
2765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
2775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
278cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests entering overview mode with two windows and selecting one by clicking.
279a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(WindowSelectorTest, Basic) {
280a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
2811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window = Shell::GetPrimaryRootWindow();
282a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
283a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
284d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
285d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
287d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
288a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  wm::ActivateWindow(window2.get());
289a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
290a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
291424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(window2.get(), GetFocusedWindow());
2921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Hide the cursor before entering overview to test that it will be shown.
2931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::client::GetCursorClient(root_window)->HideCursor();
294a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // In overview mode the windows should no longer overlap and the text filter
296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // widget should be focused.
297a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ToggleOverview();
298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
299a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
300d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get()));
301d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Panels 1 and 2 should still be overlapping being in a single selector
302d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // item.
303d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
304a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
305a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Clicking window 1 should activate it.
306a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ClickWindow(window1.get());
307a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
308a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
309424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(window1.get(), GetFocusedWindow());
31068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
31168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Cursor should have been unlocked.
3121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked());
313a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
314a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
315cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests selecting a window by tapping on it.
316cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(WindowSelectorTest, BasicGesture) {
317cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
318cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
319cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
320cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  wm::ActivateWindow(window1.get());
321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(window1.get(), GetFocusedWindow());
322cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ToggleOverview();
323116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
3245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
3255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                     window2.get());
326cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  generator.GestureTapAt(gfx::ToEnclosingRect(
327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      GetTransformedTargetBounds(window2.get())).CenterPoint());
328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(window2.get(), GetFocusedWindow());
329cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
330cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
331cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests that a window does not receive located events when in overview mode.
332cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) {
333cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Rect window_bounds(20, 10, 200, 300);
334cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  aura::Window* root_window = Shell::GetPrimaryRootWindow();
335cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateWindow(window_bounds));
336cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
337cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Point point1(window_bounds.x() + 10, window_bounds.y() + 10);
338cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
339cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point1, point1,
340cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                        ui::EF_NONE, ui::EF_NONE);
341cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
342cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui::EventTarget* root_target = root_window;
343cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui::EventTargeter* targeter = root_target->GetEventTargeter();
344cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
345cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The event should target the window because we are still not in overview
346cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // mode.
347cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(window, static_cast<aura::Window*>(
348cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      targeter->FindTargetForEvent(root_target, &event1)));
349cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
350cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ToggleOverview();
351cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
352cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The bounds have changed, take that into account.
353cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::RectF bounds = GetTransformedBoundsInRootWindow(window.get());
354cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Point point2(bounds.x() + 10, bounds.y() + 10);
355cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui::MouseEvent event2(ui::ET_MOUSE_PRESSED, point2, point2,
356cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                        ui::EF_NONE, ui::EF_NONE);
357cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
358cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Now the transparent window should be intercepting this event.
359cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_NE(window, static_cast<aura::Window*>(
360cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        targeter->FindTargetForEvent(root_target, &event2)));
361cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
362cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
363cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests that clicking on the close button effectively closes the window.
364cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(WindowSelectorTest, CloseButton) {
365cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(200, 300, 250, 450)));
366cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
367cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // We need a widget for the close button the work, a bare window will crash.
368cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<views::Widget> widget(new views::Widget);
369cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  views::Widget::InitParams params;
370cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  params.bounds = gfx::Rect(0, 0, 400, 400);
371cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
372cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  params.parent = window1->parent();
373cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  widget->Init(params);
374cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  widget->Show();
375cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ToggleOverview();
376cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
377cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  aura::Window* window2 = widget->GetNativeWindow();
378cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::RectF bounds = GetTransformedBoundsInRootWindow(window2);
379cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1);
3805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator event_generator(window2->GetRootWindow(), point);
381cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
382cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_FALSE(widget->IsClosed());
383cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  event_generator.ClickLeftButton();
384cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(widget->IsClosed());
385cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
386cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
387f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Tests entering overview mode with two windows and selecting one.
388f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(WindowSelectorTest, FullscreenWindow) {
389f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
390f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
392f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds));
393f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  wm::ActivateWindow(window1.get());
394f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  wm::GetWindowState(window1.get())->OnWMEvent(&toggle_fullscreen_event);
397f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The panel is hidden in fullscreen mode.
398f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(panel1->IsVisible());
399f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
400f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
401f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Enter overview and select the fullscreen window.
402f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ToggleOverview();
403f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
404f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The panel becomes temporarily visible for the overview.
405f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(panel1->IsVisible());
406f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ClickWindow(window1.get());
407f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
408f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The window is still fullscreen as it was selected. The panel should again
409f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // be hidden.
410f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
411f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(panel1->IsVisible());
412f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Entering overview and selecting another window, the previous window remains
414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // fullscreen.
415f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // TODO(flackr): Currently the panel remains hidden, but should become visible
416f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // again.
417f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ToggleOverview();
418f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ClickWindow(window2.get());
419a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(wm::GetWindowState(window1.get())->IsFullscreen());
420f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
421f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
4224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that the shelf dimming state is removed while in overview and restored
4234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// on exiting overview.
4244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, OverviewUndimsShelf) {
4254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
4264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
4274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window1.get());
4284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_state->Maximize();
4294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ash::ShelfWidget* shelf = Shell::GetPrimaryRootWindowController()->shelf();
4304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(shelf->GetDimsShelf());
4314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(shelf->GetDimsShelf());
4334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(shelf->GetDimsShelf());
4354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
4374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that beginning window selection hides the app list.
4384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, SelectingHidesAppList) {
4394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
4404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
4414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
4426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  Shell::GetInstance()->ShowAppList(NULL);
4434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
4444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
4464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
4494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that a minimized window's visibility and layer visibility is correctly
4504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// changed when entering overview and restored when leaving overview mode.
45146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Crashes after the skia roll in http://crrev.com/274114.
45246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// http://crbug.com/379570
45346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(WindowSelectorTest, DISABLED_MinimizedWindowVisibility) {
4544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
4554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
4564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window1.get());
4574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_state->Minimize();
4584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(window1->IsVisible());
4594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(window1->layer()->GetTargetVisibility());
4604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  {
4615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::ScopedAnimationDurationScaleMode test_duration_mode(
4625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
4634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ToggleOverview();
4644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_TRUE(window1->IsVisible());
4654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_TRUE(window1->layer()->GetTargetVisibility());
4664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
4674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  {
4685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::ScopedAnimationDurationScaleMode test_duration_mode(
4695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
4704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ToggleOverview();
4714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_FALSE(window1->IsVisible());
4724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_FALSE(window1->layer()->GetTargetVisibility());
4734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
4744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
4764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that a bounds change during overview is corrected for.
4774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, BoundsChangeDuringOverview) {
4784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 400, 400)));
4794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect overview_bounds =
4814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ToEnclosingRect(GetTransformedTargetBounds(window.get()));
4824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window->SetBounds(gfx::Rect(200, 0, 200, 200));
4834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect new_overview_bounds =
4844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ToEnclosingRect(GetTransformedTargetBounds(window.get()));
4854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(overview_bounds.x(), new_overview_bounds.x());
4864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(overview_bounds.y(), new_overview_bounds.y());
4874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(overview_bounds.width(), new_overview_bounds.width());
4884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(overview_bounds.height(), new_overview_bounds.height());
4894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
4904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
49258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Tests that a newly created window aborts overview.
49358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(WindowSelectorTest, NewWindowCancelsOveriew) {
49458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
49558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
49658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
49758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ToggleOverview();
49858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(IsSelecting());
49958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
50058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // A window being created should exit overview mode.
50158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<aura::Window> window3(CreateWindow(bounds));
50258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(IsSelecting());
50358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
50458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
50558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Tests that a window activation exits overview mode.
50658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(WindowSelectorTest, ActivationCancelsOveriew) {
50758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
50858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
50958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
51058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  window2->Focus();
51158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ToggleOverview();
51258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(IsSelecting());
51358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
51458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // A window being activated should exit overview mode.
51558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  window1->Focus();
51658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(IsSelecting());
51758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
51858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // window1 should be focused after exiting even though window2 was focused on
51958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // entering overview because we exited due to an activation.
52058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(window1.get(), GetFocusedWindow());
52158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
52258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
523424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Tests that exiting overview mode without selecting a window restores focus
524424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// to the previously focused window.
525424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(WindowSelectorTest, CancelRestoresFocus) {
526424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
527424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateWindow(bounds));
528424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  wm::ActivateWindow(window.get());
529424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(window.get(), GetFocusedWindow());
530424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
531116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // In overview mode, the text filter widget should be focused.
532424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  ToggleOverview();
533116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
534424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
535424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // If canceling overview mode, focus should be restored.
536424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  ToggleOverview();
537424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(window.get(), GetFocusedWindow());
538424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
539424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
540a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Tests that overview mode is exited if the last remaining window is destroyed.
541a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(WindowSelectorTest, LastWindowDestroyed) {
542a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
543a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
544a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
545a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ToggleOverview();
546a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
547a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  window1.reset();
548a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  window2.reset();
549ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(IsSelecting());
550a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
551a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
5523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Tests that entering overview mode restores a window to its original
5533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// target location.
5543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(WindowSelectorTest, QuickReentryRestoresInitialTransform) {
5553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
5563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateWindow(bounds));
5573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  gfx::Rect initial_bounds = ToEnclosingRect(
5583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      GetTransformedBounds(window.get()));
5593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ToggleOverview();
5603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Quickly exit and reenter overview mode. The window should still be
5613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // animating when we reenter. We cannot short circuit animations for this but
5623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // we also don't have to wait for them to complete.
5633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  {
5645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::ScopedAnimationDurationScaleMode test_duration_mode(
5655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
5663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ToggleOverview();
5673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ToggleOverview();
5683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
5693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_NE(initial_bounds, ToEnclosingRect(
5703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      GetTransformedTargetBounds(window.get())));
5713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ToggleOverview();
5723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
5733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(initial_bounds, ToEnclosingRect(
5743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      GetTransformedTargetBounds(window.get())));
5753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
5763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
5774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that non-activatable windows are hidden when entering overview mode.
5784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, NonActivatableWindowsHidden) {
5794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
5804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
5814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
5824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> non_activatable_window(
5834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      CreateNonActivatableWindow(Shell::GetPrimaryRootWindow()->bounds()));
5844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(non_activatable_window->IsVisible());
5854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
5864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(non_activatable_window->IsVisible());
5874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
5884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(non_activatable_window->IsVisible());
5894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Test that a window behind the fullscreen non-activatable window can be
5914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // clicked.
5924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  non_activatable_window->parent()->StackChildAtTop(
5934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      non_activatable_window.get());
5944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
5954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ClickWindow(window1.get());
5964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(IsSelecting());
5974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
5984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
5994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that windows with modal child windows are transformed with the modal
6014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// child even though not activatable themselves.
6024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, ModalChild) {
6034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
6044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
6054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> child1(CreateWindow(bounds));
6064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
607a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::AddTransientChild(window1.get(), child1.get());
6084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(window1->parent(), child1->parent());
6094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
6104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(window1->IsVisible());
6114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(child1->IsVisible());
6124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(ToEnclosingRect(GetTransformedTargetBounds(child1.get())),
6134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ToEnclosingRect(GetTransformedTargetBounds(window1.get())));
6144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
6154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that clicking a modal window's parent activates the modal window in
6184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// overview.
6194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(WindowSelectorTest, ClickModalWindowParent) {
6204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 180, 180)));
6214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> child1(CreateWindow(gfx::Rect(200, 0, 180, 180)));
6224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
623a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::AddTransientChild(window1.get(), child1.get());
6244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(WindowsOverlapping(window1.get(), child1.get()));
6254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(window1->parent(), child1->parent());
6264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ToggleOverview();
6274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Given that their relative positions are preserved, the windows should still
6284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // not overlap.
6294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(WindowsOverlapping(window1.get(), child1.get()));
6304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ClickWindow(window1.get());
6314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(IsSelecting());
6324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Clicking on window1 should activate child1.
6344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(child1.get()));
6354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
637a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Tests that windows remain on the display they are currently on in overview
638116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// mode, and that the close buttons are on matching displays.
639a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(WindowSelectorTest, MultipleDisplays) {
640a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (!SupportsMultipleDisplays())
641a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return;
642a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
643d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  UpdateDisplay("600x400,600x400");
644f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
645d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Rect bounds1(0, 0, 400, 400);
646d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Rect bounds2(650, 0, 400, 400);
647d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
648d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds1));
649d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds1));
650d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> window3(CreateWindow(bounds2));
651d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> window4(CreateWindow(bounds2));
652d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds1));
653d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds1));
654d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel3(CreatePanelWindow(bounds2));
655d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> panel4(CreatePanelWindow(bounds2));
656a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window1->GetRootWindow());
657a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window2->GetRootWindow());
658a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window3->GetRootWindow());
659a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window4->GetRootWindow());
660a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
661d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[0], panel1->GetRootWindow());
662d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[0], panel2->GetRootWindow());
663d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[1], panel3->GetRootWindow());
664d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[1], panel4->GetRootWindow());
665d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
666a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // In overview mode, each window remains in the same root window.
667a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ToggleOverview();
668a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window1->GetRootWindow());
669a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window2->GetRootWindow());
670a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window3->GetRootWindow());
671a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window4->GetRootWindow());
672d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[0], panel1->GetRootWindow());
673d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[0], panel2->GetRootWindow());
674d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[1], panel3->GetRootWindow());
675d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(root_windows[1], panel4->GetRootWindow());
676d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
677116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const std::vector<WindowSelectorItem*>& primary_window_items =
678116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetWindowItemsForRoot(0);
679116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const std::vector<WindowSelectorItem*>& secondary_window_items =
680116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetWindowItemsForRoot(1);
681116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
682116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Window indices are based on top-down order. The reverse of our creation.
683116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(window1.get(), primary_window_items[2]);
684116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(window2.get(), primary_window_items[1]);
685116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(window3.get(), secondary_window_items[2]);
686116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(window4.get(), secondary_window_items[1]);
687116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
688116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(panel1.get(), primary_window_items[0]);
689116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(panel2.get(), primary_window_items[0]);
690116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(panel3.get(), secondary_window_items[0]);
691116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  IsWindowAndCloseButtonInScreen(panel4.get(), secondary_window_items[0]);
692116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
693d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
694d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(WindowsOverlapping(panel3.get(), panel4.get()));
695d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_FALSE(WindowsOverlapping(panel1.get(), panel3.get()));
696d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
697d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests shutting down during overview.
6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(WindowSelectorTest, Shutdown) {
7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // These windows will be deleted when the test exits and the Shell instance
7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is shut down.
7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* window1(CreateWindow(bounds));
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* window2(CreateWindow(bounds));
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* window3(CreatePanelWindow(bounds));
7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* window4(CreatePanelWindow(bounds));
7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window4);
7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window3);
7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window2);
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window1);
7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ToggleOverview();
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests removing a display during overview.
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(WindowSelectorTest, RemoveDisplay) {
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsMultipleDisplays())
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("400x400,400x400");
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect bounds1(0, 0, 100, 100);
7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect bounds2(450, 0, 100, 100);
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds1));
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds2));
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window3(CreatePanelWindow(bounds1));
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window4(CreatePanelWindow(bounds2));
7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window1->GetRootWindow());
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window2->GetRootWindow());
7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window3->GetRootWindow());
7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window4->GetRootWindow());
7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window4.get());
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window3.get());
7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window2.get());
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::ActivateWindow(window1.get());
7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ToggleOverview();
7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(IsSelecting());
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("400x400");
7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests starting overview during a drag and drop tracking operation.
7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(flackr): Fix memory corruption crash when running locally (not failing
7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// on bots). See http://crbug.com/342528.
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(WindowSelectorTest, DISABLED_DragDropInProgress) {
7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool drag_canceled_by_test = false;
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect bounds(0, 0, 400, 400);
7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateWindow(bounds));
7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  test::ShellTestApi shell_test_api(Shell::GetInstance());
754c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ash::DragDropController* drag_drop_controller =
7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shell_test_api.drag_drop_controller();
7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::OSExchangeData data;
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::MessageLoopForUI::current()->PostTask(FROM_HERE,
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&WindowSelectorTest::ToggleOverview,
7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::MessageLoopForUI::current()->PostTask(FROM_HERE,
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&CancelDrag, drag_drop_controller, &drag_canceled_by_test));
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  data.SetString(base::UTF8ToUTF16("I am being dragged"));
7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  drag_drop_controller->StartDragAndDrop(data, window->GetRootWindow(),
7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(), gfx::Point(5, 5), ui::DragDropTypes::DRAG_MOVE,
7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RunAllPendingInMessageLoop();
7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(drag_canceled_by_test);
7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(IsSelecting());
7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RunAllPendingInMessageLoop();
7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Test that a label is created under the window on entering overview mode.
7730529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochTEST_F(WindowSelectorTest, CreateLabelUnderWindow) {
7740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100)));
7750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  base::string16 window_title = base::UTF8ToUTF16("My window");
776116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window->SetTitle(window_title);
7770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  ToggleOverview();
77846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
779116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  views::Label* label = GetLabelView(window_item);
780116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Has the label view been created?
781116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ASSERT_TRUE(label);
782116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
7830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Verify the label matches the window title.
7840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(label->text(), window_title);
785116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
786116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Update the window title and check that the label is updated, too.
787116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 updated_title = base::UTF8ToUTF16("Updated title");
788116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window->SetTitle(updated_title);
789116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(label->text(), updated_title);
790116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
7910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Labels are located based on target_bounds, not the actual window item
7920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // bounds.
7930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  gfx::Rect target_bounds(window_item->target_bounds());
7940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  gfx::Rect expected_label_bounds(target_bounds.x(),
795116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                  target_bounds.bottom() - label->
796116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                      GetPreferredSize().height(),
7970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                                  target_bounds.width(),
7980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                                  label->GetPreferredSize().height());
799116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds();
800116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(real_label_bounds, expected_label_bounds);
8010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Tests that a label is created for the active panel in a group of panels in
8040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// overview mode.
8050529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochTEST_F(WindowSelectorTest, CreateLabelUnderPanel) {
8060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
8070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
8080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  base::string16 panel1_title = base::UTF8ToUTF16("My panel");
8090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  base::string16 panel2_title = base::UTF8ToUTF16("Another panel");
810116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 updated_panel1_title = base::UTF8ToUTF16("WebDriver Torso");
811116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 updated_panel2_title = base::UTF8ToUTF16("Da panel");
812116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  panel1->SetTitle(panel1_title);
813116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  panel2->SetTitle(panel2_title);
8140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  wm::ActivateWindow(panel1.get());
8150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  ToggleOverview();
81646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
817116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  views::Label* label = GetLabelView(window_item);
818116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Has the label view been created?
819116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ASSERT_TRUE(label);
820116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
8210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Verify the label matches the active window title.
8220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(label->text(), panel1_title);
823116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Verify that updating the title also updates the label.
824116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  panel1->SetTitle(updated_panel1_title);
825116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(label->text(), updated_panel1_title);
826116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // After destroying the first panel, the label should match the second panel.
827116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  panel1.reset();
828116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  label = GetLabelView(window_item);
829116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(label->text(), panel2_title);
830116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Also test updating the title on the second panel.
831116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  panel2->SetTitle(updated_panel2_title);
832116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(label->text(), updated_panel2_title);
8330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
835cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests that overview updates the window positions if the display orientation
8365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// changes.
8375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuTEST_F(WindowSelectorTest, DisplayOrientationChanged) {
8385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (!SupportsHostWindowResize())
8395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    return;
8405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
8415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
8425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  UpdateDisplay("600x200");
8435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ("0,0 600x200", root_window->bounds().ToString());
8445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  gfx::Rect window_bounds(0, 0, 150, 150);
8455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ScopedVector<aura::Window> windows;
8465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  for (int i = 0; i < 3; i++) {
8475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    windows.push_back(CreateWindow(window_bounds));
8485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
8495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
8505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ToggleOverview();
8515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  for (ScopedVector<aura::Window>::iterator iter = windows.begin();
8525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu       iter != windows.end(); ++iter) {
8535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_TRUE(root_window->bounds().Contains(
8545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        ToEnclosingRect(GetTransformedTargetBounds(*iter))));
8555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
8565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
8575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Rotate the display, windows should be repositioned to be within the screen
8585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // bounds.
8595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  UpdateDisplay("600x200/r");
8605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ("0,0 200x600", root_window->bounds().ToString());
8615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  for (ScopedVector<aura::Window>::iterator iter = windows.begin();
8625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu       iter != windows.end(); ++iter) {
8635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_TRUE(root_window->bounds().Contains(
8645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        ToEnclosingRect(GetTransformedTargetBounds(*iter))));
8655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
8665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
8675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
8685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Tests traversing some windows in overview mode with the tab key.
8695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(WindowSelectorTest, BasicTabKeyNavigation) {
8705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  gfx::Rect bounds(0, 0, 100, 100);
8715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
8725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
8735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ToggleOverview();
8745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
8755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  SendKey(ui::VKEY_TAB);
8765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window1.get());
8775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  SendKey(ui::VKEY_TAB);
8785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window2.get());
8795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  SendKey(ui::VKEY_TAB);
8805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window1.get());
8815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
8825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
88346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Tests traversing some windows in overview mode with the arrow keys in every
88446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// possible direction.
88546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(WindowSelectorTest, BasicArrowKeyNavigation) {
88646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (!SupportsHostWindowResize())
88746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return;
8886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  const size_t test_windows = 9;
8896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  UpdateDisplay("800x600");
89046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ScopedVector<aura::Window> windows;
89146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  for (size_t i = test_windows; i > 0; i--)
89246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    windows.push_back(CreateWindowWithId(gfx::Rect(0, 0, 100, 100), i));
89346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
89446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ui::KeyboardCode arrow_keys[] = {
89546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ui::VKEY_RIGHT,
89646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ui::VKEY_DOWN,
89746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ui::VKEY_LEFT,
89846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ui::VKEY_UP
89946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  };
9006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Expected window layout, assuming that the text filtering feature is
9016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // enabled by default (i.e., --ash-disable-text-filtering-in-overview-mode
9026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // is not being used).
9036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // +-------+  +-------+  +-------+  +-------+
9046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |   1   |  |   2   |  |   3   |  |   4   |
9056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // +-------+  +-------+  +-------+  +-------+
9066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // +-------+  +-------+  +-------+  +-------+
9076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |   5   |  |   6   |  |   7   |  |   8   |
9086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // +-------+  +-------+  +-------+  +-------+
90946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // +-------+
9106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |   9   |
91146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // +-------+
91246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Index for each window during a full loop plus wrapping around.
91346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int index_path_for_direction[][test_windows + 1] = {
9146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      {1, 2, 3, 4, 5, 6, 7, 8, 9, 1},  // Right
9156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      {1, 5, 9, 2, 6, 3, 7, 4, 8, 1},  // Down
9166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      {9, 8, 7, 6, 5, 4, 3, 2, 1, 9},  // Left
9176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      {8, 4, 7, 3, 6, 2, 9, 5, 1, 8}   // Up
91846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  };
91946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
92046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  for (size_t key_index = 0; key_index < arraysize(arrow_keys); key_index++) {
92146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    ToggleOverview();
92246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    for (size_t i = 0; i < test_windows + 1; i++) {
92346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      SendKey(arrow_keys[key_index]);
924116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      // TODO(flackr): Add a more readable error message by constructing a
92546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      // string from the window IDs.
92646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      EXPECT_EQ(GetSelectedWindow()->id(),
92746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                index_path_for_direction[key_index][i]);
92846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    }
92946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    ToggleOverview();
93046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
93146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
93246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
93346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Tests basic selection across multiple monitors.
93446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) {
93546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (!SupportsMultipleDisplays())
93646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return;
93746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
93846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  UpdateDisplay("400x400,400x400");
93946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect bounds1(0, 0, 100, 100);
94046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect bounds2(450, 0, 100, 100);
94146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<aura::Window> window4(CreateWindow(bounds2));
94246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<aura::Window> window3(CreateWindow(bounds2));
94346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds1));
94446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds1));
94546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
94646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
94746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ToggleOverview();
94846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
94946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
95046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window1.get());
95146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
95246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window2.get());
95346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
95446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window3.get());
95546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
95646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(GetSelectedWindow(), window4.get());
95746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
95846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
959f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Tests selecting a window in overview mode with the return key.
960f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(WindowSelectorTest, SelectWindowWithReturnKey) {
961f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Rect bounds(0, 0, 100, 100);
962f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
963f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
964f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ToggleOverview();
965f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
966f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Pressing the return key without a selection widget should not do anything.
967f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RETURN);
968f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(IsSelecting());
969f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
970f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Select the first window.
971f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
972f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RETURN);
973f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ASSERT_FALSE(IsSelecting());
974f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
975f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
976f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Select the second window.
977f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ToggleOverview();
978f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
979f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RIGHT);
980f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SendKey(ui::VKEY_RETURN);
981f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
982f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
983f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
984f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
985f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Tests that overview mode hides the callout widget.
986f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(WindowSelectorTest, WindowOverviewHidesCalloutWidgets) {
987f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
988f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
989f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  PanelLayoutManager* panel_manager =
990f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        static_cast<PanelLayoutManager*>(panel1->parent()->layout_manager());
991f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
992f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // By default, panel callout widgets are visible.
993f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(
994f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
995f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(
996f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());
997f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
998f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Toggling the overview should hide the callout widgets.
999f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ToggleOverview();
1000f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(
1001f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
1002f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(
1003f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());
1004f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1005f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Ending the overview should show them again.
1006f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ToggleOverview();
1007f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(
1008f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
1009f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(
1010f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());
1011f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
1012f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1013f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Tests that when panels are grouped that the close button only closes the
1014f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// currently active panel. After the removal window selection should still be
1015f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// active, and the label should have changed. Removing the last panel should
1016f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// cause selection to end.
1017f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(WindowSelectorTest, CloseButtonOnPanels) {
1018f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<views::Widget> widget1(CreatePanelWindowWidget(
1019f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      gfx::Rect(0, 0, 300, 100)));
1020f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<views::Widget> widget2(CreatePanelWindowWidget(
1021f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      gfx::Rect(100, 0, 100, 100)));
1022f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  aura::Window* window1 = widget1->GetNativeWindow();
1023f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  aura::Window* window2 = widget2->GetNativeWindow();
1024f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::string16 panel1_title = base::UTF8ToUTF16("Panel 1");
1025f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::string16 panel2_title = base::UTF8ToUTF16("Panel 2");
1026116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window1->SetTitle(panel1_title);
1027116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window2->SetTitle(panel2_title);
1028f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  wm::ActivateWindow(window1);
1029f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ToggleOverview();
1030f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1031f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1);
1032f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1);
10335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator event_generator1(window1->GetRootWindow(), point1);
1034f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1035f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(widget1->IsClosed());
1036f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  event_generator1.ClickLeftButton();
1037f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(widget1->IsClosed());
1038f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  RunAllPendingInMessageLoop();
1039f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(IsSelecting());
1040f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  WindowSelectorItem* window_item = GetWindowItemsForRoot(0).front();
1041f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(window_item->empty());
1042f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(window_item->Contains(window2));
1043f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(GetCloseButton(window_item)->IsVisible());
1044f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1045116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1046116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  views::Label* label = GetLabelView(window_item);
1047f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(label->text(), panel2_title);
1048f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1049f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2);
1050f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1);
10515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator event_generator2(window2->GetRootWindow(), point2);
1052f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1053f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(widget2->IsClosed());
1054f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  event_generator2.ClickLeftButton();
1055f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(widget2->IsClosed());
1056f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  RunAllPendingInMessageLoop();
1057f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
1058f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
1059f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1060116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Creates three windows and tests filtering them by title.
1061116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST_F(WindowSelectorTest, BasicTextFiltering) {
1062116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  gfx::Rect bounds(0, 0, 100, 100);
1063116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<aura::Window> window2(CreateWindow(bounds));
1064116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
1065116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<aura::Window> window0(CreateWindow(bounds));
1066116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 window2_title = base::UTF8ToUTF16("Highway to test");
1067116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 window1_title = base::UTF8ToUTF16("For those about to test");
1068116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::string16 window0_title = base::UTF8ToUTF16("We salute you");
1069116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window0->SetTitle(window0_title);
1070116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window1->SetTitle(window1_title);
1071116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  window2->SetTitle(window2_title);
1072116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ToggleOverview();
1073116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(selection_widget_active());
1074116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(showing_filter_widget());
1075116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  FilterItems("Test");
1076116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1077116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // The selection widget should appear when filtering starts, and should be
1078116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // selecting the first matching window.
1079116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(selection_widget_active());
1080116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(showing_filter_widget());
1081116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_EQ(GetSelectedWindow(), window1.get());
1082116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1083116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Window 0 has no "test" on it so it should be the only dimmed item.
1084116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  std::vector<WindowSelectorItem*> items = GetWindowItemsForRoot(0);
1085116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(items[0]->dimmed());
1086116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(items[1]->dimmed());
1087116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(items[2]->dimmed());
1088116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1089116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // No items match the search.
1090116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  FilterItems("I'm testing 'n testing");
1091116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(items[0]->dimmed());
1092116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(items[1]->dimmed());
1093116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_TRUE(items[2]->dimmed());
1094116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1095116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // All the items should match the empty string. The filter widget should also
1096116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // disappear.
1097116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  FilterItems("");
1098116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(showing_filter_widget());
1099116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(items[0]->dimmed());
1100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(items[1]->dimmed());
1101116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_FALSE(items[2]->dimmed());
1102116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
1103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Tests selecting in the overview with dimmed and undimmed items.
1105116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST_F(WindowSelectorTest, TextFilteringSelection) {
1106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  gfx::Rect bounds(0, 0, 100, 100);
1107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   scoped_ptr<aura::Window> window2(CreateWindow(bounds));
1108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   scoped_ptr<aura::Window> window1(CreateWindow(bounds));
1109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   scoped_ptr<aura::Window> window0(CreateWindow(bounds));
1110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   base::string16 window2_title = base::UTF8ToUTF16("Rock and roll");
1111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   base::string16 window1_title = base::UTF8ToUTF16("Rock and");
1112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   base::string16 window0_title = base::UTF8ToUTF16("Rock");
1113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   window0->SetTitle(window0_title);
1114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   window1->SetTitle(window1_title);
1115116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   window2->SetTitle(window2_title);
1116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   ToggleOverview();
1117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   SendKey(ui::VKEY_RIGHT);
1118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_TRUE(selection_widget_active());
1119116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_EQ(GetSelectedWindow(), window0.get());
1120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1121116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   // Dim the first item, the selection should jump to the next item.
1122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   std::vector<WindowSelectorItem*> items = GetWindowItemsForRoot(0);
1123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   FilterItems("Rock and");
1124116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_EQ(GetSelectedWindow(), window1.get());
1125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   // Cycle the selection, the dimmed window should not be selected.
1127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   SendKey(ui::VKEY_RIGHT);
1128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_EQ(GetSelectedWindow(), window2.get());
1129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   SendKey(ui::VKEY_RIGHT);
1130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_EQ(GetSelectedWindow(), window1.get());
1131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   // Dimming all the items should hide the selection widget.
1133116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   FilterItems("Pop");
1134116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_FALSE(selection_widget_active());
1135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1136116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   // Undimming one window should automatically select it.
1137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   FilterItems("Rock and roll");
1138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch   EXPECT_EQ(GetSelectedWindow(), window2.get());
1139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
1140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
11416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Tests clicking on the desktop itself to cancel overview mode.
11426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)TEST_F(WindowSelectorTest, CancelOverviewOnMouseClick) {
11436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Overview disabled by default.
11446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Point and bounds selected so that they don't intersect. This causes
11476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // events located at the point to be passed to DesktopBackgroundController,
11486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // and not the window.
11496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Point point_in_background_page(0, 0);
11506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Rect bounds(10, 10, 100, 100);
11516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
11526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ui::test::EventGenerator& generator = GetEventGenerator();
11536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Move mouse to point in the background page. Sending an event here will pass
11546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // it to the DesktopBackgroundController in both regular and overview mode.
11556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  generator.MoveMouseTo(point_in_background_page);
11566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Clicking on the background page while not in overview should not toggle
11586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // overview.
11596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  generator.ClickLeftButton();
11606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Switch to overview mode.
11636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ToggleOverview();
11646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ASSERT_TRUE(IsSelecting());
11656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Click should now exit overview mode.
11676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  generator.ClickLeftButton();
11686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
11706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Tests tapping on the desktop itself to cancel overview mode.
11726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)TEST_F(WindowSelectorTest, CancelOverviewOnTap) {
11736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Overview disabled by default.
11746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Point and bounds selected so that they don't intersect. This causes
11776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // events located at the point to be passed to DesktopBackgroundController,
11786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // and not the window.
11796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Point point_in_background_page(0, 0);
11806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Rect bounds(10, 10, 100, 100);
11816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<aura::Window> window1(CreateWindow(bounds));
11826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ui::test::EventGenerator& generator = GetEventGenerator();
11836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Tapping on the background page while not in overview should not toggle
11856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // overview.
11866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  generator.GestureTapAt(point_in_background_page);
11876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Switch to overview mode.
11906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ToggleOverview();
11916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ASSERT_TRUE(IsSelecting());
11926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
11936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Tap should now exit overview mode.
11946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  generator.GestureTapAt(point_in_background_page);
11956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_FALSE(IsSelecting());
11966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
11976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1198a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}  // namespace ash
1199