More auto-type tests.

This commit is contained in:
Florian Geyer 2012-11-02 15:07:44 +01:00
parent 848abfc1a7
commit 8347fd36ba
4 changed files with 46 additions and 1 deletions

View file

@ -34,6 +34,7 @@ AutoType* AutoType::m_instance = Q_NULLPTR;
AutoType::AutoType(QObject* parent, bool test) AutoType::AutoType(QObject* parent, bool test)
: QObject(parent) : QObject(parent)
, m_test(test)
, m_inAutoType(false) , m_inAutoType(false)
, m_pluginLoader(new QPluginLoader(this)) , m_pluginLoader(new QPluginLoader(this))
, m_plugin(Q_NULLPTR) , m_plugin(Q_NULLPTR)
@ -132,7 +133,9 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS
hideWindow->showMinimized(); hideWindow->showMinimized();
} }
if (!m_test) {
Tools::wait(500); Tools::wait(500);
}
if (!window) { if (!window) {
window = m_plugin->activeWindow(); window = m_plugin->activeWindow();

View file

@ -69,6 +69,7 @@ private:
QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString()); QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString());
bool windowMatches(const QString& windowTitle, const QString& windowPattern); bool windowMatches(const QString& windowTitle, const QString& windowPattern);
bool m_test;
bool m_inAutoType; bool m_inAutoType;
Qt::Key m_currentGlobalKey; Qt::Key m_currentGlobalKey;
Qt::KeyboardModifiers m_currentGlobalModifiers; Qt::KeyboardModifiers m_currentGlobalModifiers;

View file

@ -52,13 +52,20 @@ void TestAutoType::init()
{ {
m_test->clearActions(); m_test->clearActions();
m_db = new Database();
m_group = new Group(); m_group = new Group();
m_db->setRootGroup(m_group);
m_entry = new Entry(); m_entry = new Entry();
m_entry->setGroup(m_group); m_entry->setGroup(m_group);
m_entry->setUsername("myuser"); m_entry->setUsername("myuser");
m_entry->setPassword("mypass"); m_entry->setPassword("mypass");
} }
void TestAutoType::cleanup()
{
delete m_db;
}
void TestAutoType::testInternal() void TestAutoType::testInternal()
{ {
QVERIFY(m_platform->activeWindowTitle().isEmpty()); QVERIFY(m_platform->activeWindowTitle().isEmpty());
@ -89,4 +96,32 @@ void TestAutoType::testAutoTypeWithSequence()
.arg(m_entry->password())); .arg(m_entry->password()));
} }
void TestAutoType::testGlobalAutoTypeWithNoMatch()
{
QList<Database*> dbList;
dbList.append(m_db);
m_autoType->performGlobalAutoType(dbList);
QCOMPARE(m_test->actionChars(), QString());
}
void TestAutoType::testGlobalAutoTypeWithOneMatch()
{
QList<Database*> 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) QTEST_GUILESS_MAIN(TestAutoType)

View file

@ -23,6 +23,7 @@
class AutoType; class AutoType;
class AutoTypePlatformInterface; class AutoTypePlatformInterface;
class AutoTypeTestInterface; class AutoTypeTestInterface;
class Database;
class Entry; class Entry;
class Group; class Group;
@ -33,14 +34,19 @@ class TestAutoType : public QObject
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
void init(); void init();
void cleanup();
void testInternal(); void testInternal();
void testAutoTypeWithoutSequence(); void testAutoTypeWithoutSequence();
void testAutoTypeWithSequence(); void testAutoTypeWithSequence();
void testGlobalAutoTypeWithNoMatch();
void testGlobalAutoTypeWithOneMatch();
private: private:
AutoTypePlatformInterface* m_platform; AutoTypePlatformInterface* m_platform;
AutoTypeTestInterface* m_test; AutoTypeTestInterface* m_test;
AutoType* m_autoType; AutoType* m_autoType;
Database* m_db;
Group* m_group; Group* m_group;
Entry* m_entry; Entry* m_entry;
}; };