diff --git a/src/autotype/test/AutoTypeTest.cpp b/src/autotype/test/AutoTypeTest.cpp index 959b0326..a6ff22db 100644 --- a/src/autotype/test/AutoTypeTest.cpp +++ b/src/autotype/test/AutoTypeTest.cpp @@ -17,6 +17,11 @@ #include "AutoTypeTest.h" +QString AutoTypePlatformTest::keyToString(Qt::Key key) +{ + return QString("[Key0x%1]").arg(key, 0, 16); +} + QStringList AutoTypePlatformTest::windowTitles() { return QStringList(); @@ -68,9 +73,9 @@ QString AutoTypePlatformTest::actionChars() return m_actionChars; } -QList AutoTypePlatformTest::actionList() +int AutoTypePlatformTest::actionCount() { - return m_actionList; + return m_actionList.size(); } void AutoTypePlatformTest::clearActions() @@ -90,6 +95,7 @@ void AutoTypePlatformTest::addActionChar(AutoTypeChar* action) void AutoTypePlatformTest::addActionKey(AutoTypeKey* action) { m_actionList.append(action->clone()); + m_actionChars.append(keyToString(action->key)); } diff --git a/src/autotype/test/AutoTypeTest.h b/src/autotype/test/AutoTypeTest.h index 55fa1598..4bcd1e70 100644 --- a/src/autotype/test/AutoTypeTest.h +++ b/src/autotype/test/AutoTypeTest.h @@ -33,6 +33,8 @@ class AutoTypePlatformTest : public QObject, Q_INTERFACES(AutoTypePlatformInterface AutoTypeTestInterface) public: + QString keyToString(Qt::Key key); + QStringList windowTitles(); WId activeWindow(); QString activeWindowTitle(); @@ -44,7 +46,7 @@ public: void setActiveWindowTitle(const QString& title); QString actionChars(); - QList actionList(); + int actionCount(); void clearActions(); void addActionChar(AutoTypeChar* action); diff --git a/src/autotype/test/AutoTypeTestInterface.h b/src/autotype/test/AutoTypeTestInterface.h index b2c6f1b4..7ee6f21a 100644 --- a/src/autotype/test/AutoTypeTestInterface.h +++ b/src/autotype/test/AutoTypeTestInterface.h @@ -27,8 +27,10 @@ public: virtual void setActiveWindowTitle(const QString& title) = 0; virtual QString actionChars() = 0; - virtual QList actionList() = 0; + virtual int actionCount() = 0; virtual void clearActions() = 0; + + virtual QString keyToString(Qt::Key key) = 0; }; Q_DECLARE_INTERFACE(AutoTypeTestInterface, "org.keepassx.AutoTypeTestInterface/1") diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 3a5d8d18..dae0b17f 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -22,6 +22,8 @@ #include "tests.h" #include "core/FilePath.h" +#include "core/Entry.h" +#include "core/Group.h" #include "crypto/Crypto.h" #include "autotype/AutoType.h" #include "autotype/AutoTypePlatformPlugin.h" @@ -42,6 +44,19 @@ void TestAutoType::initTestCase() m_test = qobject_cast(loader.instance()); QVERIFY(m_test); + + m_autoType = AutoType::instance(); +} + +void TestAutoType::init() +{ + m_test->clearActions(); + + m_group = new Group(); + m_entry = new Entry(); + m_entry->setGroup(m_group); + m_entry->setUsername("myuser"); + m_entry->setPassword("mypass"); } void TestAutoType::testInternal() @@ -52,4 +67,26 @@ void TestAutoType::testInternal() QCOMPARE(m_platform->activeWindowTitle(), QString("Test")); } +void TestAutoType::testAutoTypeWithoutSequence() +{ + m_autoType->performAutoType(m_entry, Q_NULLPTR); + + QCOMPARE(m_test->actionCount(), 14); + QCOMPARE(m_test->actionChars(), + QString("myuser%1mypass%2") + .arg(m_test->keyToString(Qt::Key_Tab)) + .arg(m_test->keyToString(Qt::Key_Enter))); +} + +void TestAutoType::testAutoTypeWithSequence() +{ + m_autoType->performAutoType(m_entry, Q_NULLPTR, "{Username}abc{PaSsWoRd}"); + + QCOMPARE(m_test->actionCount(), 15); + QCOMPARE(m_test->actionChars(), + QString("%1abc%2") + .arg(m_entry->username()) + .arg(m_entry->password())); +} + QTEST_GUILESS_MAIN(TestAutoType) diff --git a/tests/TestAutoType.h b/tests/TestAutoType.h index 10f29867..f7affaef 100644 --- a/tests/TestAutoType.h +++ b/tests/TestAutoType.h @@ -20,8 +20,11 @@ #include +class AutoType; class AutoTypePlatformInterface; class AutoTypeTestInterface; +class Entry; +class Group; class TestAutoType : public QObject { @@ -29,11 +32,17 @@ class TestAutoType : public QObject private Q_SLOTS: void initTestCase(); + void init(); void testInternal(); + void testAutoTypeWithoutSequence(); + void testAutoTypeWithSequence(); private: AutoTypePlatformInterface* m_platform; AutoTypeTestInterface* m_test; + AutoType* m_autoType; + Group* m_group; + Entry* m_entry; }; #endif // KEEPASSX_TESTAUTOTYPE_H