Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / wm / app_list_controller_unittest.cc
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.
4
5 #include "ash/shell.h"
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"
16
17 namespace ash {
18
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> {
23  public:
24   AppListControllerTest();
25   virtual ~AppListControllerTest();
26   virtual void SetUp() OVERRIDE;
27 };
28
29 AppListControllerTest::AppListControllerTest() {
30 }
31
32 AppListControllerTest::~AppListControllerTest() {
33 }
34
35 void AppListControllerTest::SetUp() {
36   AshTestBase::SetUp();
37   if (GetParam()) {
38     CommandLine* command_line = CommandLine::ForCurrentProcess();
39     command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList);
40   }
41 }
42
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());
47
48   scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
49   wm::ActivateWindow(window.get());
50
51   EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
52 }
53
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());
59
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());
65
66   EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
67 }
68
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);
73
74   aura::Window* app_window = shell->GetAppListWindow();
75   ASSERT_TRUE(app_window);
76   aura::test::EventGenerator generator(shell->GetPrimaryRootWindow(),
77                                        app_window);
78   // Click on the bubble itself. The bubble should remain visible.
79   generator.ClickLeftButton();
80   EXPECT_TRUE(shell->GetAppListTargetVisibility());
81
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()) +
86       gfx::Vector2d(10, 0);
87   EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside));
88   generator.MoveMouseToInHost(point_outside);
89   generator.ClickLeftButton();
90   EXPECT_FALSE(shell->GetAppListTargetVisibility());
91 }
92
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);
97
98   aura::Window* app_window = shell->GetAppListWindow();
99   ASSERT_TRUE(app_window);
100   gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
101
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());
106
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());
114 }
115
116 // Tests opening the app launcher on a non-primary display, then deleting the
117 // display.
118 TEST_P(AppListControllerTest, NonPrimaryDisplay) {
119   if (!SupportsMultipleDisplays())
120     return;
121
122   // Set up a screen with two displays (horizontally adjacent).
123   UpdateDisplay("800x600,800x600");
124
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());
129
130   Shell::GetInstance()->ToggleAppList(secondary_window);
131   EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
132
133   // Remove the secondary display. Shouldn't crash (http://crbug.com/368990).
134   UpdateDisplay("800x600");
135
136   // Updating the displays should close the app list.
137   EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
138 }
139
140 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance,
141                         AppListControllerTest,
142                         ::testing::Bool());
143
144 }  // namespace ash