diff options
Diffstat (limited to 'tests/gui/TestGuiBrowser.cpp')
-rw-r--r-- | tests/gui/TestGuiBrowser.cpp | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/tests/gui/TestGuiBrowser.cpp b/tests/gui/TestGuiBrowser.cpp index 834aea581..fb981d6df 100644 --- a/tests/gui/TestGuiBrowser.cpp +++ b/tests/gui/TestGuiBrowser.cpp @@ -31,6 +31,7 @@ #include <QTableView> #include <QToolBar> +#include "browser/BrowserService.h" #include "config-keepassx-tests.h" #include "core/Bootstrap.h" #include "core/Config.h" @@ -47,50 +48,55 @@ #include "gui/entry/EditEntryWidget.h" #include "gui/entry/EntryView.h" -QTEST_MAIN(TestGuiBrowser) +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); + app.applyTheme(); + QTEST_DISABLE_KEYPAD_NAVIGATION + TestGuiBrowser tc; + QTEST_SET_MAIN_SOURCE_PATH + return QTest::qExec(&tc, argc, argv); +} void TestGuiBrowser::initTestCase() { QVERIFY(Crypto::init()); Config::createTempFileInstance(); // Disable autosave so we can test the modified file indicator - config()->set("AutoSaveAfterEveryChange", false); - config()->set("AutoSaveOnExit", false); + config()->set(Config::AutoSaveAfterEveryChange, false); + config()->set(Config::AutoSaveOnExit, false); // Enable the tray icon so we can test hiding/restoring the windowQByteArray - config()->set("GUI/ShowTrayIcon", true); + config()->set(Config::GUI_ShowTrayIcon, true); // Disable advanced settings mode (activate within individual tests to test advanced settings) - config()->set("GUI/AdvancedSettings", false); + config()->set(Config::GUI_AdvancedSettings, false); // Disable the update check first time alert - config()->set("UpdateCheckMessageShown", true); + config()->set(Config::UpdateCheckMessageShown, true); m_mainWindow.reset(new MainWindow()); Bootstrap::restoreMainWindowState(*m_mainWindow); m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); m_mainWindow->show(); - - // Load the NewDatabase.kdbx file into temporary storage - QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabaseBrowser.kdbx")); - QVERIFY(sourceDbFile.open(QIODevice::ReadOnly)); - QVERIFY(Tools::readAllFromDevice(&sourceDbFile, m_dbData)); - sourceDbFile.close(); } // Every test starts with opening the temp database void TestGuiBrowser::init() { m_dbFile.reset(new TemporaryFile()); - // Write the temp storage to a temp database file for use in our tests - QVERIFY(m_dbFile->open()); - QCOMPARE(m_dbFile->write(m_dbData), static_cast<qint64>((m_dbData.size()))); - m_dbFileName = QFileInfo(m_dbFile->fileName()).fileName(); - m_dbFilePath = m_dbFile->fileName(); - m_dbFile->close(); + m_dbFile->copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabaseBrowser.kdbx")); // make sure window is activated or focus tests may fail m_mainWindow->activateWindow(); QApplication::processEvents(); - fileDialog()->setNextFileName(m_dbFilePath); + fileDialog()->setNextFileName(m_dbFile->fileName()); triggerAction("actionDatabaseOpen"); auto* databaseOpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("databaseOpenWidget"); @@ -131,7 +137,7 @@ void TestGuiBrowser::cleanupTestCase() void TestGuiBrowser::testEntrySettings() { // Enable the Browser Integration - config()->set("Browser/Enabled", true); + config()->set(Config::Browser_Enabled, true); auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); auto* entryView = m_dbWidget->findChild<EntryView*>("entryView"); @@ -226,6 +232,28 @@ void TestGuiBrowser::testAdditionalURLs() } } +void TestGuiBrowser::testGetDatabaseGroups() +{ + auto result = browserService()->getDatabaseGroups(); + QCOMPARE(result.length(), 1); + + auto groups = result["groups"].toArray(); + auto first = groups.at(0); + auto children = first.toObject()["children"].toArray(); + QCOMPARE(first.toObject()["name"].toString(), QString("NewDatabase")); + QCOMPARE(children.size(), 6); + + auto firstChild = children.at(0).toObject(); + auto secondChild = children.at(1).toObject(); + QCOMPARE(firstChild["name"].toString(), QString("General")); + QCOMPARE(secondChild["name"].toString(), QString("Windows")); + + auto subGroups = firstChild["children"].toArray(); + QCOMPARE(subGroups.count(), 1); + auto subGroupObj = subGroups.at(0).toObject(); + QCOMPARE(subGroupObj["name"].toString(), QString("SubGroup")); +} + void TestGuiBrowser::triggerAction(const QString& name) { auto* action = m_mainWindow->findChild<QAction*>(name); |