2011-12-26 13:18:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2020-10-08 22:48:45 -04:00
|
|
|
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
|
2011-12-26 13:18:21 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestGui.h"
|
2018-09-29 13:00:47 -04:00
|
|
|
#include "gui/Application.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QClipboard>
|
2015-07-22 11:03:59 -04:00
|
|
|
#include <QMimeData>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QPlainTextEdit>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPushButton>
|
2020-11-01 11:24:47 -05:00
|
|
|
#include <QRadioButton>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QSignalSpy>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QSpinBox>
|
2020-11-01 11:24:47 -05:00
|
|
|
#include <QTest>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QToolBar>
|
2011-12-26 13:18:21 -05:00
|
|
|
|
|
|
|
#include "config-keepassx-tests.h"
|
2012-11-02 06:08:41 -04:00
|
|
|
#include "core/Tools.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "crypto/Crypto.h"
|
2018-05-13 17:21:43 -04:00
|
|
|
#include "gui/ApplicationSettingsWidget.h"
|
|
|
|
#include "gui/CategoryListWidget.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/CloneDialog.h"
|
2012-04-14 14:31:35 -04:00
|
|
|
#include "gui/DatabaseTabWidget.h"
|
2020-01-10 22:28:31 -05:00
|
|
|
#include "gui/EntryPreviewWidget.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
#include "gui/FileDialog.h"
|
2013-10-08 16:11:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/PasswordEdit.h"
|
2020-02-25 18:02:46 -05:00
|
|
|
#include "gui/PasswordGeneratorWidget.h"
|
2016-11-28 19:02:21 -05:00
|
|
|
#include "gui/SearchWidget.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/TotpDialog.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "gui/TotpSetupDialog.h"
|
2020-07-01 19:16:40 -04:00
|
|
|
#include "gui/databasekey/KeyFileEditWidget.h"
|
|
|
|
#include "gui/databasekey/PasswordEditWidget.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "gui/dbsettings/DatabaseSettingsDialog.h"
|
2012-05-16 04:16:32 -04:00
|
|
|
#include "gui/entry/EditEntryWidget.h"
|
|
|
|
#include "gui/entry/EntryView.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/group/EditGroupWidget.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "gui/group/GroupModel.h"
|
|
|
|
#include "gui/group/GroupView.h"
|
2022-01-23 10:00:48 -05:00
|
|
|
#include "gui/tag/TagsEdit.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "gui/wizard/NewDatabaseWizard.h"
|
|
|
|
#include "keys/FileKey.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
#define TEST_MODAL_NO_WAIT(TEST_CODE) \
|
|
|
|
bool dialogFinished = false; \
|
|
|
|
QTimer::singleShot(0, [&]() { TEST_CODE dialogFinished = true; })
|
|
|
|
|
|
|
|
#define TEST_MODAL(TEST_CODE) \
|
|
|
|
TEST_MODAL_NO_WAIT(TEST_CODE); \
|
|
|
|
QTRY_VERIFY(dialogFinished)
|
|
|
|
|
2020-03-08 22:45:51 -04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
#endif
|
|
|
|
Application app(argc, argv);
|
|
|
|
app.setApplicationName("KeePassXC");
|
|
|
|
app.setApplicationVersion(KEEPASSXC_VERSION);
|
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
app.setAttribute(Qt::AA_Use96Dpi, true);
|
2020-06-04 08:10:43 -04:00
|
|
|
app.applyTheme();
|
2020-03-08 22:45:51 -04:00
|
|
|
QTEST_DISABLE_KEYPAD_NAVIGATION
|
|
|
|
TestGui tc;
|
|
|
|
QTEST_SET_MAIN_SOURCE_PATH
|
|
|
|
return QTest::qExec(&tc, argc, argv);
|
|
|
|
}
|
2018-09-29 13:00:47 -04:00
|
|
|
|
2011-12-26 13:18:21 -05:00
|
|
|
void TestGui::initTestCase()
|
|
|
|
{
|
2014-06-15 05:17:40 -04:00
|
|
|
QVERIFY(Crypto::init());
|
2012-06-14 16:55:25 -04:00
|
|
|
Config::createTempFileInstance();
|
2020-10-08 22:48:45 -04:00
|
|
|
Application::bootstrap();
|
2019-12-31 12:40:00 -05:00
|
|
|
|
|
|
|
m_mainWindow.reset(new MainWindow());
|
2012-07-06 13:21:19 -04:00
|
|
|
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
2012-04-26 11:52:02 -04:00
|
|
|
m_mainWindow->show();
|
2019-12-31 12:40:00 -05:00
|
|
|
m_mainWindow->resize(1024, 768);
|
2016-11-11 17:58:47 -05:00
|
|
|
}
|
2015-07-19 13:33:47 -04:00
|
|
|
|
2021-11-07 17:41:17 -05:00
|
|
|
// Every test starts with resetting config settings and opening the temp database
|
2016-11-11 17:58:47 -05:00
|
|
|
void TestGui::init()
|
|
|
|
{
|
2021-11-07 17:41:17 -05:00
|
|
|
// Reset config to defaults
|
|
|
|
config()->resetToDefaults();
|
|
|
|
// Disable autosave so we can test the modified file indicator
|
|
|
|
config()->set(Config::AutoSaveAfterEveryChange, false);
|
|
|
|
config()->set(Config::AutoSaveOnExit, false);
|
|
|
|
// Enable the tray icon so we can test hiding/restoring the windowQByteArray
|
|
|
|
config()->set(Config::GUI_ShowTrayIcon, true);
|
|
|
|
// Disable the update check first time alert
|
|
|
|
config()->set(Config::UpdateCheckMessageShown, true);
|
2022-03-28 22:49:03 -04:00
|
|
|
// Disable quick unlock
|
|
|
|
config()->set(Config::Security_QuickUnlock, false);
|
2021-11-07 17:41:17 -05:00
|
|
|
|
2019-10-20 18:23:11 -04:00
|
|
|
// Copy the test database file to the temporary file
|
2021-11-07 17:41:17 -05:00
|
|
|
auto origFilePath = QDir(KEEPASSX_TEST_DATA_DIR).absoluteFilePath("NewDatabase.kdbx");
|
|
|
|
QVERIFY(m_dbFile.copyFromFile(origFilePath));
|
2019-10-20 18:23:11 -04:00
|
|
|
|
|
|
|
m_dbFileName = QFileInfo(m_dbFile.fileName()).fileName();
|
|
|
|
m_dbFilePath = m_dbFile.fileName();
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
// make sure window is activated or focus tests may fail
|
|
|
|
m_mainWindow->activateWindow();
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
2017-01-03 22:27:41 -05:00
|
|
|
fileDialog()->setNextFileName(m_dbFilePath);
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseOpen");
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2020-11-01 11:24:47 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
m_dbWidget = m_tabWidget->currentDatabaseWidget();
|
2018-11-22 05:47:31 -05:00
|
|
|
auto* databaseOpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("databaseOpenWidget");
|
|
|
|
QVERIFY(databaseOpenWidget);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editPassword = databaseOpenWidget->findChild<QLineEdit*>("editPassword");
|
2011-12-26 13:18:21 -05:00
|
|
|
QVERIFY(editPassword);
|
2018-11-22 05:47:31 -05:00
|
|
|
editPassword->setFocus();
|
2012-06-28 03:21:15 -04:00
|
|
|
|
2011-12-26 13:18:21 -05:00
|
|
|
QTest::keyClicks(editPassword, "a");
|
2012-06-28 03:21:15 -04:00
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2020-11-01 11:24:47 -05:00
|
|
|
QTRY_VERIFY(!m_dbWidget->isLocked());
|
2016-11-02 21:01:02 -04:00
|
|
|
m_db = m_dbWidget->database();
|
2020-11-01 11:24:47 -05:00
|
|
|
|
|
|
|
QApplication::processEvents();
|
2016-11-02 21:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Every test ends with closing the temp database without saving
|
|
|
|
void TestGui::cleanup()
|
|
|
|
{
|
|
|
|
// DO NOT save the database
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db->markAsClean();
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2016-11-02 21:01:02 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::NoButton);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-01-06 18:30:18 -05:00
|
|
|
if (m_dbWidget) {
|
|
|
|
delete m_dbWidget;
|
|
|
|
}
|
2018-09-29 13:00:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::cleanupTestCase()
|
|
|
|
{
|
2019-10-20 18:23:11 -04:00
|
|
|
m_dbFile.remove();
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
void TestGui::testSettingsDefaultTabOrder()
|
2017-10-29 10:04:46 -04:00
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
// check application settings default tab order
|
|
|
|
triggerAction("actionSettings");
|
|
|
|
auto* settingsWidget = m_mainWindow->findChild<ApplicationSettingsWidget*>();
|
|
|
|
QVERIFY(settingsWidget->isVisible());
|
|
|
|
QCOMPARE(settingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
2018-10-31 23:27:38 -04:00
|
|
|
for (auto* w : settingsWidget->findChildren<QTabWidget*>()) {
|
2018-05-13 17:21:43 -04:00
|
|
|
if (w->currentIndex() != 0) {
|
|
|
|
QFAIL("Application settings contain QTabWidgets whose default index is not 0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTest::keyClick(settingsWidget, Qt::Key::Key_Escape);
|
2017-10-29 10:04:46 -04:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
// check database settings default tab order
|
2020-06-04 08:11:12 -04:00
|
|
|
triggerAction("actionDatabaseSettings");
|
2018-05-13 17:21:43 -04:00
|
|
|
auto* dbSettingsWidget = m_mainWindow->findChild<DatabaseSettingsDialog*>();
|
|
|
|
QVERIFY(dbSettingsWidget->isVisible());
|
|
|
|
QCOMPARE(dbSettingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
2018-10-31 23:27:38 -04:00
|
|
|
for (auto* w : dbSettingsWidget->findChildren<QTabWidget*>()) {
|
2018-05-13 17:21:43 -04:00
|
|
|
if (w->currentIndex() != 0) {
|
|
|
|
QFAIL("Database settings contain QTabWidgets whose default index is not 0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTest::keyClick(dbSettingsWidget, Qt::Key::Key_Escape);
|
|
|
|
}
|
2017-10-29 10:04:46 -04:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
void TestGui::testCreateDatabase()
|
|
|
|
{
|
2020-05-15 16:18:22 -04:00
|
|
|
TEST_MODAL_NO_WAIT(
|
|
|
|
NewDatabaseWizard * wizard; QTRY_VERIFY(wizard = m_tabWidget->findChild<NewDatabaseWizard*>());
|
|
|
|
|
|
|
|
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseName"), "Test Name");
|
|
|
|
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseDescription"), "Test Description");
|
|
|
|
QCOMPARE(wizard->currentId(), 0);
|
|
|
|
|
|
|
|
QTest::keyClick(wizard, Qt::Key_Enter);
|
|
|
|
QCOMPARE(wizard->currentId(), 1);
|
|
|
|
|
|
|
|
auto decryptionTimeSlider = wizard->currentPage()->findChild<QSlider*>("decryptionTimeSlider");
|
|
|
|
auto algorithmComboBox = wizard->currentPage()->findChild<QComboBox*>("algorithmComboBox");
|
|
|
|
QTRY_VERIFY(decryptionTimeSlider->isVisible());
|
|
|
|
QVERIFY(!algorithmComboBox->isVisible());
|
|
|
|
auto advancedToggle = wizard->currentPage()->findChild<QPushButton*>("advancedSettingsButton");
|
|
|
|
QTest::mouseClick(advancedToggle, Qt::MouseButton::LeftButton);
|
|
|
|
QTRY_VERIFY(!decryptionTimeSlider->isVisible());
|
|
|
|
QVERIFY(algorithmComboBox->isVisible());
|
|
|
|
|
|
|
|
auto rounds = wizard->currentPage()->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
QVERIFY(rounds);
|
|
|
|
QVERIFY(rounds->isVisible());
|
|
|
|
QTest::mouseClick(rounds, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(rounds, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(rounds, "2");
|
|
|
|
QTest::keyClick(rounds, Qt::Key_Tab);
|
|
|
|
QTest::keyClick(rounds, Qt::Key_Tab);
|
|
|
|
|
|
|
|
auto memory = wizard->currentPage()->findChild<QSpinBox*>("memorySpinBox");
|
|
|
|
QVERIFY(memory);
|
|
|
|
QVERIFY(memory->isVisible());
|
|
|
|
QTest::mouseClick(memory, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(memory, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(memory, "50");
|
|
|
|
QTest::keyClick(memory, Qt::Key_Tab);
|
|
|
|
|
|
|
|
auto parallelism = wizard->currentPage()->findChild<QSpinBox*>("parallelismSpinBox");
|
|
|
|
QVERIFY(parallelism);
|
|
|
|
QVERIFY(parallelism->isVisible());
|
|
|
|
QTest::mouseClick(parallelism, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(parallelism, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(parallelism, "1");
|
|
|
|
QTest::keyClick(parallelism, Qt::Key_Enter);
|
|
|
|
|
|
|
|
QCOMPARE(wizard->currentId(), 2);
|
|
|
|
|
|
|
|
// enter password
|
|
|
|
auto* passwordWidget = wizard->currentPage()->findChild<PasswordEditWidget*>();
|
|
|
|
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
|
|
|
auto* passwordEdit = passwordWidget->findChild<QLineEdit*>("enterPasswordEdit");
|
|
|
|
auto* passwordRepeatEdit = passwordWidget->findChild<QLineEdit*>("repeatPasswordEdit");
|
|
|
|
QTRY_VERIFY(passwordEdit->isVisible());
|
|
|
|
QTRY_VERIFY(passwordEdit->hasFocus());
|
|
|
|
QTest::keyClicks(passwordEdit, "test");
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key::Key_Tab);
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "test");
|
|
|
|
|
|
|
|
// add key file
|
|
|
|
auto* additionalOptionsButton = wizard->currentPage()->findChild<QPushButton*>("additionalKeyOptionsToggle");
|
|
|
|
auto* keyFileWidget = wizard->currentPage()->findChild<KeyFileEditWidget*>();
|
|
|
|
QVERIFY(additionalOptionsButton->isVisible());
|
|
|
|
QTest::mouseClick(additionalOptionsButton, Qt::MouseButton::LeftButton);
|
|
|
|
QTRY_VERIFY(keyFileWidget->isVisible());
|
|
|
|
QTRY_VERIFY(!additionalOptionsButton->isVisible());
|
|
|
|
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
|
|
|
QTest::mouseClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::MouseButton::LeftButton);
|
2021-04-11 16:48:35 -04:00
|
|
|
auto* fileEdit = keyFileWidget->findChild<QLineEdit*>("keyFileLineEdit");
|
|
|
|
QTRY_VERIFY(fileEdit);
|
|
|
|
QTRY_VERIFY(fileEdit->isVisible());
|
2020-05-15 16:18:22 -04:00
|
|
|
fileDialog()->setNextFileName(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
|
|
|
QTest::keyClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::Key::Key_Enter);
|
2021-04-11 16:48:35 -04:00
|
|
|
QVERIFY(fileEdit->hasFocus());
|
2020-05-15 16:18:22 -04:00
|
|
|
auto* browseButton = keyFileWidget->findChild<QPushButton*>("browseKeyFileButton");
|
|
|
|
QTest::keyClick(browseButton, Qt::Key::Key_Enter);
|
2021-04-11 16:48:35 -04:00
|
|
|
QCOMPARE(fileEdit->text(), QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
2020-05-15 16:18:22 -04:00
|
|
|
|
|
|
|
// save database to temporary file
|
|
|
|
TemporaryFile tmpFile;
|
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
tmpFile.close();
|
|
|
|
fileDialog()->setNextFileName(tmpFile.fileName());
|
|
|
|
|
2021-04-11 16:48:35 -04:00
|
|
|
QTest::keyClick(fileEdit, Qt::Key::Key_Enter);
|
2020-05-15 16:18:22 -04:00
|
|
|
tmpFile.remove(););
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
triggerAction("actionDatabaseNew");
|
2017-10-29 10:04:46 -04:00
|
|
|
|
|
|
|
// there is a new empty db
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
2017-10-29 10:04:46 -04:00
|
|
|
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
// check meta data
|
|
|
|
QCOMPARE(m_db->metadata()->name(), QString("Test Name"));
|
|
|
|
QCOMPARE(m_db->metadata()->description(), QString("Test Description"));
|
|
|
|
|
|
|
|
// check key and encryption
|
|
|
|
QCOMPARE(m_db->key()->keys().size(), 2);
|
2018-09-29 13:00:47 -04:00
|
|
|
QCOMPARE(m_db->kdf()->rounds(), 2);
|
2020-11-20 15:49:56 -05:00
|
|
|
QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2D);
|
2018-09-29 13:00:47 -04:00
|
|
|
QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES256);
|
2018-05-13 17:21:43 -04:00
|
|
|
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
|
|
|
compositeKey->addKey(QSharedPointer<PasswordKey>::create("test"));
|
|
|
|
auto fileKey = QSharedPointer<FileKey>::create();
|
|
|
|
fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
|
|
|
compositeKey->addKey(fileKey);
|
|
|
|
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
|
|
|
|
|
2017-11-02 14:58:45 -04:00
|
|
|
// close the new database
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2017-10-29 10:04:46 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-05-13 17:21:43 -04:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
// Wait for dialog to terminate
|
|
|
|
QTRY_VERIFY(dialogFinished);
|
2017-10-29 10:04:46 -04:00
|
|
|
}
|
|
|
|
|
2016-11-07 22:37:42 -05:00
|
|
|
void TestGui::testMergeDatabase()
|
|
|
|
{
|
2016-11-11 17:58:47 -05:00
|
|
|
// It is safe to ignore the warning this line produces
|
2018-11-22 05:47:31 -05:00
|
|
|
QSignalSpy dbMergeSpy(m_dbWidget.data(), SIGNAL(databaseMerged(QSharedPointer<Database>)));
|
|
|
|
QApplication::processEvents();
|
2016-11-07 22:37:42 -05:00
|
|
|
|
|
|
|
// set file to merge from
|
|
|
|
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
|
|
|
triggerAction("actionDatabaseMerge");
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
QTRY_COMPARE(QApplication::focusWidget()->objectName(), QString("editPassword"));
|
|
|
|
auto* editPasswordMerge = QApplication::focusWidget();
|
2016-11-07 22:37:42 -05:00
|
|
|
QVERIFY(editPasswordMerge->isVisible());
|
|
|
|
|
|
|
|
QTest::keyClicks(editPasswordMerge, "a");
|
|
|
|
QTest::keyClick(editPasswordMerge, Qt::Key_Enter);
|
|
|
|
|
|
|
|
QTRY_COMPARE(dbMergeSpy.count(), 1);
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).contains("*"));
|
2016-11-07 22:37:42 -05:00
|
|
|
|
|
|
|
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
|
|
|
|
|
|
|
// there are seven child groups of the root group
|
|
|
|
QCOMPARE(m_db->rootGroup()->children().size(), 7);
|
|
|
|
// the merged group should contain an entry
|
|
|
|
QCOMPARE(m_db->rootGroup()->children().at(6)->entries().size(), 1);
|
|
|
|
// the General group contains one entry merged from the other db
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
|
|
|
}
|
|
|
|
|
2016-11-11 17:58:47 -05:00
|
|
|
void TestGui::testAutoreloadDatabase()
|
|
|
|
{
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoReloadOnChange, false);
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Test accepting new file in autoreload
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Yes);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Overwrite the current database with the temp data
|
2019-10-20 18:23:11 -04:00
|
|
|
QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx")));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
QTRY_VERIFY(m_db != m_dbWidget->database());
|
2016-11-11 17:58:47 -05:00
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
// the General group contains one entry from the new db data
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
2021-11-23 16:50:57 -05:00
|
|
|
QVERIFY(!m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
2021-11-07 17:41:17 -05:00
|
|
|
config()->set(Config::AutoReloadOnChange, false);
|
|
|
|
|
2016-11-11 17:58:47 -05:00
|
|
|
// Test rejecting new file in autoreload
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2019-10-20 18:23:11 -04:00
|
|
|
// Overwrite the current database with the temp data
|
|
|
|
QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx")));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Ensure the merge did not take place
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 0);
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
// Test accepting a merge of edits into autoreload
|
2016-11-11 17:58:47 -05:00
|
|
|
// Turn on autoload so we only get one messagebox (for the merge)
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoReloadOnChange, true);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Modify some entries
|
|
|
|
testEditEntry();
|
|
|
|
|
|
|
|
// This is saying yes to merging the entries
|
2018-12-28 18:32:25 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Merge);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Overwrite the current database with the temp data
|
2019-10-20 18:23:11 -04:00
|
|
|
QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx")));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
QTRY_VERIFY(m_db != m_dbWidget->database());
|
2016-11-11 17:58:47 -05:00
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:10:19 -05:00
|
|
|
void TestGui::testTabs()
|
|
|
|
{
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->count(), 1);
|
2021-11-23 16:50:57 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_dbFileName);
|
2011-12-26 13:18:21 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 14:31:35 -04:00
|
|
|
void TestGui::testEditEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2018-11-09 21:58:42 -05:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
|
|
|
QVERIFY(entryView->hasFocus());
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Select the first entry in the database
|
|
|
|
QModelIndex entryItem = entryView->model()->index(0, 1);
|
2017-06-13 20:55:53 -04:00
|
|
|
Entry* entry = entryView->entryFromIndex(entryItem);
|
2016-11-02 21:01:02 -04:00
|
|
|
clickIndex(entryItem, entryView, Qt::LeftButton);
|
2012-04-26 11:52:02 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Confirm the edit action button is enabled
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
2012-04-26 11:52:02 -04:00
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
|
2018-11-09 21:58:42 -05:00
|
|
|
// Record current history count
|
|
|
|
int editCount = entry->historyItems().size();
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Edit the first entry ("Sample Entry")
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2016-11-02 21:01:02 -04:00
|
|
|
QTest::keyClicks(titleEdit, "_test");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-11-22 05:47:31 -05:00
|
|
|
QVERIFY(editEntryWidgetButtonBox);
|
2019-04-07 09:56:25 -04:00
|
|
|
auto* okButton = editEntryWidgetButtonBox->button(QDialogButtonBox::Ok);
|
|
|
|
QVERIFY(okButton);
|
|
|
|
auto* applyButton = editEntryWidgetButtonBox->button(QDialogButtonBox::Apply);
|
|
|
|
QVERIFY(applyButton);
|
|
|
|
|
|
|
|
// Apply the edit
|
|
|
|
QTRY_VERIFY(applyButton->isEnabled());
|
|
|
|
QTest::mouseClick(applyButton, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-06-13 20:55:53 -04:00
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2019-04-07 09:56:25 -04:00
|
|
|
QVERIFY(!applyButton->isEnabled());
|
2018-02-19 18:22:49 -05:00
|
|
|
|
2020-04-03 16:01:00 -04:00
|
|
|
// Test the "known bad" checkbox
|
|
|
|
editEntryWidget->setCurrentPage(1);
|
2021-02-26 16:43:23 -05:00
|
|
|
auto excludeReportsCheckBox = editEntryWidget->findChild<QCheckBox*>("excludeReportsCheckBox");
|
|
|
|
QVERIFY(excludeReportsCheckBox);
|
|
|
|
QCOMPARE(excludeReportsCheckBox->isChecked(), false);
|
|
|
|
excludeReportsCheckBox->setChecked(true);
|
2020-04-03 16:01:00 -04:00
|
|
|
QTest::mouseClick(applyButton, Qt::LeftButton);
|
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2021-02-26 16:43:23 -05:00
|
|
|
QVERIFY(entry->excludeFromReports());
|
2020-04-03 16:01:00 -04:00
|
|
|
|
2022-01-23 10:00:48 -05:00
|
|
|
// Test tags
|
|
|
|
auto* tags = editEntryWidget->findChild<TagsEdit*>("tagsList");
|
|
|
|
QTest::keyClicks(tags, "_tag1");
|
2022-03-28 22:49:03 -04:00
|
|
|
QTest::keyClick(tags, Qt::Key_Return);
|
2022-01-23 10:00:48 -05:00
|
|
|
QCOMPARE(tags->tags().last(), QString("_tag1"));
|
2022-03-28 22:49:03 -04:00
|
|
|
QTest::keyClicks(tags, "tag 2"); // adds another tag
|
|
|
|
QTest::keyClick(tags, Qt::Key_Return);
|
|
|
|
QCOMPARE(tags->tags().last(), QString("tag 2"));
|
2022-01-23 10:00:48 -05:00
|
|
|
QTest::keyClick(tags, Qt::Key_Backspace); // Back into editing last tag
|
2022-03-28 22:49:03 -04:00
|
|
|
QTest::keyClicks(tags, "_is!awesome");
|
|
|
|
QTest::keyClick(tags, Qt::Key_Return);
|
|
|
|
QCOMPARE(tags->tags().last(), QString("tag 2_is!awesome"));
|
2022-01-23 10:00:48 -05:00
|
|
|
|
2018-02-19 18:22:49 -05:00
|
|
|
// Test entry colors (simulate choosing a color)
|
|
|
|
editEntryWidget->setCurrentPage(1);
|
2020-01-26 21:38:43 -05:00
|
|
|
auto fgColor = QString("#FF0000");
|
|
|
|
auto bgColor = QString("#0000FF");
|
2018-02-19 18:22:49 -05:00
|
|
|
// Set foreground color
|
|
|
|
auto colorButton = editEntryWidget->findChild<QPushButton*>("fgColorButton");
|
|
|
|
auto colorCheckBox = editEntryWidget->findChild<QCheckBox*>("fgColorCheckBox");
|
|
|
|
colorButton->setProperty("color", fgColor);
|
|
|
|
colorCheckBox->setChecked(true);
|
|
|
|
// Set background color
|
|
|
|
colorButton = editEntryWidget->findChild<QPushButton*>("bgColorButton");
|
|
|
|
colorCheckBox = editEntryWidget->findChild<QCheckBox*>("bgColorCheckBox");
|
|
|
|
colorButton->setProperty("color", bgColor);
|
|
|
|
colorCheckBox->setChecked(true);
|
2019-04-07 09:56:25 -04:00
|
|
|
QTest::mouseClick(applyButton, Qt::LeftButton);
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2017-06-13 20:55:53 -04:00
|
|
|
|
2017-03-07 22:38:18 -05:00
|
|
|
// Test protected attributes
|
|
|
|
editEntryWidget->setCurrentPage(1);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* attrTextEdit = editEntryWidget->findChild<QPlainTextEdit*>("attributesEdit");
|
2017-03-07 22:38:18 -05:00
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("addAttributeButton"), Qt::LeftButton);
|
|
|
|
QString attrText = "TEST TEXT";
|
|
|
|
QTest::keyClicks(attrTextEdit, attrText);
|
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), attrText);
|
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("protectAttributeButton"), Qt::LeftButton);
|
|
|
|
QVERIFY(attrTextEdit->toPlainText().contains("PROTECTED"));
|
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("revealAttributeButton"), Qt::LeftButton);
|
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), attrText);
|
|
|
|
editEntryWidget->setCurrentPage(0);
|
|
|
|
|
2017-06-13 20:55:53 -04:00
|
|
|
// Save the edit (press OK)
|
2019-04-07 09:56:25 -04:00
|
|
|
QTest::mouseClick(okButton, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QApplication::processEvents();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Confirm edit was made
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
2020-05-31 10:00:11 -04:00
|
|
|
QCOMPARE(entry->foregroundColor().toUpper(), fgColor.toUpper());
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor));
|
2020-05-31 10:00:11 -04:00
|
|
|
QCOMPARE(entry->backgroundColor().toUpper(), bgColor.toUpper());
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor));
|
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Confirm modified indicator is showing
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_dbFileName));
|
2018-02-25 14:59:59 -05:00
|
|
|
|
|
|
|
// Test copy & paste newline sanitization
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2019-04-07 09:56:25 -04:00
|
|
|
okButton = editEntryWidgetButtonBox->button(QDialogButtonBox::Ok);
|
|
|
|
QVERIFY(okButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-02-25 14:59:59 -05:00
|
|
|
titleEdit->setText("multiline\ntitle");
|
2019-06-22 09:38:02 -04:00
|
|
|
editEntryWidget->findChild<QComboBox*>("usernameComboBox")->lineEdit()->setText("multiline\nusername");
|
2018-02-25 14:59:59 -05:00
|
|
|
editEntryWidget->findChild<QLineEdit*>("passwordEdit")->setText("multiline\npassword");
|
|
|
|
editEntryWidget->findChild<QLineEdit*>("urlEdit")->setText("multiline\nurl");
|
2019-04-07 09:56:25 -04:00
|
|
|
QTest::mouseClick(okButton, Qt::LeftButton);
|
2018-02-25 14:59:59 -05:00
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("multiline title"));
|
|
|
|
QCOMPARE(entry->username(), QString("multiline username"));
|
|
|
|
// here we keep newlines, so users can't lock themselves out accidentally
|
|
|
|
QCOMPARE(entry->password(), QString("multiline\npassword"));
|
|
|
|
QCOMPARE(entry->url(), QString("multiline url"));
|
2012-04-14 14:31:35 -04:00
|
|
|
}
|
|
|
|
|
2018-02-16 23:30:24 -05:00
|
|
|
void TestGui::testSearchEditEntry()
|
|
|
|
{
|
|
|
|
// Regression test for Issue #1447 -- Uses example from issue description
|
|
|
|
|
|
|
|
// Find buttons for group creation
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editGroupWidget = m_dbWidget->findChild<EditGroupWidget*>("editGroupWidget");
|
|
|
|
auto* nameEdit = editGroupWidget->findChild<QLineEdit*>("editName");
|
|
|
|
auto* editGroupWidgetButtonBox = editGroupWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Add groups "Good" and "Bad"
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Good");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup()); // Makes "Good" and "Bad" on the same level
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Bad");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup());
|
|
|
|
|
|
|
|
// Find buttons for entry creation
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2018-02-16 23:30:24 -05:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Create "Doggy" in "Good"
|
|
|
|
Group* goodGroup = m_dbWidget->currentGroup()->findChildByName(QString("Good"));
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(goodGroup);
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "Doggy");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
// Select "Bad" group in groupView
|
|
|
|
Group* badGroup = m_db->rootGroup()->findChildByName(QString("Bad"));
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(badGroup);
|
|
|
|
|
|
|
|
// Search for "Doggy" entry
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchWidget = toolBar->findChild<SearchWidget*>("SearchWidget");
|
|
|
|
auto* searchTextEdit = searchWidget->findChild<QLineEdit*>("searchEdit");
|
2018-02-16 23:30:24 -05:00
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(searchTextEdit, "Doggy");
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Goto "Doggy"'s edit view
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Return);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Check the path in header is "parent-group > entry"
|
|
|
|
QCOMPARE(m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget")->findChild<QLabel*>("headerLabel")->text(),
|
2020-10-14 14:45:24 -04:00
|
|
|
QStringLiteral("Good \u2022 Doggy \u2022 Edit entry"));
|
2018-02-16 23:30:24 -05:00
|
|
|
}
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
void TestGui::testAddEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2012-05-10 04:29:25 -04:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
2012-05-10 04:29:25 -04:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Click the new entry button and check that we enter edit mode
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
2019-06-22 09:38:02 -04:00
|
|
|
auto* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
|
|
|
|
QVERIFY(usernameComboBox);
|
|
|
|
QTest::mouseClick(usernameComboBox, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(usernameComboBox, "AutocompletionUsername");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2012-05-12 07:22:41 -04:00
|
|
|
QModelIndex item = entryView->model()->index(1, 1);
|
2012-05-11 06:01:01 -04:00
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("test"));
|
2019-06-22 09:38:02 -04:00
|
|
|
QCOMPARE(entry->username(), QString("AutocompletionUsername"));
|
2012-05-10 04:29:25 -04:00
|
|
|
QCOMPARE(entry->historyItems().size(), 0);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2019-06-22 09:38:02 -04:00
|
|
|
m_db->updateCommonUsernames();
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "something 2"
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 2");
|
2019-06-22 09:38:02 -04:00
|
|
|
QTest::mouseClick(usernameComboBox, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(usernameComboBox, "Auto");
|
|
|
|
QTest::keyPress(usernameComboBox, Qt::Key_Right);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
2016-12-23 12:13:08 -05:00
|
|
|
QTest::keyClicks(passwordEdit, "something 2");
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2019-06-22 09:38:02 -04:00
|
|
|
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);
|
|
|
|
|
2017-10-28 09:23:45 -04:00
|
|
|
// Add entry "something 5" but click cancel button (does NOT add entry)
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 5");
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Discard);
|
2017-10-28 09:23:45 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
|
|
|
|
|
2017-03-16 21:08:09 -04:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2018-08-13 09:04:18 -04:00
|
|
|
// Confirm entry count
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
2012-05-10 04:29:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 13:24:08 -05:00
|
|
|
void TestGui::testPasswordEntryEntropy()
|
2016-11-23 21:59:24 -05:00
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2016-11-23 21:59:24 -05:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2016-11-23 21:59:24 -05:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2016-11-23 21:59:24 -05:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2016-11-23 21:59:24 -05:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
// Open the password generator
|
2020-03-08 22:22:01 -04:00
|
|
|
auto* passwordEdit = editEntryWidget->findChild<PasswordEdit*>();
|
|
|
|
QVERIFY(passwordEdit);
|
|
|
|
QTest::mouseClick(passwordEdit, Qt::LeftButton);
|
2020-02-25 18:02:46 -05:00
|
|
|
|
2021-09-26 06:35:42 -04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::MetaModifier);
|
|
|
|
#else
|
2020-03-08 22:22:01 -04:00
|
|
|
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::ControlModifier);
|
2021-09-26 06:35:42 -04:00
|
|
|
#endif
|
2020-02-25 18:02:46 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
TEST_MODAL(PasswordGeneratorWidget * pwGeneratorWidget;
|
|
|
|
QTRY_VERIFY(pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>());
|
|
|
|
|
|
|
|
// Type in some password
|
|
|
|
auto* generatedPassword = pwGeneratorWidget->findChild<QLineEdit*>("editNewPassword");
|
|
|
|
auto* entropyLabel = pwGeneratorWidget->findChild<QLabel*>("entropyLabel");
|
|
|
|
auto* strengthLabel = pwGeneratorWidget->findChild<QLabel*>("strengthLabel");
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "hello");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 6.38 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "helloworld");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 13.10 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "password1");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 4.00 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "D0g..................");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 19.02 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "Tr0ub4dour&3");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 30.87 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "correcthorsebatterystaple");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 47.98 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Weak"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "YQC3kbXbjC652dTDH");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 95.83 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
|
|
|
|
|
|
|
|
generatedPassword->setText("");
|
|
|
|
QTest::keyClicks(generatedPassword, "Bs5ZFfthWzR8DGFEjaCM6bGqhmCT4km");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 174.59 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Excellent"));
|
|
|
|
|
|
|
|
QTest::mouseClick(generatedPassword, Qt::LeftButton);
|
|
|
|
QTest::keyClick(generatedPassword, Qt::Key_Escape););
|
2016-11-23 21:59:24 -05:00
|
|
|
}
|
|
|
|
|
2017-03-04 13:24:08 -05:00
|
|
|
void TestGui::testDicewareEntryEntropy()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2017-03-04 13:24:08 -05:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2017-03-04 13:24:08 -05:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-03-04 13:24:08 -05:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2017-03-04 13:24:08 -05:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
// Open the password generator
|
2020-03-08 22:22:01 -04:00
|
|
|
auto* passwordEdit = editEntryWidget->findChild<PasswordEdit*>();
|
|
|
|
QVERIFY(passwordEdit);
|
|
|
|
QTest::mouseClick(passwordEdit, Qt::LeftButton);
|
2020-02-25 18:02:46 -05:00
|
|
|
|
2021-09-26 06:35:42 -04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::MetaModifier);
|
|
|
|
#else
|
2020-03-08 22:22:01 -04:00
|
|
|
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::ControlModifier);
|
2021-09-26 06:35:42 -04:00
|
|
|
#endif
|
2020-02-25 18:02:46 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
TEST_MODAL(PasswordGeneratorWidget * pwGeneratorWidget;
|
|
|
|
QTRY_VERIFY(pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>());
|
2017-03-04 13:24:08 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
// Select Diceware
|
|
|
|
auto* generatedPassword = pwGeneratorWidget->findChild<QLineEdit*>("editNewPassword");
|
|
|
|
auto* tabWidget = pwGeneratorWidget->findChild<QTabWidget*>("tabWidget");
|
|
|
|
auto* dicewareWidget = pwGeneratorWidget->findChild<QWidget*>("dicewareWidget");
|
|
|
|
tabWidget->setCurrentWidget(dicewareWidget);
|
2017-03-04 13:24:08 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
auto* comboBoxWordList = dicewareWidget->findChild<QComboBox*>("comboBoxWordList");
|
|
|
|
comboBoxWordList->setCurrentText("eff_large.wordlist");
|
|
|
|
auto* spinBoxWordCount = dicewareWidget->findChild<QSpinBox*>("spinBoxWordCount");
|
|
|
|
spinBoxWordCount->setValue(6);
|
2017-03-04 13:24:08 -05:00
|
|
|
|
2020-06-04 08:16:47 -04:00
|
|
|
// Confirm a password was generated
|
|
|
|
QVERIFY(!pwGeneratorWidget->getGeneratedPassword().isEmpty());
|
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
// Verify entropy and strength
|
|
|
|
auto* entropyLabel = pwGeneratorWidget->findChild<QLabel*>("entropyLabel");
|
|
|
|
auto* strengthLabel = pwGeneratorWidget->findChild<QLabel*>("strengthLabel");
|
2017-03-04 13:24:08 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 77.55 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
|
2020-02-25 18:02:46 -05:00
|
|
|
|
2020-05-15 16:18:22 -04:00
|
|
|
QTest::mouseClick(generatedPassword, Qt::LeftButton);
|
|
|
|
QTest::keyClick(generatedPassword, Qt::Key_Escape););
|
2017-03-04 13:24:08 -05:00
|
|
|
}
|
|
|
|
|
2017-04-13 06:05:36 -04:00
|
|
|
void TestGui::testTotp()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-04-13 06:05:36 -04:00
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
|
|
|
clickIndex(item, entryView, Qt::LeftButton);
|
|
|
|
|
|
|
|
triggerAction("actionEntrySetupTotp");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* setupTotpDialog = m_dbWidget->findChild<TotpSetupDialog*>("TotpSetupDialog");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2019-11-08 18:06:13 -05:00
|
|
|
QString exampleSeed = "gezd gnbvgY 3tqojqGEZdgnb vgy3tqoJq===";
|
|
|
|
QString expectedFinalSeed = exampleSeed.toUpper().remove(" ").remove("=");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* seedEdit = setupTotpDialog->findChild<QLineEdit*>("seedEdit");
|
2018-11-09 21:58:42 -05:00
|
|
|
seedEdit->setText("");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::keyClicks(seedEdit, exampleSeed);
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* setupTotpButtonBox = setupTotpDialog->findChild<QDialogButtonBox*>("buttonBox");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(setupTotpButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2018-11-16 10:00:59 -05:00
|
|
|
QTRY_VERIFY(!setupTotpDialog->isVisible());
|
|
|
|
|
|
|
|
// Make sure the entryView is selected and active
|
|
|
|
entryView->activateWindow();
|
|
|
|
QApplication::processEvents();
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
2017-04-13 06:05:36 -04:00
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
2018-11-16 10:00:59 -05:00
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-11-16 10:00:59 -05:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2017-04-13 06:05:36 -04:00
|
|
|
editEntryWidget->setCurrentPage(1);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* attrTextEdit = editEntryWidget->findChild<QPlainTextEdit*>("attributesEdit");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("revealAttributeButton"), Qt::LeftButton);
|
2019-11-08 18:06:13 -05:00
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), expectedFinalSeed);
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
triggerAction("actionEntryTotp");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* totpDialog = m_dbWidget->findChild<TotpDialog*>("TotpDialog");
|
|
|
|
auto* totpLabel = totpDialog->findChild<QLabel*>("totpLabel");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2017-05-03 20:26:08 -04:00
|
|
|
QCOMPARE(totpLabel->text().replace(" ", ""), entry->totp());
|
2017-04-13 06:05:36 -04:00
|
|
|
}
|
|
|
|
|
2012-05-16 03:56:40 -04:00
|
|
|
void TestGui::testSearch()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add canned entries for consistent testing
|
2021-06-08 22:55:53 -04:00
|
|
|
addCannedEntries();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchWidget = toolBar->findChild<SearchWidget*>("SearchWidget");
|
2016-11-28 19:02:21 -05:00
|
|
|
QVERIFY(searchWidget->isEnabled());
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchTextEdit = searchWidget->findChild<QLineEdit*>("searchEdit");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
QVERIFY(entryView->isVisible());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2020-10-07 21:14:32 -04:00
|
|
|
QVERIFY(searchTextEdit->isClearButtonEnabled());
|
2017-04-05 04:42:15 -04:00
|
|
|
|
2018-11-01 21:33:27 -04:00
|
|
|
auto* helpButton = searchWidget->findChild<QAction*>("helpIcon");
|
|
|
|
auto* helpPanel = searchWidget->findChild<QWidget*>("SearchHelpWidget");
|
|
|
|
QVERIFY(helpButton->isVisible());
|
|
|
|
QVERIFY(!helpPanel->isVisible());
|
|
|
|
|
2014-11-18 21:46:38 -05:00
|
|
|
// Enter search
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2018-11-01 21:33:27 -04:00
|
|
|
// Show/Hide search help
|
|
|
|
helpButton->trigger();
|
|
|
|
QTRY_VERIFY(helpPanel->isVisible());
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(helpPanel->isVisible());
|
2021-09-26 06:35:42 -04:00
|
|
|
QApplication::processEvents();
|
2018-11-01 21:33:27 -04:00
|
|
|
helpButton->trigger();
|
|
|
|
QTRY_VERIFY(!helpPanel->isVisible());
|
2014-11-18 02:26:04 -05:00
|
|
|
// Search for "ZZZ"
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "ZZZ");
|
|
|
|
QTRY_COMPARE(searchTextEdit->text(), QString("ZZZ"));
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
2017-01-14 22:29:16 -05:00
|
|
|
// Press the search clear button
|
2022-01-23 10:00:48 -05:00
|
|
|
searchTextEdit->clear();
|
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
|
|
|
|
// Test tag search
|
|
|
|
searchTextEdit->clear();
|
|
|
|
QTest::keyClicks(searchTextEdit, "tag: testTag");
|
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
|
2020-10-07 21:14:32 -04:00
|
|
|
searchTextEdit->clear();
|
2017-01-14 22:29:16 -05:00
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2016-11-02 21:01:02 -04:00
|
|
|
// Escape clears searchedit and retains focus
|
2017-01-14 22:29:16 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "ZZZ");
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Escape);
|
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2014-11-18 02:26:04 -05:00
|
|
|
// Search for "some"
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "some");
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
2016-11-28 19:02:21 -05:00
|
|
|
// Search for "someTHING"
|
|
|
|
QTest::keyClicks(searchTextEdit, "THING");
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2017-01-04 20:46:52 -05:00
|
|
|
// Press Down to focus on the entry view
|
2016-12-23 12:13:08 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Right, Qt::ControlModifier);
|
2016-12-22 02:21:52 -05:00
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2019-04-07 12:00:02 -04:00
|
|
|
auto* searchedEntry = entryView->currentEntry();
|
2020-07-14 18:34:53 -04:00
|
|
|
// Restore focus using F3 key and search text selection
|
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_F3);
|
2019-04-07 12:00:02 -04:00
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2020-07-14 18:34:53 -04:00
|
|
|
QTRY_COMPARE(searchTextEdit->selectedText(), QString("someTHING"));
|
2019-04-07 12:00:02 -04:00
|
|
|
|
|
|
|
searchedEntry->setPassword("password");
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
|
|
|
|
// Attempt password copy with selected test (should fail)
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
|
|
|
QVERIFY(clipboard->text() != searchedEntry->password());
|
|
|
|
// Deselect text and confirm password copies
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->selectedText().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
|
|
|
QCOMPARE(searchedEntry->password(), clipboard->text());
|
2017-01-04 20:46:52 -05:00
|
|
|
// Ensure Down focuses on entry view when search text is selected
|
2020-01-27 21:02:50 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_A, Qt::ControlModifier);
|
2017-01-04 20:46:52 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2019-04-07 12:00:02 -04:00
|
|
|
QCOMPARE(entryView->currentEntry(), searchedEntry);
|
|
|
|
// Test that password copies with entry focused
|
2018-03-25 16:24:30 -04:00
|
|
|
QTest::keyClick(entryView, Qt::Key_C, Qt::ControlModifier);
|
2019-04-07 12:00:02 -04:00
|
|
|
QCOMPARE(searchedEntry->password(), clipboard->text());
|
2018-11-16 10:00:59 -05:00
|
|
|
// Refocus back to search edit
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
// Test that password does not copy
|
|
|
|
searchTextEdit->selectAll();
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
|
|
|
QTRY_COMPARE(clipboard->text(), QString("someTHING"));
|
2016-11-28 19:02:21 -05:00
|
|
|
|
|
|
|
// Test case sensitive search
|
|
|
|
searchWidget->setCaseSensitive(true);
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
searchWidget->setCaseSensitive(false);
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
|
|
|
|
// Test group search
|
2018-11-28 16:13:56 -05:00
|
|
|
searchWidget->setLimitGroup(false);
|
2016-11-28 19:02:21 -05:00
|
|
|
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QModelIndex rootGroupIndex = groupView->model()->index(0, 0);
|
|
|
|
clickIndex(groupView->model()->index(0, 0, rootGroupIndex), groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup()->name(), QString("General"));
|
2018-11-28 16:13:56 -05:00
|
|
|
// Selecting a group should cancel search
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
// Restore search
|
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_F, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(searchTextEdit, "someTHING");
|
2017-06-20 15:54:13 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2018-11-28 16:13:56 -05:00
|
|
|
// Enable group limiting
|
2017-06-20 15:54:13 -04:00
|
|
|
searchWidget->setLimitGroup(true);
|
2016-11-28 19:02:21 -05:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
2018-11-28 16:13:56 -05:00
|
|
|
// Selecting another group should NOT cancel search
|
|
|
|
clickIndex(rootGroupIndex, groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2017-06-20 15:54:13 -04:00
|
|
|
|
2016-11-28 19:02:21 -05:00
|
|
|
// reset
|
2018-11-28 16:13:56 -05:00
|
|
|
searchWidget->setLimitGroup(false);
|
2016-11-28 19:02:21 -05:00
|
|
|
clickIndex(rootGroupIndex, groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
2020-04-21 18:46:21 -04:00
|
|
|
QVERIFY(!m_dbWidget->isSearchActive());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Try to edit the first entry from the search view
|
2017-01-04 20:46:52 -05:00
|
|
|
// Refocus back to search edit
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2020-04-21 18:46:21 -04:00
|
|
|
QTest::keyClicks(searchTextEdit, "someTHING");
|
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2017-01-04 20:46:52 -05:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
2017-01-04 20:46:52 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Return);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Perform the edit and save it
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2016-11-02 21:01:02 -04:00
|
|
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QString origTitle = titleEdit->text();
|
|
|
|
QTest::keyClicks(titleEdit, "_edited");
|
2012-05-16 03:56:40 -04:00
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2017-01-04 20:46:52 -05:00
|
|
|
// Confirm the edit was made and we are back in search mode
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(entry->title(), origTitle.append("_edited"));
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Cancel search, should return to normal view
|
2018-09-29 13:00:47 -04:00
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_Escape);
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_COMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2016-11-02 21:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testDeleteEntry()
|
|
|
|
{
|
|
|
|
// Add canned entries for consistent testing
|
2021-06-08 22:55:53 -04:00
|
|
|
addCannedEntries();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
|
2012-05-16 03:56:40 -04:00
|
|
|
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Move one entry to the recycling bin
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
|
2012-05-16 03:56:40 -04:00
|
|
|
QVERIFY(entryDeleteWidget->isVisible());
|
|
|
|
QVERIFY(entryDeleteWidget->isEnabled());
|
2013-10-08 16:14:02 -04:00
|
|
|
QVERIFY(!m_db->metadata()->recycleBin());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2020-12-12 12:14:18 -05:00
|
|
|
// Test with confirmation dialog
|
|
|
|
if (!config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) {
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Move);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
|
|
|
} else {
|
|
|
|
// no confirm dialog
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
|
|
|
}
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Select multiple entries and move them to the recycling bin
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(2, 1), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2013-10-08 16:11:40 -04:00
|
|
|
QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2);
|
|
|
|
|
2020-12-12 12:14:18 -05:00
|
|
|
if (!config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) {
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
|
|
|
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Move);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
} else {
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
}
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Go to the recycling bin
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QModelIndex rootGroupIndex = groupView->model()->index(0, 0);
|
|
|
|
clickIndex(groupView->model()->index(groupView->model()->rowCount(rootGroupIndex) - 1, 0, rootGroupIndex),
|
2018-03-31 16:01:30 -04:00
|
|
|
groupView,
|
|
|
|
Qt::LeftButton);
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
|
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Delete one entry from the bin
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Delete);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2);
|
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Select the remaining entries and delete them
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Delete);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
|
|
|
|
|
2020-01-10 22:28:31 -05:00
|
|
|
// Ensure the entry preview widget shows the recycling group since all entries are deleted
|
|
|
|
auto* previewWidget = m_dbWidget->findChild<EntryPreviewWidget*>("previewWidget");
|
|
|
|
QVERIFY(previewWidget);
|
|
|
|
auto* groupTitleLabel = previewWidget->findChild<QLabel*>("groupTitleLabel");
|
|
|
|
QVERIFY(groupTitleLabel);
|
|
|
|
|
|
|
|
QTRY_VERIFY(groupTitleLabel->isVisible());
|
|
|
|
QVERIFY(groupTitleLabel->text().contains(m_db->metadata()->recycleBin()->name()));
|
|
|
|
|
|
|
|
// Go back to the root group
|
2018-03-31 16:01:30 -04:00
|
|
|
clickIndex(groupView->model()->index(0, 0), groupView, Qt::LeftButton);
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
}
|
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
void TestGui::testCloneEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
2012-07-21 18:00:44 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
|
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entryOrg = entryView->entryFromIndex(item);
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(item, entryView, Qt::LeftButton);
|
2012-07-21 18:00:44 -04:00
|
|
|
|
|
|
|
triggerAction("actionEntryClone");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* cloneDialog = m_dbWidget->findChild<CloneDialog*>("CloneDialog");
|
|
|
|
auto* cloneButtonBox = cloneDialog->findChild<QDialogButtonBox*>("buttonBox");
|
2018-03-31 16:01:30 -04:00
|
|
|
QTest::mouseClick(cloneButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2017-03-04 19:42:21 -05:00
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
Entry* entryClone = entryView->entryFromIndex(entryView->model()->index(1, 1));
|
|
|
|
QVERIFY(entryOrg->uuid() != entryClone->uuid());
|
2017-01-25 20:02:32 -05:00
|
|
|
QCOMPARE(entryClone->title(), entryOrg->title() + QString(" - Clone"));
|
2012-07-21 18:00:44 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 15:31:14 -04:00
|
|
|
void TestGui::testEntryPlaceholders()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2017-03-16 15:31:14 -04:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2017-03-16 15:31:14 -04:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-03-16 15:31:14 -04:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2017-03-16 15:31:14 -04:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
2019-06-22 09:38:02 -04:00
|
|
|
QComboBox* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
|
|
|
|
QTest::keyClicks(usernameComboBox, "john");
|
2017-03-16 15:31:14 -04:00
|
|
|
QLineEdit* urlEdit = editEntryWidget->findChild<QLineEdit*>("urlEdit");
|
|
|
|
QTest::keyClicks(urlEdit, "{TITLE}.{USERNAME}");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-03-16 15:31:14 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-03-16 15:31:14 -04:00
|
|
|
QModelIndex item = entryView->model()->index(1, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("test"));
|
|
|
|
QCOMPARE(entry->url(), QString("{TITLE}.{USERNAME}"));
|
|
|
|
|
|
|
|
// Test password copy
|
2018-03-31 16:01:30 -04:00
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
2017-03-16 15:31:14 -04:00
|
|
|
m_dbWidget->copyURL();
|
|
|
|
QTRY_COMPARE(clipboard->text(), QString("test.john"));
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::testDragAndDropEntry()
|
|
|
|
{
|
2020-12-12 09:46:23 -05:00
|
|
|
auto entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
auto groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
auto groupModel = qobject_cast<GroupModel*>(groupView->model());
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
QModelIndex sourceIndex = entryView->model()->index(0, 1);
|
|
|
|
QModelIndex targetIndex = groupModel->index(0, 0, groupModel->index(0, 0));
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
2020-12-12 09:46:23 -05:00
|
|
|
auto targetGroup = groupModel->groupFromIndex(targetIndex);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
QMimeData mimeData;
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
2020-12-12 09:46:23 -05:00
|
|
|
|
|
|
|
auto entry = entryView->entryFromIndex(sourceIndex);
|
2012-07-17 17:29:25 -04:00
|
|
|
stream << entry->group()->database()->uuid() << entry->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-entry", encoded);
|
|
|
|
|
2020-12-12 09:46:23 -05:00
|
|
|
// Test Copy, UUID should change, history remain
|
|
|
|
QVERIFY(groupModel->dropMimeData(&mimeData, Qt::CopyAction, -1, 0, targetIndex));
|
|
|
|
// Find the copied entry
|
|
|
|
auto newEntry = targetGroup->findEntryByPath(entry->title());
|
|
|
|
QVERIFY(newEntry);
|
|
|
|
QVERIFY(entry->uuid() != newEntry->uuid());
|
|
|
|
QCOMPARE(entry->historyItems().count(), newEntry->historyItems().count());
|
|
|
|
|
|
|
|
encoded.clear();
|
|
|
|
entry = entryView->entryFromIndex(sourceIndex);
|
|
|
|
auto history = entry->historyItems().count();
|
|
|
|
auto uuid = entry->uuid();
|
2012-07-17 17:29:25 -04:00
|
|
|
stream << entry->group()->database()->uuid() << entry->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-entry", encoded);
|
|
|
|
|
2020-12-12 09:46:23 -05:00
|
|
|
// Test Move, entry pointer should remain the same
|
|
|
|
QCOMPARE(entry->group()->name(), QString("NewDatabase"));
|
2012-07-17 17:29:25 -04:00
|
|
|
QVERIFY(groupModel->dropMimeData(&mimeData, Qt::MoveAction, -1, 0, targetIndex));
|
|
|
|
QCOMPARE(entry->group()->name(), QString("General"));
|
2020-12-12 09:46:23 -05:00
|
|
|
QCOMPARE(entry->uuid(), uuid);
|
|
|
|
QCOMPARE(entry->historyItems().count(), history);
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testDragAndDropGroup()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
QAbstractItemModel* groupModel = m_dbWidget->findChild<GroupView*>("groupView")->model();
|
2012-07-17 17:29:25 -04:00
|
|
|
QModelIndex rootIndex = groupModel->index(0, 0);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex), groupModel->index(1, 0, rootIndex), -1, true, "Windows", 0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
// dropping parent on child is supposed to fail
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
2018-10-31 23:27:38 -04:00
|
|
|
groupModel->index(0, 0, groupModel->index(0, 0, rootIndex)),
|
|
|
|
-1,
|
|
|
|
false,
|
|
|
|
"NewDatabase",
|
|
|
|
0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(1, 0, rootIndex), rootIndex, 0, true, "NewDatabase", 0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex), rootIndex, -1, true, "NewDatabase", 4);
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
void TestGui::testSaveAs()
|
|
|
|
{
|
2017-01-03 22:27:41 -05:00
|
|
|
QFileInfo fileInfo(m_dbFilePath);
|
2012-07-06 13:21:19 -04:00
|
|
|
QDateTime lastModified = fileInfo.lastModified();
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testSaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
// open temporary file so it creates a filename
|
2018-10-19 14:10:37 -04:00
|
|
|
TemporaryFile tmpFile;
|
2016-11-02 21:01:02 -04:00
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
QString tmpFileName = tmpFile.fileName();
|
|
|
|
tmpFile.remove();
|
|
|
|
|
|
|
|
fileDialog()->setNextFileName(tmpFileName);
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2021-11-23 16:50:57 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSaveAs"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
checkDatabase(tmpFileName);
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
fileInfo.refresh();
|
|
|
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
2018-09-29 13:00:47 -04:00
|
|
|
tmpFile.remove();
|
2012-07-06 13:21:19 -04:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:48:03 -04:00
|
|
|
void TestGui::testSaveBackup()
|
|
|
|
{
|
|
|
|
m_db->metadata()->setName("testSaveBackup");
|
|
|
|
|
|
|
|
QFileInfo fileInfo(m_dbFilePath);
|
|
|
|
QDateTime lastModified = fileInfo.lastModified();
|
|
|
|
|
|
|
|
// open temporary file so it creates a filename
|
|
|
|
TemporaryFile tmpFile;
|
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
QString tmpFileName = tmpFile.fileName();
|
|
|
|
tmpFile.remove();
|
|
|
|
|
|
|
|
// wait for modified timer
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSaveBackup*"));
|
|
|
|
|
|
|
|
fileDialog()->setNextFileName(tmpFileName);
|
|
|
|
|
|
|
|
triggerAction("actionDatabaseSaveBackup");
|
|
|
|
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSaveBackup*"));
|
2020-05-08 23:48:03 -04:00
|
|
|
|
|
|
|
checkDatabase(tmpFileName);
|
|
|
|
|
|
|
|
fileInfo.refresh();
|
|
|
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
|
|
|
tmpFile.remove();
|
|
|
|
}
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
void TestGui::testSave()
|
|
|
|
{
|
2021-11-23 16:50:57 -05:00
|
|
|
// Make a modification to the database then save
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testSave");
|
2021-11-23 16:50:57 -05:00
|
|
|
checkSaveDatabase();
|
2012-07-06 13:21:19 -04:00
|
|
|
}
|
|
|
|
|
2021-11-07 17:41:17 -05:00
|
|
|
void TestGui::testSaveBackupPath_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("backupFilePathPattern");
|
|
|
|
QTest::addColumn<QString>("expectedBackupFile");
|
|
|
|
|
|
|
|
// Absolute paths should remain absolute
|
|
|
|
TemporaryFile tmpFile;
|
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
tmpFile.remove();
|
|
|
|
|
|
|
|
QTest::newRow("Absolute backup path") << tmpFile.fileName() << tmpFile.fileName();
|
|
|
|
// relative paths should be resolved to database parent directory
|
|
|
|
QTest::newRow("Relative backup path (implicit)") << "other_dir/test.old.kdbx"
|
|
|
|
<< "other_dir/test.old.kdbx";
|
|
|
|
QTest::newRow("Relative backup path (explicit)") << "./other_dir2/test2.old.kdbx"
|
|
|
|
<< "other_dir2/test2.old.kdbx";
|
|
|
|
|
|
|
|
QTest::newRow("Path with placeholders") << "{DB_FILENAME}.old.kdbx"
|
|
|
|
<< "KeePassXC.old.kdbx";
|
|
|
|
// empty path should be replaced with default pattern
|
|
|
|
QTest::newRow("Empty path") << QString("") << config()->getDefault(Config::BackupFilePathPattern).toString();
|
|
|
|
// {DB_FILENAME} should be replaced with database filename
|
|
|
|
QTest::newRow("") << "{DB_FILENAME}_.old.kdbx"
|
|
|
|
<< "{DB_FILENAME}_.old.kdbx";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testSaveBackupPath()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Tests that the backupFilePathPattern config entry is respected. We do not test patterns like {TIME} etc here
|
|
|
|
* as this is done in a separate test case. We do however check {DB_FILENAME} as this is a feature of the
|
|
|
|
* performBackup() function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get test data
|
|
|
|
QFETCH(QString, backupFilePathPattern);
|
|
|
|
QFETCH(QString, expectedBackupFile);
|
|
|
|
|
|
|
|
// Enable automatic backups
|
|
|
|
config()->set(Config::BackupBeforeSave, true);
|
|
|
|
config()->set(Config::BackupFilePathPattern, backupFilePathPattern);
|
|
|
|
|
|
|
|
// Replace placeholders and resolve relative paths. This cannot be done in the _data() function as the
|
|
|
|
// db path/filename is not known yet
|
|
|
|
auto dbFileInfo = QFileInfo(m_dbFilePath);
|
|
|
|
if (!QDir::isAbsolutePath(expectedBackupFile)) {
|
|
|
|
expectedBackupFile = QDir(dbFileInfo.absolutePath()).absoluteFilePath(expectedBackupFile);
|
|
|
|
}
|
|
|
|
expectedBackupFile.replace("{DB_FILENAME}", dbFileInfo.completeBaseName());
|
|
|
|
|
|
|
|
// Save a modified database
|
|
|
|
auto prevName = m_db->metadata()->name();
|
|
|
|
m_db->metadata()->setName("testBackupPathPattern");
|
2021-11-23 16:50:57 -05:00
|
|
|
checkSaveDatabase();
|
2021-11-07 17:41:17 -05:00
|
|
|
|
|
|
|
// Test that the backup file has the previous database name
|
|
|
|
checkDatabase(expectedBackupFile, prevName);
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
QFile(expectedBackupFile).remove();
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:35:17 -04:00
|
|
|
void TestGui::testDatabaseSettings()
|
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testDatabaseSettings");
|
2020-06-04 08:11:12 -04:00
|
|
|
triggerAction("actionDatabaseSettings");
|
2018-05-13 17:21:43 -04:00
|
|
|
auto* dbSettingsDialog = m_dbWidget->findChild<QWidget*>("databaseSettingsDialog");
|
|
|
|
auto* transformRoundsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
auto advancedToggle = dbSettingsDialog->findChild<QCheckBox*>("advancedSettingsToggle");
|
|
|
|
|
|
|
|
advancedToggle->setChecked(true);
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
2018-01-01 14:24:37 -05:00
|
|
|
QVERIFY(transformRoundsSpinBox != nullptr);
|
2018-01-06 11:06:51 -05:00
|
|
|
transformRoundsSpinBox->setValue(123456);
|
2012-07-17 04:35:17 -04:00
|
|
|
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_COMPARE(m_db->kdf()->rounds(), 123456);
|
2018-05-13 17:21:43 -04:00
|
|
|
|
2021-11-23 16:50:57 -05:00
|
|
|
checkSaveDatabase();
|
2012-07-17 04:35:17 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 09:54:34 -04:00
|
|
|
void TestGui::testKeePass1Import()
|
|
|
|
{
|
|
|
|
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/basic.kdb"));
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionImportKeePass1");
|
2012-06-29 09:54:34 -04:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
auto* keepass1OpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("keepass1OpenWidget");
|
2018-05-13 17:21:43 -04:00
|
|
|
auto* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
2012-06-29 09:54:34 -04:00
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPassword, "masterpw");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->count(), 2);
|
2021-11-23 16:50:57 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("basic [New Database]*"));
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Close the KeePass1 Database
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2016-11-02 21:01:02 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2012-06-29 09:54:34 -04:00
|
|
|
}
|
|
|
|
|
2012-10-12 06:12:00 -04:00
|
|
|
void TestGui::testDatabaseLocking()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
QString origDbName = m_tabWidget->tabText(0);
|
2015-01-11 10:20:59 -05:00
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2021-07-02 05:33:12 -04:00
|
|
|
triggerAction("actionLockAllDatabases");
|
2012-10-12 06:12:00 -04:00
|
|
|
|
2021-11-23 16:50:57 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabText(0), origDbName + " [Locked]");
|
2012-10-12 06:12:00 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* actionDatabaseMerge = m_mainWindow->findChild<QAction*>("actionDatabaseMerge", Qt::FindChildrenRecursively);
|
2018-04-30 17:07:07 -04:00
|
|
|
QCOMPARE(actionDatabaseMerge->isEnabled(), false);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* actionDatabaseSave = m_mainWindow->findChild<QAction*>("actionDatabaseSave", Qt::FindChildrenRecursively);
|
2018-04-30 17:07:07 -04:00
|
|
|
QCOMPARE(actionDatabaseSave->isEnabled(), false);
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
QVERIFY(dbWidget->isLocked());
|
|
|
|
auto* unlockDatabaseWidget = dbWidget->findChild<QWidget*>("databaseOpenWidget");
|
2012-10-12 06:12:00 -04:00
|
|
|
QWidget* editPassword = unlockDatabaseWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QTest::keyClicks(editPassword, "a");
|
2012-10-12 06:12:00 -04:00
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
QVERIFY(!dbWidget->isLocked());
|
2021-11-23 16:50:57 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabText(0), origDbName);
|
2018-04-30 17:07:07 -04:00
|
|
|
|
|
|
|
actionDatabaseMerge = m_mainWindow->findChild<QAction*>("actionDatabaseMerge", Qt::FindChildrenRecursively);
|
|
|
|
QCOMPARE(actionDatabaseMerge->isEnabled(), true);
|
2012-10-12 06:12:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-22 13:05:33 -05:00
|
|
|
void TestGui::testDragAndDropKdbxFiles()
|
|
|
|
{
|
2018-03-31 16:01:30 -04:00
|
|
|
const int openedDatabasesCount = m_tabWidget->count();
|
2017-12-22 13:05:33 -05:00
|
|
|
|
|
|
|
const QString badDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NotDatabase.notkdbx"));
|
2021-11-07 17:41:17 -05:00
|
|
|
const QString goodDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
|
|
|
|
2017-12-22 13:05:33 -05:00
|
|
|
QMimeData badMimeData;
|
|
|
|
badMimeData.setUrls({QUrl::fromLocalFile(badDatabaseFilePath)});
|
|
|
|
QDragEnterEvent badDragEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &badDragEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(badDragEvent.isAccepted(), false);
|
|
|
|
|
|
|
|
QDropEvent badDropEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &badDropEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(badDropEvent.isAccepted(), false);
|
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->count(), openedDatabasesCount);
|
|
|
|
|
|
|
|
QMimeData goodMimeData;
|
2021-11-07 17:41:17 -05:00
|
|
|
goodMimeData.setUrls({QUrl::fromLocalFile(goodDatabaseFilePath)});
|
2017-12-22 13:05:33 -05:00
|
|
|
QDragEnterEvent goodDragEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &goodDragEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(goodDragEvent.isAccepted(), true);
|
|
|
|
|
|
|
|
QDropEvent goodDropEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &goodDropEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(goodDropEvent.isAccepted(), true);
|
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->count(), openedDatabasesCount + 1);
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2017-12-22 13:05:33 -05:00
|
|
|
triggerAction("actionDatabaseClose");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->count(), openedDatabasesCount);
|
2017-12-22 13:05:33 -05:00
|
|
|
}
|
|
|
|
|
2019-06-18 16:58:47 -04:00
|
|
|
void TestGui::testSortGroups()
|
|
|
|
{
|
|
|
|
auto* editGroupWidget = m_dbWidget->findChild<EditGroupWidget*>("editGroupWidget");
|
|
|
|
auto* nameEdit = editGroupWidget->findChild<QLineEdit*>("editName");
|
|
|
|
auto* editGroupWidgetButtonBox = editGroupWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
|
|
|
|
// Create some sub-groups
|
|
|
|
Group* rootGroup = m_db->rootGroup();
|
|
|
|
Group* internetGroup = rootGroup->findGroupByPath("Internet");
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Google");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "eBay");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Amazon");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Facebook");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(rootGroup);
|
|
|
|
|
|
|
|
triggerAction("actionGroupSortAsc");
|
|
|
|
QList<Group*> children = rootGroup->children();
|
|
|
|
QCOMPARE(children[0]->name(), QString("eMail"));
|
|
|
|
QCOMPARE(children[1]->name(), QString("General"));
|
|
|
|
QCOMPARE(children[2]->name(), QString("Homebanking"));
|
|
|
|
QCOMPARE(children[3]->name(), QString("Internet"));
|
|
|
|
QCOMPARE(children[4]->name(), QString("Network"));
|
|
|
|
QCOMPARE(children[5]->name(), QString("Windows"));
|
|
|
|
QList<Group*> subChildren = internetGroup->children();
|
|
|
|
QCOMPARE(subChildren[0]->name(), QString("Amazon"));
|
|
|
|
QCOMPARE(subChildren[1]->name(), QString("eBay"));
|
|
|
|
QCOMPARE(subChildren[2]->name(), QString("Facebook"));
|
|
|
|
QCOMPARE(subChildren[3]->name(), QString("Google"));
|
|
|
|
|
|
|
|
triggerAction("actionGroupSortDesc");
|
|
|
|
children = rootGroup->children();
|
|
|
|
QCOMPARE(children[0]->name(), QString("Windows"));
|
|
|
|
QCOMPARE(children[1]->name(), QString("Network"));
|
|
|
|
QCOMPARE(children[2]->name(), QString("Internet"));
|
|
|
|
QCOMPARE(children[3]->name(), QString("Homebanking"));
|
|
|
|
QCOMPARE(children[4]->name(), QString("General"));
|
|
|
|
QCOMPARE(children[5]->name(), QString("eMail"));
|
|
|
|
subChildren = internetGroup->children();
|
|
|
|
QCOMPARE(subChildren[0]->name(), QString("Google"));
|
|
|
|
QCOMPARE(subChildren[1]->name(), QString("Facebook"));
|
|
|
|
QCOMPARE(subChildren[2]->name(), QString("eBay"));
|
|
|
|
QCOMPARE(subChildren[3]->name(), QString("Amazon"));
|
|
|
|
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
triggerAction("actionGroupSortAsc");
|
|
|
|
children = rootGroup->children();
|
|
|
|
QCOMPARE(children[0]->name(), QString("Windows"));
|
|
|
|
QCOMPARE(children[1]->name(), QString("Network"));
|
|
|
|
QCOMPARE(children[2]->name(), QString("Internet"));
|
|
|
|
QCOMPARE(children[3]->name(), QString("Homebanking"));
|
|
|
|
QCOMPARE(children[4]->name(), QString("General"));
|
|
|
|
QCOMPARE(children[5]->name(), QString("eMail"));
|
|
|
|
subChildren = internetGroup->children();
|
|
|
|
QCOMPARE(subChildren[0]->name(), QString("Amazon"));
|
|
|
|
QCOMPARE(subChildren[1]->name(), QString("eBay"));
|
|
|
|
QCOMPARE(subChildren[2]->name(), QString("Facebook"));
|
|
|
|
QCOMPARE(subChildren[3]->name(), QString("Google"));
|
|
|
|
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(rootGroup);
|
|
|
|
triggerAction("actionGroupSortAsc");
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(internetGroup);
|
|
|
|
triggerAction("actionGroupSortDesc");
|
|
|
|
children = rootGroup->children();
|
|
|
|
QCOMPARE(children[0]->name(), QString("eMail"));
|
|
|
|
QCOMPARE(children[1]->name(), QString("General"));
|
|
|
|
QCOMPARE(children[2]->name(), QString("Homebanking"));
|
|
|
|
QCOMPARE(children[3]->name(), QString("Internet"));
|
|
|
|
QCOMPARE(children[4]->name(), QString("Network"));
|
|
|
|
QCOMPARE(children[5]->name(), QString("Windows"));
|
|
|
|
subChildren = internetGroup->children();
|
|
|
|
QCOMPARE(subChildren[0]->name(), QString("Google"));
|
|
|
|
QCOMPARE(subChildren[1]->name(), QString("Facebook"));
|
|
|
|
QCOMPARE(subChildren[2]->name(), QString("eBay"));
|
|
|
|
QCOMPARE(subChildren[3]->name(), QString("Amazon"));
|
|
|
|
}
|
|
|
|
|
2018-03-11 10:29:48 -04:00
|
|
|
void TestGui::testTrayRestoreHide()
|
|
|
|
{
|
2018-03-11 11:27:26 -04:00
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
2021-02-14 19:15:10 -05:00
|
|
|
QSKIP("QSystemTrayIcon::isSystemTrayAvailable() = false, skipping tray restore/hide test…");
|
2018-03-11 11:27:26 -04:00
|
|
|
}
|
2018-03-11 10:29:48 -04:00
|
|
|
|
2021-09-26 06:35:42 -04:00
|
|
|
#ifndef Q_OS_MACOS
|
2019-05-03 14:40:45 -04:00
|
|
|
m_mainWindow->hideWindow();
|
|
|
|
QVERIFY(!m_mainWindow->isVisible());
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* trayIcon = m_mainWindow->findChild<QSystemTrayIcon*>();
|
2019-05-03 14:40:45 -04:00
|
|
|
QVERIFY(trayIcon);
|
2018-03-11 10:29:48 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2019-05-03 14:40:45 -04:00
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2019-05-03 14:40:45 -04:00
|
|
|
QTRY_VERIFY(!m_mainWindow->isVisible());
|
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::MiddleClick);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
2019-05-03 14:40:45 -04:00
|
|
|
trayIcon->activated(QSystemTrayIcon::MiddleClick);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(!m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
2019-05-03 14:40:45 -04:00
|
|
|
trayIcon->activated(QSystemTrayIcon::DoubleClick);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2019-05-03 14:40:45 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::DoubleClick);
|
|
|
|
QTRY_VERIFY(!m_mainWindow->isVisible());
|
2020-11-01 11:24:47 -05:00
|
|
|
|
|
|
|
// Ensure window is visible at the end
|
|
|
|
trayIcon->activated(QSystemTrayIcon::DoubleClick);
|
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2021-09-26 06:35:42 -04:00
|
|
|
#endif
|
2020-11-01 11:24:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testAutoType()
|
|
|
|
{
|
|
|
|
// Clear entries from root group to guarantee order
|
|
|
|
for (Entry* entry : m_db->rootGroup()->entries()) {
|
|
|
|
m_db->rootGroup()->removeEntry(entry);
|
|
|
|
}
|
|
|
|
Tools::wait(150);
|
|
|
|
|
|
|
|
// 1. Create an entry with Auto-Type disabled
|
|
|
|
|
|
|
|
// 1.a) Click the new entry button and set the title
|
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
QVERIFY(toolBar);
|
|
|
|
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
|
|
|
|
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
QVERIFY(editEntryWidget);
|
|
|
|
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QVERIFY(titleEdit);
|
|
|
|
|
|
|
|
QTest::keyClicks(titleEdit, "1. Entry With Disabled Auto-Type");
|
|
|
|
|
|
|
|
auto* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
|
|
|
|
QVERIFY(usernameComboBox);
|
|
|
|
|
|
|
|
QTest::mouseClick(usernameComboBox, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(usernameComboBox, "AutocompletionUsername");
|
|
|
|
|
|
|
|
// 1.b) Uncheck Auto-Type checkbox
|
|
|
|
editEntryWidget->setCurrentPage(3);
|
|
|
|
auto* enableAutoTypeButton = editEntryWidget->findChild<QCheckBox*>("enableButton");
|
|
|
|
QVERIFY(enableAutoTypeButton);
|
|
|
|
QVERIFY(enableAutoTypeButton->isVisible());
|
|
|
|
QVERIFY(enableAutoTypeButton->isEnabled());
|
|
|
|
|
|
|
|
enableAutoTypeButton->click();
|
|
|
|
QVERIFY(!enableAutoTypeButton->isChecked());
|
|
|
|
|
|
|
|
// 1.c) Save changes
|
|
|
|
editEntryWidget->setCurrentPage(0);
|
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
// 2. Create an entry with default/inherited Auto-Type sequence
|
|
|
|
|
|
|
|
// 2.a) Click the new entry button and set the title
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
|
|
|
QTest::keyClicks(titleEdit, "2. Entry With Default Auto-Type Sequence");
|
|
|
|
QTest::mouseClick(usernameComboBox, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(usernameComboBox, "AutocompletionUsername");
|
|
|
|
|
|
|
|
// 2.b) Confirm AutoType is enabled and default
|
|
|
|
editEntryWidget->setCurrentPage(3);
|
|
|
|
QVERIFY(enableAutoTypeButton->isChecked());
|
|
|
|
auto* inheritSequenceButton = editEntryWidget->findChild<QRadioButton*>("inheritSequenceButton");
|
|
|
|
QVERIFY(inheritSequenceButton->isChecked());
|
|
|
|
|
|
|
|
// 2.c) Save changes
|
|
|
|
editEntryWidget->setCurrentPage(0);
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
// 3. Create an entry with custom Auto-Type sequence
|
|
|
|
|
|
|
|
// 3.a) Click the new entry button and set the title
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
|
|
|
QTest::keyClicks(titleEdit, "3. Entry With Custom Auto-Type Sequence");
|
|
|
|
QTest::mouseClick(usernameComboBox, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(usernameComboBox, "AutocompletionUsername");
|
|
|
|
|
|
|
|
// 3.b) Confirm AutoType is enabled and set custom sequence
|
|
|
|
editEntryWidget->setCurrentPage(3);
|
|
|
|
QVERIFY(enableAutoTypeButton->isChecked());
|
|
|
|
auto* customSequenceButton = editEntryWidget->findChild<QRadioButton*>("customSequenceButton");
|
|
|
|
QTest::mouseClick(customSequenceButton, Qt::LeftButton);
|
|
|
|
QVERIFY(customSequenceButton->isChecked());
|
|
|
|
QVERIFY(!inheritSequenceButton->isChecked());
|
|
|
|
auto* sequenceEdit = editEntryWidget->findChild<QLineEdit*>("sequenceEdit");
|
|
|
|
QVERIFY(sequenceEdit);
|
|
|
|
sequenceEdit->setFocus();
|
|
|
|
QTRY_VERIFY(sequenceEdit->hasFocus());
|
|
|
|
QTest::keyClicks(sequenceEdit, "{USERNAME}{TAB}{TAB}{PASSWORD}{ENTER}");
|
|
|
|
|
|
|
|
// 3.c) Save changes
|
|
|
|
editEntryWidget->setCurrentPage(0);
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
// Check total number of entries matches expected
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
QVERIFY(entryView);
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
|
|
|
|
// Sort entries by title
|
|
|
|
entryView->sortByColumn(1, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
// Select first entry
|
|
|
|
entryView->selectionModel()->clearSelection();
|
|
|
|
QModelIndex entryIndex = entryView->model()->index(0, 0);
|
|
|
|
entryView->selectionModel()->select(entryIndex, QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
|
|
|
|
|
|
|
auto* entryPreviewWidget = m_dbWidget->findChild<EntryPreviewWidget*>("previewWidget");
|
|
|
|
QVERIFY(entryPreviewWidget->isVisible());
|
|
|
|
|
|
|
|
// Check that the Autotype tab in entry preview pane is disabled for entry with disabled Auto-Type
|
|
|
|
auto* entryAutotypeTab = entryPreviewWidget->findChild<QWidget*>("entryAutotypeTab");
|
|
|
|
QVERIFY(!entryAutotypeTab->isEnabled());
|
|
|
|
|
|
|
|
// Check that Auto-Type is disabled in the actual entry model as well
|
|
|
|
Entry* entry = entryView->entryFromIndex(entryIndex);
|
|
|
|
QVERIFY(!entry->autoTypeEnabled());
|
|
|
|
|
|
|
|
// Select second entry
|
|
|
|
entryView->selectionModel()->clearSelection();
|
|
|
|
entryIndex = entryView->model()->index(1, 0);
|
|
|
|
entryView->selectionModel()->select(entryIndex, QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
|
|
|
QVERIFY(entryPreviewWidget->isVisible());
|
|
|
|
|
|
|
|
// Check that the Autotype tab in entry preview pane is enabled for entry with default Auto-Type sequence;
|
|
|
|
QVERIFY(entryAutotypeTab->isEnabled());
|
|
|
|
|
|
|
|
// Check that Auto-Type is enabled in the actual entry model as well
|
|
|
|
entry = entryView->entryFromIndex(entryIndex);
|
|
|
|
QVERIFY(entry->autoTypeEnabled());
|
|
|
|
|
|
|
|
// Select third entry
|
|
|
|
entryView->selectionModel()->clearSelection();
|
|
|
|
entryIndex = entryView->model()->index(2, 0);
|
|
|
|
entryView->selectionModel()->select(entryIndex, QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
|
|
|
QVERIFY(entryPreviewWidget->isVisible());
|
|
|
|
|
|
|
|
// Check that the Autotype tab in entry preview pane is enabled for entry with custom Auto-Type sequence
|
|
|
|
QVERIFY(entryAutotypeTab->isEnabled());
|
|
|
|
|
|
|
|
// Check that Auto-Type is enabled in the actual entry model as well
|
|
|
|
entry = entryView->entryFromIndex(entryIndex);
|
|
|
|
QVERIFY(entry->autoTypeEnabled());
|
|
|
|
|
|
|
|
// De-select third entry
|
|
|
|
entryView->selectionModel()->clearSelection();
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
|
|
|
|
2021-06-08 22:55:53 -04:00
|
|
|
void TestGui::addCannedEntries()
|
2017-10-28 09:23:45 -04:00
|
|
|
{
|
|
|
|
// Find buttons
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2017-10-28 09:23:45 -04:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
2017-10-28 09:23:45 -04:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "test");
|
2022-01-23 10:00:48 -05:00
|
|
|
auto* editEntryWidgetTagsEdit = editEntryWidget->findChild<TagsEdit*>("tagsList");
|
|
|
|
editEntryWidgetTagsEdit->tags(QStringList() << "testTag");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-10-28 09:23:45 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
// Add entry "something 2"
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 2");
|
|
|
|
QTest::keyClicks(passwordEdit, "something 2");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
// Add entry "something 3"
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 3");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
}
|
|
|
|
|
2021-11-07 17:41:17 -05:00
|
|
|
void TestGui::checkDatabase(const QString& filePath, const QString& expectedDbName)
|
2012-07-17 04:16:59 -04:00
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
auto key = QSharedPointer<CompositeKey>::create();
|
|
|
|
key->addKey(QSharedPointer<PasswordKey>::create("a"));
|
2018-11-22 05:47:31 -05:00
|
|
|
auto dbSaved = QSharedPointer<Database>::create();
|
2022-01-28 21:26:53 -05:00
|
|
|
QVERIFY(dbSaved->open(filePath, key, nullptr));
|
2021-11-07 17:41:17 -05:00
|
|
|
QCOMPARE(dbSaved->metadata()->name(), expectedDbName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::checkDatabase(const QString& filePath)
|
|
|
|
{
|
|
|
|
checkDatabase(filePath.isEmpty() ? m_dbFilePath : filePath, m_db->metadata()->name());
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:50:57 -05:00
|
|
|
void TestGui::checkSaveDatabase()
|
|
|
|
{
|
|
|
|
// Attempt to save the database up to two times to overcome transient file errors
|
|
|
|
QTRY_VERIFY(m_db->isModified());
|
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
triggerAction("actionDatabaseSave");
|
|
|
|
if (!m_db->isModified()) {
|
|
|
|
checkDatabase();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QWARN("Failed to save database, trying again...");
|
|
|
|
Tools::wait(250);
|
|
|
|
} while (++i < 2);
|
|
|
|
|
|
|
|
QFAIL("Could not save database.");
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::triggerAction(const QString& name)
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* action = m_mainWindow->findChild<QAction*>(name);
|
2012-07-17 17:29:25 -04:00
|
|
|
QVERIFY(action);
|
|
|
|
QVERIFY(action->isEnabled());
|
|
|
|
action->trigger();
|
2018-05-13 17:21:43 -04:00
|
|
|
QApplication::processEvents();
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex,
|
|
|
|
const QModelIndex& targetIndex,
|
|
|
|
int row,
|
|
|
|
bool expectedResult,
|
|
|
|
const QString& expectedParentName,
|
|
|
|
int expectedPos)
|
2012-07-17 17:29:25 -04:00
|
|
|
{
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
2018-01-06 18:30:18 -05:00
|
|
|
auto groupModel = qobject_cast<GroupModel*>(m_dbWidget->findChild<GroupView*>("groupView")->model());
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
QMimeData mimeData;
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
Group* group = groupModel->groupFromIndex(sourceIndex);
|
|
|
|
stream << group->database()->uuid() << group->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-group", encoded);
|
|
|
|
|
|
|
|
QCOMPARE(groupModel->dropMimeData(&mimeData, Qt::MoveAction, row, 0, targetIndex), expectedResult);
|
|
|
|
QCOMPARE(group->parentGroup()->name(), expectedParentName);
|
|
|
|
QCOMPARE(group->parentGroup()->children().indexOf(group), expectedPos);
|
2012-07-17 04:16:59 -04:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
void TestGui::clickIndex(const QModelIndex& index,
|
|
|
|
QAbstractItemView* view,
|
|
|
|
Qt::MouseButton button,
|
2013-10-08 16:36:27 -04:00
|
|
|
Qt::KeyboardModifiers stateKey)
|
|
|
|
{
|
|
|
|
QTest::mouseClick(view->viewport(), button, stateKey, view->visualRect(index).center());
|
|
|
|
}
|