Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Drexler <mdrexler@posteo.de>2019-06-22 16:38:02 +0300
committerJonathan White <support@dmapps.us>2019-06-24 05:22:57 +0300
commitf85642741d9bd6a48c98092ec5fd905de6b0207f (patch)
treefb5b148d28adf4618c80b7aba30573005cda7d27 /tests
parenta22e8a1f4001970e1cb23e7fc57c196ba7faaf7a (diff)
Autocomplete usernames based on most frequent in database
* Fixes #3126 * Limit autocompletion to the top ten used usernames - Load common usernames when database is opened - Transition from QLineEdit to QComboBox for usernames - Dropdown menu of the combobox lets user choose a common username - Common usernames are autocompleted via inline completion - Common usernames are sorted by frequency (first) and name (second)
Diffstat (limited to 'tests')
-rw-r--r--tests/TestGroup.cpp26
-rw-r--r--tests/TestGroup.h1
-rw-r--r--tests/gui/TestGui.cpp24
3 files changed, 48 insertions, 3 deletions
diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp
index f78cb96af..bd3d36081 100644
--- a/tests/TestGroup.cpp
+++ b/tests/TestGroup.cpp
@@ -1181,3 +1181,29 @@ void TestGroup::testApplyGroupIconRecursively()
QVERIFY(subsubgroup->iconNumber() == iconForGroups);
QVERIFY(subsubgroupEntry->iconNumber() == iconForEntries);
}
+
+void TestGroup::testUsernamesRecursive()
+{
+ Database* database = new Database();
+
+ // Create a subgroup
+ Group* subgroup = new Group();
+ subgroup->setName("Subgroup");
+ subgroup->setParent(database->rootGroup());
+
+ // Generate entries in the root group and the subgroup
+ Entry* rootGroupEntry = database->rootGroup()->addEntryWithPath("Root group entry");
+ rootGroupEntry->setUsername("Name1");
+
+ Entry* subgroupEntry = subgroup->addEntryWithPath("Subgroup entry");
+ subgroupEntry->setUsername("Name2");
+
+ Entry* subgroupEntryReusingUsername = subgroup->addEntryWithPath("Another subgroup entry");
+ subgroupEntryReusingUsername->setUsername("Name2");
+
+ QList<QString> usernames = database->rootGroup()->usernamesRecursive();
+ QCOMPARE(usernames.size(), 2);
+ QVERIFY(usernames.contains("Name1"));
+ QVERIFY(usernames.contains("Name2"));
+ QVERIFY(usernames.indexOf("Name2") < usernames.indexOf("Name1"));
+}
diff --git a/tests/TestGroup.h b/tests/TestGroup.h
index 0ee735949..dbe5d6f4d 100644
--- a/tests/TestGroup.h
+++ b/tests/TestGroup.h
@@ -48,6 +48,7 @@ private slots:
void testChildrenSort();
void testHierarchy();
void testApplyGroupIconRecursively();
+ void testUsernamesRecursive();
};
#endif // KEEPASSX_TESTGROUP_H
diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp
index 3579d90f3..af5107288 100644
--- a/tests/gui/TestGui.cpp
+++ b/tests/gui/TestGui.cpp
@@ -507,7 +507,7 @@ void TestGui::testEditEntry()
QVERIFY(okButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
titleEdit->setText("multiline\ntitle");
- editEntryWidget->findChild<QLineEdit*>("usernameEdit")->setText("multiline\nusername");
+ editEntryWidget->findChild<QComboBox*>("usernameComboBox")->lineEdit()->setText("multiline\nusername");
editEntryWidget->findChild<QLineEdit*>("passwordEdit")->setText("multiline\npassword");
editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit")->setText("multiline\npassword");
editEntryWidget->findChild<QLineEdit*>("urlEdit")->setText("multiline\nurl");
@@ -594,6 +594,10 @@ void TestGui::testAddEntry()
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
QTest::keyClicks(titleEdit, "test");
+ auto* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
+ QVERIFY(usernameComboBox);
+ QTest::mouseClick(usernameComboBox, Qt::LeftButton);
+ QTest::keyClicks(usernameComboBox, "AutocompletionUsername");
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
@@ -602,17 +606,31 @@ void TestGui::testAddEntry()
Entry* entry = entryView->entryFromIndex(item);
QCOMPARE(entry->title(), QString("test"));
+ QCOMPARE(entry->username(), QString("AutocompletionUsername"));
QCOMPARE(entry->historyItems().size(), 0);
+ m_db->updateCommonUsernames();
+
// Add entry "something 2"
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 2");
+ QTest::mouseClick(usernameComboBox, Qt::LeftButton);
+ QTest::keyClicks(usernameComboBox, "Auto");
+ QTest::keyPress(usernameComboBox, Qt::Key_Right);
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
auto* passwordRepeatEdit = editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit");
QTest::keyClicks(passwordEdit, "something 2");
QTest::keyClicks(passwordRepeatEdit, "something 2");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
+ QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
+ item = entryView->model()->index(1, 1);
+ entry = entryView->entryFromIndex(item);
+
+ QCOMPARE(entry->title(), QString("something 2"));
+ QCOMPARE(entry->username(), QString("AutocompletionUsername"));
+ QCOMPARE(entry->historyItems().size(), 0);
+
// Add entry "something 5" but click cancel button (does NOT add entry)
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 5");
@@ -1063,8 +1081,8 @@ void TestGui::testEntryPlaceholders()
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
QTest::keyClicks(titleEdit, "test");
- QLineEdit* usernameEdit = editEntryWidget->findChild<QLineEdit*>("usernameEdit");
- QTest::keyClicks(usernameEdit, "john");
+ QComboBox* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
+ QTest::keyClicks(usernameComboBox, "john");
QLineEdit* urlEdit = editEntryWidget->findChild<QLineEdit*>("urlEdit");
QTest::keyClicks(urlEdit, "{TITLE}.{USERNAME}");
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");