mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-13 10:32:11 +01:00
[KWalletBackend] Small changes to make tests pass.
This commit is contained in:
parent
c54031793e
commit
a5a5cfbbf0
|
@ -48,11 +48,6 @@ QString KWalletPasswordBackend::name() const
|
||||||
return KWalletPlugin::tr("KWallet");
|
return KWalletPlugin::tr("KWallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool compareEntries(const PasswordEntry &e1, const PasswordEntry &e2)
|
|
||||||
{
|
|
||||||
return e1.id.toString() > e2.id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector<PasswordEntry> KWalletPasswordBackend::getEntries(const QUrl &url)
|
QVector<PasswordEntry> KWalletPasswordBackend::getEntries(const QUrl &url)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
|
@ -68,7 +63,7 @@ QVector<PasswordEntry> KWalletPasswordBackend::getEntries(const QUrl &url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort to prefer last updated entries
|
// Sort to prefer last updated entries
|
||||||
qSort(list.begin(), list.end(), compareEntries);
|
qSort(list.begin(), list.end());
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -84,10 +79,9 @@ void KWalletPasswordBackend::addEntry(const PasswordEntry &entry)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
|
|
||||||
|
|
||||||
PasswordEntry stored = entry;
|
PasswordEntry stored = entry;
|
||||||
stored.id = id;
|
stored.id = QString("%1/%2").arg(entry.host, entry.username);
|
||||||
|
stored.updated = QDateTime::currentDateTime().toTime_t();
|
||||||
|
|
||||||
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
|
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
|
||||||
m_allEntries.append(stored);
|
m_allEntries.append(stored);
|
||||||
|
@ -111,15 +105,13 @@ void KWalletPasswordBackend::updateLastUsed(PasswordEntry &entry)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
|
|
||||||
|
|
||||||
m_wallet->removeEntry(entry.id.toString());
|
m_wallet->removeEntry(entry.id.toString());
|
||||||
|
|
||||||
int index = m_allEntries.indexOf(entry);
|
entry.updated = QDateTime::currentDateTime().toTime_t();
|
||||||
entry.id = id;
|
|
||||||
|
|
||||||
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
||||||
|
|
||||||
|
int index = m_allEntries.indexOf(entry);
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
m_allEntries[index] = entry;
|
m_allEntries[index] = entry;
|
||||||
|
@ -143,6 +135,8 @@ void KWalletPasswordBackend::removeAll()
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
|
m_allEntries.clear();
|
||||||
|
|
||||||
m_wallet->removeFolder("QupZilla");
|
m_wallet->removeFolder("QupZilla");
|
||||||
m_wallet->createFolder("QupZilla");
|
m_wallet->createFolder("QupZilla");
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ void PasswordBackendTest::initTestCase()
|
||||||
// Backup entries
|
// Backup entries
|
||||||
reloadBackend();
|
reloadBackend();
|
||||||
m_entries = m_backend->getAllEntries();
|
m_entries = m_backend->getAllEntries();
|
||||||
|
m_backend->removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasswordBackendTest::cleanupTestCase()
|
void PasswordBackendTest::cleanupTestCase()
|
||||||
|
@ -192,6 +193,13 @@ void PasswordBackendTest::updateLastUsedTest()
|
||||||
QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()));
|
QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()));
|
||||||
reloadBackend();
|
reloadBackend();
|
||||||
QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()));
|
QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()));
|
||||||
|
|
||||||
|
m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).first());
|
||||||
|
m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).first());
|
||||||
|
|
||||||
|
QCOMPARE(m_backend->getAllEntries().count(), 0);
|
||||||
|
reloadBackend();
|
||||||
|
QCOMPARE(m_backend->getAllEntries().count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user