1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "ash/shell_window_ids.h"
7 #include "ash/test/ash_test_base.h"
8 #include "ash/test/test_shell_delegate.h"
9 #include "ash/wm/window_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/aura/test/event_generator.h"
12 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.h"
17 typedef test::AshTestBase AppListControllerTest
;
19 // Tests that app launcher hides when focus moves to a normal window.
20 TEST_F(AppListControllerTest
, HideOnFocusOut
) {
21 Shell::GetInstance()->ToggleAppList(NULL
);
22 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
24 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithId(0));
25 wm::ActivateWindow(window
.get());
27 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
30 // Tests that app launcher remains visible when focus is moved to a different
31 // window in kShellWindowId_AppListContainer.
32 TEST_F(AppListControllerTest
, RemainVisibleWhenFocusingToApplistContainer
) {
33 Shell::GetInstance()->ToggleAppList(NULL
);
34 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
36 aura::Window
* applist_container
= Shell::GetContainer(
37 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer
);
38 scoped_ptr
<aura::Window
> window(
39 aura::test::CreateTestWindowWithId(0, applist_container
));
40 wm::ActivateWindow(window
.get());
42 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
45 // Tests that clicking outside the app-list bubble closes it.
46 TEST_F(AppListControllerTest
, ClickOutsideBubbleClosesBubble
) {
47 Shell
* shell
= Shell::GetInstance();
48 shell
->ToggleAppList(NULL
);
50 aura::Window
* app_window
= shell
->GetAppListWindow();
51 ASSERT_TRUE(app_window
);
52 aura::test::EventGenerator
generator(shell
->GetPrimaryRootWindow(),
54 // Click on the bubble itself. The bubble should remain visible.
55 generator
.ClickLeftButton();
56 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
58 // Click outside the bubble. This should close it.
59 gfx::Rect app_window_bounds
= app_window
->GetBoundsInRootWindow();
60 gfx::Point point_outside
=
61 gfx::Point(app_window_bounds
.right(), app_window_bounds
.y()) +
63 EXPECT_TRUE(shell
->GetPrimaryRootWindow()->bounds().Contains(point_outside
));
64 generator
.MoveMouseToInHost(point_outside
);
65 generator
.ClickLeftButton();
66 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
69 // Tests that clicking outside the app-list bubble closes it.
70 TEST_F(AppListControllerTest
, TapOutsideBubbleClosesBubble
) {
71 Shell
* shell
= Shell::GetInstance();
72 shell
->ToggleAppList(NULL
);
74 aura::Window
* app_window
= shell
->GetAppListWindow();
75 ASSERT_TRUE(app_window
);
76 gfx::Rect app_window_bounds
= app_window
->GetBoundsInRootWindow();
78 aura::test::EventGenerator
generator(shell
->GetPrimaryRootWindow());
79 // Click on the bubble itself. The bubble should remain visible.
80 generator
.GestureTapAt(app_window_bounds
.CenterPoint());
81 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
83 // Click outside the bubble. This should close it.
84 gfx::Point point_outside
=
85 gfx::Point(app_window_bounds
.right(), app_window_bounds
.y()) +
87 EXPECT_TRUE(shell
->GetPrimaryRootWindow()->bounds().Contains(point_outside
));
88 generator
.GestureTapAt(point_outside
);
89 EXPECT_FALSE(shell
->GetAppListTargetVisibility());