~saviq/unity/phablet-mods.bump-release

« back to all changes in this revision

Viewing changes to tests/test_switcher_controller.cpp

  • Committer: Tarmac
  • Author(s): Brandon Schaefer
  • Date: 2013-03-21 01:41:34 UTC
  • mfrom: (3225.2.2 unity)
  • Revision ID: tarmac-20130321014134-dt3qafmrpm5560ww
Moved slow unit tests in switcher controller over to test-gtest-slow.

Approved by PS Jenkins bot, Marco Trevisan (Treviño).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 */
20
20
 
21
 
#include <NuxCore/AnimationController.h>
22
 
#include <gmock/gmock.h>
23
 
#include <chrono>
24
 
 
25
 
#include "test_utils.h"
26
 
#include "DesktopLauncherIcon.h"
27
 
#include "SimpleLauncherIcon.h"
28
 
#include "SwitcherController.h"
29
 
#include "SwitcherView.h"
30
 
#include "TimeUtil.h"
31
 
#include "unity-shared/UnitySettings.h"
32
 
#include "mock-base-window.h"
 
21
#include "test_switcher_controller.h"
33
22
 
34
23
using namespace testing;
35
24
using namespace unity;
36
25
using namespace unity::switcher;
37
26
using namespace std::chrono;
38
27
 
39
 
namespace
40
 
{
41
 
typedef std::chrono::high_resolution_clock Clock;
42
 
 
43
 
#ifdef ENABLE_DELAYED_TWO_PHASE_CONSTRUCTION_TESTS
44
 
unsigned int DEFAULT_LAZY_CONSTRUCT_TIMEOUT = 20;
45
 
#endif
46
 
 
47
 
const unsigned FADE_DURATION = 80 * 1000; // in microseconds
48
 
const unsigned TICK_DURATION = 10 * 1000;
49
 
 
50
 
 
51
 
/**
52
 
 * A fake ApplicationWindow for verifying selection of the switcher.
53
 
 */
54
 
class FakeApplicationWindow : public ApplicationWindow
55
 
{
56
 
public:
57
 
  FakeApplicationWindow(Window xid) : xid_(xid) {}
58
 
 
59
 
  std::string title() const { return "FakeApplicationWindow"; }
60
 
  virtual std::string icon() const { return ""; }
61
 
  virtual std::string type() const { return "mock"; }
62
 
 
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 {}
68
 
private:
69
 
  Window xid_;
70
 
};
71
 
 
72
 
/**
73
 
 * A fake LauncherIcon for verifying selection operations of the switcher.
74
 
 */
75
 
class FakeLauncherIcon : public launcher::SimpleLauncherIcon
76
 
{
77
 
public:
78
 
  FakeLauncherIcon(std::string const& app_name, unsigned priority)
79
 
    : launcher::SimpleLauncherIcon(IconType::APPLICATION)
80
 
    , priority_(priority)
81
 
    , window_list{ std::make_shared<FakeApplicationWindow>(priority_ | 0x0001),
82
 
                   std::make_shared<FakeApplicationWindow>(priority_ | 0x0002) }
83
 
  { tooltip_text = app_name; }
84
 
 
85
 
  WindowList Windows()
86
 
  { return window_list; }
87
 
 
88
 
  unsigned long long SwitcherPriority()
89
 
  { return 0xffffffff - priority_; }
90
 
 
91
 
private:
92
 
  unsigned   priority_;
93
 
  WindowList window_list;
94
 
};
95
 
 
96
 
 
97
 
/**
98
 
 * The base test fixture for verifying the Switcher interface.
99
 
 */
100
 
class TestSwitcherController : public testing::Test
101
 
{
102
 
protected:
103
 
  TestSwitcherController()
104
 
    : animation_controller_(tick_source_)
105
 
    , mock_window_(new NiceMock<testmocks::MockBaseWindow>())
106
 
  {
107
 
    ON_CALL(*mock_window_, SetOpacity(_))
108
 
      .WillByDefault(Invoke(mock_window_.GetPointer(),
109
 
                     &testmocks::MockBaseWindow::RealSetOpacity));
110
 
 
111
 
    auto create_window = [this] { return mock_window_; };
112
 
    controller_.reset(new Controller(create_window));
113
 
    controller_->timeout_length = 0;
114
 
 
115
 
    icons_.push_back(launcher::AbstractLauncherIcon::Ptr(new launcher::DesktopLauncherIcon()));
116
 
 
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));
121
 
  }
122
 
 
123
 
  // required to create hidden secret global variables before test objects
124
 
  Settings unity_settings_;
125
 
 
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_;
131
 
};
132
 
 
133
 
 
134
28
#ifdef ENABLE_DELAYED_TWO_PHASE_CONSTRUCTION_TESTS
135
29
TEST_F(TestSwitcherController, LazyConstructionTimeoutLength)
136
30
{
152
46
}
153
47
#endif
154
48
 
155
 
TEST_F(TestSwitcherController, InitialDetailTimeout)
156
 
{
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;
160
 
 
161
 
  controller_->detail_on_timeout = true;
162
 
  controller_->initial_detail_timeout_length = initial_details_timeout;
163
 
  controller_->detail_timeout_length = details_timeout;
164
 
 
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);
169
 
 
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);
174
 
 
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);
179
 
}
180
 
 
181
 
TEST_F(TestSwitcherController, DetailTimeoutRemoval)
182
 
{
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;
186
 
 
187
 
  controller_->detail_on_timeout = true;
188
 
  controller_->detail_timeout_length = details_timeout;
189
 
  controller_->initial_detail_timeout_length = initial_details_timeout;
190
 
 
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);
195
 
 
196
 
  controller_->Next();
197
 
  selection = controller_->GetCurrentSelection();
198
 
  EXPECT_EQ(selection.application_->tooltip_text(), "Show Desktop");
199
 
  EXPECT_EQ(selection.window_, 0);
200
 
 
201
 
  controller_->Next();
202
 
  selection = controller_->GetCurrentSelection();
203
 
  EXPECT_EQ(selection.application_->tooltip_text(), "First");
204
 
  EXPECT_EQ(selection.window_, 0);
205
 
 
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);
210
 
 
211
 
 
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);
216
 
}
217
 
 
218
 
TEST_F(TestSwitcherController, DetailTimeoutOnDetailActivate)
219
 
{
220
 
  static const int initial_details_timeout = 500;
221
 
  static const int details_timeout = 10 * initial_details_timeout;
222
 
 
223
 
  controller_->detail_on_timeout = true;
224
 
  controller_->initial_detail_timeout_length = initial_details_timeout;
225
 
  controller_->detail_timeout_length = details_timeout;
226
 
 
227
 
  controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
228
 
  EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
229
 
 
230
 
  // Manually open-close the detail mode before that the timeout has occurred
231
 
  controller_->SetDetail(true);
232
 
  controller_->SetDetail(false);
233
 
 
234
 
  Utils::WaitForTimeoutMSec(initial_details_timeout * 1.1);
235
 
  EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
236
 
}
237
 
 
238
49
TEST_F(TestSwitcherController, InitiateDetail)
239
50
{
240
51
  controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
350
161
  EXPECT_EQ(mock_window_->GetOpacity(), 0.0f);
351
162
  Mock::VerifyAndClearExpectations(mock_window_.GetPointer());
352
163
}
353
 
 
354
 
}