From 22de41f3cc382adbf06be8642af5cfa7ec664c8e Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 21 Sep 2015 16:01:33 +0200 Subject: Added separated integration tests for desktop and phone, with different instances of pulseaudio --- tests/integration/test-indicator.cpp | 186 +++++++++++++++++++++++++++++++---- 1 file changed, 169 insertions(+), 17 deletions(-) (limited to 'tests/integration/test-indicator.cpp') diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index bb5adec..a248658 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -32,16 +32,15 @@ class TestIndicator: public IndicatorSoundTestBase { }; -TEST_F(TestIndicator, ChangeRoleVolume) +TEST_F(TestIndicator, PhoneChangeRoleVolume) { double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); - ASSERT_NO_THROW(startPulse()); + ASSERT_NO_THROW(startPulsePhone()); // initialize volumes in pulseaudio - EXPECT_TRUE(setVolume("mutimedia", INITIAL_VOLUME)); - EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); @@ -53,7 +52,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) double randomVolume = randInt / 100.0; // set an initial volume to the alert role - setVolume("alert", 1.0); + setStreamRestoreVolume("alert", 1.0); EXPECT_TRUE(waitVolumeChangedInIndicator()); // play a test sound, it should change the role in the indicator @@ -61,31 +60,31 @@ TEST_F(TestIndicator, ChangeRoleVolume) EXPECT_TRUE(waitVolumeChangedInIndicator()); // set the random volume to the multimedia role - EXPECT_TRUE(setVolume("multimedia", randomVolume)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", randomVolume)); if (randomVolume != INITIAL_VOLUME) { EXPECT_TRUE(waitVolumeChangedInIndicator()); } // check the indicator - EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + 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(mh::MenuItemMatcher().checkbox() - .label("Mute") - ) + .item(silentModeSwitch(false)) .item(volumeSlider(randomVolume)) ) ).match()); // check that the last item is Sound Settings - EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") .string_attribute("x-canonical-type", "com.canonical.indicator.root") @@ -94,6 +93,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) .submenu() .item(mh::MenuItemMatcher() .label("Sound Settings…") + .action("indicator.phone-settings") ) ).match()); @@ -106,6 +106,97 @@ TEST_F(TestIndicator, ChangeRoleVolume) EXPECT_TRUE(waitVolumeChangedInIndicator()); } + // check the initial volume for the alert role + 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)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); +} + +TEST_F(TestIndicator, PhoneBasicInitialVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // check the initial volume for the alert role + 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(INITIAL_VOLUME)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); +} + +TEST_F(TestIndicator, DesktopBasicInitialVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulseDesktop()); + + // initialize volumes in pulseaudio + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + // check the initial volume for the alert role EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() @@ -119,7 +210,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(1.0)) + .item(volumeSlider(INITIAL_VOLUME)) ) ).match()); @@ -137,20 +228,42 @@ TEST_F(TestIndicator, ChangeRoleVolume) ).match()); } -TEST_F(TestIndicator, BasicInitialVolume) +TEST_F(TestIndicator, DesktopChangeRoleVolume) { double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); - ASSERT_NO_THROW(startPulse()); + ASSERT_NO_THROW(startPulseDesktop()); // initialize volumes in pulseaudio - EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + // expect false for stream restore, because the module + // is not loaded in the desktop pulseaudio instance + EXPECT_FALSE(setStreamRestoreVolume("mutimedia", INITIAL_VOLUME)); + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // check the initial volume for the alert role + // Generate a random volume + QTime now = QTime::currentTime(); + qsrand(now.msec()); + int randInt = qrand() % 100; + double randomVolume = randInt / 100.0; + +// // play a test sound, it should NOT change the role in the indicator + EXPECT_TRUE(startTestSound("multimedia")); + EXPECT_FALSE(waitVolumeChangedInIndicator()); + + // set the random volume + EXPECT_TRUE(setSinkVolume(randomVolume)); + if (randomVolume != INITIAL_VOLUME) + { + EXPECT_FALSE(waitVolumeChangedInIndicator()); + } + + // check the indicator EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") @@ -163,7 +276,7 @@ TEST_F(TestIndicator, BasicInitialVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(randomVolume)) ) ).match()); @@ -179,6 +292,45 @@ TEST_F(TestIndicator, BasicInitialVolume) .label("Sound Settings…") ) ).match()); + + // stop the test sound, the role should change again to alert + stopTestSound(); + + // although we were playing something in the multimedia role + // the server does not have the streamrestore module, so + // the volume does not change (the role does not change) + EXPECT_FALSE(waitVolumeChangedInIndicator()); + + // check the initial volume for the alert role + 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(randomVolume)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); } } // namespace -- cgit v1.2.3