aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-23 16:10:54 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-23 16:10:54 +0200
commiteb22c54e4587e5941378b066ec8220a56d26db4b (patch)
treeae85ae46280dc6bd1c27c85bec9413c59c264808 /tests
parentb9ef4f6abdefb7b1d31d34f35b742016f1b5b87f (diff)
downloadayatana-indicator-sound-eb22c54e4587e5941378b066ec8220a56d26db4b.tar.gz
ayatana-indicator-sound-eb22c54e4587e5941378b066ec8220a56d26db4b.tar.bz2
ayatana-indicator-sound-eb22c54e4587e5941378b066ec8220a56d26db4b.zip
Added test MPRIS player integration test
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/integration/CMakeLists.txt5
-rw-r--r--tests/integration/indicator-sound-test-base.cpp36
-rw-r--r--tests/integration/indicator-sound-test-base.h6
-rw-r--r--tests/integration/test-indicator.cpp74
-rw-r--r--tests/service-mocks/CMakeLists.txt2
-rw-r--r--tests/service-mocks/DBusPropertiesNotifier.cpp (renamed from tests/accounts-mock/DBusPropertiesNotifier.cpp)0
-rw-r--r--tests/service-mocks/DBusPropertiesNotifier.h (renamed from tests/accounts-mock/DBusPropertiesNotifier.h)0
-rw-r--r--tests/service-mocks/accounts-mock/AccountsDefs.h (renamed from tests/accounts-mock/AccountsDefs.h)0
-rw-r--r--tests/service-mocks/accounts-mock/AccountsMock.cpp (renamed from tests/accounts-mock/AccountsMock.cpp)0
-rw-r--r--tests/service-mocks/accounts-mock/AccountsMock.h (renamed from tests/accounts-mock/AccountsMock.h)0
-rw-r--r--tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp (renamed from tests/accounts-mock/AccountsServiceSoundMock.cpp)0
-rw-r--r--tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h (renamed from tests/accounts-mock/AccountsServiceSoundMock.h)0
-rw-r--r--tests/service-mocks/accounts-mock/CMakeLists.txt (renamed from tests/accounts-mock/CMakeLists.txt)5
-rw-r--r--tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml (renamed from tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml)0
-rw-r--r--tests/service-mocks/accounts-mock/main.cpp (renamed from tests/accounts-mock/main.cpp)0
-rw-r--r--tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml (renamed from tests/accounts-mock/org.freedesktop.Accounts.Mock.xml)0
-rw-r--r--tests/service-mocks/media-player-mpris-mock/CMakeLists.txt63
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h37
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp103
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h77
-rw-r--r--tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop21
-rw-r--r--tests/service-mocks/media-player-mpris-mock/main.cpp64
-rw-r--r--tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml24
-rw-r--r--tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml6
-rw-r--r--tests/service-mocks/media-player-mpris-mock/player-update.cpp93
26 files changed, 594 insertions, 28 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d818a2d..adc08de 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -22,7 +22,8 @@ set_source_files_properties (gschemas.compiled GENERATED)
# GSettings:
# compile the indicator-sound schema into a gschemas.compiled file in this directory,
# and help the tests to find that file by setting -DSCHEMA_DIR
-set (SCHEMA_DIR "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas")
+set (XDG_DATA_DIRS "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas")
+set (SCHEMA_DIR "${XDG_DATA_DIRS}/glib-2.0/schemas")
add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}")
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas
OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
@@ -31,6 +32,7 @@ add_custom_command (OUTPUT gschemas.compiled
DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.sound.gschema.xml
COMMAND mkdir -p ${SCHEMA_DIR}
COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR}
+ COMMAND cp -f /usr/share/glib-2.0/schemas/com.ubuntu.sound.gschema.xml ${SCHEMA_DIR}
COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR})
###########################
@@ -281,4 +283,4 @@ add_test(indcator-test
add_subdirectory(integration)
add_subdirectory(dbus-types)
-add_subdirectory(accounts-mock) \ No newline at end of file
+add_subdirectory(service-mocks) \ No newline at end of file
diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt
index 52c4e70..5798f14 100644
--- a/tests/integration/CMakeLists.txt
+++ b/tests/integration/CMakeLists.txt
@@ -29,10 +29,11 @@ include_directories("${CMAKE_BINARY_DIR}/tests/dbus-types")
add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-service"
-DSTREAM_RESTORE_TABLE="${CMAKE_SOURCE_DIR}/tests/integration/touch-stream-restore.table"
-DVOLUME_SET_BIN="${CMAKE_BINARY_DIR}/tests/integration/set-volume"
- -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/accounts-mock/accounts-service-sound"
+ -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/accounts-mock/accounts-service-sound"
+ -DMEDIA_PLAYER_MPRIS_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/media-player-mpris-mock/media-player-mpris-mock"
-DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav"
-DQT_NO_KEYWORDS=1
- -DSCHEMA_DIR="${SCHEMA_DIR}"
+ -DXDG_DATA_DIRS="${XDG_DATA_DIRS}"
)
set(GLIB_REQUIRED_VERSION 2.26)
diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp
index bbede82..2b6b3d7 100644
--- a/tests/integration/indicator-sound-test-base.cpp
+++ b/tests/integration/indicator-sound-test-base.cpp
@@ -79,6 +79,36 @@ bool IndicatorSoundTestBase::setSinkVolume(double volume)
return setVolume.exitCode() == 0;
}
+bool IndicatorSoundTestBase::clearGSettingsPlayers()
+{
+ QProcess clearPlayers;
+
+ clearPlayers.start("gsettings", QStringList()
+ << "set"
+ << "com.canonical.indicator.sound"
+ << "interested-media-players"
+ << "[]");
+ if (!clearPlayers.waitForStarted())
+ return false;
+
+ if (!clearPlayers.waitForFinished())
+ return false;
+
+ return clearPlayers.exitCode() == 0;
+}
+
+bool IndicatorSoundTestBase::startTestMprisPlayer(QString const& playerName)
+{
+ testPlayer1.terminate();
+ testPlayer1.start(MEDIA_PLAYER_MPRIS_BIN, QStringList()
+ << playerName);
+ if (!testPlayer1.waitForStarted())
+ return false;
+
+
+ return true;
+}
+
bool IndicatorSoundTestBase::startTestSound(QString const &role)
{
testSoundProcess.terminate();
@@ -218,15 +248,13 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::phoneParameters()
void IndicatorSoundTestBase::SetUp()
{
- setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true);
- setenv("GSETTINGS_BACKEND", "memory", true);
+ setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, true);
setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true);
}
void IndicatorSoundTestBase::TearDown()
{
- unsetenv("GSETTINGS_SCHEMA_DIR");
- unsetenv("GSETTINGS_BACKEND");
+ unsetenv("XDG_DATA_DIRS");
unsetenv("PULSE_SERVER");
}
diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h
index 019efc9..741580b 100644
--- a/tests/integration/indicator-sound-test-base.h
+++ b/tests/integration/indicator-sound-test-base.h
@@ -49,6 +49,10 @@ protected:
void startPulsePhone();
void startAccountsService();
+ bool clearGSettingsPlayers();
+
+ bool startTestMprisPlayer(QString const& playerName);
+
bool setStreamRestoreVolume(QString const &role, double volume);
bool setSinkVolume(double volume);
@@ -85,6 +89,8 @@ protected:
QProcess testSoundProcess;
+ QProcess testPlayer1;
+
std::unique_ptr<MenusInterface> menu_interface_;
std::unique_ptr<DBusPropertiesInterface> accounts_interface_;
diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp
index a248658..ca3d298 100644
--- a/tests/integration/test-indicator.cpp
+++ b/tests/integration/test-indicator.cpp
@@ -143,6 +143,7 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume)
double INITIAL_VOLUME = 0.0;
ASSERT_NO_THROW(startAccountsService());
+ EXPECT_TRUE(clearGSettingsPlayers());
ASSERT_NO_THROW(startPulsePhone());
// initialize volumes in pulseaudio
@@ -151,7 +152,6 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume)
// 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")
@@ -159,23 +159,17 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume)
.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)
+ .mode(mh::MenuItemMatcher::Mode::all)
.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()
+// .section()
+// .action("indicator.testplayer1.desktop")
+// )
.item(mh::MenuItemMatcher()
.label("Sound Settings…")
.action("indicator.phone-settings")
@@ -188,6 +182,7 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume)
double INITIAL_VOLUME = 0.0;
ASSERT_NO_THROW(startAccountsService());
+ EXPECT_TRUE(clearGSettingsPlayers());
ASSERT_NO_THROW(startPulseDesktop());
// initialize volumes in pulseaudio
@@ -197,13 +192,12 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume)
// 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()
.action("indicator.root")
.string_attribute("x-canonical-type", "com.canonical.indicator.root")
.string_attribute("x-canonical-secondary-action", "indicator.mute")
- .mode(mh::MenuItemMatcher::Mode::starts_with)
+ .mode(mh::MenuItemMatcher::Mode::all)
.submenu()
.item(mh::MenuItemMatcher()
.section()
@@ -212,19 +206,63 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume)
)
.item(volumeSlider(INITIAL_VOLUME))
)
+ .item(mh::MenuItemMatcher()
+ .label("Sound Settings…")
+ )
).match());
+}
- // check that the last item is Sound Settings
+TEST_F(TestIndicator, DesktopAddPlayer)
+{
+ double INITIAL_VOLUME = 0.0;
+
+ ASSERT_NO_THROW(startAccountsService());
+ EXPECT_TRUE(clearGSettingsPlayers());
+ ASSERT_NO_THROW(startPulseDesktop());
+
+ // initialize volumes in pulseaudio
+ EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME));
+ EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME));
+
+ // start the test player
+ EXPECT_TRUE(startTestMprisPlayer("testplayer1"));
+
+ // start now the indicator, so it picks the new volumes
+ ASSERT_NO_THROW(startIndicator());
+
+ // check that the player is added
EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters())
.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)
+ .mode(mh::MenuItemMatcher::Mode::all)
.submenu()
.item(mh::MenuItemMatcher()
- .label("Sound Settings…")
+ .section()
+ .item(mh::MenuItemMatcher().checkbox()
+ .label("Mute")
+ )
+ .item(volumeSlider(INITIAL_VOLUME))
)
+ .item(mh::MenuItemMatcher()
+ .section()
+ .item(mh::MenuItemMatcher()
+ .action("indicator.testplayer1.desktop")
+ .label("TestPlayer1")
+ .themed_icon("icon", {"testplayer"})
+ .string_attribute("x-canonical-type", "com.canonical.unity.media-player")
+ )
+ .item(mh::MenuItemMatcher()
+ .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop")
+ .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop")
+ .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop")
+ .string_attribute("x-canonical-type","com.canonical.unity.playback-item")
+ )
+ )
+ .item(mh::MenuItemMatcher()
+ .label("Sound Settings…")
+ )
).match());
}
@@ -252,7 +290,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume)
int randInt = qrand() % 100;
double randomVolume = randInt / 100.0;
-// // play a test sound, it should NOT change the role in the indicator
+ // play a test sound, it should NOT change the role in the indicator
EXPECT_TRUE(startTestSound("multimedia"));
EXPECT_FALSE(waitVolumeChangedInIndicator());
diff --git a/tests/service-mocks/CMakeLists.txt b/tests/service-mocks/CMakeLists.txt
new file mode 100644
index 0000000..9cd8acb
--- /dev/null
+++ b/tests/service-mocks/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(accounts-mock)
+add_subdirectory(media-player-mpris-mock)
diff --git a/tests/accounts-mock/DBusPropertiesNotifier.cpp b/tests/service-mocks/DBusPropertiesNotifier.cpp
index 686e4e9..686e4e9 100644
--- a/tests/accounts-mock/DBusPropertiesNotifier.cpp
+++ b/tests/service-mocks/DBusPropertiesNotifier.cpp
diff --git a/tests/accounts-mock/DBusPropertiesNotifier.h b/tests/service-mocks/DBusPropertiesNotifier.h
index 9fa013b..9fa013b 100644
--- a/tests/accounts-mock/DBusPropertiesNotifier.h
+++ b/tests/service-mocks/DBusPropertiesNotifier.h
diff --git a/tests/accounts-mock/AccountsDefs.h b/tests/service-mocks/accounts-mock/AccountsDefs.h
index 0e4f270..0e4f270 100644
--- a/tests/accounts-mock/AccountsDefs.h
+++ b/tests/service-mocks/accounts-mock/AccountsDefs.h
diff --git a/tests/accounts-mock/AccountsMock.cpp b/tests/service-mocks/accounts-mock/AccountsMock.cpp
index 5c92dc5..5c92dc5 100644
--- a/tests/accounts-mock/AccountsMock.cpp
+++ b/tests/service-mocks/accounts-mock/AccountsMock.cpp
diff --git a/tests/accounts-mock/AccountsMock.h b/tests/service-mocks/accounts-mock/AccountsMock.h
index 72372e0..72372e0 100644
--- a/tests/accounts-mock/AccountsMock.h
+++ b/tests/service-mocks/accounts-mock/AccountsMock.h
diff --git a/tests/accounts-mock/AccountsServiceSoundMock.cpp b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp
index 37de377..37de377 100644
--- a/tests/accounts-mock/AccountsServiceSoundMock.cpp
+++ b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp
diff --git a/tests/accounts-mock/AccountsServiceSoundMock.h b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h
index bb3dbe8..bb3dbe8 100644
--- a/tests/accounts-mock/AccountsServiceSoundMock.h
+++ b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h
diff --git a/tests/accounts-mock/CMakeLists.txt b/tests/service-mocks/accounts-mock/CMakeLists.txt
index aab7940..bc71a8b 100644
--- a/tests/accounts-mock/CMakeLists.txt
+++ b/tests/service-mocks/accounts-mock/CMakeLists.txt
@@ -2,7 +2,8 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5DBus REQUIRED)
-include_directories(${Qt5DBus_INCLUDE_DIRS})
+include_directories(${Qt5DBus_INCLUDE_DIRS}
+ "${CMAKE_SOURCE_DIR}/tests/service-mocks")
add_definitions(-DQT_NO_KEYWORDS=1)
@@ -30,7 +31,7 @@ add_executable(
${adaptor_files}
AccountsServiceSoundMock.cpp
AccountsMock.cpp
- DBusPropertiesNotifier.cpp
+ ${CMAKE_SOURCE_DIR}/tests/service-mocks/DBusPropertiesNotifier.cpp
main.cpp
)
diff --git a/tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml b/tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml
index 859cd46..859cd46 100644
--- a/tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml
+++ b/tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml
diff --git a/tests/accounts-mock/main.cpp b/tests/service-mocks/accounts-mock/main.cpp
index d6cd1d3..d6cd1d3 100644
--- a/tests/accounts-mock/main.cpp
+++ b/tests/service-mocks/accounts-mock/main.cpp
diff --git a/tests/accounts-mock/org.freedesktop.Accounts.Mock.xml b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml
index f284d54..f284d54 100644
--- a/tests/accounts-mock/org.freedesktop.Accounts.Mock.xml
+++ b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml
diff --git a/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt b/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt
new file mode 100644
index 0000000..a1f9e83
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt
@@ -0,0 +1,63 @@
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fPIC -pthread")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -Wextra -fPIC -pthread")
+
+find_package(Qt5DBus REQUIRED)
+include_directories(${Qt5DBus_INCLUDE_DIRS}
+ "${CMAKE_SOURCE_DIR}/tests/service-mocks")
+
+add_definitions(-DQT_NO_KEYWORDS=1)
+
+set(dbusinterface_mediaplayermpris_xml "org.mpris.MediaPlayer2.Player.xml")
+set_source_files_properties(${dbusinterface_mediaplayermpris_xml} PROPERTIES
+ CLASSNAME MediaPlayerMprisMockInterface)
+
+qt5_add_dbus_interface(interface_files ${dbusinterface_mediaplayermpris_xml} MediaPlayerMprisMockInterface)
+
+qt5_add_dbus_adaptor(adaptor_files
+ org.mpris.MediaPlayer2.Player.xml
+ MediaPlayerMprisMock.h
+ ubuntu::indicators::testing::MediaPlayerMprisMock
+ MediaPlayerMprisMockAdaptor)
+
+qt5_add_dbus_adaptor(adaptor_files
+ org.mpris.MediaPlayer2.xml
+ MediaPlayerMprisMock.h
+ ubuntu::indicators::testing::MediaPlayerMprisMock
+ MediaPlayer2MockAdaptor)
+
+add_executable(
+ media-player-mpris-mock
+ ${adaptor_files}
+ MediaPlayerMprisMock.cpp
+ ${CMAKE_SOURCE_DIR}/tests/service-mocks/DBusPropertiesNotifier.cpp
+ main.cpp
+ testplayers
+)
+
+add_executable(
+ media-player-mpris-mock-update
+ ${interface_files}
+ player-update.cpp
+ testplayers
+)
+
+qt5_use_modules(
+ media-player-mpris-mock
+ Core
+ DBus
+)
+
+qt5_use_modules(
+ media-player-mpris-mock-update
+ Core
+ DBus
+)
+
+# test players desktop files
+add_custom_command (OUTPUT testplayers
+ DEPENDS ${CMAKE_SOURCE_DIR}/tests/service-mocks/media-player-mpris-mock/applications
+ COMMAND mkdir -p ${SCHEMA_DIR}
+ COMMAND cp -r ${CMAKE_SOURCE_DIR}/tests/service-mocks/media-player-mpris-mock/applications ${SCHEMA_DIR})
diff --git a/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h
new file mode 100644
index 0000000..4d28b38
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+namespace ubuntu
+{
+
+namespace indicators
+{
+
+namespace testing
+{
+ constexpr const char MEDIA_PLAYER_MPRIS_SERVICE[] = "org.freedesktop.Accounts";
+ constexpr const char USER_PATH[] = "/org/freedesktop/Accounts/UserTest";
+ constexpr const char ACCOUNTS_PATH[] = "/org/freedesktop/Accounts";
+ constexpr const char ACCOUNTS_SOUND_INTERFACE[] = "com.ubuntu.AccountsService.Sound";
+} // namespace testing
+
+} // namespace indicators
+
+} // namespace ubuntu
+
diff --git a/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp
new file mode 100644
index 0000000..25fe0b7
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QDebug>
+
+#include "MediaPlayerMprisMock.h"
+
+using namespace ubuntu::indicators::testing;
+
+MediaPlayerMprisMock::MediaPlayerMprisMock(QString const &playerName, QObject* parent)
+ : QObject(parent)
+ , can_play_(true)
+ , can_pause_(true)
+ , can_gonext_(true)
+ , can_goprevious_(true)
+ , player_name_(playerName)
+{
+}
+
+MediaPlayerMprisMock::~MediaPlayerMprisMock() = default;
+
+bool MediaPlayerMprisMock::canPlay() const
+{
+ return can_play_;
+}
+
+void MediaPlayerMprisMock::setCanPlay(bool canPlay)
+{
+ can_play_ = canPlay;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanPlay",
+ property("CanPlay"));
+}
+
+bool MediaPlayerMprisMock::canPause() const
+{
+ return can_pause_;
+}
+
+void MediaPlayerMprisMock::setCanPause(bool canPause)
+{
+ can_pause_ = canPause;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanPause",
+ property("CanPause"));
+}
+
+bool MediaPlayerMprisMock::canGoNext() const
+{
+ return can_gonext_;
+}
+
+void MediaPlayerMprisMock::setCanGoNext(bool canGoNext)
+{
+ can_gonext_ = canGoNext;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanGoNext",
+ property("CanGoNext"));
+}
+
+bool MediaPlayerMprisMock::canGoPrevious() const
+{
+ return can_goprevious_;
+}
+
+void MediaPlayerMprisMock::setCanGoPrevious(bool canGoPrevious)
+{
+ can_goprevious_ = canGoPrevious;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanGoPrevious",
+ property("CanGoPrevious"));
+}
+
+QString MediaPlayerMprisMock::desktopEntry() const
+{
+ return player_name_;
+}
+
+void MediaPlayerMprisMock::setDesktopEntry(QString const &)
+{
+}
diff --git a/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h
new file mode 100644
index 0000000..58dce8d
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+#include <QDBusContext>
+#include <QDBusObjectPath>
+#include <QObject>
+
+#include "DBusPropertiesNotifier.h"
+
+namespace ubuntu
+{
+
+namespace indicators
+{
+
+namespace testing
+{
+
+class MediaPlayerMprisMock : public QObject, protected QDBusContext
+{
+ Q_OBJECT
+ Q_PROPERTY(bool CanPlay READ canPlay WRITE setCanPlay)
+ Q_PROPERTY(bool CanPause READ canPause WRITE setCanPause)
+ Q_PROPERTY(bool CanGoNext READ canGoNext WRITE setCanGoNext)
+ Q_PROPERTY(bool CanGoPrevious READ canGoPrevious WRITE setCanGoPrevious)
+ Q_PROPERTY(QString DesktopEntry READ desktopEntry WRITE setDesktopEntry)
+
+public Q_SLOTS:
+ bool canPlay() const;
+ void setCanPlay(bool canPlay);
+
+ bool canPause() const;
+ void setCanPause(bool canPause);
+
+ bool canGoNext() const;
+ void setCanGoNext(bool canGoNext);
+
+ bool canGoPrevious() const;
+ void setCanGoPrevious(bool canGoPrevious);
+
+ QString desktopEntry() const;
+ void setDesktopEntry(QString const &destopEntry);
+
+public:
+ MediaPlayerMprisMock(QString const &playerName, QObject* parent = 0);
+ virtual ~MediaPlayerMprisMock();
+
+private:
+ bool can_play_;
+ bool can_pause_;
+ bool can_gonext_;
+ bool can_goprevious_;
+ DBusPropertiesNotifier notifier_;
+ QString player_name_;
+};
+
+} // namespace testing
+
+} // namespace indicators
+
+} // namespace ubuntu
diff --git a/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop b/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop
new file mode 100644
index 0000000..2ed5008
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Name=TestPlayer1
+GenericName=Test Player 1
+X-GNOME-FullName=Test Player 1
+Comment=Play and organize your music collection
+Keywords=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio;
+Exec=echo %U
+Terminal=false
+Type=Application
+Icon=testplayer
+X-GNOME-DocPath=testplayer/testplayer.xml
+Categories=GNOME;GTK;AudioVideo;Audio;Player;
+MimeType=application/x-ogg;application/ogg;audio/x-vorbis+ogg;audio/x-scpls;audio/x-mp3;audio/x-mpeg;audio/mpeg;audio/x-mpegurl;audio/x-flac;audio/mp4;x-scheme-handler/itms;x-scheme-handler/itmss;
+StartupNotify=true
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=testplayer
+X-GNOME-Bugzilla-Component=general
+X-GNOME-Bugzilla-OtherBinaries=rhythmbox-client;rhythmbox-metadata;
+X-GNOME-Bugzilla-Version=3.1
+X-GNOME-UsesNotifications=true
+
diff --git a/tests/service-mocks/media-player-mpris-mock/main.cpp b/tests/service-mocks/media-player-mpris-mock/main.cpp
new file mode 100644
index 0000000..8945673
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/main.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusConnectionInterface>
+
+#include <string>
+
+#include "MediaPlayerMprisDefs.h"
+#include "MediaPlayerMprisMock.h"
+#include "MediaPlayerMprisMockAdaptor.h"
+#include "MediaPlayer2MockAdaptor.h"
+
+using namespace ubuntu::indicators::testing;
+
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ qWarning() << "usage: " << argv[0] << "TEST_PLAYER_NAME";
+ return 1;
+ }
+ QString playerName = QString(argv[1]);
+
+ QCoreApplication app(argc, argv);
+ QString playerService = QString("org.mpris.MediaPlayer2.") + playerName;
+ QDBusConnection connection = QDBusConnection::sessionBus();
+ if (!connection.interface()->isServiceRegistered(playerService))
+ {
+ auto service = new MediaPlayerMprisMock(playerName, &app);
+ new PlayerAdaptor(service);
+ new MediaPlayer2Adaptor(service);
+
+ if (!connection.registerService(playerService))
+ {
+ qDebug() << connection.lastError();
+ qFatal("Could not register MediaPlayerMprisMock service.");
+ }
+
+ if (!connection.registerObject("/org/mpris/MediaPlayer2", service))
+ {
+ qFatal("Could not register MediaPlayerMprisMock object.");
+ }
+ }
+ else
+ {
+ qDebug() << "Service is already registered!.";
+ }
+ return app.exec();
+}
diff --git a/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml
new file mode 100644
index 0000000..3efd002
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml
@@ -0,0 +1,24 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.mpris.MediaPlayer2.Player">
+ <property name="CanPlay" type="b" access="read"/>
+ <method name="setCanPlay">
+ <arg direction="in" type="b" name="canPlay" />
+ </method>
+
+ <property name="CanPause" type="b" access="read"/>
+ <method name="setCanPause">
+ <arg direction="in" type="b" name="canPause" />
+ </method>
+
+ <property name="CanGoNext" type="b" access="read"/>
+ <method name="setCanGoNext">
+ <arg direction="in" type="b" name="canGoNext" />
+ </method>
+
+ <property name="CanGoPrevious" type="b" access="read"/>
+ <method name="setCanGoPrevious">
+ <arg direction="in" type="b" name="canGoPrevious" />
+ </method>
+ </interface>
+</node>
diff --git a/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml
new file mode 100644
index 0000000..489c68a
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml
@@ -0,0 +1,6 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.mpris.MediaPlayer2">
+ <property name="DesktopEntry" type="s" access="read"/>
+ </interface>
+</node>
diff --git a/tests/service-mocks/media-player-mpris-mock/player-update.cpp b/tests/service-mocks/media-player-mpris-mock/player-update.cpp
new file mode 100644
index 0000000..5768372
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/player-update.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include "MediaPlayerMprisMockInterface.h"
+
+#include <memory>
+
+QMap<QString, QString> getPropertiesMap()
+{
+ QMap<QString, QString> retMap;
+
+ retMap["CANPLAY"] = "setCanPlay";
+ retMap["CANPAUSE"] = "setCanPause";
+ retMap["CANGONEXT"] = "setCanGoNext";
+ retMap["CANGOPREVIOUS"] = "setCanGoPrevious";
+
+ return retMap;
+}
+
+bool getBoolValue(QString const & str)
+{
+ if (str == "TRUE")
+ {
+ return true;
+ }
+ return false;
+}
+
+QTextStream& qStdErr()
+{
+ static QTextStream ts( stderr );
+ return ts;
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (argc != 4)
+ {
+ qStdErr() << "usage: " << argv[0] << "TEST_PLAYER_NAME PropertyName true|false\n";
+ return 1;
+ }
+
+ QString state = QString(argv[3]).toUpper();
+ QString property = QString(argv[2]).toUpper();
+ QString playerName = QString(argv[1]);
+
+ auto propertiesMap = getPropertiesMap();
+
+ std::shared_ptr<MediaPlayerMprisMockInterface> iface(
+ new MediaPlayerMprisMockInterface("org.mpris.MediaPlayer2." + playerName,
+ "/org/mpris/MediaPlayer2",
+ QDBusConnection::sessionBus()));
+ if (!iface)
+ {
+ qWarning() << argv[0] << ": error creating interface";
+ return 1;
+ }
+
+ QMap<QString, QString>::iterator iter = propertiesMap.find(property);
+ if (iter == propertiesMap.end())
+ {
+ qWarning() << argv[0] << ": property " << property << " was not found.";
+ return 1;
+ }
+
+ QDBusReply<void> set_prop = iface->call(QLatin1String((*iter).toStdString().c_str()),
+ QVariant::fromValue(getBoolValue(state)));
+
+ if (!set_prop.isValid())
+ {
+ qWarning() << argv[0] << ": D-Bus error: " << set_prop.error().message();
+ return 1;
+ }
+
+ return 0;
+}
+