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/command_line.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/app_list/app_list_switches.h"
13 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h"
19 // The parameter is true to test the centered app list, false for normal.
20 // (The test name ends in "/0" for normal, "/1" for centered.)
21 class AppListControllerTest : public test::AshTestBase,
22 public ::testing::WithParamInterface<bool> {
24 AppListControllerTest();
25 virtual ~AppListControllerTest();
26 virtual void SetUp() OVERRIDE;
29 AppListControllerTest::AppListControllerTest() {
32 AppListControllerTest::~AppListControllerTest() {
35 void AppListControllerTest::SetUp() {
38 CommandLine* command_line = CommandLine::ForCurrentProcess();
39 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList);
43 // Tests that app launcher hides when focus moves to a normal window.
44 TEST_P(AppListControllerTest, HideOnFocusOut) {
45 Shell::GetInstance()->ToggleAppList(NULL);
46 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
48 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
49 wm::ActivateWindow(window.get());
51 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
54 // Tests that app launcher remains visible when focus is moved to a different
55 // window in kShellWindowId_AppListContainer.
56 TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) {
57 Shell::GetInstance()->ToggleAppList(NULL);
58 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
60 aura::Window* applist_container = Shell::GetContainer(
61 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer);
62 scoped_ptr<aura::Window> window(
63 aura::test::CreateTestWindowWithId(0, applist_container));
64 wm::ActivateWindow(window.get());
66 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
69 // Tests that clicking outside the app-list bubble closes it.
70 TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) {
71 Shell* shell = Shell::GetInstance();
72 shell->ToggleAppList(NULL);
74 aura::Window* app_window = shell->GetAppListWindow();
75 ASSERT_TRUE(app_window);
76 aura::test::EventGenerator generator(shell->GetPrimaryRootWindow(),
78 // Click on the bubble itself. The bubble should remain visible.
79 generator.ClickLeftButton();
80 EXPECT_TRUE(shell->GetAppListTargetVisibility());
82 // Click outside the bubble. This should close it.
83 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
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.MoveMouseToInHost(point_outside);
89 generator.ClickLeftButton();
90 EXPECT_FALSE(shell->GetAppListTargetVisibility());
93 // Tests that clicking outside the app-list bubble closes it.
94 TEST_P(AppListControllerTest, TapOutsideBubbleClosesBubble) {
95 Shell* shell = Shell::GetInstance();
96 shell->ToggleAppList(NULL);
98 aura::Window* app_window = shell->GetAppListWindow();
99 ASSERT_TRUE(app_window);
100 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
102 aura::test::EventGenerator generator(shell->GetPrimaryRootWindow());
103 // Click on the bubble itself. The bubble should remain visible.
104 generator.GestureTapAt(app_window_bounds.CenterPoint());
105 EXPECT_TRUE(shell->GetAppListTargetVisibility());
107 // Click outside the bubble. This should close it.
108 gfx::Point point_outside =
109 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
110 gfx::Vector2d(10, 0);
111 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside));
112 generator.GestureTapAt(point_outside);
113 EXPECT_FALSE(shell->GetAppListTargetVisibility());
116 // Tests opening the app launcher on a non-primary display, then deleting the
118 TEST_P(AppListControllerTest, NonPrimaryDisplay) {
119 if (!SupportsMultipleDisplays())
122 // Set up a screen with two displays (horizontally adjacent).
123 UpdateDisplay("800x600,800x600");
125 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
126 ASSERT_EQ(2u, root_windows.size());
127 aura::Window* secondary_window = root_windows[1];
128 EXPECT_EQ("800,0 800x600", secondary_window->GetBoundsInScreen().ToString());
130 Shell::GetInstance()->ToggleAppList(secondary_window);
131 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
133 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990).
134 UpdateDisplay("800x600");
136 // Updating the displays should close the app list.
137 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
140 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance,
141 AppListControllerTest,