Merge lp:~xavi-garcia-mena/indicator-sound/bug-1555831-get-root-icon into lp:indicator-sound/15.10

Proposed by Xavi Garcia
Status: Merged
Approved by: Charles Kerr
Approved revision: 534
Merged at revision: 534
Proposed branch: lp:~xavi-garcia-mena/indicator-sound/bug-1555831-get-root-icon
Merge into: lp:indicator-sound/15.10
Diff against target: 201 lines (+116/-41)
4 files modified
src/service.vala (+9/-41)
tests/integration/indicator-sound-test-base.cpp (+43/-0)
tests/integration/indicator-sound-test-base.h (+2/-0)
tests/integration/test-indicator.cpp (+62/-0)
To merge this branch: bzr merge lp:~xavi-garcia-mena/indicator-sound/bug-1555831-get-root-icon
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+289203@code.launchpad.net

Commit message

Changed to code to get the root icon. Now it does not take into account the source output, as in fact that code was not differentiating between any particular case.
The code was added in the past in the case that we should differentiate between bluetooth, headphones, etc... but it was never used.

Description of the change

Changed to code to get the root icon. Now it does not take into account the source output, as in fact that code was not differentiating between any particular case.
The code was added in the past in the case that we should differentiate between bluetooth, headphones, etc... but it was never used.

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

Looks very good to me.

Not an issue with this MP, but rather just thinking out loud -- is there anything analogous to the Menu Matcher harness for GActions? Extracting these states out is repetitive and wastes a lot of LOC.

review: Approve
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Thanks for the review, Charles.

I don't think we have anything like gmenuharness yet (will ask Pete), but I agree: it would be good to have something similar for actions...

535. By Xavi Garcia

Added volume check to root icon test

Revision history for this message
Charles Kerr (charlesk) wrote :

reapproved with r535

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.vala'
2--- src/service.vala 2016-03-02 13:50:43 +0000
3+++ src/service.vala 2016-03-17 10:07:26 +0000
4@@ -290,48 +290,16 @@
5
6 private bool block_info_notifications = false;
7
8- private static unowned string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output) {
9- switch (active_output) {
10- case VolumeControl.ActiveOutput.SPEAKERS:
11- case VolumeControl.ActiveOutput.HEADPHONES:
12- case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
13- case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
14- case VolumeControl.ActiveOutput.USB_SPEAKER:
15- case VolumeControl.ActiveOutput.USB_HEADPHONES:
16- case VolumeControl.ActiveOutput.HDMI_SPEAKER:
17- case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
18- if (volume <= 0.0)
19- return "audio-volume-muted-panel";
20- if (volume <= 0.3)
21- return "audio-volume-low-panel";
22- if (volume <= 0.7)
23- return "audio-volume-medium-panel";
24- return "audio-volume-high-panel";
25-
26- default:
27- return "";
28- }
29- }
30-
31 private unowned string get_volume_root_icon (double volume, bool mute, VolumeControl.ActiveOutput active_output) {
32- switch (active_output) {
33- case VolumeControl.ActiveOutput.SPEAKERS:
34- case VolumeControl.ActiveOutput.HEADPHONES:
35- case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
36- case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
37- case VolumeControl.ActiveOutput.USB_SPEAKER:
38- case VolumeControl.ActiveOutput.USB_HEADPHONES:
39- case VolumeControl.ActiveOutput.HDMI_SPEAKER:
40- case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
41- if (mute || volume <= 0.0)
42- return this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
43- if (this.accounts_service != null && this.accounts_service.silentMode)
44- return "audio-volume-muted-panel";
45- return get_volume_root_icon_by_volume (volume, active_output);
46-
47- default:
48- return "";
49- }
50+ if (mute || volume <= 0.0)
51+ return this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
52+ if (this.accounts_service != null && this.accounts_service.silentMode)
53+ return "audio-volume-muted-panel";
54+ if (volume <= 0.3)
55+ return "audio-volume-low-panel";
56+ if (volume <= 0.7)
57+ return "audio-volume-medium-panel";
58+ return "audio-volume-high-panel";
59 }
60
61 private void update_notification () {
62
63=== modified file 'tests/integration/indicator-sound-test-base.cpp'
64--- tests/integration/indicator-sound-test-base.cpp 2016-03-04 15:25:39 +0000
65+++ tests/integration/indicator-sound-test-base.cpp 2016-03-17 10:07:26 +0000
66@@ -989,6 +989,49 @@
67 return QVariantList();
68 }
69
70+QStringList IndicatorSoundTestBase::getRootIconValue(bool *isValid)
71+{
72+ QString result = 0;
73+
74+ QVariantList varList = getActionValue("root");
75+ if (isValid != nullptr)
76+ {
77+ *isValid = false;
78+ }
79+ if (varList.at(0).canConvert<QDBusArgument>())
80+ {
81+ const QDBusArgument dbusArg = qvariant_cast<QDBusArgument>(varList.at(0));
82+ if (dbusArg.currentType() == QDBusArgument::MapType)
83+ {
84+ QVariantMap map;
85+ dbusArg >> map;
86+ QVariantMap::const_iterator iter = map.find("icon");
87+ if (iter != map.end())
88+ {
89+ const QDBusArgument iconArg = qvariant_cast<QDBusArgument>((*iter));
90+ if (iconArg.currentType() == QDBusArgument::StructureType)
91+ {
92+ QString name;
93+ QVariant iconValue;
94+ iconArg.beginStructure();
95+ iconArg >> name;
96+ iconArg >> iconValue;
97+ if (name == "themed" && iconValue.type() == QVariant::StringList)
98+ {
99+ if (isValid != nullptr)
100+ {
101+ *isValid = true;
102+ }
103+ }
104+ iconArg.endStructure();
105+ return iconValue.toStringList();
106+ }
107+ }
108+ }
109+ }
110+ return QStringList();
111+}
112+
113 qlonglong IndicatorSoundTestBase::getVolumeSyncValue(bool *isValid)
114 {
115 qlonglong result = 0;
116
117=== modified file 'tests/integration/indicator-sound-test-base.h'
118--- tests/integration/indicator-sound-test-base.h 2016-03-04 15:25:39 +0000
119+++ tests/integration/indicator-sound-test-base.h 2016-03-17 10:07:26 +0000
120@@ -148,6 +148,8 @@
121
122 qlonglong getVolumeSyncValue(bool *isValid = nullptr);
123
124+ QStringList getRootIconValue(bool *isValid = nullptr);
125+
126 float getVolumeValue(bool *isValid = nullptr);
127
128 static QVariant waitPropertyChanged(QSignalSpy * signalSpy, QString property);
129
130=== modified file 'tests/integration/test-indicator.cpp'
131--- tests/integration/test-indicator.cpp 2016-03-04 15:25:39 +0000
132+++ tests/integration/test-indicator.cpp 2016-03-17 10:07:26 +0000
133@@ -32,6 +32,68 @@
134 {
135 };
136
137+TEST_F(TestIndicator, PhoneCheckRootIcon)
138+{
139+ double INITIAL_VOLUME = 0.0;
140+
141+ ASSERT_NO_THROW(startAccountsService());
142+ EXPECT_TRUE(clearGSettingsPlayers());
143+ ASSERT_NO_THROW(startPulsePhone());
144+
145+ // initialize volumes in pulseaudio
146+ EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME));
147+
148+ // start now the indicator, so it picks the new volumes
149+ ASSERT_NO_THROW(startIndicator());
150+
151+ // check that the volume is set and give
152+ // time to the indicator to start
153+ EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters())
154+ .item(mh::MenuItemMatcher()
155+ .action("indicator.root")
156+ .string_attribute("x-canonical-type", "com.canonical.indicator.root")
157+ .string_attribute("x-canonical-scroll-action", "indicator.scroll")
158+ .string_attribute("x-canonical-secondary-action", "indicator.mute")
159+ .string_attribute("submenu-action", "indicator.indicator-shown")
160+ .mode(mh::MenuItemMatcher::Mode::all)
161+ .submenu()
162+ .item(mh::MenuItemMatcher()
163+ .section()
164+ .item(silentModeSwitch(false))
165+ .item(volumeSlider(INITIAL_VOLUME, "Volume"))
166+ )
167+ .item(mh::MenuItemMatcher()
168+ .label("Sound Settingsā€¦")
169+ .action("indicator.phone-settings")
170+ )
171+ ).match());
172+
173+ QStringList mutedIcon = {"audio-volume-muted-panel", "audio-volume-muted", "audio-volume", "audio"};
174+ EXPECT_EQ(getRootIconValue(), mutedIcon);
175+
176+ QStringList lowVolumeIcon = {"audio-volume-low-panel", "audio-volume-low", "audio-volume", "audio"};
177+ for( double volume = 0.1; volume <= 0.3; volume+=0.1)
178+ {
179+ EXPECT_TRUE(setStreamRestoreVolume("alert", volume));
180+ EXPECT_EQ(getRootIconValue(), lowVolumeIcon);
181+ }
182+ EXPECT_TRUE(setStreamRestoreVolume("alert", 0.4));
183+
184+ QStringList mediumVolumeIcon = {"audio-volume-medium-panel", "audio-volume-medium", "audio-volume", "audio"};
185+ for( double volume = 0.4; volume <= 0.7; volume+=0.1)
186+ {
187+ EXPECT_TRUE(setStreamRestoreVolume("alert", volume));
188+ EXPECT_EQ(getRootIconValue(), mediumVolumeIcon);
189+ }
190+
191+ QStringList highVolumeIcon = {"audio-volume-high-panel", "audio-volume-high", "audio-volume", "audio"};
192+ for( double volume = 0.8; volume <= 1.0; volume+=0.1)
193+ {
194+ EXPECT_TRUE(setStreamRestoreVolume("alert", volume));
195+ EXPECT_EQ(getRootIconValue(), highVolumeIcon);
196+ }
197+}
198+
199 TEST_F(TestIndicator, PhoneTestExternalMicInOut)
200 {
201 double INITIAL_VOLUME = 0.0;

Subscribers

People subscribed via source and target branches