Merge lp:~xavi-garcia-mena/indicator-sound/next-play-prev-buttons-bug-1373313 into lp:indicator-sound/15.10
- next-play-prev-buttons-bug-1373313
- Merge into trunk.15.10
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Charles Kerr | ||||||||
Approved revision: | 506 | ||||||||
Merged at revision: | 506 | ||||||||
Proposed branch: | lp:~xavi-garcia-mena/indicator-sound/next-play-prev-buttons-bug-1373313 | ||||||||
Merge into: | lp:indicator-sound/15.10 | ||||||||
Diff against target: |
538 lines (+275/-91) 7 files modified
debian/changelog (+24/-6) src/media-player-mpris.vala (+22/-0) src/media-player.vala (+4/-0) src/mpris2-interfaces.vala (+4/-1) src/sound-menu.vala (+61/-6) tests/media-player-mock.vala (+6/-0) tests/sound-menu.cc (+154/-78) |
||||||||
To merge this branch: | bzr merge lp:~xavi-garcia-mena/indicator-sound/next-play-prev-buttons-bug-1373313 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Charles Kerr (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+271114@code.launchpad.net |
Commit message
Synchronize the state of the Previous/Play/Next buttons with the state obtained from MPRIS.
The state is updated every time the properties are modified.
Description of the change
Synchronize the state of the Previous/Play/Next buttons with the state obtained from MPRIS.
The state is updated every time the properties are modified.
PS Jenkins bot (ps-jenkins) wrote : | # |
Charles Kerr (charlesk) wrote : | # |
Mostly looks good. A couple of questions inline below.
- 505. By Xavi Garcia
-
Unit tests refactored
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:505
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 506. By Xavi Garcia
-
merged with trunk
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:506
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Charles Kerr (charlesk) wrote : | # |
Thanks for the test changes, Xavi. LGTM.
- 507. By Xavi Garcia
-
Fixed property name when checking if CanGoPrevious changed
- 508. By Xavi Garcia
-
Fixed version in changelog
- 509. By Xavi Garcia
-
Updating MPRIS control in the menu not only when next and previous are updated
Preview Diff
1 | === modified file 'debian/changelog' | |||
2 | --- debian/changelog 2015-09-15 08:19:51 +0000 | |||
3 | +++ debian/changelog 2015-10-14 14:58:07 +0000 | |||
4 | @@ -1,4 +1,11 @@ | |||
6 | 1 | indicator-sound (12.10.2+15.10.20150915-0ubuntu1) wily; urgency=medium | 1 | indicator-sound (12.10.2+15.04.20150917-0ubuntu1) vivid; urgency=medium |
7 | 2 | |||
8 | 3 | [ Xavi Garcia Mena ] | ||
9 | 4 | * Merged lp:~xavi-garcia-mena/indicator-sound/icon-volume-zero | ||
10 | 5 | |||
11 | 6 | -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +0000 | ||
12 | 7 | |||
13 | 8 | indicator-sound (12.10.2+15.04.20150915-0ubuntu1) vivid; urgency=medium | ||
14 | 2 | 9 | ||
15 | 3 | [ Sebastien Bacher ] | 10 | [ Sebastien Bacher ] |
16 | 4 | * under unity8 start system-settings instead unity-control-center (LP: | 11 | * under unity8 start system-settings instead unity-control-center (LP: |
17 | @@ -9,7 +16,7 @@ | |||
18 | 9 | 16 | ||
19 | 10 | -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +0000 | 17 | -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +0000 |
20 | 11 | 18 | ||
22 | 12 | indicator-sound (12.10.2+15.10.20150812.3-0ubuntu1) wily; urgency=medium | 19 | indicator-sound (12.10.2+15.04.20150812.3-0ubuntu1) vivid; urgency=medium |
23 | 13 | 20 | ||
24 | 14 | [ CI Train Bot ] | 21 | [ CI Train Bot ] |
25 | 15 | * New rebuild forced. | 22 | * New rebuild forced. |
26 | @@ -20,7 +27,7 @@ | |||
27 | 20 | 27 | ||
28 | 21 | -- CI Train Bot <ci-train-bot@canonical.com> Wed, 12 Aug 2015 20:55:05 +0000 | 28 | -- CI Train Bot <ci-train-bot@canonical.com> Wed, 12 Aug 2015 20:55:05 +0000 |
29 | 22 | 29 | ||
31 | 23 | indicator-sound (12.10.2+15.10.20150807.6-0ubuntu1) wily; urgency=medium | 30 | indicator-sound (12.10.2+15.04.20150807.6-0ubuntu1) vivid; urgency=medium |
32 | 24 | 31 | ||
33 | 25 | [ CI Train Bot ] | 32 | [ CI Train Bot ] |
34 | 26 | * New rebuild forced. | 33 | * New rebuild forced. |
35 | @@ -31,19 +38,19 @@ | |||
36 | 31 | 38 | ||
37 | 32 | -- CI Train Bot <ci-train-bot@canonical.com> Fri, 07 Aug 2015 22:35:58 +0000 | 39 | -- CI Train Bot <ci-train-bot@canonical.com> Fri, 07 Aug 2015 22:35:58 +0000 |
38 | 33 | 40 | ||
40 | 34 | indicator-sound (12.10.2+15.10.20150605-0ubuntu1) wily; urgency=medium | 41 | indicator-sound (12.10.2+15.04.20150605-0ubuntu1) vivid; urgency=medium |
41 | 35 | 42 | ||
42 | 36 | * | 43 | * |
43 | 37 | 44 | ||
44 | 38 | -- CI Train Bot <ci-train-bot@canonical.com> Fri, 05 Jun 2015 19:50:06 +0000 | 45 | -- CI Train Bot <ci-train-bot@canonical.com> Fri, 05 Jun 2015 19:50:06 +0000 |
45 | 39 | 46 | ||
47 | 40 | indicator-sound (12.10.2+15.10.20150507+eventually4-0ubuntu1) wily; urgency=medium | 47 | indicator-sound (12.10.2+15.04.20150507+eventually4-0ubuntu1) vivid; urgency=medium |
48 | 41 | 48 | ||
49 | 42 | * Using eventually to avoid arbitrary timeouts in tests | 49 | * Using eventually to avoid arbitrary timeouts in tests |
50 | 43 | 50 | ||
51 | 44 | -- Ted Gould <ted@ubuntu.com> Wed, 27 May 2015 11:11:19 -0500 | 51 | -- Ted Gould <ted@ubuntu.com> Wed, 27 May 2015 11:11:19 -0500 |
52 | 45 | 52 | ||
54 | 46 | indicator-sound (12.10.2+15.10.20150507-0ubuntu1) wily; urgency=medium | 53 | indicator-sound (12.10.2+15.04.20150507-0ubuntu1) vivid; urgency=medium |
55 | 47 | 54 | ||
56 | 48 | [ Charles Kerr ] | 55 | [ Charles Kerr ] |
57 | 49 | * Use the BusWatcher to look for org.freedesktop.Notifications | 56 | * Use the BusWatcher to look for org.freedesktop.Notifications |
58 | @@ -51,6 +58,17 @@ | |||
59 | 51 | 58 | ||
60 | 52 | -- CI Train Bot <ci-train-bot@canonical.com> Thu, 07 May 2015 15:27:00 +0000 | 59 | -- CI Train Bot <ci-train-bot@canonical.com> Thu, 07 May 2015 15:27:00 +0000 |
61 | 53 | 60 | ||
62 | 61 | indicator-sound (12.10.2+15.04.20150508-0ubuntu1) vivid; urgency=medium | ||
63 | 62 | |||
64 | 63 | [ CI Train Bot ] | ||
65 | 64 | * New rebuild forced. | ||
66 | 65 | |||
67 | 66 | [ Charles Kerr ] | ||
68 | 67 | * Use the BusWatcher to look for org.freedesktop.Notifications | ||
69 | 68 | ownership changes on the bus. (LP: #1432446) | ||
70 | 69 | |||
71 | 70 | -- CI Train Bot <ci-train-bot@canonical.com> Fri, 08 May 2015 12:20:07 +0000 | ||
72 | 71 | |||
73 | 54 | indicator-sound (12.10.2+15.04.20150421-0ubuntu1) vivid; urgency=medium | 72 | indicator-sound (12.10.2+15.04.20150421-0ubuntu1) vivid; urgency=medium |
74 | 55 | 73 | ||
75 | 56 | [ Ted Gould ] | 74 | [ Ted Gould ] |
76 | 57 | 75 | ||
77 | === modified file 'src/media-player-mpris.vala' | |||
78 | --- src/media-player-mpris.vala 2015-03-26 15:56:49 +0000 | |||
79 | +++ src/media-player-mpris.vala 2015-10-14 14:58:07 +0000 | |||
80 | @@ -79,6 +79,24 @@ | |||
81 | 79 | } | 79 | } |
82 | 80 | } | 80 | } |
83 | 81 | 81 | ||
84 | 82 | public override bool can_do_play { | ||
85 | 83 | get { | ||
86 | 84 | return this.proxy.CanPlay; | ||
87 | 85 | } | ||
88 | 86 | } | ||
89 | 87 | |||
90 | 88 | public override bool can_do_prev { | ||
91 | 89 | get { | ||
92 | 90 | return this.proxy.CanGoPrevious; | ||
93 | 91 | } | ||
94 | 92 | } | ||
95 | 93 | |||
96 | 94 | public override bool can_do_next { | ||
97 | 95 | get { | ||
98 | 96 | return this.proxy.CanGoNext; | ||
99 | 97 | } | ||
100 | 98 | } | ||
101 | 99 | |||
102 | 82 | /** | 100 | /** |
103 | 83 | * Attach this object to a process of the associated media player. The player must own @dbus_name and | 101 | * Attach this object to a process of the associated media player. The player must own @dbus_name and |
104 | 84 | * implement the org.mpris.MediaPlayer2.Player interface. | 102 | * implement the org.mpris.MediaPlayer2.Player interface. |
105 | @@ -272,6 +290,10 @@ | |||
106 | 272 | if (changed_properties.lookup ("PlaybackStatus", "s", null)) { | 290 | if (changed_properties.lookup ("PlaybackStatus", "s", null)) { |
107 | 273 | this.state = this.proxy.PlaybackStatus != null ? this.proxy.PlaybackStatus : "Unknown"; | 291 | this.state = this.proxy.PlaybackStatus != null ? this.proxy.PlaybackStatus : "Unknown"; |
108 | 274 | } | 292 | } |
109 | 293 | if (changed_properties.lookup ("CanGoNext", "b", null) || changed_properties.lookup ("CanGoPrevious", "b", null) || | ||
110 | 294 | changed_properties.lookup ("CanPlay", "b", null) || changed_properties.lookup ("CanPause", "b", null)) { | ||
111 | 295 | this.playbackstatus_changed (); | ||
112 | 296 | } | ||
113 | 275 | 297 | ||
114 | 276 | var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}")); | 298 | var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}")); |
115 | 277 | if (metadata != null) | 299 | if (metadata != null) |
116 | 278 | 300 | ||
117 | === modified file 'src/media-player.vala' | |||
118 | --- src/media-player.vala 2014-02-12 16:21:32 +0000 | |||
119 | +++ src/media-player.vala 2015-10-14 14:58:07 +0000 | |||
120 | @@ -26,6 +26,9 @@ | |||
121 | 26 | 26 | ||
122 | 27 | public virtual bool is_running { get { not_implemented(); return false; } } | 27 | public virtual bool is_running { get { not_implemented(); return false; } } |
123 | 28 | public virtual bool can_raise { get { not_implemented(); return false; } } | 28 | public virtual bool can_raise { get { not_implemented(); return false; } } |
124 | 29 | public virtual bool can_do_next { get { not_implemented(); return false; } } | ||
125 | 30 | public virtual bool can_do_prev { get { not_implemented(); return false; } } | ||
126 | 31 | public virtual bool can_do_play { get { not_implemented(); return false; } } | ||
127 | 29 | 32 | ||
128 | 30 | public class Track : Object { | 33 | public class Track : Object { |
129 | 31 | public string artist { get; construct; } | 34 | public string artist { get; construct; } |
130 | @@ -44,6 +47,7 @@ | |||
131 | 44 | } | 47 | } |
132 | 45 | 48 | ||
133 | 46 | public signal void playlists_changed (); | 49 | public signal void playlists_changed (); |
134 | 50 | public signal void playbackstatus_changed (); | ||
135 | 47 | 51 | ||
136 | 48 | public abstract void activate (); | 52 | public abstract void activate (); |
137 | 49 | public abstract void play_pause (); | 53 | public abstract void play_pause (); |
138 | 50 | 54 | ||
139 | === modified file 'src/mpris2-interfaces.vala' | |||
140 | --- src/mpris2-interfaces.vala 2015-03-26 15:56:49 +0000 | |||
141 | +++ src/mpris2-interfaces.vala 2015-10-14 14:58:07 +0000 | |||
142 | @@ -37,7 +37,10 @@ | |||
143 | 37 | // properties | 37 | // properties |
144 | 38 | public abstract HashTable<string, Variant?> Metadata{owned get; set;} | 38 | public abstract HashTable<string, Variant?> Metadata{owned get; set;} |
145 | 39 | public abstract int32 Position{owned get; set;} | 39 | public abstract int32 Position{owned get; set;} |
147 | 40 | public abstract string? PlaybackStatus{owned get; set;} | 40 | public abstract string? PlaybackStatus{owned get; set;} |
148 | 41 | public abstract bool CanPlay{owned get; set;} | ||
149 | 42 | public abstract bool CanGoNext{owned get; set;} | ||
150 | 43 | public abstract bool CanGoPrevious{owned get; set;} | ||
151 | 41 | // methods | 44 | // methods |
152 | 42 | public abstract async void PlayPause() throws IOError; | 45 | public abstract async void PlayPause() throws IOError; |
153 | 43 | public abstract async void Next() throws IOError; | 46 | public abstract async void Next() throws IOError; |
154 | 44 | 47 | ||
155 | === modified file 'src/sound-menu.vala' | |||
156 | --- src/sound-menu.vala 2015-02-12 00:44:34 +0000 | |||
157 | +++ src/sound-menu.vala 2015-10-14 14:58:07 +0000 | |||
158 | @@ -157,18 +157,26 @@ | |||
159 | 157 | this.update_playlists (player); | 157 | this.update_playlists (player); |
160 | 158 | 158 | ||
161 | 159 | var handler_id = player.notify["is-running"].connect ( () => { | 159 | var handler_id = player.notify["is-running"].connect ( () => { |
164 | 160 | if (player.is_running) | 160 | if (player.is_running) { |
165 | 161 | if (this.find_player_section(player) == -1) | 161 | int index = this.find_player_section(player); |
166 | 162 | if (index == -1) { | ||
167 | 162 | this.insert_player_section (player); | 163 | this.insert_player_section (player); |
169 | 163 | else | 164 | } |
170 | 165 | else { | ||
171 | 166 | update_player_section (player, index); | ||
172 | 167 | } | ||
173 | 168 | } | ||
174 | 169 | else { | ||
175 | 164 | if (this.hide_inactive) | 170 | if (this.hide_inactive) |
176 | 165 | this.remove_player_section (player); | 171 | this.remove_player_section (player); |
177 | 172 | } | ||
178 | 166 | 173 | ||
179 | 167 | this.update_playlists (player); | 174 | this.update_playlists (player); |
180 | 168 | }); | 175 | }); |
181 | 169 | this.notify_handlers.insert (player, handler_id); | 176 | this.notify_handlers.insert (player, handler_id); |
182 | 170 | 177 | ||
183 | 171 | player.playlists_changed.connect (this.update_playlists); | 178 | player.playlists_changed.connect (this.update_playlists); |
184 | 179 | player.playbackstatus_changed.connect (this.update_playbackstatus); | ||
185 | 172 | } | 180 | } |
186 | 173 | 181 | ||
187 | 174 | public void remove_player (MediaPlayer player) { | 182 | public void remove_player (MediaPlayer player) { |
188 | @@ -215,6 +223,23 @@ | |||
189 | 215 | return -1; | 223 | return -1; |
190 | 216 | } | 224 | } |
191 | 217 | 225 | ||
192 | 226 | MenuItem create_playback_menu_item (MediaPlayer player) { | ||
193 | 227 | var playback_item = new MenuItem (null, null); | ||
194 | 228 | playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); | ||
195 | 229 | if (player.is_running) { | ||
196 | 230 | if (player.can_do_play) { | ||
197 | 231 | playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); | ||
198 | 232 | } | ||
199 | 233 | if (player.can_do_next) { | ||
200 | 234 | playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); | ||
201 | 235 | } | ||
202 | 236 | if (player.can_do_prev) { | ||
203 | 237 | playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); | ||
204 | 238 | } | ||
205 | 239 | } | ||
206 | 240 | return playback_item; | ||
207 | 241 | } | ||
208 | 242 | |||
209 | 218 | void insert_player_section (MediaPlayer player) { | 243 | void insert_player_section (MediaPlayer player) { |
210 | 219 | if (this.hide_players) | 244 | if (this.hide_players) |
211 | 220 | return; | 245 | return; |
212 | @@ -240,9 +265,21 @@ | |||
213 | 240 | 265 | ||
214 | 241 | var playback_item = new MenuItem (null, null); | 266 | var playback_item = new MenuItem (null, null); |
215 | 242 | playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); | 267 | playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); |
219 | 243 | playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); | 268 | playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id + ".disabled"); |
220 | 244 | playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); | 269 | playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id + ".disabled"); |
221 | 245 | playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); | 270 | playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id + ".disabled"); |
222 | 271 | |||
223 | 272 | if (player.is_running) { | ||
224 | 273 | if (player.can_do_play) { | ||
225 | 274 | playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); | ||
226 | 275 | } | ||
227 | 276 | if (player.can_do_next) { | ||
228 | 277 | playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); | ||
229 | 278 | } | ||
230 | 279 | if (player.can_do_prev) { | ||
231 | 280 | playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); | ||
232 | 281 | } | ||
233 | 282 | } | ||
234 | 246 | section.append_item (playback_item); | 283 | section.append_item (playback_item); |
235 | 247 | 284 | ||
236 | 248 | /* Add new players to the end of the player sections, just before the settings */ | 285 | /* Add new players to the end of the player sections, just before the settings */ |
237 | @@ -262,6 +299,17 @@ | |||
238 | 262 | this.menu.remove (index); | 299 | this.menu.remove (index); |
239 | 263 | } | 300 | } |
240 | 264 | 301 | ||
241 | 302 | void update_player_section (MediaPlayer player, int index) { | ||
242 | 303 | var player_section = this.menu.get_item_link(index, Menu.LINK_SECTION) as Menu; | ||
243 | 304 | if (player_section.get_n_items () == 2) { | ||
244 | 305 | // we have 2 items, the second one is the playback item | ||
245 | 306 | // remove it first | ||
246 | 307 | player_section.remove (1); | ||
247 | 308 | MenuItem playback_item = create_playback_menu_item (player); | ||
248 | 309 | player_section.append_item (playback_item); | ||
249 | 310 | } | ||
250 | 311 | } | ||
251 | 312 | |||
252 | 265 | void update_playlists (MediaPlayer player) { | 313 | void update_playlists (MediaPlayer player) { |
253 | 266 | int index = find_player_section (player); | 314 | int index = find_player_section (player); |
254 | 267 | if (index < 0) | 315 | if (index < 0) |
255 | @@ -292,6 +340,13 @@ | |||
256 | 292 | submenu.append_section (null, playlists_section); | 340 | submenu.append_section (null, playlists_section); |
257 | 293 | player_section.append_submenu (_("Choose Playlist"), submenu); | 341 | player_section.append_submenu (_("Choose Playlist"), submenu); |
258 | 294 | } | 342 | } |
259 | 343 | |||
260 | 344 | void update_playbackstatus (MediaPlayer player) { | ||
261 | 345 | int index = find_player_section (player); | ||
262 | 346 | if (index != -1) { | ||
263 | 347 | update_player_section (player, index); | ||
264 | 348 | } | ||
265 | 349 | } | ||
266 | 295 | 350 | ||
267 | 296 | MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name) { | 351 | MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name) { |
268 | 297 | var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name); | 352 | var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name); |
269 | 298 | 353 | ||
270 | === modified file 'tests/media-player-mock.vala' | |||
271 | --- tests/media-player-mock.vala 2014-02-12 19:54:59 +0000 | |||
272 | +++ tests/media-player-mock.vala 2015-10-14 14:58:07 +0000 | |||
273 | @@ -28,6 +28,9 @@ | |||
274 | 28 | 28 | ||
275 | 29 | public override bool is_running { get { return mock_is_running; } } | 29 | public override bool is_running { get { return mock_is_running; } } |
276 | 30 | public override bool can_raise { get { return mock_can_raise; } } | 30 | public override bool can_raise { get { return mock_can_raise; } } |
277 | 31 | public override bool can_do_next { get { return mock_can_do_next; } } | ||
278 | 32 | public override bool can_do_prev { get { return mock_can_do_prev; } } | ||
279 | 33 | public override bool can_do_play { get { return mock_can_do_play; } } | ||
280 | 31 | 34 | ||
281 | 32 | public override MediaPlayer.Track? current_track { get { return mock_current_track; } set { this.mock_current_track = value; } } | 35 | public override MediaPlayer.Track? current_track { get { return mock_current_track; } set { this.mock_current_track = value; } } |
282 | 33 | 36 | ||
283 | @@ -40,6 +43,9 @@ | |||
284 | 40 | 43 | ||
285 | 41 | public bool mock_is_running { get; set; } | 44 | public bool mock_is_running { get; set; } |
286 | 42 | public bool mock_can_raise { get; set; } | 45 | public bool mock_can_raise { get; set; } |
287 | 46 | public bool mock_can_do_next { get; set; } | ||
288 | 47 | public bool mock_can_do_prev { get; set; } | ||
289 | 48 | public bool mock_can_do_play { get; set; } | ||
290 | 43 | 49 | ||
291 | 44 | public MediaPlayer.Track? mock_current_track { get; set; } | 50 | public MediaPlayer.Track? mock_current_track { get; set; } |
292 | 45 | 51 | ||
293 | 46 | 52 | ||
294 | === modified file 'tests/sound-menu.cc' | |||
295 | --- tests/sound-menu.cc 2014-03-03 21:38:38 +0000 | |||
296 | +++ tests/sound-menu.cc 2015-10-14 14:58:07 +0000 | |||
297 | @@ -27,87 +27,163 @@ | |||
298 | 27 | 27 | ||
299 | 28 | class SoundMenuTest : public ::testing::Test | 28 | class SoundMenuTest : public ::testing::Test |
300 | 29 | { | 29 | { |
328 | 30 | protected: | 30 | protected: |
329 | 31 | GTestDBus * bus = nullptr; | 31 | GTestDBus * bus = nullptr; |
330 | 32 | 32 | ||
331 | 33 | virtual void SetUp() { | 33 | virtual void SetUp() { |
332 | 34 | bus = g_test_dbus_new(G_TEST_DBUS_NONE); | 34 | bus = g_test_dbus_new(G_TEST_DBUS_NONE); |
333 | 35 | g_test_dbus_up(bus); | 35 | g_test_dbus_up(bus); |
334 | 36 | } | 36 | } |
335 | 37 | 37 | ||
336 | 38 | virtual void TearDown() { | 38 | virtual void TearDown() { |
337 | 39 | g_test_dbus_down(bus); | 39 | g_test_dbus_down(bus); |
338 | 40 | g_clear_object(&bus); | 40 | g_clear_object(&bus); |
339 | 41 | } | 41 | } |
340 | 42 | 42 | ||
341 | 43 | void verify_item_attribute (GMenuModel * mm, guint index, const gchar * name, GVariant * value) { | 43 | void verify_item_attribute (GMenuModel * mm, guint index, const gchar * name, GVariant * value) { |
342 | 44 | g_variant_ref_sink(value); | 44 | g_variant_ref_sink(value); |
343 | 45 | 45 | ||
344 | 46 | gchar * variantstr = g_variant_print(value, TRUE); | 46 | gchar * variantstr = g_variant_print(value, TRUE); |
345 | 47 | g_debug("Expecting item %d to have a '%s' attribute: %s", index, name, variantstr); | 47 | g_debug("Expecting item %d to have a '%s' attribute: %s", index, name, variantstr); |
346 | 48 | 48 | ||
347 | 49 | const GVariantType * type = g_variant_get_type(value); | 49 | const GVariantType * type = g_variant_get_type(value); |
348 | 50 | GVariant * itemval = g_menu_model_get_item_attribute_value(mm, index, name, type); | 50 | GVariant * itemval = g_menu_model_get_item_attribute_value(mm, index, name, type); |
349 | 51 | 51 | ||
350 | 52 | ASSERT_NE(nullptr, itemval); | 52 | ASSERT_NE(nullptr, itemval); |
351 | 53 | EXPECT_TRUE(g_variant_equal(itemval, value)); | 53 | EXPECT_TRUE(g_variant_equal(itemval, value)); |
352 | 54 | 54 | ||
353 | 55 | g_variant_unref(value); | 55 | g_variant_unref(value); |
354 | 56 | } | 56 | } |
355 | 57 | |||
356 | 58 | void verify_item_attribute_is_not_set(GMenuModel * mm, guint index, const gchar * name, const GVariantType * type) { | ||
357 | 59 | GVariant * itemval = g_menu_model_get_item_attribute_value(mm, index, name, type); | ||
358 | 60 | EXPECT_EQ(itemval, nullptr); | ||
359 | 61 | } | ||
360 | 62 | |||
361 | 63 | void check_player_control_buttons(bool canPlay, bool canNext, bool canPrev) | ||
362 | 64 | { | ||
363 | 65 | SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE); | ||
364 | 66 | |||
365 | 67 | MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url"); | ||
366 | 68 | |||
367 | 69 | MediaPlayerMock * media = MEDIA_PLAYER_MOCK( | ||
368 | 70 | g_object_new(TYPE_MEDIA_PLAYER_MOCK, | ||
369 | 71 | "mock-id", "player-id", | ||
370 | 72 | "mock-name", "Test Player", | ||
371 | 73 | "mock-state", "Playing", | ||
372 | 74 | "mock-is-running", TRUE, | ||
373 | 75 | "mock-can-raise", FALSE, | ||
374 | 76 | "mock-current-track", track, | ||
375 | 77 | "mock-can-do-play", canPlay, | ||
376 | 78 | "mock-can-do-next", canNext, | ||
377 | 79 | "mock-can-do-prev", canPrev, | ||
378 | 80 | NULL) | ||
379 | 81 | ); | ||
380 | 82 | g_clear_object(&track); | ||
381 | 83 | |||
382 | 84 | sound_menu_add_player(menu, MEDIA_PLAYER(media)); | ||
383 | 85 | |||
384 | 86 | ASSERT_NE(nullptr, menu->menu); | ||
385 | 87 | EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); | ||
386 | 88 | |||
387 | 89 | GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION); | ||
388 | 90 | ASSERT_NE(nullptr, section); | ||
389 | 91 | EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */ | ||
390 | 92 | |||
391 | 93 | /* Player display */ | ||
392 | 94 | verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id")); | ||
393 | 95 | verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player")); | ||
394 | 96 | |||
395 | 97 | /* Player control */ | ||
396 | 98 | verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item")); | ||
397 | 99 | verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string(canPlay ? "indicator.play.player-id" : "indicator.play.player-id.disabled")); | ||
398 | 100 | verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string(canNext ? "indicator.next.player-id" : "indicator.next.player-id.disabled")); | ||
399 | 101 | verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string(canPrev ? "indicator.previous.player-id" : "indicator.previous.player-id.disabled")); | ||
400 | 102 | |||
401 | 103 | g_clear_object(§ion); | ||
402 | 104 | |||
403 | 105 | sound_menu_remove_player(menu, MEDIA_PLAYER(media)); | ||
404 | 106 | |||
405 | 107 | EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); | ||
406 | 108 | |||
407 | 109 | g_clear_object(&media); | ||
408 | 110 | g_clear_object(&menu); | ||
409 | 111 | } | ||
410 | 57 | }; | 112 | }; |
411 | 58 | 113 | ||
412 | 59 | TEST_F(SoundMenuTest, BasicObject) { | 114 | TEST_F(SoundMenuTest, BasicObject) { |
419 | 60 | SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE); | 115 | SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE); |
420 | 61 | 116 | ||
421 | 62 | ASSERT_NE(nullptr, menu); | 117 | ASSERT_NE(nullptr, menu); |
422 | 63 | 118 | ||
423 | 64 | g_clear_object(&menu); | 119 | g_clear_object(&menu); |
424 | 65 | return; | 120 | return; |
425 | 66 | } | 121 | } |
426 | 67 | 122 | ||
427 | 68 | TEST_F(SoundMenuTest, AddRemovePlayer) { | 123 | TEST_F(SoundMenuTest, AddRemovePlayer) { |
473 | 69 | SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE); | 124 | SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE); |
474 | 70 | 125 | ||
475 | 71 | MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url"); | 126 | MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url"); |
476 | 72 | 127 | ||
477 | 73 | MediaPlayerMock * media = MEDIA_PLAYER_MOCK( | 128 | MediaPlayerMock * media = MEDIA_PLAYER_MOCK( |
478 | 74 | g_object_new(TYPE_MEDIA_PLAYER_MOCK, | 129 | g_object_new(TYPE_MEDIA_PLAYER_MOCK, |
479 | 75 | "mock-id", "player-id", | 130 | "mock-id", "player-id", |
480 | 76 | "mock-name", "Test Player", | 131 | "mock-name", "Test Player", |
481 | 77 | "mock-state", "Playing", | 132 | "mock-state", "Playing", |
482 | 78 | "mock-is-running", TRUE, | 133 | "mock-is-running", TRUE, |
483 | 79 | "mock-can-raise", FALSE, | 134 | "mock-can-raise", FALSE, |
484 | 80 | "mock-current-track", track, | 135 | "mock-current-track", track, |
485 | 81 | NULL) | 136 | "mock-can-do-play", TRUE, |
486 | 82 | ); | 137 | "mock-can-do-next", TRUE, |
487 | 83 | g_clear_object(&track); | 138 | "mock-can-do-prev", TRUE, |
488 | 84 | 139 | NULL) | |
489 | 85 | sound_menu_add_player(menu, MEDIA_PLAYER(media)); | 140 | ); |
490 | 86 | 141 | g_clear_object(&track); | |
491 | 87 | ASSERT_NE(nullptr, menu->menu); | 142 | |
492 | 88 | EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); | 143 | sound_menu_add_player(menu, MEDIA_PLAYER(media)); |
493 | 89 | 144 | ||
494 | 90 | GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION); | 145 | ASSERT_NE(nullptr, menu->menu); |
495 | 91 | ASSERT_NE(nullptr, section); | 146 | EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); |
496 | 92 | EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */ | 147 | |
497 | 93 | 148 | GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION); | |
498 | 94 | /* Player display */ | 149 | ASSERT_NE(nullptr, section); |
499 | 95 | verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id")); | 150 | EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */ |
500 | 96 | verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player")); | 151 | |
501 | 97 | 152 | /* Player display */ | |
502 | 98 | /* Player control */ | 153 | verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id")); |
503 | 99 | verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item")); | 154 | verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player")); |
504 | 100 | verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id")); | 155 | |
505 | 101 | verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id")); | 156 | /* Player control */ |
506 | 102 | verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id")); | 157 | verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item")); |
507 | 103 | 158 | verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id")); | |
508 | 104 | g_clear_object(§ion); | 159 | verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id")); |
509 | 105 | 160 | verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id")); | |
510 | 106 | sound_menu_remove_player(menu, MEDIA_PLAYER(media)); | 161 | |
511 | 107 | 162 | g_clear_object(§ion); | |
512 | 108 | EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); | 163 | |
513 | 109 | 164 | sound_menu_remove_player(menu, MEDIA_PLAYER(media)); | |
514 | 110 | g_clear_object(&media); | 165 | |
515 | 111 | g_clear_object(&menu); | 166 | EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu))); |
516 | 112 | return; | 167 | |
517 | 113 | } | 168 | g_clear_object(&media); |
518 | 169 | g_clear_object(&menu); | ||
519 | 170 | return; | ||
520 | 171 | } | ||
521 | 172 | |||
522 | 173 | TEST_F(SoundMenuTest, AddRemovePlayerNoPlayNextPrev) { | ||
523 | 174 | check_player_control_buttons(false, false, false); | ||
524 | 175 | } | ||
525 | 176 | |||
526 | 177 | TEST_F(SoundMenuTest, AddRemovePlayerNoNext) { | ||
527 | 178 | check_player_control_buttons(true, false, true); | ||
528 | 179 | } | ||
529 | 180 | |||
530 | 181 | TEST_F(SoundMenuTest, AddRemovePlayerNoPrev) { | ||
531 | 182 | check_player_control_buttons(true, true, false); | ||
532 | 183 | } | ||
533 | 184 | |||
534 | 185 | TEST_F(SoundMenuTest, AddRemovePlayerNoPlay) { | ||
535 | 186 | check_player_control_buttons(false, true, true); | ||
536 | 187 | } | ||
537 | 188 | |||
538 | 189 | // |
PASSED: Continuous integration, rev:504 jenkins. qa.ubuntu. com/job/ indicator- sound-ci/ 242/ jenkins. qa.ubuntu. com/job/ indicator- sound-wily- amd64-ci/ 18 jenkins. qa.ubuntu. com/job/ indicator- sound-wily- armhf-ci/ 18 jenkins. qa.ubuntu. com/job/ indicator- sound-wily- armhf-ci/ 18/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- sound-ci/ 242/rebuild
http://