on bionic help sign in
unity8/tests/plugins/Utils/URLDispatcherTest.cpp
78 lines 2.3 kB history raw
1/*
2 * Copyright (C) 2016 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 */
17#include "URLDispatcher.h"
19#include <QDBusInterface>
20#include <QSignalSpy>
21#include <QTest>
23class URLDispatcherTest : public QObject
25 Q_OBJECT
27private Q_SLOTS:
29 void initTestCase() {
30 dispatchServer = new QDBusInterface("com.canonical.URLDispatcher",
31 "/com/canonical/URLDispatcher",
32 "com.canonical.URLDispatcher",
33 QDBusConnection::sessionBus(), this);
34 }
36 void init()
37 {
38 dispatcher = new URLDispatcher(this);
39 dispatchSpy = new QSignalSpy(dispatcher,
40 SIGNAL(urlRequested(const QString &)));
41 }
43 void cleanup()
44 {
45 delete dispatcher;
46 }
48 void testInactiveByDefault() {
49 QVERIFY(!dispatcher->active());
50 }
52 void testActiveRequest() {
53 dispatcher->setActive(true);
54 dispatchServer->call("DispatchURL", "test:", "package");
55 QCOMPARE(dispatchSpy->count(), 1);
56 QCOMPARE((*dispatchSpy)[0][0], QVariant("test:"));
57 }
59 void testInactiveRequest() {
60 dispatchServer->call("DispatchURL", "test:", "package");
61 QCOMPARE(dispatchSpy->count(), 0);
62 }
64 void testInactiveAfterActiveRequest() {
65 dispatcher->setActive(true);
66 dispatcher->setActive(false);
67 dispatchServer->call("DispatchURL", "test:", "package");
68 QCOMPARE(dispatchSpy->count(), 0);
69 }
71private:
72 QDBusInterface *dispatchServer;
73 URLDispatcher *dispatcher;
74 QSignalSpy *dispatchSpy;
75};
77QTEST_GUILESS_MAIN(URLDispatcherTest)
78#include "URLDispatcherTest.moc"