Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / rotation / tray_rotation_lock_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/chromeos/rotation/tray_rotation_lock.h"
6
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/root_window_controller.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/tray/system_tray.h"
14 #include "ash/system/tray/system_tray_delegate.h"
15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/status_area_widget_test_helper.h"
17 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
18 #include "base/command_line.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/time/time.h"
21 #include "ui/events/event.h"
22 #include "ui/events/event_constants.h"
23 #include "ui/views/view.h"
24
25 namespace ash {
26
27 class TrayRotationLockTest : public test::AshTestBase {
28  public:
29   TrayRotationLockTest() {}
30   virtual ~TrayRotationLockTest() {}
31
32   TrayRotationLock* tray() {
33     return tray_.get();
34   }
35
36   views::View* tray_view() {
37     return tray_view_.get();
38   }
39
40   views::View* default_view() {
41     return default_view_.get();
42   }
43
44   // Sets up a TrayRotationLock, its tray view, and its default view, for the
45   // given SystemTray and its display. On a primary display all will be
46   // created. On a secondary display both the tray view and default view will
47   // be null.
48   void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget);
49
50   // Resets |tray_| |tray_view_| and |default_view_| so that all components of
51   // TrayRotationLock have been cleared. Tests may then call
52   // SetUpForStatusAreaWidget in order to initial the components.
53   void TearDownViews();
54
55   // test::AshTestBase:
56   virtual void SetUp() OVERRIDE;
57   virtual void TearDown() OVERRIDE;
58
59  private:
60   scoped_ptr<TrayRotationLock> tray_;
61   scoped_ptr<views::View> tray_view_;
62   scoped_ptr<views::View> default_view_;
63
64   DISALLOW_COPY_AND_ASSIGN(TrayRotationLockTest);
65 };
66
67 void TrayRotationLockTest::SetUpForStatusAreaWidget(
68     StatusAreaWidget* status_area_widget) {
69   tray_.reset(new TrayRotationLock(status_area_widget->system_tray()));
70   tray_view_.reset(tray_->CreateTrayView(
71       StatusAreaWidgetTestHelper::GetUserLoginStatus()));
72   default_view_.reset(tray_->CreateDefaultView(
73       StatusAreaWidgetTestHelper::GetUserLoginStatus()));
74 }
75
76 void TrayRotationLockTest::TearDownViews() {
77   tray_view_.reset();
78   default_view_.reset();
79   tray_.reset();
80 }
81
82 void TrayRotationLockTest::SetUp() {
83   // The Display used for testing is not an internal display. This flag
84   // allows for DisplayManager to treat it as one. TrayRotationLock is only
85   // visible on internal primary displays.
86   CommandLine::ForCurrentProcess()->AppendSwitch(
87         switches::kAshUseFirstDisplayAsInternal);
88   test::AshTestBase::SetUp();
89   SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
90 }
91
92 void TrayRotationLockTest::TearDown() {
93   TearDownViews();
94   test::AshTestBase::TearDown();
95 }
96
97 // Tests that when the tray view is initially created, that it is created
98 // not visible.
99 TEST_F(TrayRotationLockTest, CreateTrayView) {
100   EXPECT_FALSE(tray_view()->visible());
101 }
102
103 // Tests that when the tray view is created, while MaximizeMode is active, that
104 // it is not visible.
105 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) {
106   TearDownViews();
107   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
108   SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
109   EXPECT_FALSE(tray_view()->visible());
110   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
111 }
112
113 // Tests that when the tray view is created, while MaximizeMode is active, and
114 // rotation is locked, that it is visible.
115 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) {
116   TearDownViews();
117   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
118   Shell::GetInstance()-> maximize_mode_controller()->set_rotation_locked(true);
119   SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
120   EXPECT_TRUE(tray_view()->visible());
121   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
122 }
123
124 // Tests that the enabling of MaximizeMode affects a previously created tray
125 // view, changing the visibility.
126 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) {
127   TearDownViews();
128   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
129   Shell::GetInstance()-> maximize_mode_controller()->set_rotation_locked(true);
130   SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
131   EXPECT_TRUE(tray_view()->visible());
132   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
133   EXPECT_FALSE(tray_view()->visible());
134 }
135
136 // Tests that the when the tray view is created for a secondary display, that
137 // it is not visible, and that MaximizeMode does not affect visibility.
138 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) {
139   if (!SupportsMultipleDisplays())
140     return;
141   UpdateDisplay("400x400,200x200");
142
143   SetUpForStatusAreaWidget(
144       StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget());
145   EXPECT_FALSE(tray_view()->visible());
146   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
147   EXPECT_FALSE(tray_view()->visible());
148   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
149   EXPECT_FALSE(tray_view()->visible());
150 }
151
152 // Tests that when the default view is initially created, that it is created
153 // not visible.
154 TEST_F(TrayRotationLockTest, CreateDefaultView) {
155   EXPECT_FALSE(default_view()->visible());
156 }
157
158 // Tests that when the default view is created, while MaximizeMode is active,
159 // that it is visible.
160 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) {
161   TearDownViews();
162   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
163   SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
164   EXPECT_TRUE(default_view()->visible());
165   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
166 }
167
168 // Tests that the enabling of MaximizeMode affects a previously created default
169 // view, changing the visibility.
170 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) {
171   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
172   EXPECT_TRUE(default_view()->visible());
173   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
174   EXPECT_FALSE(default_view()->visible());
175 }
176
177 // Tests that no default view is created when the target is a secondary
178 // display.
179 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) {
180   if (!SupportsMultipleDisplays())
181     return;
182   UpdateDisplay("400x400,200x200");
183
184   TearDownViews();
185   SetUpForStatusAreaWidget(
186       StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget());
187   EXPECT_EQ(NULL, default_view());
188 }
189
190 // Tests that activating the default view causes the display to have its
191 // rotation locked, and that the tray view becomes visible.
192 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) {
193   MaximizeModeController* maximize_mode_controller = Shell::GetInstance()->
194       maximize_mode_controller();
195   ASSERT_FALSE(maximize_mode_controller->rotation_locked());
196   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
197   ASSERT_FALSE(tray_view()->visible());
198
199   ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
200       ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0.0f, 0.0f), 0);
201   default_view()->OnGestureEvent(&tap);
202   EXPECT_TRUE(maximize_mode_controller->rotation_locked());
203   EXPECT_TRUE(tray_view()->visible());
204
205   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
206 }
207
208 }  // namespace ash