diff options
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/indicator-sound-test-base.cpp | 181 | ||||
-rw-r--r-- | tests/integration/indicator-sound-test-base.h | 18 | ||||
-rw-r--r-- | tests/integration/test-indicator.cpp | 81 |
3 files changed, 240 insertions, 40 deletions
diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index f9db365..c261fcf 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -209,7 +209,7 @@ void IndicatorSoundTestBase::stopTestSound() testSoundProcess.terminate(); } -void IndicatorSoundTestBase::startPulseDesktop() +void IndicatorSoundTestBase::startPulseDesktop(DevicePortType speakerPort, DevicePortType headphonesPort) { try { @@ -225,8 +225,8 @@ void IndicatorSoundTestBase::startPulseDesktop() << "--system=false" << "--exit-idle-time=-1" << "-n" - << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker") - << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones") + << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker sink_properties=device.bus=%1").arg(getDevicePortString(speakerPort)) + << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones sink_properties=device.bus=%1").arg(getDevicePortString(headphonesPort)) << "--log-target=file:/tmp/pulse-daemon.log" << "--load=module-dbus-protocol" << "--load=module-native-protocol-tcp auth-ip-acl=127.0.0.1" @@ -240,7 +240,7 @@ void IndicatorSoundTestBase::startPulseDesktop() } } -void IndicatorSoundTestBase::startPulsePhone() +void IndicatorSoundTestBase::startPulsePhone(DevicePortType speakerPort, DevicePortType headphonesPort) { try { @@ -256,8 +256,8 @@ void IndicatorSoundTestBase::startPulsePhone() << "--system=false" << "--exit-idle-time=-1" << "-n" - << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker") - << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones") + << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker sink_properties=device.bus=%1").arg(getDevicePortString(speakerPort)) + << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones sink_properties=device.bus=%1").arg(getDevicePortString(headphonesPort)) << "--log-target=file:/tmp/pulse-daemon.log" << QString("--load=module-stream-restore restore_device=false restore_muted=false fallback_table=%1").arg(STREAM_RESTORE_TABLE) << "--load=module-dbus-protocol" @@ -327,10 +327,10 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::phoneParameters() "/com/canonical/indicator/sound/phone"); } -unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double volume) +unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double volume, QString const &label) { return mh::MenuItemMatcher().radio() - .label("Volume") + .label(label.toStdString()) .round_doubles(0.1) .int32_attribute("target", 0) .double_attribute("min-value", 0.0) @@ -626,3 +626,168 @@ bool IndicatorSoundTestBase::activateHeadphones(bool headphonesActive) return pacltProcess.exitCode() == 0; } + +QString IndicatorSoundTestBase::getDevicePortString(DevicePortType port) +{ + QString portString; + + switch (port) + { + case WIRED: + portString = "wired"; + break; + case BLUETOOTH: + portString = "bluetooth"; + break; + case USB: + portString = "usb"; + break; + case HDMI: + portString = "hdmi"; + break; + default: + portString = "not_defined"; + break; + } + + return portString; +} + +void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, DevicePortType headphonesPort) +{ + double INITIAL_VOLUME = 1.0; + + QString speakerString; + QString speakerStringMenu; + switch(speakerPort) + { + case WIRED: + speakerString = "Speakers"; + speakerStringMenu = "Volume"; + break; + case BLUETOOTH: + speakerString = "Bluetooth speaker"; + speakerStringMenu = "Volume (Bluetooth)"; + break; + case USB: + speakerString = "Usb speaker"; + speakerStringMenu = "Volume (Usb)"; + break; + case HDMI: + speakerString = "HDMI speaker"; + speakerStringMenu = "Volume (HDMI)"; + break; + } + + QString headphonesString; + QString headphonesStringMenu; + switch(headphonesPort) + { + case WIRED: + headphonesString = "Headphones"; + headphonesStringMenu = "Volume (Headphones)"; + break; + case BLUETOOTH: + headphonesString = "Bluetooth headphones"; + headphonesStringMenu = "Volume (Bluetooth headphones)"; + break; + case USB: + headphonesString = "Usb headphones"; + headphonesStringMenu = "Volume (Usb headphones)"; + break; + case HDMI: + headphonesString = "HDMI headphones"; + headphonesStringMenu = "Volume (HDMI headphones)"; + break; + } + + QSignalSpy notificationsSpy(¬ificationsMockInterface(), + SIGNAL(MethodCalled(const QString &, const QVariantList &))); + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulsePhone(speakerPort, headphonesPort)); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // if the speaker is the normal one it does not emit any notification, as that's + // the default one. + // for the rest it notifies the output + if (speakerPort != WIRED) + { + WAIT_FOR_SIGNALS(notificationsSpy, 3); + + // the first time we also have the calls to + // GetServerInformation and GetCapabilities + checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); + checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); + checkVolumeNotification(1.0, speakerString, false, notificationsSpy.at(2)); + notificationsSpy.clear(); + } + + // activate the headphones + EXPECT_TRUE(activateHeadphones(true)); + + if (speakerPort == WIRED) + { + WAIT_FOR_SIGNALS(notificationsSpy, 3); + + // the first time we also have the calls to + // GetServerInformation and GetCapabilities + checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); + checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); + checkVolumeNotification(1.0, headphonesString, false, notificationsSpy.at(2)); + notificationsSpy.clear(); + } + else + { + WAIT_FOR_SIGNALS(notificationsSpy, 1); + checkVolumeNotification(1.0, headphonesString, false, notificationsSpy.at(0)); + notificationsSpy.clear(); + } + + // check the label in the menu + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(1.0, headphonesStringMenu)) + ) + ).match()); + + // deactivate the headphones + EXPECT_TRUE(activateHeadphones(false)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1); + checkVolumeNotification(1.0, speakerString, false, notificationsSpy.at(0)); + notificationsSpy.clear(); + + // check the label in the menu + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(1.0, speakerStringMenu)) + ) + ).match()); +} diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 20e44fc..6879bcb 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -49,13 +49,21 @@ public: ~IndicatorSoundTestBase(); + enum DevicePortType + { + WIRED, + BLUETOOTH, + USB, + HDMI + }; + protected: void SetUp() override; void TearDown() override; void startIndicator(); - void startPulseDesktop(); - void startPulsePhone(); + void startPulseDesktop(DevicePortType speakerPort=WIRED, DevicePortType headphonesPort=WIRED); + void startPulsePhone(DevicePortType speakerPort=WIRED, DevicePortType headphonesPort=WIRED); void startAccountsService(); bool clearGSettingsPlayers(); @@ -78,7 +86,7 @@ protected: static unity::gmenuharness::MenuMatcher::Parameters phoneParameters(); - static unity::gmenuharness::MenuItemMatcher volumeSlider(double volume); + static unity::gmenuharness::MenuItemMatcher volumeSlider(double volume, QString const &label); static unity::gmenuharness::MenuItemMatcher silentModeSwitch(bool toggled); @@ -110,6 +118,10 @@ protected: bool activateHeadphones(bool headphonesActive); + QString getDevicePortString(DevicePortType port); + + void checkPortDevicesLabels(DevicePortType speakerPort, DevicePortType headphonesPort); + QtDBusTest::DBusTestRunner dbusTestRunner; QtDBusMock::DBusMock dbusMock; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 1607367..fccaf84 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -41,6 +41,7 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) // initialize volumes in pulseaudio EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", INITIAL_VOLUME)); // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); @@ -79,7 +80,7 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(randomVolume)) + .item(volumeSlider(randomVolume, "Volume")) ) ).match()); @@ -119,7 +120,7 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(1.0)) + .item(volumeSlider(1.0, "Volume")) ) ).match()); @@ -164,7 +165,7 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .label("Sound Settings…") @@ -199,7 +200,7 @@ TEST_F(TestIndicator, PhoneAddMprisPlayer) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .label("Sound Settings…") @@ -229,7 +230,7 @@ TEST_F(TestIndicator, PhoneAddMprisPlayer) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -283,7 +284,7 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -337,7 +338,7 @@ TEST_F(TestIndicator, DesktopAddMprisPlayer) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -391,7 +392,7 @@ TEST_F(TestIndicator, DesktopMprisPlayerButtonsState) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -429,7 +430,7 @@ TEST_F(TestIndicator, DesktopMprisPlayerButtonsState) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -468,7 +469,7 @@ TEST_F(TestIndicator, DesktopMprisPlayerButtonsState) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -506,7 +507,7 @@ TEST_F(TestIndicator, DesktopMprisPlayerButtonsState) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .section() @@ -577,7 +578,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(randomVolume)) + .item(volumeSlider(randomVolume, "Volume")) ) ).match()); @@ -615,7 +616,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(randomVolume)) + .item(volumeSlider(randomVolume, "Volume")) ) ).match()); @@ -664,7 +665,7 @@ TEST_F(TestIndicator, PhoneNotificationVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(INITIAL_VOLUME, "Volume")) ) .item(mh::MenuItemMatcher() .label("Sound Settings…") @@ -681,21 +682,21 @@ TEST_F(TestIndicator, PhoneNotificationVolume) // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); - checkVolumeNotification(1.0, "", false, notificationsSpy.at(2)); + checkVolumeNotification(1.0, "Speakers", false, notificationsSpy.at(2)); notificationsSpy.clear(); setActionValue("volume", QVariant::fromValue(0.0)); WAIT_FOR_SIGNALS(notificationsSpy, 1) - checkVolumeNotification(0.0, "", false, notificationsSpy.at(0)); + checkVolumeNotification(0.0, "Speakers", false, notificationsSpy.at(0)); notificationsSpy.clear(); setActionValue("volume", QVariant::fromValue(0.5)); WAIT_FOR_SIGNALS(notificationsSpy, 1) - checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + checkVolumeNotification(0.5, "Speakers", false, notificationsSpy.at(0)); } TEST_F(TestIndicator, PhoneNotificationWarningVolume) @@ -729,13 +730,14 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) // change volume to 0.0... no warning should be emitted setActionValue("volume", QVariant::fromValue(0.0)); - WAIT_FOR_SIGNALS(notificationsSpy, 3); + WAIT_FOR_SIGNALS(notificationsSpy, 4); // the first time we also have the calls to // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); - checkVolumeNotification(0.0, "", false, notificationsSpy.at(2)); + checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(2)); + checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(3)); notificationsSpy.clear(); // change volume to 0.5... no warning should be emitted @@ -743,7 +745,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) WAIT_FOR_SIGNALS(notificationsSpy, 1); - checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(0)); notificationsSpy.clear(); // change volume to 1.0... warning should be emitted @@ -779,7 +781,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(0.74)) + .item(volumeSlider(0.74, "Volume (Headphones)")) ) ).match()); @@ -817,7 +819,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(1.0)) + .item(volumeSlider(1.0, "Volume (Headphones)")) .item(mh::MenuItemMatcher() .action("indicator.high-volume-warning-item") .label("High volume can damage your hearing.") @@ -835,8 +837,8 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) WAIT_FOR_SIGNALS(notificationsSpy, 2); // check the notification TODO check why the sound indicator sends it twice - checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); - checkVolumeNotification(0.5, "", false, notificationsSpy.at(1)); + checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(0)); + checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(1)); // check that the volume was applied // and that we don't have the warning item @@ -852,7 +854,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(0.5)) + .item(volumeSlider(0.5, "Volume (Headphones)")) ) ).match()); @@ -896,13 +898,14 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolumeAlertMode) // change volume to 0.0... no warning should be emitted setActionValue("volume", QVariant::fromValue(0.0)); - WAIT_FOR_SIGNALS(notificationsSpy, 3); + WAIT_FOR_SIGNALS(notificationsSpy, 4); // the first time we also have the calls to // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); - checkVolumeNotification(0.0, "", false, notificationsSpy.at(2)); + checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(2)); + checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(3)); notificationsSpy.clear(); // change volume to 0.5... no warning should be emitted @@ -910,7 +913,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolumeAlertMode) WAIT_FOR_SIGNALS(notificationsSpy, 1); - checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(0)); notificationsSpy.clear(); // change volume to 1.0... no warning should be emitted, we are in alert mode @@ -918,8 +921,28 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolumeAlertMode) WAIT_FOR_SIGNALS(notificationsSpy, 1); - checkVolumeNotification(1.0, "", false, notificationsSpy.at(0)); + checkVolumeNotification(1.0, "Headphones", false, notificationsSpy.at(0)); notificationsSpy.clear(); } +TEST_F(TestIndicator, PhoneNotificationHeadphoneSpeakerWiredLabels) +{ + checkPortDevicesLabels(WIRED, WIRED); +} + +TEST_F(TestIndicator, PhoneNotificationHeadphoneSpeakerBluetoothLabels) +{ + checkPortDevicesLabels(BLUETOOTH, BLUETOOTH); +} + +TEST_F(TestIndicator, PhoneNotificationHeadphoneSpeakerUSBLabels) +{ + checkPortDevicesLabels(USB, USB); +} + +TEST_F(TestIndicator, PhoneNotificationHeadphoneSpeakerHDMILabels) +{ + checkPortDevicesLabels(HDMI, HDMI); +} + } // namespace |