Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / system / overview / overview_button_tray_unittest.cc
1 // Copyright 2014 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/system/overview/overview_button_tray.h"
6
7 #include "ash/display/display_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/system/status_area_widget.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/status_area_widget_test_helper.h"
16 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
17 #include "ash/wm/overview/window_selector_controller.h"
18 #include "base/time/time.h"
19 #include "ui/events/event.h"
20 #include "ui/events/event_constants.h"
21 #include "ui/events/gestures/gesture_types.h"
22 #include "ui/views/controls/image_view.h"
23
24 namespace ash {
25
26 namespace {
27
28 OverviewButtonTray* GetTray() {
29   return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->
30       overview_button_tray();
31 }
32
33 OverviewButtonTray* GetSecondaryTray() {
34   return StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()->
35       overview_button_tray();
36 }
37
38 }  // namespace
39
40 class OverviewButtonTrayTest : public test::AshTestBase {
41  public:
42   OverviewButtonTrayTest() {}
43   ~OverviewButtonTrayTest() override {}
44
45  protected:
46   views::ImageView* GetImageView(OverviewButtonTray* tray) {
47     return tray->icon_;
48   }
49
50  private:
51   DISALLOW_COPY_AND_ASSIGN(OverviewButtonTrayTest);
52 };
53
54 // Ensures that creation doesn't cause any crashes and adds the image icon.
55 TEST_F(OverviewButtonTrayTest, BasicConstruction) {
56   EXPECT_TRUE(GetImageView(GetTray()) != NULL);
57 }
58
59 // Test that maximize mode toggle changes visibility.
60 // OverviewButtonTray should only be visible when MaximizeMode is enabled.
61 // By default the system should not have MaximizeMode enabled.
62 TEST_F(OverviewButtonTrayTest, MaximizeModeObserverOnMaximizeModeToggled) {
63   ASSERT_FALSE(GetTray()->visible());
64   Shell::GetInstance()->maximize_mode_controller()->
65       EnableMaximizeModeWindowManager(true);
66   EXPECT_TRUE(GetTray()->visible());
67
68   Shell::GetInstance()->maximize_mode_controller()->
69       EnableMaximizeModeWindowManager(false);
70   EXPECT_FALSE(GetTray()->visible());
71 }
72
73 // Tests that activating this control brings up window selection mode.
74 TEST_F(OverviewButtonTrayTest, PerformAction) {
75   ASSERT_FALSE(Shell::GetInstance()->window_selector_controller()->
76       IsSelecting());
77
78   // Overview Mode only works when there is a window
79   scoped_ptr<aura::Window> window(
80       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
81   ui::GestureEvent tap(
82       0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
83   GetTray()->PerformAction(tap);
84   EXPECT_TRUE(Shell::GetInstance()->window_selector_controller()->
85       IsSelecting());
86 }
87
88 // Tests that a second OverviewButtonTray has been created, and only shows
89 // when MaximizeMode has been enabled,  when we are using multiple displays.
90 // By default the DisplayManger is in extended mode.
91 TEST_F(OverviewButtonTrayTest, DisplaysOnBothDisplays) {
92   if (!SupportsMultipleDisplays())
93     return;
94
95   UpdateDisplay("400x400,200x200");
96   EXPECT_FALSE(GetTray()->visible());
97   EXPECT_FALSE(GetSecondaryTray()->visible());
98   Shell::GetInstance()->maximize_mode_controller()->
99       EnableMaximizeModeWindowManager(true);
100   EXPECT_TRUE(GetTray()->visible());
101   EXPECT_TRUE(GetSecondaryTray()->visible());
102   Shell::GetInstance()->maximize_mode_controller()->
103       EnableMaximizeModeWindowManager(false);
104 }
105
106 // Tests if Maximize Mode is enabled before a secondary display is attached
107 // that the second OverviewButtonTray should be created in a visible state.
108 TEST_F(OverviewButtonTrayTest, SecondaryTrayCreatedVisible) {
109   if (!SupportsMultipleDisplays())
110     return;
111
112   Shell::GetInstance()->maximize_mode_controller()->
113       EnableMaximizeModeWindowManager(true);
114   UpdateDisplay("400x400,200x200");
115   EXPECT_TRUE(GetSecondaryTray()->visible());
116   Shell::GetInstance()->maximize_mode_controller()->
117       EnableMaximizeModeWindowManager(false);
118 }
119
120 // Tests that the tray loses visibility when a user logs out, and that it
121 // regains visibility when a user logs back in.
122 TEST_F(OverviewButtonTrayTest, VisibilityChangesForLoginStatus) {
123   Shell::GetInstance()->maximize_mode_controller()->
124       EnableMaximizeModeWindowManager(true);
125   SetUserLoggedIn(false);
126   Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_NONE);
127   EXPECT_FALSE(GetTray()->visible());
128   SetUserLoggedIn(true);
129   SetSessionStarted(true);
130   Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER);
131   EXPECT_TRUE(GetTray()->visible());
132   Shell::GetInstance()->maximize_mode_controller()->
133       EnableMaximizeModeWindowManager(false);
134 }
135
136 // Tests that the tray only renders as active while selection is ongoing. Any
137 // dismissal of overview mode clears the active state.
138 TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) {
139   ASSERT_FALSE(
140       Shell::GetInstance()->window_selector_controller()->IsSelecting());
141   ASSERT_FALSE(GetTray()->draw_background_as_active());
142
143   // Overview Mode only works when there is a window
144   scoped_ptr<aura::Window> window(
145       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
146   ui::GestureEvent tap(
147       0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
148   GetTray()->PerformAction(tap);
149   EXPECT_TRUE(
150       Shell::GetInstance()->window_selector_controller()->IsSelecting());
151   EXPECT_TRUE(GetTray()->draw_background_as_active());
152
153   Shell::GetInstance()->window_selector_controller()->OnSelectionEnded();
154   EXPECT_FALSE(
155       Shell::GetInstance()->window_selector_controller()->IsSelecting());
156   EXPECT_FALSE(GetTray()->draw_background_as_active());
157 }
158
159 }  // namespace ash