bc3fd695031be4bc6dbe61263f6e00725c0ed365
[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/overview/window_selector_controller.h"
17 #include "base/time/time.h"
18 #include "ui/events/event.h"
19 #include "ui/events/event_constants.h"
20 #include "ui/events/gestures/gesture_types.h"
21 #include "ui/views/controls/image_view.h"
22
23 namespace ash {
24
25 namespace {
26
27 OverviewButtonTray* GetTray() {
28   return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->
29       overview_button_tray();
30 }
31
32 OverviewButtonTray* GetSecondaryTray() {
33   return StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()->
34       overview_button_tray();
35 }
36
37 }  // namespace
38
39 class OverviewButtonTrayTest : public test::AshTestBase {
40  public:
41   OverviewButtonTrayTest() {}
42   virtual ~OverviewButtonTrayTest() {}
43
44  protected:
45   views::ImageView* GetImageView(OverviewButtonTray* tray) {
46     return tray->icon_;
47   }
48
49  private:
50   DISALLOW_COPY_AND_ASSIGN(OverviewButtonTrayTest);
51 };
52
53 // Ensures that creation doesn't cause any crashes and adds the image icon.
54 TEST_F(OverviewButtonTrayTest, BasicConstruction) {
55   EXPECT_TRUE(GetImageView(GetTray()) != NULL);
56 }
57
58 // Test that maximize mode toggle changes visibility.
59 // OverviewButtonTray should only be visible when MaximizeMode is enabled.
60 // By default the system should not have MaximizeMode enabled.
61 TEST_F(OverviewButtonTrayTest, MaximizeModeObserverOnMaximizeModeToggled) {
62   ASSERT_FALSE(GetTray()->visible());
63   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
64   EXPECT_TRUE(GetTray()->visible());
65
66   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
67   EXPECT_FALSE(GetTray()->visible());
68 }
69
70 // Tests that activating this control brings up window selection mode.
71 TEST_F(OverviewButtonTrayTest, PerformAction) {
72   ASSERT_FALSE(Shell::GetInstance()->window_selector_controller()->
73       IsSelecting());
74
75   // Overview Mode only works when there is a window
76   scoped_ptr<aura::Window> window(
77       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
78   ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
79       ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0.0f, 0.0f), 0);
80   GetTray()->PerformAction(tap);
81   EXPECT_TRUE(Shell::GetInstance()->window_selector_controller()->
82       IsSelecting());
83 }
84
85 // Tests that a second OverviewButtonTray has been created, and only shows
86 // when MaximizeMode has been enabled,  when we are using multiple displays.
87 // By default the DisplayManger is in extended mode.
88 TEST_F(OverviewButtonTrayTest, DisplaysOnBothDisplays) {
89   if (!SupportsMultipleDisplays())
90     return;
91
92   UpdateDisplay("400x400,200x200");
93   EXPECT_FALSE(GetTray()->visible());
94   EXPECT_FALSE(GetSecondaryTray()->visible());
95   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
96   EXPECT_TRUE(GetTray()->visible());
97   EXPECT_TRUE(GetSecondaryTray()->visible());
98   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
99 }
100
101 // Tests if Maximize Mode is enabled before a secondary display is attached
102 // that the second OverviewButtonTray should be created in a visible state.
103 TEST_F(OverviewButtonTrayTest, SecondaryTrayCreatedVisible) {
104   if (!SupportsMultipleDisplays())
105     return;
106
107   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
108   UpdateDisplay("400x400,200x200");
109   EXPECT_TRUE(GetSecondaryTray()->visible());
110   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
111 }
112
113 // Tests that the tray loses visibility when a user logs out, and that it
114 // regains visibility when a user logs back in.
115 TEST_F(OverviewButtonTrayTest, VisibilityChangesForLoginStatus) {
116   Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
117   SetUserLoggedIn(false);
118   Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_NONE);
119   EXPECT_FALSE(GetTray()->visible());
120   SetUserLoggedIn(true);
121   SetSessionStarted(true);
122   Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER);
123   EXPECT_TRUE(GetTray()->visible());
124   Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
125 }
126
127 }  // namespace ash