on xenial help sign in
adding DownloadDaemonListener mock
9ec5276Diego Sarmentero
Dash/Apps/AppPreview.qml+1
@@ -117,6 +117,7 @@ DashPreview {
117 }
117 }
118
118
119 DownloadTracker {
119 DownloadTracker {
120+ service: "com.canonical.applications.Downloader"
120 dbusPath: root.previewData.infoMap["progressbar_source"] ? root.previewData.infoMap["progressbar_source"].value : ""
121 dbusPath: root.previewData.infoMap["progressbar_source"] ? root.previewData.infoMap["progressbar_source"].value : ""
121
122
122 onProgress: {
123 onProgress: {
plugins/Ubuntu/DownloadDaemonListener/download_tracker.cpp+16−1
@@ -41,7 +41,22 @@ void DownloadTracker::setDbusPath(QString& path)
41{
41{
42 if(path != ""){
42 if(path != ""){
43 this->m_dbusPath = path;
43 this->m_dbusPath = path;
44+ this->startService();
45+ }
46+}
47+
48+void DownloadTracker::setService(QString& service)
49+{
50+ if(service != ""){
51+ this->m_service = service;
52+ this->startService();
53+ }
54+}
55+
56+void DownloadTracker::startService()
57+{
58+ if(!this->m_service.isEmpty() && !this->m_dbusPath.isEmpty()) {
44− this->adaptor = new DownloadTrackerAdaptor("com.canonical.applications.Downloader", this->m_dbusPath, QDBusConnection::sessionBus(), 0);
59+ this->adaptor = new DownloadTrackerAdaptor(this->m_service, this->m_dbusPath, QDBusConnection::sessionBus(), 0);
45
60
46 this->connect(this->adaptor, SIGNAL(canceled(bool)), this, SIGNAL(canceled(bool)));
61 this->connect(this->adaptor, SIGNAL(canceled(bool)), this, SIGNAL(canceled(bool)));
47 this->connect(this->adaptor, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
62 this->connect(this->adaptor, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
plugins/Ubuntu/DownloadDaemonListener/download_tracker.h+5
@@ -31,6 +31,7 @@ class DownloadTracker : public QObject
31{
31{
32 Q_OBJECT
32 Q_OBJECT
33 Q_DISABLE_COPY(DownloadTracker)
33 Q_DISABLE_COPY(DownloadTracker)
34+ Q_PROPERTY(QString service WRITE setService)
34 Q_PROPERTY(QString dbusPath WRITE setDbusPath)
35 Q_PROPERTY(QString dbusPath WRITE setDbusPath)
35 Q_PROPERTY(bool serviceReady READ isServiceReady)
36 Q_PROPERTY(bool serviceReady READ isServiceReady)
36
37
@@ -38,6 +39,7 @@ public:
38 explicit DownloadTracker(QObject *parent = 0);
39 explicit DownloadTracker(QObject *parent = 0);
39
40
40 void setDbusPath(QString& path);
41 void setDbusPath(QString& path);
42+ void setService(QString& service);
41 bool isServiceReady();
43 bool isServiceReady();
42
44
43Q_SIGNALS:
45Q_SIGNALS:
@@ -51,7 +53,10 @@ Q_SIGNALS:
51
53
52private:
54private:
53 QString m_dbusPath;
55 QString m_dbusPath;
56+ QString m_service;
54 DownloadTrackerAdaptor* adaptor;
57 DownloadTrackerAdaptor* adaptor;
58+
59+ void startService();
55};
60};
56
61
57#endif // MYTYPE_H
62#endif // MYTYPE_H
tests/mocks/Ubuntu/CMakeLists.txt+1
@@ -1 +1,2 @@
1add_subdirectory(Application)
1add_subdirectory(Application)
2+add_subdirectory(DownloadDaemonListener)
tests/mocks/Ubuntu/DownloadDaemonListener/CMakeLists.txtnew file+24
@@ -0,0 +1,24 @@
1+set(CMAKE_AUTOMOC ON)
2+
3+include(FindPkgConfig)
4+find_package(Qt5Core REQUIRED)
5+find_package(Qt5Quick REQUIRED)
6+
7+set(FakeUbuntuDownloadDaemonListenerQml_SOURCES
8+ plugin.cpp
9+ download_tracker.cpp
10+)
11+
12+add_library(FakeUbuntuDownloadDaemonListenerQml MODULE ${FakeUbuntuDownloadDaemonListenerQml_SOURCES})
13+
14+qt5_use_modules(FakeUbuntuDownloadDaemonListenerQml Core Quick)
15+
16+# copy files into build directory for shadow builds
17+add_custom_target(UbuntuDownloadQmlDirFile ALL
18+ COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
19+ DEPENDS qmldir
20+)
21+
22+install(TARGETS FakeUbuntuDownloadDaemonListenerQml
23+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/Ubuntu/DownloadDaemonListener
24+ )
tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.cppnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2013 - Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ *
18+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19+ */
20+
21+
22+#include "download_tracker.h"
23+
24+DownloadTracker::DownloadTracker(QObject *parent) :
25+ QObject(parent)
26+{
27+}
28+
29+bool DownloadTracker::isServiceReady()
30+{
31+ return active;
32+}
33+
34+void DownloadTracker::setDbusPath(QString& path)
35+{
36+ if(path != ""){
37+ this->m_dbusPath = path;
38+ this->startService();
39+ }
40+}
41+
42+void DownloadTracker::setService(QString& service)
43+{
44+ if(service != ""){
45+ this->m_service = service;
46+ this->startService();
47+ }
48+}
49+
50+void DownloadTracker::startService()
51+{
52+ if(!this->m_service.isEmpty() && !this->m_dbusPath.isEmpty()) {
53+ this->active = true;
54+ }
55+}
tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.hnew file+60
@@ -0,0 +1,60 @@
1+/*
2+ * Copyright (C) 2013 - Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ *
18+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19+ */
20+
21+
22+#ifndef MYTYPE_H
23+#define MYTYPE_H
24+
25+#include <QObject>
26+#include <QList>
27+
28+class DownloadTracker : public QObject
29+{
30+ Q_OBJECT
31+ Q_DISABLE_COPY(DownloadTracker)
32+ Q_PROPERTY(QString service WRITE setService)
33+ Q_PROPERTY(QString dbusPath WRITE setDbusPath)
34+ Q_PROPERTY(bool serviceReady READ isServiceReady)
35+
36+public:
37+ explicit DownloadTracker(QObject *parent = 0);
38+
39+ void setDbusPath(QString& path);
40+ void setService(QString& service);
41+ bool isServiceReady();
42+
43+Q_SIGNALS:
44+ void canceled(bool success);
45+ void error(const QString &error);
46+ void finished(const QString &path);
47+ void paused(bool success);
48+ void progress(qulonglong received, qulonglong total);
49+ void resumed(bool success);
50+ void started(bool success);
51+
52+private:
53+ QString m_dbusPath;
54+ QString m_service;
55+ bool active = false;
56+
57+ void startService();
58+};
59+
60+#endif // MYTYPE_H
tests/mocks/Ubuntu/DownloadDaemonListener/plugin.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+#include "download_tracker.h"
19+
20+#include <QtQml>
21+#include <QtQml/QQmlContext>
22+#include <qqml.h>
23+
24+
25+void FakeUbuntuDownloadDaemonListenerQmlPlugin::registerTypes(const char *uri)
26+{
27+ qmlRegisterType<DownloadTracker>(uri, 0, 1, "DownloadTracker");
28+}
tests/mocks/Ubuntu/DownloadDaemonListener/plugin.hnew file+30
@@ -0,0 +1,30 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef PLUGIN_H
18+#define PLUGIN_H
19+
20+#include <QQmlExtensionPlugin>
21+
22+class FakeUbuntuDownloadDaemonListenerQmlPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+public:
27+ void registerTypes(const char *uri);
28+};
29+
30+#endif
tests/mocks/Ubuntu/DownloadDaemonListener/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Ubuntu.DownloadDaemonListener
2+plugin FakeUbuntuDownloadDaemonListenerQml
tests/qmltests/Dash/Apps/tst_AppPreview.qml+2−1
@@ -99,7 +99,8 @@ Item {
99 when: windowShown
99 when: windowShown
100
100
101 function cleanup() {
101 function cleanup() {
102− sendReviewSpy.clear();
102+ sendPreviewSpy.clear();
103+ var reviewField = findChild(appPreview, "reviewField");
103 reviewField.focus = false;
104 reviewField.focus = false;
104 reviewField.text = "";
105 reviewField.text = "";
105 }
106 }