2
* Copyright 2012 Canonical Ltd.
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.
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.
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/>
19
#include <gmock/gmock.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"
30
using namespace testing;
35
struct TestPanelMenuView : public testing::Test
38
: WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
41
struct MockPanelMenuView : public PanelMenuView
43
MOCK_METHOD0(QueueDraw, void());
44
MOCK_CONST_METHOD1(GetActiveViewName, std::string(bool));
46
using PanelMenuView::GetCurrentTitle;
47
using PanelMenuView::window_buttons_;
48
using PanelMenuView::titlebar_grab_area_;
51
nux::ObjectPtr<nux::BaseWindow> AddPanelToWindow(int monitor)
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();
64
menu_view.SetMonitor(monitor);
70
// The order is important, i.e. menu_view needs
71
// panel::Style that needs Settings
74
panel::Style panelStyle;
75
StandaloneWindowManager* WM;
76
testing::NiceMock<MockPanelMenuView> menu_view;
79
TEST_F(TestPanelMenuView, Escaping)
81
ON_CALL(menu_view, GetActiveViewName(testing::_)).WillByDefault(Return("<>'"));
82
static const char *escapedText = "Panel d&Inici";
83
EXPECT_TRUE(menu_view.GetCurrentTitle().empty());
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;});
92
WM->SetScaleActive(true);
93
WM->SetScaleActiveForGroup(true);
94
ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV);
95
Utils::WaitUntilMSec([this] {return menu_view.GetCurrentTitle() == "<>'";});
98
TEST_F(TestPanelMenuView, QueuesDrawOnButtonsOpacityChange)
100
EXPECT_CALL(menu_view, QueueDraw());
101
menu_view.window_buttons_->opacity.changed.emit(0.5f);
104
struct ProgressTester : TestPanelMenuView, WithParamInterface<double> {};
105
INSTANTIATE_TEST_CASE_P(TestPanelMenuView, ProgressTester, Range(0.0, 1.0, 0.1));
107
TEST_P(ProgressTester, RestoreOnGrabInBiggerWorkArea)
109
uscreen.SetupFakeMultiMonitor();
110
unsigned monitor = uscreen.GetMonitors().size() - 1;
111
auto const& monitor_geo = uscreen.GetMonitorGeometry(monitor);
112
WM->SetWorkareaGeometry(monitor_geo);
114
auto panel_win = AddPanelToWindow(monitor);
116
auto max_window = std::make_shared<StandaloneWindow>(g_random_int());
117
WM->AddStandaloneWindow(max_window);
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;
124
bool restored = 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);});
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());
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);
137
EXPECT_TRUE(restored);
139
EXPECT_FALSE(max_window->maximized());
140
EXPECT_EQ(max_window->geo(), expected_geo);