2011-12-26 13:18:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QAction>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLineEdit>
|
2015-07-22 11:03:59 -04:00
|
|
|
#include <QMimeData>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QTest>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QToolButton>
|
2011-12-26 13:18:21 -05:00
|
|
|
|
|
|
|
#include "config-keepassx-tests.h"
|
2012-06-14 16:55:25 -04:00
|
|
|
#include "core/Config.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "core/Database.h"
|
2012-05-10 04:29:25 -04:00
|
|
|
#include "core/Entry.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "core/Group.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "core/Metadata.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"
|
|
|
|
#include "format/KeePass2Reader.h"
|
2012-04-14 14:31:35 -04:00
|
|
|
#include "gui/DatabaseTabWidget.h"
|
|
|
|
#include "gui/DatabaseWidget.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
#include "gui/FileDialog.h"
|
|
|
|
#include "gui/MainWindow.h"
|
2013-10-08 16:11:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2012-05-16 04:16:32 -04:00
|
|
|
#include "gui/entry/EditEntryWidget.h"
|
|
|
|
#include "gui/entry/EntryView.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "gui/group/GroupModel.h"
|
|
|
|
#include "gui/group/GroupView.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "keys/PasswordKey.h"
|
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();
|
2011-12-29 14:10:19 -05:00
|
|
|
m_mainWindow = 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();
|
2015-09-12 17:12:17 -04:00
|
|
|
m_mainWindow->activateWindow();
|
2012-11-02 06:08:41 -04:00
|
|
|
Tools::wait(50);
|
2015-07-19 13:33:47 -04:00
|
|
|
|
|
|
|
QByteArray tmpData;
|
|
|
|
QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
|
|
|
QVERIFY(sourceDbFile.open(QIODevice::ReadOnly));
|
|
|
|
QVERIFY(Tools::readAllFromDevice(&sourceDbFile, tmpData));
|
|
|
|
|
|
|
|
QVERIFY(m_orgDbFile.open());
|
|
|
|
m_orgDbFileName = QFileInfo(m_orgDbFile.fileName()).fileName();
|
|
|
|
QCOMPARE(m_orgDbFile.write(tmpData), static_cast<qint64>((tmpData.size())));
|
|
|
|
m_orgDbFile.close();
|
2011-12-26 13:18:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testOpenDatabase()
|
|
|
|
{
|
2015-07-19 13:33:47 -04:00
|
|
|
fileDialog()->setNextFileName(m_orgDbFile.fileName());
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseOpen");
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2012-06-28 03:21:15 -04:00
|
|
|
QWidget* databaseOpenWidget = m_mainWindow->findChild<QWidget*>("databaseOpenWidget");
|
|
|
|
QLineEdit* editPassword = databaseOpenWidget->findChild<QLineEdit*>("editPassword");
|
2011-12-26 13:18:21 -05:00
|
|
|
QVERIFY(editPassword);
|
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);
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
2011-12-26 13:18:21 -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);
|
2015-07-19 13:33:47 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_orgDbFileName);
|
2012-07-17 04:16:59 -04:00
|
|
|
|
|
|
|
m_dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
m_db = m_dbWidget->database();
|
2011-12-26 13:18:21 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 14:31:35 -04:00
|
|
|
void TestGui::testEditEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2012-05-12 07:22:41 -04:00
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
2012-04-14 14:31:35 -04:00
|
|
|
QRect itemRect = entryView->visualRect(item);
|
|
|
|
QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
|
2012-04-26 11:52:02 -04:00
|
|
|
|
|
|
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
QVERIFY(m_dbWidget->currentWidget() == editEntryWidget);
|
2012-04-14 14:31:35 -04:00
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QVERIFY(editEntryWidgetButtonBox);
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
// make sure the database isn't marked as modified
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
2015-07-19 13:33:47 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_orgDbFileName);
|
2012-04-14 14:31:35 -04:00
|
|
|
}
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
void TestGui::testAddEntry()
|
|
|
|
{
|
2012-07-17 04:16:59 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2012-05-10 04:29:25 -04:00
|
|
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2012-05-10 04:29:25 -04:00
|
|
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::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"));
|
|
|
|
QCOMPARE(entry->historyItems().size(), 0);
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
2015-07-19 13:33:47 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_orgDbFileName));
|
2012-05-10 04:29:25 -04:00
|
|
|
|
|
|
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::keyClicks(titleEdit, "something");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("testsomething"));
|
|
|
|
QCOMPARE(entry->historyItems().size(), 1);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 2");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 3");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 4);
|
2012-05-10 04:29:25 -04:00
|
|
|
}
|
|
|
|
|
2012-05-16 03:56:40 -04:00
|
|
|
void TestGui::testSearch()
|
|
|
|
{
|
2014-11-18 21:46:38 -05:00
|
|
|
QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
|
|
|
|
QVERIFY(searchAction->isEnabled());
|
2012-05-19 05:53:32 -04:00
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2014-11-18 21:46:38 -05:00
|
|
|
QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
|
2012-07-17 04:16:59 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
|
|
|
|
QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton");
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2015-11-01 07:37:03 -05:00
|
|
|
QVERIFY(!searchEdit->isVisible());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2014-11-18 21:46:38 -05:00
|
|
|
// Enter search
|
|
|
|
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
|
2014-11-18 02:26:04 -05:00
|
|
|
QTRY_VERIFY(searchEdit->hasFocus());
|
|
|
|
// Search for "ZZZ"
|
|
|
|
QTest::keyClicks(searchEdit, "ZZZ");
|
2012-07-23 18:00:53 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
2014-11-18 02:26:04 -05:00
|
|
|
// Escape
|
|
|
|
QTest::keyClick(m_mainWindow, Qt::Key_Escape);
|
|
|
|
QTRY_VERIFY(!searchEdit->hasFocus());
|
2014-11-18 21:46:38 -05:00
|
|
|
// Enter search again
|
|
|
|
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
|
2014-11-18 02:26:04 -05:00
|
|
|
QTRY_VERIFY(searchEdit->hasFocus());
|
|
|
|
// Input and clear
|
|
|
|
QTest::keyClicks(searchEdit, "ZZZ");
|
|
|
|
QTRY_COMPARE(searchEdit->text(), QString("ZZZ"));
|
2012-05-16 03:56:40 -04:00
|
|
|
QTest::mouseClick(clearSearch, Qt::LeftButton);
|
2014-11-18 02:26:04 -05:00
|
|
|
QTRY_COMPARE(searchEdit->text(), QString(""));
|
2014-11-18 21:46:38 -05:00
|
|
|
// Triggering search should select the existing text
|
2014-11-18 02:26:04 -05:00
|
|
|
QTest::keyClicks(searchEdit, "ZZZ");
|
2014-11-18 21:46:38 -05:00
|
|
|
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
|
2014-11-18 02:26:04 -05:00
|
|
|
QTRY_VERIFY(searchEdit->hasFocus());
|
|
|
|
// Search for "some"
|
2012-05-16 03:56:40 -04:00
|
|
|
QTest::keyClicks(searchEdit, "some");
|
2013-10-08 16:11:40 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 4);
|
2015-01-05 08:37:37 -05:00
|
|
|
// Press Down to focus on the entry view
|
|
|
|
QVERIFY(!entryView->hasFocus());
|
|
|
|
QTest::keyClick(searchEdit, Qt::Key_Down);
|
|
|
|
QVERIFY(entryView->hasFocus());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
2012-05-16 03:56:40 -04:00
|
|
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2012-05-16 03:56:40 -04:00
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton);
|
2012-05-16 03:56:40 -04:00
|
|
|
QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
|
|
|
|
|
|
|
|
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
|
|
|
|
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
|
|
|
|
2016-09-02 06:00:12 -04:00
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
2012-05-16 03:56:40 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(2, 0), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2013-10-08 16:11:40 -04:00
|
|
|
QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2);
|
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton");
|
|
|
|
QTest::mouseClick(closeSearchButton, Qt::LeftButton);
|
2012-05-16 03:56:40 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:36:27 -04:00
|
|
|
void TestGui::testDeleteEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2013-10-08 16:36:27 -04:00
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
|
|
|
|
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
|
|
|
|
QModelIndex rootGroupIndex = groupView->model()->index(0, 0);
|
|
|
|
clickIndex(groupView->model()->index(groupView->model()->rowCount(rootGroupIndex) - 1, 0, rootGroupIndex),
|
|
|
|
groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
|
|
|
|
|
|
|
|
clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton);
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2);
|
|
|
|
|
|
|
|
clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton, Qt::ControlModifier);
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
|
|
|
|
|
|
|
|
clickIndex(groupView->model()->index(0, 0),
|
|
|
|
groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
}
|
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
void TestGui::testCloneEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
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");
|
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
Entry* entryClone = entryView->entryFromIndex(entryView->model()->index(1, 1));
|
|
|
|
QVERIFY(entryOrg->uuid() != entryClone->uuid());
|
|
|
|
QCOMPARE(entryClone->title(), entryOrg->title());
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::testDragAndDropEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
2012-07-17 17:29:25 -04:00
|
|
|
QAbstractItemModel* groupModel = groupView->model();
|
|
|
|
|
|
|
|
QModelIndex sourceIndex = entryView->model()->index(0, 1);
|
|
|
|
QModelIndex targetIndex = groupModel->index(0, 0, groupModel->index(0, 0));
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
|
|
|
QMimeData mimeData;
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
Entry* entry = entryView->entryFromIndex(sourceIndex);
|
|
|
|
stream << entry->group()->database()->uuid() << entry->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-entry", encoded);
|
|
|
|
|
|
|
|
QVERIFY(groupModel->dropMimeData(&mimeData, Qt::MoveAction, -1, 0, targetIndex));
|
|
|
|
QCOMPARE(entry->group()->name(), QString("General"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
groupModel->index(1, 0, rootIndex),
|
|
|
|
-1, true, "Windows", 0);
|
|
|
|
|
|
|
|
// dropping parent on child is supposed to fail
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
groupModel->index(0, 0, groupModel->index(0, 0, rootIndex)),
|
|
|
|
-1, false, "NewDatabase", 0);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(1, 0, rootIndex),
|
|
|
|
rootIndex,
|
|
|
|
0, true, "NewDatabase", 0);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
rootIndex,
|
|
|
|
-1, true, "NewDatabase", 5);
|
|
|
|
}
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
void TestGui::testSaveAs()
|
|
|
|
{
|
2015-07-19 13:33:47 -04:00
|
|
|
QFileInfo fileInfo(m_orgDbFile.fileName());
|
2012-07-06 13:21:19 -04:00
|
|
|
QDateTime lastModified = fileInfo.lastModified();
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
m_db->metadata()->setName("SaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-10-22 11:52:08 -04:00
|
|
|
QTemporaryFile* tmpFile = new QTemporaryFile();
|
2012-07-06 13:21:19 -04:00
|
|
|
// open temporary file so it creates a filename
|
2012-10-22 11:52:08 -04:00
|
|
|
QVERIFY(tmpFile->open());
|
|
|
|
m_tmpFileName = tmpFile->fileName();
|
|
|
|
delete tmpFile;
|
|
|
|
fileDialog()->setNextFileName(m_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
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("SaveAs"));
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
checkDatabase();
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
fileInfo.refresh();
|
|
|
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testSave()
|
|
|
|
{
|
2012-07-17 04:16:59 -04:00
|
|
|
m_db->metadata()->setName("Save");
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
checkDatabase();
|
2012-07-06 13:21:19 -04:00
|
|
|
}
|
|
|
|
|
2012-07-17 04:35:17 -04:00
|
|
|
void TestGui::testDatabaseSettings()
|
|
|
|
{
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionChangeDatabaseSettings");
|
2012-07-17 04:35:17 -04:00
|
|
|
QWidget* dbSettingsWidget = m_dbWidget->findChild<QWidget*>("databaseSettingsWidget");
|
|
|
|
QSpinBox* transformRoundsSpinBox = dbSettingsWidget->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
transformRoundsSpinBox->setValue(100);
|
|
|
|
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
2012-07-17 04:35:17 -04:00
|
|
|
QCOMPARE(m_db->transformRounds(), Q_UINT64_C(100));
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2012-07-17 04:35:17 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
checkDatabase();
|
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
|
|
|
|
|
|
|
QWidget* keepass1OpenWidget = m_mainWindow->findChild<QWidget*>("keepass1OpenWidget");
|
|
|
|
QLineEdit* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPassword, "masterpw");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->count(), 2);
|
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("basic [New database]*"));
|
2012-06-29 09:54:34 -04:00
|
|
|
}
|
|
|
|
|
2012-10-12 06:12:00 -04:00
|
|
|
void TestGui::testDatabaseLocking()
|
|
|
|
{
|
2015-01-11 10:20:59 -05:00
|
|
|
MessageBox::setNextAnswer(QMessageBox::Cancel);
|
|
|
|
|
2012-10-12 06:12:00 -04:00
|
|
|
triggerAction("actionLockDatabases");
|
|
|
|
|
2015-09-12 09:48:38 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(0).remove('&'), QString("Save [locked]"));
|
|
|
|
QCOMPARE(m_tabWidget->tabText(1).remove('&'), QString("basic [New database]*"));
|
2012-10-12 06:12:00 -04:00
|
|
|
|
|
|
|
QWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
QWidget* unlockDatabaseWidget = dbWidget->findChild<QWidget*>("unlockDatabaseWidget");
|
|
|
|
QWidget* editPassword = unlockDatabaseWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPassword, "masterpw");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2015-09-12 09:48:38 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()).remove('&'), QString("basic [New database]*"));
|
2012-10-12 06:12:00 -04:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:10:19 -05:00
|
|
|
void TestGui::cleanupTestCase()
|
|
|
|
{
|
2012-04-18 16:08:22 -04:00
|
|
|
delete m_mainWindow;
|
2012-10-22 11:52:08 -04:00
|
|
|
QFile::remove(m_tmpFileName);
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::checkDatabase()
|
2012-07-17 04:16:59 -04:00
|
|
|
{
|
|
|
|
CompositeKey key;
|
|
|
|
key.addKey(PasswordKey("a"));
|
|
|
|
KeePass2Reader reader;
|
2012-10-22 11:52:08 -04:00
|
|
|
QScopedPointer<Database> dbSaved(reader.readDatabase(m_tmpFileName, key));
|
2012-07-17 17:29:25 -04:00
|
|
|
QVERIFY(dbSaved);
|
|
|
|
QVERIFY(!reader.hasError());
|
|
|
|
QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::triggerAction(const QString& name)
|
|
|
|
{
|
|
|
|
QAction* action = m_mainWindow->findChild<QAction*>(name);
|
|
|
|
QVERIFY(action);
|
|
|
|
QVERIFY(action->isEnabled());
|
|
|
|
action->trigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex, const QModelIndex& targetIndex, int row,
|
|
|
|
bool expectedResult, const QString& expectedParentName, int expectedPos)
|
|
|
|
{
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
2014-05-17 05:21:17 -04:00
|
|
|
GroupModel* 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
|
|
|
}
|
|
|
|
|
2013-10-08 16:36:27 -04:00
|
|
|
void TestGui::clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button,
|
|
|
|
Qt::KeyboardModifiers stateKey)
|
|
|
|
{
|
|
|
|
QTest::mouseClick(view->viewport(), button, stateKey, view->visualRect(index).center());
|
|
|
|
}
|
|
|
|
|
2012-07-23 18:07:28 -04:00
|
|
|
QTEST_MAIN(TestGui)
|