Merge lp:~xavi-garcia-mena/indicator-sound/next-play-prev-buttons-bug-1373313 into lp:indicator-sound/15.10

Proposed by Xavi Garcia
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
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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Mostly looks good. A couple of questions inline below.

review: Needs Information
505. By Xavi Garcia

Unit tests refactored

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
506. By Xavi Garcia

merged with trunk

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

Thanks for the test changes, Xavi. LGTM.

review: Approve
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2015-09-15 08:19:51 +0000
+++ debian/changelog 2015-10-14 14:58:07 +0000
@@ -1,4 +1,11 @@
1indicator-sound (12.10.2+15.10.20150915-0ubuntu1) wily; urgency=medium1indicator-sound (12.10.2+15.04.20150917-0ubuntu1) vivid; urgency=medium
2
3 [ Xavi Garcia Mena ]
4 * Merged lp:~xavi-garcia-mena/indicator-sound/icon-volume-zero
5
6 -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +0000
7
8indicator-sound (12.10.2+15.04.20150915-0ubuntu1) vivid; urgency=medium
29
3 [ Sebastien Bacher ]10 [ Sebastien Bacher ]
4 * under unity8 start system-settings instead unity-control-center (LP:11 * under unity8 start system-settings instead unity-control-center (LP:
@@ -9,7 +16,7 @@
916
10 -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +000017 -- Sebastien Bacher <seb128@ubuntu.com> Tue, 15 Sep 2015 08:19:51 +0000
1118
12indicator-sound (12.10.2+15.10.20150812.3-0ubuntu1) wily; urgency=medium19indicator-sound (12.10.2+15.04.20150812.3-0ubuntu1) vivid; urgency=medium
1320
14 [ CI Train Bot ]21 [ CI Train Bot ]
15 * New rebuild forced.22 * New rebuild forced.
@@ -20,7 +27,7 @@
2027
21 -- CI Train Bot <ci-train-bot@canonical.com> Wed, 12 Aug 2015 20:55:05 +000028 -- CI Train Bot <ci-train-bot@canonical.com> Wed, 12 Aug 2015 20:55:05 +0000
2229
23indicator-sound (12.10.2+15.10.20150807.6-0ubuntu1) wily; urgency=medium30indicator-sound (12.10.2+15.04.20150807.6-0ubuntu1) vivid; urgency=medium
2431
25 [ CI Train Bot ]32 [ CI Train Bot ]
26 * New rebuild forced.33 * New rebuild forced.
@@ -31,19 +38,19 @@
3138
32 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 07 Aug 2015 22:35:58 +000039 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 07 Aug 2015 22:35:58 +0000
3340
34indicator-sound (12.10.2+15.10.20150605-0ubuntu1) wily; urgency=medium41indicator-sound (12.10.2+15.04.20150605-0ubuntu1) vivid; urgency=medium
3542
36 * 43 *
3744
38 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 05 Jun 2015 19:50:06 +000045 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 05 Jun 2015 19:50:06 +0000
3946
40indicator-sound (12.10.2+15.10.20150507+eventually4-0ubuntu1) wily; urgency=medium47indicator-sound (12.10.2+15.04.20150507+eventually4-0ubuntu1) vivid; urgency=medium
4148
42 * Using eventually to avoid arbitrary timeouts in tests49 * Using eventually to avoid arbitrary timeouts in tests
4350
44 -- Ted Gould <ted@ubuntu.com> Wed, 27 May 2015 11:11:19 -050051 -- Ted Gould <ted@ubuntu.com> Wed, 27 May 2015 11:11:19 -0500
4552
46indicator-sound (12.10.2+15.10.20150507-0ubuntu1) wily; urgency=medium53indicator-sound (12.10.2+15.04.20150507-0ubuntu1) vivid; urgency=medium
4754
48 [ Charles Kerr ]55 [ Charles Kerr ]
49 * Use the BusWatcher to look for org.freedesktop.Notifications56 * Use the BusWatcher to look for org.freedesktop.Notifications
@@ -51,6 +58,17 @@
5158
52 -- CI Train Bot <ci-train-bot@canonical.com> Thu, 07 May 2015 15:27:00 +000059 -- CI Train Bot <ci-train-bot@canonical.com> Thu, 07 May 2015 15:27:00 +0000
5360
61indicator-sound (12.10.2+15.04.20150508-0ubuntu1) vivid; urgency=medium
62
63 [ CI Train Bot ]
64 * New rebuild forced.
65
66 [ Charles Kerr ]
67 * Use the BusWatcher to look for org.freedesktop.Notifications
68 ownership changes on the bus. (LP: #1432446)
69
70 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 08 May 2015 12:20:07 +0000
71
54indicator-sound (12.10.2+15.04.20150421-0ubuntu1) vivid; urgency=medium72indicator-sound (12.10.2+15.04.20150421-0ubuntu1) vivid; urgency=medium
5573
56 [ Ted Gould ]74 [ Ted Gould ]
5775
=== modified file 'src/media-player-mpris.vala'
--- src/media-player-mpris.vala 2015-03-26 15:56:49 +0000
+++ src/media-player-mpris.vala 2015-10-14 14:58:07 +0000
@@ -79,6 +79,24 @@
79 }79 }
80 }80 }
8181
82 public override bool can_do_play {
83 get {
84 return this.proxy.CanPlay;
85 }
86 }
87
88 public override bool can_do_prev {
89 get {
90 return this.proxy.CanGoPrevious;
91 }
92 }
93
94 public override bool can_do_next {
95 get {
96 return this.proxy.CanGoNext;
97 }
98 }
99
82 /**100 /**
83 * Attach this object to a process of the associated media player. The player must own @dbus_name and101 * Attach this object to a process of the associated media player. The player must own @dbus_name and
84 * implement the org.mpris.MediaPlayer2.Player interface.102 * implement the org.mpris.MediaPlayer2.Player interface.
@@ -272,6 +290,10 @@
272 if (changed_properties.lookup ("PlaybackStatus", "s", null)) {290 if (changed_properties.lookup ("PlaybackStatus", "s", null)) {
273 this.state = this.proxy.PlaybackStatus != null ? this.proxy.PlaybackStatus : "Unknown";291 this.state = this.proxy.PlaybackStatus != null ? this.proxy.PlaybackStatus : "Unknown";
274 }292 }
293 if (changed_properties.lookup ("CanGoNext", "b", null) || changed_properties.lookup ("CanGoPrevious", "b", null) ||
294 changed_properties.lookup ("CanPlay", "b", null) || changed_properties.lookup ("CanPause", "b", null)) {
295 this.playbackstatus_changed ();
296 }
275297
276 var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}"));298 var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}"));
277 if (metadata != null)299 if (metadata != null)
278300
=== modified file 'src/media-player.vala'
--- src/media-player.vala 2014-02-12 16:21:32 +0000
+++ src/media-player.vala 2015-10-14 14:58:07 +0000
@@ -26,6 +26,9 @@
2626
27 public virtual bool is_running { get { not_implemented(); return false; } }27 public virtual bool is_running { get { not_implemented(); return false; } }
28 public virtual bool can_raise { get { not_implemented(); return false; } }28 public virtual bool can_raise { get { not_implemented(); return false; } }
29 public virtual bool can_do_next { get { not_implemented(); return false; } }
30 public virtual bool can_do_prev { get { not_implemented(); return false; } }
31 public virtual bool can_do_play { get { not_implemented(); return false; } }
2932
30 public class Track : Object {33 public class Track : Object {
31 public string artist { get; construct; }34 public string artist { get; construct; }
@@ -44,6 +47,7 @@
44 }47 }
4548
46 public signal void playlists_changed ();49 public signal void playlists_changed ();
50 public signal void playbackstatus_changed ();
4751
48 public abstract void activate ();52 public abstract void activate ();
49 public abstract void play_pause ();53 public abstract void play_pause ();
5054
=== modified file 'src/mpris2-interfaces.vala'
--- src/mpris2-interfaces.vala 2015-03-26 15:56:49 +0000
+++ src/mpris2-interfaces.vala 2015-10-14 14:58:07 +0000
@@ -37,7 +37,10 @@
37 // properties37 // properties
38 public abstract HashTable<string, Variant?> Metadata{owned get; set;}38 public abstract HashTable<string, Variant?> Metadata{owned get; set;}
39 public abstract int32 Position{owned get; set;}39 public abstract int32 Position{owned get; set;}
40 public abstract string? PlaybackStatus{owned get; set;} 40 public abstract string? PlaybackStatus{owned get; set;}
41 public abstract bool CanPlay{owned get; set;}
42 public abstract bool CanGoNext{owned get; set;}
43 public abstract bool CanGoPrevious{owned get; set;}
41 // methods44 // methods
42 public abstract async void PlayPause() throws IOError;45 public abstract async void PlayPause() throws IOError;
43 public abstract async void Next() throws IOError;46 public abstract async void Next() throws IOError;
4447
=== modified file 'src/sound-menu.vala'
--- src/sound-menu.vala 2015-02-12 00:44:34 +0000
+++ src/sound-menu.vala 2015-10-14 14:58:07 +0000
@@ -157,18 +157,26 @@
157 this.update_playlists (player);157 this.update_playlists (player);
158158
159 var handler_id = player.notify["is-running"].connect ( () => {159 var handler_id = player.notify["is-running"].connect ( () => {
160 if (player.is_running)160 if (player.is_running) {
161 if (this.find_player_section(player) == -1)161 int index = this.find_player_section(player);
162 if (index == -1) {
162 this.insert_player_section (player);163 this.insert_player_section (player);
163 else164 }
165 else {
166 update_player_section (player, index);
167 }
168 }
169 else {
164 if (this.hide_inactive)170 if (this.hide_inactive)
165 this.remove_player_section (player);171 this.remove_player_section (player);
172 }
166173
167 this.update_playlists (player);174 this.update_playlists (player);
168 });175 });
169 this.notify_handlers.insert (player, handler_id);176 this.notify_handlers.insert (player, handler_id);
170177
171 player.playlists_changed.connect (this.update_playlists);178 player.playlists_changed.connect (this.update_playlists);
179 player.playbackstatus_changed.connect (this.update_playbackstatus);
172 }180 }
173181
174 public void remove_player (MediaPlayer player) {182 public void remove_player (MediaPlayer player) {
@@ -215,6 +223,23 @@
215 return -1;223 return -1;
216 }224 }
217225
226 MenuItem create_playback_menu_item (MediaPlayer player) {
227 var playback_item = new MenuItem (null, null);
228 playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item");
229 if (player.is_running) {
230 if (player.can_do_play) {
231 playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
232 }
233 if (player.can_do_next) {
234 playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
235 }
236 if (player.can_do_prev) {
237 playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
238 }
239 }
240 return playback_item;
241 }
242
218 void insert_player_section (MediaPlayer player) {243 void insert_player_section (MediaPlayer player) {
219 if (this.hide_players)244 if (this.hide_players)
220 return;245 return;
@@ -240,9 +265,21 @@
240265
241 var playback_item = new MenuItem (null, null);266 var playback_item = new MenuItem (null, null);
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");
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");
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");
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");
271
272 if (player.is_running) {
273 if (player.can_do_play) {
274 playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
275 }
276 if (player.can_do_next) {
277 playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
278 }
279 if (player.can_do_prev) {
280 playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
281 }
282 }
246 section.append_item (playback_item);283 section.append_item (playback_item);
247284
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 */
@@ -262,6 +299,17 @@
262 this.menu.remove (index);299 this.menu.remove (index);
263 }300 }
264301
302 void update_player_section (MediaPlayer player, int index) {
303 var player_section = this.menu.get_item_link(index, Menu.LINK_SECTION) as Menu;
304 if (player_section.get_n_items () == 2) {
305 // we have 2 items, the second one is the playback item
306 // remove it first
307 player_section.remove (1);
308 MenuItem playback_item = create_playback_menu_item (player);
309 player_section.append_item (playback_item);
310 }
311 }
312
265 void update_playlists (MediaPlayer player) {313 void update_playlists (MediaPlayer player) {
266 int index = find_player_section (player);314 int index = find_player_section (player);
267 if (index < 0)315 if (index < 0)
@@ -292,6 +340,13 @@
292 submenu.append_section (null, playlists_section);340 submenu.append_section (null, playlists_section);
293 player_section.append_submenu (_("Choose Playlist"), submenu);341 player_section.append_submenu (_("Choose Playlist"), submenu);
294 }342 }
343
344 void update_playbackstatus (MediaPlayer player) {
345 int index = find_player_section (player);
346 if (index != -1) {
347 update_player_section (player, index);
348 }
349 }
295350
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) {
297 var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name);352 var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name);
298353
=== modified file 'tests/media-player-mock.vala'
--- tests/media-player-mock.vala 2014-02-12 19:54:59 +0000
+++ tests/media-player-mock.vala 2015-10-14 14:58:07 +0000
@@ -28,6 +28,9 @@
2828
29 public override bool is_running { get { return mock_is_running; } }29 public override bool is_running { get { return mock_is_running; } }
30 public override bool can_raise { get { return mock_can_raise; } }30 public override bool can_raise { get { return mock_can_raise; } }
31 public override bool can_do_next { get { return mock_can_do_next; } }
32 public override bool can_do_prev { get { return mock_can_do_prev; } }
33 public override bool can_do_play { get { return mock_can_do_play; } }
3134
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; } }
3336
@@ -40,6 +43,9 @@
4043
41 public bool mock_is_running { get; set; }44 public bool mock_is_running { get; set; }
42 public bool mock_can_raise { get; set; }45 public bool mock_can_raise { get; set; }
46 public bool mock_can_do_next { get; set; }
47 public bool mock_can_do_prev { get; set; }
48 public bool mock_can_do_play { get; set; }
4349
44 public MediaPlayer.Track? mock_current_track { get; set; } 50 public MediaPlayer.Track? mock_current_track { get; set; }
4551
4652
=== modified file 'tests/sound-menu.cc'
--- tests/sound-menu.cc 2014-03-03 21:38:38 +0000
+++ tests/sound-menu.cc 2015-10-14 14:58:07 +0000
@@ -27,87 +27,163 @@
2727
28class SoundMenuTest : public ::testing::Test28class SoundMenuTest : public ::testing::Test
29{29{
30 protected:30 protected:
31 GTestDBus * bus = nullptr;31 GTestDBus * bus = nullptr;
3232
33 virtual void SetUp() {33 virtual void SetUp() {
34 bus = g_test_dbus_new(G_TEST_DBUS_NONE);34 bus = g_test_dbus_new(G_TEST_DBUS_NONE);
35 g_test_dbus_up(bus);35 g_test_dbus_up(bus);
36 }36 }
3737
38 virtual void TearDown() {38 virtual void TearDown() {
39 g_test_dbus_down(bus);39 g_test_dbus_down(bus);
40 g_clear_object(&bus);40 g_clear_object(&bus);
41 }41 }
4242
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) {
44 g_variant_ref_sink(value);44 g_variant_ref_sink(value);
4545
46 gchar * variantstr = g_variant_print(value, TRUE);46 gchar * variantstr = g_variant_print(value, TRUE);
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);
4848
49 const GVariantType * type = g_variant_get_type(value);49 const GVariantType * type = g_variant_get_type(value);
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);
5151
52 ASSERT_NE(nullptr, itemval);52 ASSERT_NE(nullptr, itemval);
53 EXPECT_TRUE(g_variant_equal(itemval, value));53 EXPECT_TRUE(g_variant_equal(itemval, value));
5454
55 g_variant_unref(value);55 g_variant_unref(value);
56 }56 }
57
58 void verify_item_attribute_is_not_set(GMenuModel * mm, guint index, const gchar * name, const GVariantType * type) {
59 GVariant * itemval = g_menu_model_get_item_attribute_value(mm, index, name, type);
60 EXPECT_EQ(itemval, nullptr);
61 }
62
63 void check_player_control_buttons(bool canPlay, bool canNext, bool canPrev)
64 {
65 SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
66
67 MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
68
69 MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
70 g_object_new(TYPE_MEDIA_PLAYER_MOCK,
71 "mock-id", "player-id",
72 "mock-name", "Test Player",
73 "mock-state", "Playing",
74 "mock-is-running", TRUE,
75 "mock-can-raise", FALSE,
76 "mock-current-track", track,
77 "mock-can-do-play", canPlay,
78 "mock-can-do-next", canNext,
79 "mock-can-do-prev", canPrev,
80 NULL)
81 );
82 g_clear_object(&track);
83
84 sound_menu_add_player(menu, MEDIA_PLAYER(media));
85
86 ASSERT_NE(nullptr, menu->menu);
87 EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
88
89 GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
90 ASSERT_NE(nullptr, section);
91 EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
92
93 /* Player display */
94 verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
95 verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
96
97 /* Player control */
98 verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
99 verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string(canPlay ? "indicator.play.player-id" : "indicator.play.player-id.disabled"));
100 verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string(canNext ? "indicator.next.player-id" : "indicator.next.player-id.disabled"));
101 verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string(canPrev ? "indicator.previous.player-id" : "indicator.previous.player-id.disabled"));
102
103 g_clear_object(&section);
104
105 sound_menu_remove_player(menu, MEDIA_PLAYER(media));
106
107 EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
108
109 g_clear_object(&media);
110 g_clear_object(&menu);
111 }
57};112};
58113
59TEST_F(SoundMenuTest, BasicObject) {114TEST_F(SoundMenuTest, BasicObject) {
60 SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);115 SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
61116
62 ASSERT_NE(nullptr, menu);117 ASSERT_NE(nullptr, menu);
63118
64 g_clear_object(&menu);119 g_clear_object(&menu);
65 return;120 return;
66}121}
67122
68TEST_F(SoundMenuTest, AddRemovePlayer) {123TEST_F(SoundMenuTest, AddRemovePlayer) {
69 SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);124 SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
70125
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");
72127
73 MediaPlayerMock * media = MEDIA_PLAYER_MOCK(128 MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
74 g_object_new(TYPE_MEDIA_PLAYER_MOCK,129 g_object_new(TYPE_MEDIA_PLAYER_MOCK,
75 "mock-id", "player-id",130 "mock-id", "player-id",
76 "mock-name", "Test Player",131 "mock-name", "Test Player",
77 "mock-state", "Playing",132 "mock-state", "Playing",
78 "mock-is-running", TRUE,133 "mock-is-running", TRUE,
79 "mock-can-raise", FALSE,134 "mock-can-raise", FALSE,
80 "mock-current-track", track,135 "mock-current-track", track,
81 NULL)136 "mock-can-do-play", TRUE,
82 );137 "mock-can-do-next", TRUE,
83 g_clear_object(&track);138 "mock-can-do-prev", TRUE,
84139 NULL)
85 sound_menu_add_player(menu, MEDIA_PLAYER(media));140 );
86141 g_clear_object(&track);
87 ASSERT_NE(nullptr, menu->menu);142
88 EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));143 sound_menu_add_player(menu, MEDIA_PLAYER(media));
89144
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);
91 ASSERT_NE(nullptr, section);146 EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
92 EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */147
93148 GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
94 /* Player display */149 ASSERT_NE(nullptr, section);
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 */
96 verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));151
97152 /* Player display */
98 /* Player control */153 verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
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"));
100 verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id"));155
101 verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));156 /* Player control */
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"));
103158 verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id"));
104 g_clear_object(&section);159 verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));
105160 verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id"));
106 sound_menu_remove_player(menu, MEDIA_PLAYER(media));161
107162 g_clear_object(&section);
108 EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));163
109164 sound_menu_remove_player(menu, MEDIA_PLAYER(media));
110 g_clear_object(&media);165
111 g_clear_object(&menu);166 EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
112 return;167
113}168 g_clear_object(&media);
169 g_clear_object(&menu);
170 return;
171}
172
173TEST_F(SoundMenuTest, AddRemovePlayerNoPlayNextPrev) {
174 check_player_control_buttons(false, false, false);
175}
176
177TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
178 check_player_control_buttons(true, false, true);
179}
180
181TEST_F(SoundMenuTest, AddRemovePlayerNoPrev) {
182 check_player_control_buttons(true, true, false);
183}
184
185TEST_F(SoundMenuTest, AddRemovePlayerNoPlay) {
186 check_player_control_buttons(false, true, true);
187}
188
189//

Subscribers

People subscribed via source and target branches