Merge lp:~3v1n0/unity/spread-launcher-desaturate into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3577
Proposed branch: lp:~3v1n0/unity/spread-launcher-desaturate
Merge into: lp:unity
Diff against target: 764 lines (+378/-74)
10 files modified
dash/DashController.h (+1/-1)
hud/HudController.h (+1/-1)
launcher/Launcher.cpp (+50/-9)
launcher/Launcher.h (+1/-0)
tests/autopilot/unity/tests/test_spread.py (+72/-2)
tests/mock-base-window.h (+8/-6)
tests/test_dash_controller.cpp (+21/-22)
tests/test_hud_controller.cpp (+29/-19)
tests/test_launcher.cpp (+194/-8)
tests/test_switcher_controller_class.cpp (+1/-6)
To merge this branch: bzr merge lp:~3v1n0/unity/spread-launcher-desaturate
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+192066@code.launchpad.net

This proposal supersedes a proposal from 2013-10-11.

Commit message

Launcher: desaturate the inactive icons when in Spread mode

Description of the change

Desaturate the Launcher and hide tooltips when spread is initiated as designed.

Added unit and autopilot tests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote : Posted in a previous version of this proposal

Seems Jenkins CI is segfaulting:

[ RUN ] TestLauncher.DesaturateAllIconsOnSpread
Segmentation fault

I don't see that locally:(

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote : Posted in a previous version of this proposal

LGTM

review: Approve
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Still looks good!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dash/DashController.h'
--- dash/DashController.h 2013-10-03 13:18:57 +0000
+++ dash/DashController.h 2013-10-21 23:51:09 +0000
@@ -41,7 +41,7 @@
41namespace dash41namespace dash
42{42{
4343
44class Controller : public unity::debug::Introspectable44class Controller : public unity::debug::Introspectable, public sigc::trackable
45{45{
46public:46public:
47 typedef std::shared_ptr<Controller> Ptr;47 typedef std::shared_ptr<Controller> Ptr;
4848
=== modified file 'hud/HudController.h'
--- hud/HudController.h 2013-10-16 03:42:03 +0000
+++ hud/HudController.h 2013-10-21 23:51:09 +0000
@@ -40,7 +40,7 @@
40namespace hud40namespace hud
41{41{
4242
43class Controller : public unity::debug::Introspectable43class Controller : public unity::debug::Introspectable, public sigc::trackable
44{44{
45public:45public:
46 typedef std::shared_ptr<Controller> Ptr;46 typedef std::shared_ptr<Controller> Ptr;
4747
=== modified file 'launcher/Launcher.cpp'
--- launcher/Launcher.cpp 2013-10-04 03:55:52 +0000
+++ launcher/Launcher.cpp 2013-10-21 23:51:09 +0000
@@ -94,6 +94,7 @@
94const std::string START_DRAGICON_TIMEOUT = "start-dragicon-timeout";94const std::string START_DRAGICON_TIMEOUT = "start-dragicon-timeout";
95const std::string SCROLL_TIMEOUT = "scroll-timeout";95const std::string SCROLL_TIMEOUT = "scroll-timeout";
96const std::string ANIMATION_IDLE = "animation-idle";96const std::string ANIMATION_IDLE = "animation-idle";
97const std::string SCALE_DESATURATE_IDLE = "scale-desaturate-idle";
97const std::string URGENT_TIMEOUT = "urgent-timeout";98const std::string URGENT_TIMEOUT = "urgent-timeout";
98}99}
99100
@@ -173,9 +174,9 @@
173 ql_manager.quicklist_closed.connect(sigc::mem_fun(this, &Launcher::RecvQuicklistClosed));174 ql_manager.quicklist_closed.connect(sigc::mem_fun(this, &Launcher::RecvQuicklistClosed));
174175
175 WindowManager& wm = WindowManager::Default();176 WindowManager& wm = WindowManager::Default();
176 wm.initiate_spread.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));177 wm.initiate_spread.connect(sigc::mem_fun(this, &Launcher::OnSpreadChanged));
178 wm.terminate_spread.connect(sigc::mem_fun(this, &Launcher::OnSpreadChanged));
177 wm.initiate_expo.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));179 wm.initiate_expo.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));
178 wm.terminate_spread.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));
179 wm.terminate_expo.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));180 wm.terminate_expo.connect(sigc::mem_fun(this, &Launcher::OnPluginStateChanged));
180 wm.screen_viewport_switch_ended.connect(sigc::mem_fun(this, &Launcher::QueueDraw));181 wm.screen_viewport_switch_ended.connect(sigc::mem_fun(this, &Launcher::QueueDraw));
181182
@@ -1125,23 +1126,30 @@
1125 }1126 }
1126}1127}
11271128
1129// FIXME: add monitor-aware quirks!
1128void Launcher::DesaturateIcons()1130void Launcher::DesaturateIcons()
1129{1131{
1130 for (auto icon : *model_)1132 bool inactive_only = WindowManager::Default().IsScaleActiveForGroup();
1133
1134 for (auto const& icon : *model_)
1131 {1135 {
1136 bool desaturate = false;
1137
1132 if (icon->GetIconType () != AbstractLauncherIcon::IconType::HOME &&1138 if (icon->GetIconType () != AbstractLauncherIcon::IconType::HOME &&
1133 icon->GetIconType () != AbstractLauncherIcon::IconType::HUD)1139 icon->GetIconType () != AbstractLauncherIcon::IconType::HUD &&
1140 (!inactive_only || !icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE)))
1134 {1141 {
1135 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, true);1142 desaturate = true;
1136 }1143 }
11371144
1145 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, desaturate);
1138 icon->HideTooltip();1146 icon->HideTooltip();
1139 }1147 }
1140}1148}
11411149
1142void Launcher::SaturateIcons()1150void Launcher::SaturateIcons()
1143{1151{
1144 for (auto icon : *model_)1152 for (auto const& icon : *model_)
1145 {1153 {
1146 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, false);1154 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, false);
1147 }1155 }
@@ -1243,7 +1251,7 @@
12431251
1244bool Launcher::IsOverlayOpen() const1252bool Launcher::IsOverlayOpen() const
1245{1253{
1246 return dash_is_open_ || hud_is_open_;1254 return dash_is_open_ || hud_is_open_ || WindowManager::Default().IsScaleActive();
1247}1255}
12481256
1249void Launcher::SetHidden(bool hide_launcher)1257void Launcher::SetHidden(bool hide_launcher)
@@ -1303,8 +1311,34 @@
1303void Launcher::OnPluginStateChanged()1311void Launcher::OnPluginStateChanged()
1304{1312{
1305 WindowManager& wm = WindowManager::Default();1313 WindowManager& wm = WindowManager::Default();
1306 hide_machine_.SetQuirk(LauncherHideMachine::EXPO_ACTIVE, wm.IsExpoActive());1314 bool expo_active = wm.IsExpoActive();
1307 hide_machine_.SetQuirk(LauncherHideMachine::SCALE_ACTIVE, wm.IsScaleActive());1315 hide_machine_.SetQuirk(LauncherHideMachine::EXPO_ACTIVE, expo_active);
1316
1317 if (expo_active && icon_under_mouse_)
1318 icon_under_mouse_->HideTooltip();
1319}
1320
1321void Launcher::OnSpreadChanged()
1322{
1323 WindowManager& wm = WindowManager::Default();
1324 bool active = wm.IsScaleActive();
1325 hide_machine_.SetQuirk(LauncherHideMachine::SCALE_ACTIVE, active);
1326
1327 bg_effect_helper_.enabled = active;
1328
1329 if (active && icon_under_mouse_)
1330 icon_under_mouse_->HideTooltip();
1331
1332 if (active && (!hovered_ || wm.IsScaleActiveForGroup()))
1333 {
1334 // The icons can take some ms to update their active state, this can protect us.
1335 sources_.AddIdle([this] { DesaturateIcons(); return false; }, SCALE_DESATURATE_IDLE);
1336 }
1337 else
1338 {
1339 sources_.Remove(SCALE_DESATURATE_IDLE);
1340 SaturateIcons();
1341 }
1308}1342}
13091343
1310LauncherHideMode Launcher::GetHideMode() const1344LauncherHideMode Launcher::GetHideMode() const
@@ -2231,6 +2265,13 @@
2231 if (!hidden_)2265 if (!hidden_)
2232 UpdateChangeInMousePosition(dx, dy);2266 UpdateChangeInMousePosition(dx, dy);
22332267
2268 if (WindowManager::Default().IsScaleActiveForGroup())
2269 {
2270 auto icon = MouseIconIntersection(x, y);
2271 if (icon && !icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE))
2272 SaturateIcons();
2273 }
2274
2234 // Every time the mouse moves, we check if it is inside an icon...2275 // Every time the mouse moves, we check if it is inside an icon...
2235 EventLogic();2276 EventLogic();
22362277
22372278
=== modified file 'launcher/Launcher.h'
--- launcher/Launcher.h 2013-09-30 15:08:09 +0000
+++ launcher/Launcher.h 2013-10-21 23:51:09 +0000
@@ -200,6 +200,7 @@
200#endif200#endif
201201
202 void OnPluginStateChanged();202 void OnPluginStateChanged();
203 void OnSpreadChanged();
203204
204 void OnSelectionChanged(AbstractLauncherIcon::Ptr const& selection);205 void OnSelectionChanged(AbstractLauncherIcon::Ptr const& selection);
205206
206207
=== modified file 'tests/autopilot/unity/tests/test_spread.py'
--- tests/autopilot/unity/tests/test_spread.py 2013-10-08 14:08:52 +0000
+++ tests/autopilot/unity/tests/test_spread.py 2013-10-21 23:51:09 +0000
@@ -8,9 +8,11 @@
88
9from __future__ import absolute_import9from __future__ import absolute_import
1010
11from autopilot.display import Display
11from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
12from testtools.matchers import Equals, NotEquals13from testtools.matchers import Equals, NotEquals
13from time import sleep14from time import sleep
15from unity.emulators.icons import BFBLauncherIcon
1416
15from unity.tests import UnityTestCase17from unity.tests import UnityTestCase
1618
@@ -18,6 +20,10 @@
18class SpreadTests(UnityTestCase):20class SpreadTests(UnityTestCase):
19 """Spread tests"""21 """Spread tests"""
2022
23 def setUp(self):
24 super(SpreadTests, self).setUp()
25 self.launcher = self.unity.launcher.get_launcher_for_monitor(self.display.get_primary_screen())
26
21 def start_test_application_windows(self, app_name, num_windows=2):27 def start_test_application_windows(self, app_name, num_windows=2):
22 """Start a given number of windows of the requested application"""28 """Start a given number of windows of the requested application"""
23 self.process_manager.close_all_app(app_name)29 self.process_manager.close_all_app(app_name)
@@ -44,10 +50,9 @@
44 """Initiate the Spread for windows of the given app"""50 """Initiate the Spread for windows of the given app"""
45 icon = self.unity.launcher.model.get_icon(desktop_id=desktop_id)51 icon = self.unity.launcher.model.get_icon(desktop_id=desktop_id)
46 self.assertThat(icon, NotEquals(None))52 self.assertThat(icon, NotEquals(None))
47 launcher = self.unity.launcher.get_launcher_for_monitor(self.display.get_primary_screen())
4853
49 self.addCleanup(self.unity.window_manager.terminate_spread)54 self.addCleanup(self.unity.window_manager.terminate_spread)
50 launcher.click_launcher_icon(icon)55 self.launcher.click_launcher_icon(icon, move_mouse_after=False)
51 self.assertThat(self.unity.window_manager.scale_active_for_group, Eventually(Equals(True)))56 self.assertThat(self.unity.window_manager.scale_active_for_group, Eventually(Equals(True)))
5257
53 def assertWindowIsNotScaled(self, window):58 def assertWindowIsNotScaled(self, window):
@@ -60,6 +65,17 @@
60 refresh_fn = lambda: xid in [w.x_id for w in self.process_manager.get_open_windows()]65 refresh_fn = lambda: xid in [w.x_id for w in self.process_manager.get_open_windows()]
61 self.assertThat(refresh_fn, Eventually(Equals(False)))66 self.assertThat(refresh_fn, Eventually(Equals(False)))
6267
68 def assertLauncherIconsSaturated(self):
69 for icon in self.unity.launcher.model.get_launcher_icons():
70 self.assertThat(icon.desaturated, Eventually(Equals(False)))
71
72 def assertLauncherIconsDesaturated(self, also_active=True):
73 for icon in self.unity.launcher.model.get_launcher_icons():
74 if isinstance(icon, BFBLauncherIcon) or (not also_active and icon.active):
75 self.assertThat(icon.desaturated, Eventually(Equals(False)))
76 else:
77 self.assertThat(icon.desaturated, Eventually(Equals(True)))
78
63 def test_scale_application_windows(self):79 def test_scale_application_windows(self):
64 """All the windows of an application must be scaled when application80 """All the windows of an application must be scaled when application
65 spread is initiated81 spread is initiated
@@ -120,3 +136,57 @@
120136
121 self.assertWindowIsNotScaled(target_win)137 self.assertWindowIsNotScaled(target_win)
122 self.assertWindowIsClosed(target_xid)138 self.assertWindowIsClosed(target_xid)
139
140 def test_spread_desaturate_launcher_icons(self):
141 """Test that the screen spread desaturates the launcher icons"""
142 self.start_test_application_windows("Calculator", 1)
143 self.initiate_spread_for_screen()
144 self.launcher.move_mouse_to_right_of_launcher()
145 self.assertLauncherIconsDesaturated()
146
147 def test_spread_saturate_launcher_icons_on_mouse_over(self):
148 """Test that the screen spread re-saturates the launcher icons on mouse over"""
149 win = self.start_test_application_windows("Calculator", 2)[0]
150 self.initiate_spread_for_application(win.application.desktop_file)
151 self.launcher.move_mouse_over_launcher()
152 self.assertLauncherIconsSaturated()
153
154 def test_app_spread_desaturate_inactive_launcher_icons(self):
155 """Test that the app spread desaturates the inactive launcher icons"""
156 win = self.start_test_application_windows("Calculator", 2)[0]
157 self.initiate_spread_for_application(win.application.desktop_file)
158 self.assertLauncherIconsDesaturated(also_active=False)
159
160 def test_app_spread_saturate_launcher_icons_on_mouse_move(self):
161 """Test that the app spread re-saturates the launcher icons on mouse move"""
162 win = self.start_test_application_windows("Calculator", 2)[0]
163 self.initiate_spread_for_application(win.application.desktop_file)
164 self.launcher.move_mouse_to_icon(self.unity.launcher.model.get_bfb_icon())
165 self.assertLauncherIconsSaturated()
166
167 def test_app_spread_saturate_launcher_icons_on_mouse_over(self):
168 """Test that the app spread re-saturates the launcher icons on mouse over"""
169 win = self.start_test_application_windows("Calculator", 2)[0]
170 self.initiate_spread_for_application(win.application.desktop_file)
171 self.launcher.move_mouse_over_launcher()
172 self.assertLauncherIconsSaturated()
173
174 def test_app_spread_desaturate_launcher_icons_switching_application(self):
175 """Test that the app spread desaturates the launcher icons on mouse over"""
176 cal_win = self.start_test_application_windows("Calculator", 2)[0]
177 char_win = self.start_test_application_windows("Character Map", 2)[0]
178 self.initiate_spread_for_application(char_win.application.desktop_file)
179 self.initiate_spread_for_application(cal_win.application.desktop_file)
180 self.assertLauncherIconsDesaturated(also_active=False)
181
182 def test_spread_hides_icon_tooltip(self):
183 """Tests that the screen spread hides the active tooltip."""
184 [win] = self.start_test_application_windows("Calculator", 1)
185 icon = self.unity.launcher.model.get_icon(desktop_id=win.application.desktop_file)
186 self.mouse.move(icon.center_x, icon.center_y)
187
188 self.assertThat(lambda: icon.get_tooltip(), Eventually(NotEquals(None)))
189 self.assertThat(icon.get_tooltip().active, Eventually(Equals(True)))
190
191 self.initiate_spread_for_screen()
192 self.assertThat(icon.get_tooltip().active, Eventually(Equals(False)))
123\ No newline at end of file193\ No newline at end of file
124194
=== modified file 'tests/mock-base-window.h'
--- tests/mock-base-window.h 2013-02-07 16:55:11 +0000
+++ tests/mock-base-window.h 2013-10-21 23:51:09 +0000
@@ -16,6 +16,7 @@
16#ifndef TESTS_MOCK_BASEWINDOW_H16#ifndef TESTS_MOCK_BASEWINDOW_H
17#define TESTS_MOCK_BASEWINDOW_H17#define TESTS_MOCK_BASEWINDOW_H
1818
19#include <gmock/gmock.h>
19#include "ResizingBaseWindow.h"20#include "ResizingBaseWindow.h"
2021
21namespace unity22namespace unity
@@ -23,25 +24,26 @@
23namespace testmocks24namespace testmocks
24{25{
2526
27using namespace testing;
28
26class MockBaseWindow : public ResizingBaseWindow29class MockBaseWindow : public ResizingBaseWindow
27{30{
28public:31public:
29 typedef nux::ObjectPtr<MockBaseWindow> Ptr;32 typedef nux::ObjectPtr<MockBaseWindow> Ptr;
33 typedef NiceMock<MockBaseWindow> Nice;
3034
31 MockBaseWindow(ResizingBaseWindow::GeometryAdjuster const& input_adjustment, const char *name = "Mock")35 MockBaseWindow(ResizingBaseWindow::GeometryAdjuster const& input_adjustment, const char *name = "Mock")
32 : ResizingBaseWindow(name, input_adjustment)36 : ResizingBaseWindow(name, input_adjustment)
33 {}37 {
38 ON_CALL(*this, SetOpacity(_)).WillByDefault(Invoke([this] (float o) { ResizingBaseWindow::SetOpacity(o); }));
39 }
3440
35 MockBaseWindow(const char *name = "Mock")41 MockBaseWindow(const char *name = "Mock")
36 : ResizingBaseWindow(name, [](nux::Geometry const& geo) { return geo; })42 : MockBaseWindow([](nux::Geometry const& geo) { return geo; }, name)
37 {}43 {}
3844
39 MOCK_METHOD2(ShowWindow, void(bool, bool));45 MOCK_METHOD2(ShowWindow, void(bool, bool));
40 MOCK_METHOD1(SetOpacity, void(float));46 MOCK_METHOD1(SetOpacity, void(float));
41
42 // Really invoke the SetOpacity member function, a callthrough for use with
43 // ::testing::Invoke().
44 void RealSetOpacity(float opacity) { ResizingBaseWindow::SetOpacity(opacity); }
45};47};
4648
47} // namespace testmocks49} // namespace testmocks
4850
=== modified file 'tests/test_dash_controller.cpp'
--- tests/test_dash_controller.cpp 2013-02-07 16:56:07 +0000
+++ tests/test_dash_controller.cpp 2013-10-21 23:51:09 +0000
@@ -21,6 +21,7 @@
21#include "unity-shared/DashStyle.h"21#include "unity-shared/DashStyle.h"
22#include "unity-shared/PanelStyle.h"22#include "unity-shared/PanelStyle.h"
23#include "unity-shared/UnitySettings.h"23#include "unity-shared/UnitySettings.h"
24#include "unity-shared/WindowManager.h"
24#include "test_utils.h"25#include "test_utils.h"
2526
26#include <NuxCore/AnimationController.h>27#include <NuxCore/AnimationController.h>
@@ -32,42 +33,32 @@
32namespace33namespace
33{34{
3435
35class TestDashController : public Test36struct TestDashController : Test
36{37{
37public:
38 TestDashController()38 TestDashController()
39 : animation_controller(tick_source)39 : animation_controller(tick_source)
40 , base_window_(new NiceMock<testmocks::MockBaseWindow>())40 , base_window_(new testmocks::MockBaseWindow::Nice())
41 { }41 , controller_(std::make_shared<dash::Controller>([this] { return base_window_.GetPointer(); }))
4242 {}
43 virtual void SetUp()
44 {
45 ON_CALL(*base_window_, SetOpacity(_))
46 .WillByDefault(Invoke(base_window_.GetPointer(),
47 &testmocks::MockBaseWindow::RealSetOpacity));
48
49 // Set expectations for creating the controller
50 EXPECT_CALL(*base_window_, SetOpacity(0.0f))
51 .WillOnce(Invoke(base_window_.GetPointer(),
52 &testmocks::MockBaseWindow::RealSetOpacity));
53
54 controller_.reset(new dash::Controller([&](){ return base_window_.GetPointer();}));
55 Mock::VerifyAndClearExpectations(base_window_.GetPointer());
56 }
5743
58protected:44protected:
59 nux::animation::TickSource tick_source;45 nux::animation::TickSource tick_source;
60 nux::animation::AnimationController animation_controller;46 nux::animation::AnimationController animation_controller;
6147
62 dash::Controller::Ptr controller_;
63 testmocks::MockBaseWindow::Ptr base_window_;
64
65 // required to create hidden secret global variables48 // required to create hidden secret global variables
66 Settings unity_settings_;49 Settings unity_settings_;
67 dash::Style dash_style_;50 dash::Style dash_style_;
68 panel::Style panel_style_;51 panel::Style panel_style_;
52
53 testmocks::MockBaseWindow::Ptr base_window_;
54 dash::Controller::Ptr controller_;
69};55};
7056
57TEST_F(TestDashController, Construction)
58{
59 EXPECT_CALL(*base_window_, SetOpacity(0.0f));
60 controller_ = std::make_shared<dash::Controller>([this] { return base_window_.GetPointer(); });
61}
7162
72TEST_F(TestDashController, TestShowAndHideDash)63TEST_F(TestDashController, TestShowAndHideDash)
73{64{
@@ -100,5 +91,13 @@
100 EXPECT_EQ(base_window_->GetOpacity(), 0.0);91 EXPECT_EQ(base_window_->GetOpacity(), 0.0);
101}92}
10293
94TEST_F(TestDashController, DisconnectWMSignalsOnDestruction)
95{
96 auto& signal = WindowManager::Default().initiate_spread;
97 size_t before = signal.size();
98 { auto controller = std::make_shared<dash::Controller>([this] { return base_window_.GetPointer(); }); }
99 ASSERT_EQ(before, signal.size());
100 signal.emit();
103}101}
104102
103}
105104
=== modified file 'tests/test_hud_controller.cpp'
--- tests/test_hud_controller.cpp 2013-02-19 15:07:36 +0000
+++ tests/test_hud_controller.cpp 2013-10-21 23:51:09 +0000
@@ -28,6 +28,7 @@
28#include "unity-shared/DashStyle.h"28#include "unity-shared/DashStyle.h"
29#include "unity-shared/PanelStyle.h"29#include "unity-shared/PanelStyle.h"
30#include "unity-shared/UnitySettings.h"30#include "unity-shared/UnitySettings.h"
31#include "unity-shared/WindowManager.h"
31#include "test_utils.h"32#include "test_utils.h"
32using namespace unity;33using namespace unity;
3334
@@ -62,35 +63,32 @@
62};63};
6364
6465
65class TestHudController : public Test66struct TestHudController : Test
66{67{
67public:
68 TestHudController()68 TestHudController()
69 : view_(new NiceMock<MockHudView>)69 : view_(new NiceMock<MockHudView>)
70 , base_window_(new NiceMock<testmocks::MockBaseWindow>())70 , base_window_(new testmocks::MockBaseWindow::Nice())
71 {71 , controller_(std::make_shared<hud::Controller>([this] { return view_.GetPointer(); },
72 ON_CALL(*base_window_, SetOpacity(_))72 [this] { return base_window_.GetPointer(); }))
73 .WillByDefault(Invoke(base_window_.GetPointer(),73 {}
74 &testmocks::MockBaseWindow::RealSetOpacity));
75
76 // Set expectations for creating the controller
77 EXPECT_CALL(*base_window_, SetOpacity(0.0f));
78
79 controller_.reset(new hud::Controller([&](){ return view_.GetPointer(); },
80 [&](){ return base_window_.GetPointer();}));
81 }
8274
83protected:75protected:
84 hud::Controller::Ptr controller_;
85 MockHudView::Ptr view_;
86 testmocks::MockBaseWindow::Ptr base_window_;
87
88 // required to create hidden secret global variables76 // required to create hidden secret global variables
89 Settings unity_settings_;77 Settings unity_settings_;
90 dash::Style dash_style_;78 dash::Style dash_style_;
91 panel::Style panel_style_;79 panel::Style panel_style_;
80
81 MockHudView::Ptr view_;
82 testmocks::MockBaseWindow::Ptr base_window_;
83 hud::Controller::Ptr controller_;
92};84};
9385
86TEST_F(TestHudController, Construction)
87{
88 EXPECT_CALL(*base_window_, SetOpacity(0.0f));
89 controller_ = std::make_shared<hud::Controller>([this] { return view_.GetPointer(); },
90 [this] { return base_window_.GetPointer(); });
91}
9492
95TEST_F(TestHudController, TestShowAndHideHud)93TEST_F(TestHudController, TestShowAndHideHud)
96{94{
@@ -141,4 +139,16 @@
141 EXPECT_EQ(base_window_->GetOpacity(), 0.0);139 EXPECT_EQ(base_window_->GetOpacity(), 0.0);
142}140}
143141
142TEST_F(TestHudController, DisconnectWMSignalsOnDestruction)
143{
144 auto& signal = WindowManager::Default().initiate_spread;
145 size_t before = signal.size();
146 {
147 auto controller = std::make_shared<hud::Controller>([this] { return view_.GetPointer(); },
148 [this] { return base_window_.GetPointer(); });
149 }
150 ASSERT_EQ(before, signal.size());
151 signal.emit();
152}
153
144}154}
145155
=== modified file 'tests/test_launcher.cpp'
--- tests/test_launcher.cpp 2013-10-04 00:19:56 +0000
+++ tests/test_launcher.cpp 2013-10-21 23:51:09 +0000
@@ -31,6 +31,7 @@
31#include "unity-shared/PanelStyle.h"31#include "unity-shared/PanelStyle.h"
32#include "unity-shared/UnitySettings.h"32#include "unity-shared/UnitySettings.h"
33#include "unity-shared/IconRenderer.h"33#include "unity-shared/IconRenderer.h"
34#include "StandaloneWindowManager.h"
34#include "test_utils.h"35#include "test_utils.h"
3536
36namespace unity37namespace unity
@@ -46,6 +47,7 @@
46{47{
47public:48public:
48 typedef nux::ObjectPtr<MockMockLauncherIcon> Ptr;49 typedef nux::ObjectPtr<MockMockLauncherIcon> Ptr;
50 typedef testing::NiceMock<MockMockLauncherIcon> Nice;
49 MockMockLauncherIcon(IconType type = IconType::APPLICATION)51 MockMockLauncherIcon(IconType type = IconType::APPLICATION)
50 : MockLauncherIcon(type)52 : MockLauncherIcon(type)
51 {}53 {}
@@ -53,6 +55,7 @@
53 MOCK_METHOD1(ShouldHighlightOnDrag, bool(DndData const&));55 MOCK_METHOD1(ShouldHighlightOnDrag, bool(DndData const&));
54 MOCK_METHOD1(Stick, void(bool));56 MOCK_METHOD1(Stick, void(bool));
55 MOCK_METHOD2(PerformScroll, void(ScrollDirection, Time));57 MOCK_METHOD2(PerformScroll, void(ScrollDirection, Time));
58 MOCK_METHOD0(HideTooltip, void());
56};59};
5760
58}61}
@@ -115,6 +118,7 @@
115 using Launcher::SetHidden;118 using Launcher::SetHidden;
116 using Launcher::HandleUrgentIcon;119 using Launcher::HandleUrgentIcon;
117 using Launcher::SetUrgentTimer;120 using Launcher::SetUrgentTimer;
121 using Launcher::SetIconUnderMouse;
118 using Launcher::urgent_timer_running_;122 using Launcher::urgent_timer_running_;
119 using Launcher::urgent_finished_time_;123 using Launcher::urgent_finished_time_;
120 using Launcher::urgent_wiggle_time_;124 using Launcher::urgent_wiggle_time_;
@@ -140,7 +144,8 @@
140 };144 };
141145
142 TestLauncher()146 TestLauncher()
143 : parent_window_(new MockableBaseWindow("TestLauncherWindow"))147 : WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
148 , parent_window_(new MockableBaseWindow("TestLauncherWindow"))
144 , model_(new LauncherModel)149 , model_(new LauncherModel)
145 , options_(new Options)150 , options_(new Options)
146 , launcher_(new MockLauncher(parent_window_.GetPointer()))151 , launcher_(new MockLauncher(parent_window_.GetPointer()))
@@ -149,6 +154,15 @@
149 launcher_->SetModel(model_);154 launcher_->SetModel(model_);
150 }155 }
151156
157 ~TestLauncher()
158 {
159 WM->SetScaleActiveForGroup(false);
160 WM->SetScaleActive(false);
161
162 if (WM->IsExpoActive())
163 WM->TerminateExpo();
164 }
165
152 std::vector<MockMockLauncherIcon::Ptr> AddMockIcons(unsigned number)166 std::vector<MockMockLauncherIcon::Ptr> AddMockIcons(unsigned number)
153 {167 {
154 std::vector<MockMockLauncherIcon::Ptr> icons;168 std::vector<MockMockLauncherIcon::Ptr> icons;
@@ -159,7 +173,7 @@
159173
160 for (unsigned i = 0; i < number; ++i)174 for (unsigned i = 0; i < number; ++i)
161 {175 {
162 MockMockLauncherIcon::Ptr icon(new MockMockLauncherIcon);176 MockMockLauncherIcon::Ptr icon(new MockMockLauncherIcon::Nice);
163 icon->SetCenter(nux::Point3(launcher_geo.x + icon_size/2.0f, launcher_geo.y + icon_size/2.0f * (i+1) + 1, 0), monitor);177 icon->SetCenter(nux::Point3(launcher_geo.x + icon_size/2.0f, launcher_geo.y + icon_size/2.0f * (i+1) + 1, 0), monitor);
164178
165 icons.push_back(icon);179 icons.push_back(icon);
@@ -173,6 +187,7 @@
173 }187 }
174188
175 MockUScreen uscreen;189 MockUScreen uscreen;
190 StandaloneWindowManager* WM;
176 nux::ObjectPtr<MockableBaseWindow> parent_window_;191 nux::ObjectPtr<MockableBaseWindow> parent_window_;
177 Settings settings;192 Settings settings;
178 panel::Style panel_style;193 panel::Style panel_style;
@@ -688,9 +703,180 @@
688 launcher_->HandleUrgentIcon(icon, current);703 launcher_->HandleUrgentIcon(icon, current);
689704
690 EXPECT_THAT(launcher_->urgent_finished_time_.tv_sec, Gt(0));705 EXPECT_THAT(launcher_->urgent_finished_time_.tv_sec, Gt(0));
691 EXPECT_THAT(launcher_->urgent_finished_time_.tv_nsec, Gt(0)); 706 EXPECT_THAT(launcher_->urgent_finished_time_.tv_nsec, Gt(0));
692} 707}
693708
694}709TEST_F(TestLauncher, DesaturateAllIconsOnSpread)
695}710{
696711 auto const& icons = AddMockIcons(5);
712 icons[g_random_int()%icons.size()]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
713
714 WM->SetScaleActiveForGroup(false);
715 WM->SetScaleActive(true);
716 WM->initiate_spread.emit();
717
718 Utils::WaitUntilMSec([&icons] {
719 for (auto const& icon : icons)
720 {
721 if (!icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT))
722 return false;
723 }
724 return true;
725 });
726
727 for (auto const& icon : icons)
728 ASSERT_TRUE(icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
729}
730
731TEST_F(TestLauncher, SaturateAllIconsOnSpreadTerminated)
732{
733 auto const& icons = AddMockIcons(5);
734 icons[g_random_int()%icons.size()]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
735
736 for (auto const& icon : icons)
737 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, true);
738
739 WM->SetScaleActiveForGroup(false);
740 WM->SetScaleActive(false);
741 WM->terminate_spread.emit();
742
743 for (auto const& icon : icons)
744 ASSERT_FALSE(icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
745}
746
747TEST_F(TestLauncher, SaturatesAllIconsOnSpreadWithMouseOver)
748{
749 auto const& icons = AddMockIcons(5);
750 icons[g_random_int()%icons.size()]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
751
752 for (auto const& icon : icons)
753 icon->SetQuirk(AbstractLauncherIcon::Quirk::DESAT, true);
754
755 launcher_->SetHover(true);
756 WM->SetScaleActiveForGroup(false);
757 WM->SetScaleActive(true);
758 WM->initiate_spread.emit();
759
760 Utils::WaitPendingEvents();
761
762 for (auto const& icon : icons)
763 ASSERT_FALSE(icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
764}
765
766TEST_F(TestLauncher, DesaturateInactiveIconsOnAppSpread)
767{
768 auto const& icons = AddMockIcons(5);
769 icons[g_random_int()%icons.size()]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
770
771 WM->SetScaleActiveForGroup(true);
772 WM->SetScaleActive(true);
773 WM->initiate_spread.emit();
774
775 Utils::WaitUntilMSec([&icons] {
776 for (auto const& icon : icons)
777 {
778 if (icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE) == icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT))
779 return false;
780 }
781 return true;
782 });
783
784 for (auto const& icon : icons)
785 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
786}
787
788TEST_F(TestLauncher, SaturatesAllIconsOnAppSpreadMouseMove)
789{
790 auto const& icons = AddMockIcons(5);
791 unsigned active_idx = g_random_int()%icons.size();
792 icons[active_idx]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
793
794 launcher_->SetHover(true);
795 WM->SetScaleActiveForGroup(true);
796 WM->SetScaleActive(true);
797 WM->initiate_spread.emit();
798
799 Utils::WaitUntilMSec([&icons] {
800 for (auto const& icon : icons)
801 {
802 if (icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE) == icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT))
803 return false;
804 }
805 return true;
806 });
807
808 for (auto const& icon : icons)
809 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
810
811 auto const& active_center = icons[active_idx]->GetCenter(launcher_->monitor());
812 launcher_->mouse_move.emit(active_center.x, active_center.y, 0, 0, 0, 0);
813
814 for (auto const& icon : icons)
815 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
816
817 auto const& other_center = icons[(active_idx+1)%icons.size()]->GetCenter(launcher_->monitor());
818 launcher_->mouse_move.emit(other_center.x, other_center.y, 0, 0, 0, 0);
819
820 for (auto const& icon : icons)
821 ASSERT_FALSE(icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
822
823 launcher_->SetHover(false);
824 for (auto const& icon : icons)
825 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
826
827 launcher_->SetHover(true);
828 for (auto const& icon : icons)
829 ASSERT_FALSE(icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
830}
831
832TEST_F(TestLauncher, DesaturateActiveIconOnAppSpreadIconUpdate)
833{
834 auto const& icons = AddMockIcons(5);
835 unsigned active_idx = g_random_int()%icons.size();
836 icons[active_idx]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
837
838 launcher_->SetHover(true);
839 WM->SetScaleActiveForGroup(true);
840 WM->SetScaleActive(true);
841 WM->initiate_spread.emit();
842
843 Utils::WaitPendingEvents();
844 for (auto const& icon : icons)
845 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
846
847 unsigned new_active_idx = (active_idx+1)%icons.size();
848 icons[active_idx]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, false);
849 icons[new_active_idx]->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
850
851 WM->terminate_spread.emit();
852 WM->initiate_spread.emit();
853
854 Utils::WaitPendingEvents();
855 for (auto const& icon : icons)
856 ASSERT_NE(icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE), icon->GetQuirk(AbstractLauncherIcon::Quirk::DESAT));
857}
858
859TEST_F(TestLauncher, HideTooltipOnSpread)
860{
861 auto icon = AddMockIcons(1).front();
862 EXPECT_CALL(*icon, HideTooltip());
863
864 launcher_->SetIconUnderMouse(icon);
865 WM->SetScaleActive(true);
866 WM->initiate_spread.emit();
867}
868
869TEST_F(TestLauncher, HideTooltipOnExpo)
870{
871 auto icon = AddMockIcons(1).front();
872 EXPECT_CALL(*icon, HideTooltip());
873
874 if (!WM->IsExpoActive())
875 WM->InitiateExpo();
876
877 launcher_->SetIconUnderMouse(icon);
878 WM->initiate_expo.emit();
879}
880
881} // namespace launcher
882} // namespace unity
697883
=== modified file 'tests/test_switcher_controller_class.cpp'
--- tests/test_switcher_controller_class.cpp 2013-06-26 17:10:45 +0000
+++ tests/test_switcher_controller_class.cpp 2013-10-21 23:51:09 +0000
@@ -78,13 +78,8 @@
78 : WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))78 : WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
79 , animation_controller_(tick_source_)79 , animation_controller_(tick_source_)
80 , mock_window_(new NiceMock<testmocks::MockBaseWindow>())80 , mock_window_(new NiceMock<testmocks::MockBaseWindow>())
81 , controller_(std::make_shared<Controller>([this] { return mock_window_; }))
81{82{
82 ON_CALL(*mock_window_, SetOpacity(_))
83 .WillByDefault(Invoke(mock_window_.GetPointer(),
84 &testmocks::MockBaseWindow::RealSetOpacity));
85
86 auto create_window = [this] { return mock_window_; };
87 controller_.reset(new Controller(create_window));
88 controller_->timeout_length = 0;83 controller_->timeout_length = 0;
8984
90 icons_.push_back(launcher::AbstractLauncherIcon::Ptr(new launcher::DesktopLauncherIcon()));85 icons_.push_back(launcher::AbstractLauncherIcon::Ptr(new launcher::DesktopLauncherIcon()));