2
* Copyright 2012-2013 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/>
17
* Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
22
#include "test_switcher_controller.h"
24
using namespace testing;
25
using namespace unity;
26
using namespace unity::switcher;
27
using namespace std::chrono;
29
TEST_F(TestSwitcherController, InitialDetailTimeout)
31
Clock::time_point start_time = Clock::now();
32
static const int initial_details_timeout = 500;
33
static const int details_timeout = 10 * initial_details_timeout;
35
controller_->detail_on_timeout = true;
36
controller_->initial_detail_timeout_length = initial_details_timeout;
37
controller_->detail_timeout_length = details_timeout;
39
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
40
Selection selection = controller_->GetCurrentSelection();
41
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
42
EXPECT_EQ(selection.window_, 0);
44
Utils::WaitForTimeoutMSec(initial_details_timeout * 1.1);
45
selection = controller_->GetCurrentSelection();
46
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
47
EXPECT_EQ(selection.window_, 0x0201);
49
auto elapsed_time = Clock::now() - start_time;
50
auto time_diff = duration_cast<milliseconds>(elapsed_time).count();
51
EXPECT_TRUE(initial_details_timeout < time_diff);
52
EXPECT_TRUE(time_diff < details_timeout);
55
TEST_F(TestSwitcherController, DetailTimeoutRemoval)
57
Clock::time_point start_time = Clock::now();
58
static const int details_timeout = 500;
59
static const int initial_details_timeout = 10 * details_timeout;
61
controller_->detail_on_timeout = true;
62
controller_->detail_timeout_length = details_timeout;
63
controller_->initial_detail_timeout_length = initial_details_timeout;
65
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
66
Selection selection = controller_->GetCurrentSelection();
67
EXPECT_EQ(selection.application_->tooltip_text(), "Second");
68
EXPECT_EQ(selection.window_, 0);
71
selection = controller_->GetCurrentSelection();
72
EXPECT_EQ(selection.application_->tooltip_text(), "Show Desktop");
73
EXPECT_EQ(selection.window_, 0);
76
selection = controller_->GetCurrentSelection();
77
EXPECT_EQ(selection.application_->tooltip_text(), "First");
78
EXPECT_EQ(selection.window_, 0);
80
Utils::WaitForTimeoutMSec(details_timeout * 1.1);
81
selection = controller_->GetCurrentSelection();
82
EXPECT_EQ(selection.application_->tooltip_text(), "First");
83
EXPECT_EQ(selection.window_, 0x0101);
86
auto elapsed_time = Clock::now() - start_time;
87
auto time_diff = duration_cast<milliseconds>(elapsed_time).count();
88
EXPECT_TRUE(details_timeout < time_diff);
89
EXPECT_TRUE(time_diff < initial_details_timeout);
92
TEST_F(TestSwitcherController, DetailTimeoutOnDetailActivate)
94
static const int initial_details_timeout = 500;
95
static const int details_timeout = 10 * initial_details_timeout;
97
controller_->detail_on_timeout = true;
98
controller_->initial_detail_timeout_length = initial_details_timeout;
99
controller_->detail_timeout_length = details_timeout;
101
controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
102
EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
104
// Manually open-close the detail mode before that the timeout has occurred
105
controller_->SetDetail(true);
106
controller_->SetDetail(false);
108
Utils::WaitForTimeoutMSec(initial_details_timeout * 1.1);
109
EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);