~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_panel_menu_view.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as published
6
 
 * by the  Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * version 3 along with this program.  If not, see
15
 
 * <http://www.gnu.org/licenses/>
16
 
 *
17
 
 */
18
 
 
19
 
#include <gmock/gmock.h>
20
 
 
21
 
#include <Nux/Nux.h>
22
 
#include "PanelMenuView.h"
23
 
#include "PanelStyle.h"
24
 
#include "UnitySettings.h"
25
 
#include "UBusMessages.h"
26
 
#include "StandaloneWindowManager.h"
27
 
#include "test_uscreen_mock.h"
28
 
#include "test_utils.h"
29
 
 
30
 
using namespace testing;
31
 
 
32
 
namespace unity
33
 
{
34
 
 
35
 
struct TestPanelMenuView : public testing::Test
36
 
{
37
 
  TestPanelMenuView()
38
 
    : WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
39
 
  {}
40
 
 
41
 
  struct MockPanelMenuView : public PanelMenuView
42
 
  {
43
 
    MOCK_METHOD0(QueueDraw, void());
44
 
    MOCK_CONST_METHOD1(GetActiveViewName, std::string(bool));
45
 
 
46
 
    using PanelMenuView::GetCurrentTitle;
47
 
    using PanelMenuView::window_buttons_;
48
 
    using PanelMenuView::titlebar_grab_area_;
49
 
  };
50
 
 
51
 
  nux::ObjectPtr<nux::BaseWindow> AddPanelToWindow(int monitor)
52
 
  {
53
 
    nux::ObjectPtr<nux::BaseWindow> panel_win(new nux::BaseWindow());
54
 
    auto const& monitor_geo = uscreen.GetMonitorGeometry(monitor);
55
 
    panel_win->SetGeometry(monitor_geo);
56
 
    panel_win->SetMaximumHeight(panelStyle.panel_height());
57
 
    panel_win->SetLayout(new nux::HLayout(NUX_TRACKER_LOCATION));
58
 
    panel_win->GetLayout()->AddView(&menu_view, 1);
59
 
    panel_win->GetLayout()->SetContentDistribution(nux::MAJOR_POSITION_START);
60
 
    panel_win->GetLayout()->SetVerticalExternalMargin(0);
61
 
    panel_win->GetLayout()->SetHorizontalExternalMargin(0);
62
 
    panel_win->ComputeContentSize();
63
 
 
64
 
    menu_view.SetMonitor(monitor);
65
 
 
66
 
    return panel_win;
67
 
  }
68
 
 
69
 
protected:
70
 
  // The order is important, i.e. menu_view needs
71
 
  // panel::Style that needs Settings
72
 
  MockUScreen uscreen;
73
 
  Settings settings;
74
 
  panel::Style panelStyle;
75
 
  StandaloneWindowManager* WM;
76
 
  testing::NiceMock<MockPanelMenuView> menu_view;
77
 
};
78
 
 
79
 
TEST_F(TestPanelMenuView, Escaping)
80
 
{
81
 
  ON_CALL(menu_view, GetActiveViewName(testing::_)).WillByDefault(Return("<>'"));
82
 
  static const char *escapedText = "Panel d&amp;Inici";
83
 
  EXPECT_TRUE(menu_view.GetCurrentTitle().empty());
84
 
 
85
 
  UBusManager ubus;
86
 
  ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV);
87
 
  ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED,
88
 
                   g_variant_new_string(escapedText));
89
 
  Utils::WaitUntilMSec([this] {return menu_view.GetCurrentTitle() == escapedText;});
90
 
 
91
 
 
92
 
  WM->SetScaleActive(true);
93
 
  WM->SetScaleActiveForGroup(true);
94
 
  ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV);
95
 
  Utils::WaitUntilMSec([this] {return menu_view.GetCurrentTitle() == "&lt;&gt;&apos;";});
96
 
}
97
 
 
98
 
TEST_F(TestPanelMenuView, QueuesDrawOnButtonsOpacityChange)
99
 
{
100
 
  EXPECT_CALL(menu_view, QueueDraw());
101
 
  menu_view.window_buttons_->opacity.changed.emit(0.5f);
102
 
}
103
 
 
104
 
struct ProgressTester : TestPanelMenuView, WithParamInterface<double> {};
105
 
INSTANTIATE_TEST_CASE_P(TestPanelMenuView, ProgressTester, Range(0.0, 1.0, 0.1));
106
 
 
107
 
TEST_P(ProgressTester, RestoreOnGrabInBiggerWorkArea)
108
 
{
109
 
  uscreen.SetupFakeMultiMonitor();
110
 
  unsigned monitor = uscreen.GetMonitors().size() - 1;
111
 
  auto const& monitor_geo = uscreen.GetMonitorGeometry(monitor);
112
 
  WM->SetWorkareaGeometry(monitor_geo);
113
 
 
114
 
  auto panel_win = AddPanelToWindow(monitor);
115
 
 
116
 
  auto max_window = std::make_shared<StandaloneWindow>(g_random_int());
117
 
  WM->AddStandaloneWindow(max_window);
118
 
 
119
 
  max_window->maximized = true;
120
 
  nux::Geometry win_geo(monitor_geo.x + monitor_geo.width/4, monitor_geo.y + monitor_geo.height/4,
121
 
                        monitor_geo.width/2, monitor_geo.height/2);
122
 
  max_window->geo = win_geo;
123
 
 
124
 
  bool restored = false;
125
 
  bool moved = false;
126
 
  WM->window_restored.connect([&] (Window xid) {restored = (max_window->Xid() == xid);});
127
 
  WM->window_moved.connect([&] (Window xid) {moved = (max_window->Xid() == xid);});
128
 
 
129
 
  // Grab the window outside the panel shape
130
 
  nux::Point mouse_pos(panel_win->GetX() + panel_win->GetWidth() * GetParam(), panel_win->GetY() + panel_win->GetHeight() + 1);
131
 
  menu_view.titlebar_grab_area_->grab_move(mouse_pos.x - panel_win->GetX(), mouse_pos.y - panel_win->GetY());
132
 
 
133
 
  nux::Geometry expected_geo(win_geo);
134
 
  expected_geo.SetPosition(mouse_pos.x - (win_geo.width * (mouse_pos.x - panel_win->GetX()) / panel_win->GetWidth()), mouse_pos.y);
135
 
  expected_geo.x = std::max<int>(expected_geo.x, monitor_geo.x);
136
 
 
137
 
  EXPECT_TRUE(restored);
138
 
  EXPECT_TRUE(moved);
139
 
  EXPECT_FALSE(max_window->maximized());
140
 
  EXPECT_EQ(max_window->geo(), expected_geo);
141
 
}
142
 
 
143
 
 
144
 
}