21
#include <NuxCore/AnimationController.h>
22
#include <gmock/gmock.h>
25
#include "test_utils.h"
26
#include "DesktopLauncherIcon.h"
27
#include "SimpleLauncherIcon.h"
28
#include "SwitcherController.h"
29
#include "SwitcherView.h"
31
#include "unity-shared/UnitySettings.h"
32
#include "mock-base-window.h"
21
#include "test_switcher_controller.h"
34
23
using namespace testing;
35
24
using namespace unity;
36
25
using namespace unity::switcher;
37
26
using namespace std::chrono;
41
typedef std::chrono::high_resolution_clock Clock;
43
#ifdef ENABLE_DELAYED_TWO_PHASE_CONSTRUCTION_TESTS
44
unsigned int DEFAULT_LAZY_CONSTRUCT_TIMEOUT = 20;
47
const unsigned FADE_DURATION = 80 * 1000; // in microseconds
48
const unsigned TICK_DURATION = 10 * 1000;
52
* A fake ApplicationWindow for verifying selection of the switcher.
54
class FakeApplicationWindow : public ApplicationWindow
57
FakeApplicationWindow(Window xid) : xid_(xid) {}
59
std::string title() const { return "FakeApplicationWindow"; }
60
virtual std::string icon() const { return ""; }
61
virtual std::string type() const { return "mock"; }
63
virtual Window window_id() const { return xid_; }
64
virtual int monitor() const { return -1; }
65
virtual ApplicationPtr application() const { return ApplicationPtr(); }
66
virtual bool Focus() const { return false; }
67
virtual void Quit() const {}
73
* A fake LauncherIcon for verifying selection operations of the switcher.
75
class FakeLauncherIcon : public launcher::SimpleLauncherIcon
78
FakeLauncherIcon(std::string const& app_name, unsigned priority)
79
: launcher::SimpleLauncherIcon(IconType::APPLICATION)
81
, window_list{ std::make_shared<FakeApplicationWindow>(priority_ | 0x0001),
82
std::make_shared<FakeApplicationWindow>(priority_ | 0x0002) }
83
{ tooltip_text = app_name; }
86
{ return window_list; }
88
unsigned long long SwitcherPriority()
89
{ return 0xffffffff - priority_; }
93
WindowList window_list;
98
* The base test fixture for verifying the Switcher interface.
100
class TestSwitcherController : public testing::Test
103
TestSwitcherController()
104
: animation_controller_(tick_source_)
105
, mock_window_(new NiceMock<testmocks::MockBaseWindow>())
107
ON_CALL(*mock_window_, SetOpacity(_))
108
.WillByDefault(Invoke(mock_window_.GetPointer(),
109
&testmocks::MockBaseWindow::RealSetOpacity));
111
auto create_window = [this] { return mock_window_; };
112
controller_.reset(new Controller(create_window));
113
controller_->timeout_length = 0;
115
icons_.push_back(launcher::AbstractLauncherIcon::Ptr(new launcher::DesktopLauncherIcon()));
117
FakeLauncherIcon* first_app = new FakeLauncherIcon("First", 0x0100);
118
icons_.push_back(launcher::AbstractLauncherIcon::Ptr(first_app));
119
FakeLauncherIcon* second_app = new FakeLauncherIcon("Second", 0x0200);
120
icons_.push_back(launcher::AbstractLauncherIcon::Ptr(second_app));
123
// required to create hidden secret global variables before test objects
124
Settings unity_settings_;
126
nux::animation::TickSource tick_source_;
127
nux::animation::AnimationController animation_controller_;
128
testmocks::MockBaseWindow::Ptr mock_window_;
129
Controller::Ptr controller_;
130
std::vector<unity::launcher::AbstractLauncherIcon::Ptr> icons_;
134
28
#ifdef ENABLE_DELAYED_TWO_PHASE_CONSTRUCTION_TESTS
135
29
TEST_F(TestSwitcherController, LazyConstructionTimeoutLength)
155
TEST_F(TestSwitcherController, InitialDetailTimeout)
157
Clock::time_point start_time = Clock::now();
158
static const int initial_details_timeout = 500;
159
static const int details_timeout = 10 * initial_details_timeout;
161
controller_->detail_on_timeout = true;
162
controller_->initial_detail_timeout_length = initial_details_timeout;
163
controller_->detail_timeout_length = details_timeout;
165
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
166
Selection selection = controller_->GetCurrentSelection();
167
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
168
EXPECT_EQ(selection.window_, 0);
170
Utils::WaitForTimeoutMSec(initial_details_timeout * 1.1);
171
selection = controller_->GetCurrentSelection();
172
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
173
EXPECT_EQ(selection.window_, 0x0201);
175
auto elapsed_time = Clock::now() - start_time;
176
auto time_diff = duration_cast<milliseconds>(elapsed_time).count();
177
EXPECT_TRUE(initial_details_timeout < time_diff);
178
EXPECT_TRUE(time_diff < details_timeout);
181
TEST_F(TestSwitcherController, DetailTimeoutRemoval)
183
Clock::time_point start_time = Clock::now();
184
static const int details_timeout = 500;
185
static const int initial_details_timeout = 10 * details_timeout;
187
controller_->detail_on_timeout = true;
188
controller_->detail_timeout_length = details_timeout;
189
controller_->initial_detail_timeout_length = initial_details_timeout;
191
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
192
Selection selection = controller_->GetCurrentSelection();
193
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
194
EXPECT_EQ(selection.window_, 0);
197
selection = controller_->GetCurrentSelection();
198
EXPECT_EQ(selection.application_->tooltip_text(), "Show Desktop");
199
EXPECT_EQ(selection.window_, 0);
202
selection = controller_->GetCurrentSelection();
203
EXPECT_EQ(selection.application_->tooltip_text(), "First");
204
EXPECT_EQ(selection.window_, 0);
206
Utils::WaitForTimeoutMSec(details_timeout * 1.1);
207
selection = controller_->GetCurrentSelection();
208
EXPECT_EQ(selection.application_->tooltip_text(), "First");
209
EXPECT_EQ(selection.window_, 0x0101);
212
auto elapsed_time = Clock::now() - start_time;
213
auto time_diff = duration_cast<milliseconds>(elapsed_time).count();
214
EXPECT_TRUE(details_timeout < time_diff);
215
EXPECT_TRUE(time_diff < initial_details_timeout);
218
TEST_F(TestSwitcherController, DetailTimeoutOnDetailActivate)
220
static const int initial_details_timeout = 500;
221
static const int details_timeout = 10 * initial_details_timeout;
223
controller_->detail_on_timeout = true;
224
controller_->initial_detail_timeout_length = initial_details_timeout;
225
controller_->detail_timeout_length = details_timeout;
227
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
228
EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
230
// Manually open-close the detail mode before that the timeout has occurred
231
controller_->SetDetail(true);
232
controller_->SetDetail(false);
234
Utils::WaitForTimeoutMSec(initial_details_timeout * 1.1);
235
EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
238
49
TEST_F(TestSwitcherController, InitiateDetail)
240
51
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);