From 8347fd36ba235d03c61b166ed58c42869d96c30d Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Fri, 2 Nov 2012 15:07:44 +0100 Subject: [PATCH] More auto-type tests. --- src/autotype/AutoType.cpp | 5 ++++- src/autotype/AutoType.h | 1 + tests/TestAutoType.cpp | 35 +++++++++++++++++++++++++++++++++++ tests/TestAutoType.h | 6 ++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index fa9b5abb9..67cb17cf7 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -34,6 +34,7 @@ AutoType* AutoType::m_instance = Q_NULLPTR; AutoType::AutoType(QObject* parent, bool test) : QObject(parent) + , m_test(test) , m_inAutoType(false) , m_pluginLoader(new QPluginLoader(this)) , m_plugin(Q_NULLPTR) @@ -132,7 +133,9 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS hideWindow->showMinimized(); } - Tools::wait(500); + if (!m_test) { + Tools::wait(500); + } if (!window) { window = m_plugin->activeWindow(); diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 51b6a540a..26e8c8abc 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -69,6 +69,7 @@ private: QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString()); bool windowMatches(const QString& windowTitle, const QString& windowPattern); + bool m_test; bool m_inAutoType; Qt::Key m_currentGlobalKey; Qt::KeyboardModifiers m_currentGlobalModifiers; diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index dae0b17f9..cd7b379fe 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -52,13 +52,20 @@ void TestAutoType::init() { m_test->clearActions(); + m_db = new Database(); m_group = new Group(); + m_db->setRootGroup(m_group); m_entry = new Entry(); m_entry->setGroup(m_group); m_entry->setUsername("myuser"); m_entry->setPassword("mypass"); } +void TestAutoType::cleanup() +{ + delete m_db; +} + void TestAutoType::testInternal() { QVERIFY(m_platform->activeWindowTitle().isEmpty()); @@ -89,4 +96,32 @@ void TestAutoType::testAutoTypeWithSequence() .arg(m_entry->password())); } +void TestAutoType::testGlobalAutoTypeWithNoMatch() +{ + QList dbList; + dbList.append(m_db); + + m_autoType->performGlobalAutoType(dbList); + + QCOMPARE(m_test->actionChars(), QString()); +} + +void TestAutoType::testGlobalAutoTypeWithOneMatch() +{ + QList dbList; + dbList.append(m_db); + AutoTypeAssociations::Association association; + association.window = "custom window"; + association.sequence = "{username}association{password}"; + m_entry->autoTypeAssociations()->add(association); + + m_test->setActiveWindowTitle("custom window"); + m_autoType->performGlobalAutoType(dbList); + + QCOMPARE(m_test->actionChars(), + QString("%1association%2") + .arg(m_entry->username()) + .arg(m_entry->password())); +} + QTEST_GUILESS_MAIN(TestAutoType) diff --git a/tests/TestAutoType.h b/tests/TestAutoType.h index f7affaef6..9f4445ae9 100644 --- a/tests/TestAutoType.h +++ b/tests/TestAutoType.h @@ -23,6 +23,7 @@ class AutoType; class AutoTypePlatformInterface; class AutoTypeTestInterface; +class Database; class Entry; class Group; @@ -33,14 +34,19 @@ class TestAutoType : public QObject private Q_SLOTS: void initTestCase(); void init(); + void cleanup(); + void testInternal(); void testAutoTypeWithoutSequence(); void testAutoTypeWithSequence(); + void testGlobalAutoTypeWithNoMatch(); + void testGlobalAutoTypeWithOneMatch(); private: AutoTypePlatformInterface* m_platform; AutoTypeTestInterface* m_test; AutoType* m_autoType; + Database* m_db; Group* m_group; Entry* m_entry; };