on ee2f4bd help sign in
unity8/tests/plugins/GlobalShortcut/GlobalShortcutTest.cpp
77 lines 2.5 kB history raw
1/*
2 * Copyright (C) 2015 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 "globalshortcut.h"
19#include <QtTest>
20#include <QtQuick/QQuickView>
21#include <QtQuick/QQuickItem>
22#include <QQmlEngine>
24class GlobalShortcutTest: public QObject
26 Q_OBJECT
28private Q_SLOTS:
30 void initTestCase()
31 {
32 m_view = new QQuickView();
33 m_view->engine()->addImportPath(BUILT_PLUGINS_DIR);
34 m_view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/shortcut.qml"));
35 m_shortcut = dynamic_cast<GlobalShortcut*>(m_view->rootObject()->property("shortcut").value<QObject*>());
36 QVERIFY(m_shortcut);
37 m_inactiveShortcut = dynamic_cast<GlobalShortcut*>(m_view->rootObject()->property("inactiveShortcut").value<QObject*>());
38 QVERIFY(m_inactiveShortcut);
39 m_view->show();
40 QTest::qWaitForWindowExposed(m_view);
41 }
43 void cleanupTestCase()
44 {
45 m_view.clear();
46 }
48 void testGlobalShortcut()
49 {
50 QSignalSpy shortcutSpy(m_shortcut, &GlobalShortcut::triggered);
51 // test pressing "Mute Volume"
52 QTest::keyClick(m_view, Qt::Key_VolumeMute);
53 QTRY_COMPARE(shortcutSpy.count(), 1);
54 const QVariantList args = shortcutSpy.takeFirst();
55 // verify we got the signal back and a non-empty shortcut
56 QCOMPARE(args.count(), 1);
57 QVERIFY(!args.first().toString().isEmpty());
58 }
60 void testInactiveGlobalShortcut()
61 {
62 QSignalSpy shortcutSpy(m_inactiveShortcut, &GlobalShortcut::triggered);
63 // test pressing Ctrl+Alt+L
64 QTest::keyClick(m_view, Qt::Key_L, Qt::ControlModifier|Qt::AltModifier);
65 // verify we didn't get any signal back, shortcut is not active
66 QTRY_COMPARE(shortcutSpy.count(), 0);
67 }
69private:
70 QPointer<QQuickView> m_view;
71 GlobalShortcut *m_shortcut = nullptr;
72 GlobalShortcut *m_inactiveShortcut = nullptr;
73};
75QTEST_MAIN(GlobalShortcutTest)
77#include "GlobalShortcutTest.moc"