summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-09-05 16:17:50 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-09-05 23:07:42 +0300
commit6b0c8f7e769a141f13194cf341e888c9b49f294c (patch)
tree308895235933e1246759ffb540269a349d0ef151 /src
parentUrlBar: add completer (diff)
downloadrekonq-6b0c8f7e769a141f13194cf341e888c9b49f294c.tar.xz
Add RekonqWindow tests
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt20
-rw-r--r--src/plugins/CMakeLists.txt2
-rw-r--r--src/rekonqwindow.cpp56
-rw-r--r--src/rekonqwindow.hpp12
-rw-r--r--src/rekonqwindow.ui14
-rw-r--r--src/rekonqwindow_class.cpp91
-rw-r--r--src/test/rekonqwindow_mock.hpp17
l---------src/test/settings_mock.hpp1
-rw-r--r--src/test/test_rekonqwindow.cpp38
9 files changed, 172 insertions, 79 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cc197ee3..b9712235 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,21 +8,27 @@ add_subdirectory(urlbar)
### ------- sources --------
+set(rekonqwindow_SRCS
+ rekonqwindow_class.cpp rekonqwindow.hpp rekonqwindow.ui
+ tabbar/tabbar.cpp tabbar/tabbar.h
+ urlbar/urlbar.cpp urlbar/urlbar.hpp urlbar/completer.cpp urlbar/completer.hpp
+)
+set(rekonqwindow_IFACES ${PROJECT_SOURCE_DIR}/include/rview.hpp)
+
# rekonq
set(rekonq_SRCS
#----------------------------------------
main.cpp application.cpp application_instance.cpp application.hpp
- #----------------------------------------
- rekonqwindow.cpp rekonqwindow.hpp rekonqwindow.ui
taskmanager.cpp taskmanager.h taskmanager.ui
#----------------------------------------
- plugins/rplugininterface.hpp
+ rekonqwindow.cpp ${rekonqwindow_SRCS}
#----------------------------------------
)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
list(APPEND rekonq_SRCS test/rview_fake.cpp test/rview_fake.h test/rview_fake.ui)
endif()
list(TRANSFORM rekonq_SRCS PREPEND src/)
+set(rekonq_SRCS ${rekonq_SRCS} ${rekonqwindow_IFACES})
set(rekonq_SRCS ${rekonq_SRCS} PARENT_SCOPE)
@@ -110,11 +116,19 @@ ENDIF(HAVE_QCA2 AND HAVE_QTOAUTH)
# tests
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+ # application test
add_executable(test_application test/test_application.cpp test/application_mock.hpp
application_instance.cpp application.hpp)
target_compile_definitions(test_application PRIVATE REKONQ_TEST)
target_link_libraries(test_application GTest::gtest GTest::gmock GTest::gtest_main SingleApplication::SingleApplication)
gtest_discover_tests(test_application)
+
+ # rekonqwindow test
+ add_executable(test_rekonqwindow test/test_rekonqwindow.cpp test/rekonqwindow_mock.hpp test/settings_mock.hpp
+ ${rekonqwindow_SRCS} ${rekonqwindow_IFACES})
+ target_compile_definitions(test_rekonqwindow PRIVATE REKONQ_TEST)
+ target_link_libraries(test_rekonqwindow GTest::gtest GTest::gmock settings)
+ gtest_discover_tests(test_rekonqwindow)
endif()
### ------------ INSTALL FILES...
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index a978542f..9d80b057 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_library(pluginloader STATIC pluginloader.cpp pluginloader.h)
+add_library(pluginloader STATIC pluginloader.cpp pluginloader.h rplugininterface.hpp)
target_link_libraries(pluginloader PUBLIC Qt6::Core Qt6::Widgets)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
diff --git a/src/rekonqwindow.cpp b/src/rekonqwindow.cpp
index f969622c..f9f26186 100644
--- a/src/rekonqwindow.cpp
+++ b/src/rekonqwindow.cpp
@@ -9,66 +9,10 @@
#include "rekonqwindow.hpp"
#include "application.hpp"
-#include "settings/settingsdialog.h"
-#include "taskmanager.h"
#include "ui_rekonqwindow.h"
#include <rsettings.hpp>
#include <rview.hpp>
-#ifdef QT_DEBUG
-#include "test/rview_fake.h"
-#endif
-
-RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::RekonqWindow)
-{
- ui->setupUi(this);
-
- connect(ui->tabs, &TabBar::currentChanged, this, [this](RekonqView *view) {
- if (view == nullptr) { // last tab has been closed
- close();
- return;
- }
-
- ui->views->setCurrentWidget(view);
- ui->urlBar->setCurrentView(view);
- });
- connect(ui->tabs, &TabBar::removeView, this, [this](RekonqView *view) { ui->views->removeWidget(view); });
-
- connect(ui->back, &QToolButton::clicked, this, [this]() { currentView()->back(); });
- connect(ui->forward, &QToolButton::clicked, this, [this]() { currentView()->forward(); });
- connect(ui->refresh, &QToolButton::clicked, this, [this]() { currentView()->refresh(); });
- connect(ui->home, &QToolButton::clicked, this, [this]() { loadUrl(rekonq::HomePage, rekonq::CurrentTab); });
-
- // connect menu actions
- // file menu
-#ifdef QT_DEBUG
- {
- auto *actionNewDebugTab = new QAction(tr("New Debug Tab"), ui->menuFile);
- connect(actionNewDebugTab, &QAction::triggered, this, [this]() { addView(new RekonqView_fake(this)); });
- ui->menuFile->insertAction(ui->actionNewTab, actionNewDebugTab);
- }
-#endif
- connect(ui->actionNewTab, &QAction::triggered, this,
- [this]() { loadUrl(rekonq::NewTabPage, rekonq::NewFocusedTab); });
- connect(ui->actionCloseTab, &QAction::triggered, this,
- [this]() { emit ui->tabs->tabCloseRequested(ui->tabs->currentIndex()); });
- connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit);
- // edit menu
- // view menu
- // history menu
- // bookmarks menu
- // settings menu
- connect(ui->actionSettings, &QAction::triggered, this,
- [this]() { (new SettingsDialog(Application::instance()->settings(), this))->show(); });
- connect(ui->actionTaskManager, &QAction::triggered, this, [this]() { (new TaskManager(this))->show(); });
- // help menu
- connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
-
- connect(ui->newTab, &QToolButton::clicked, ui->actionNewTab, &QAction::trigger);
-}
-
-RekonqWindow::~RekonqWindow() { delete ui; }
-
// --------------------------------------------------------------------------------------------------
RekonqView *RekonqWindow::currentView()
diff --git a/src/rekonqwindow.hpp b/src/rekonqwindow.hpp
index 742adbdb..58dbe539 100644
--- a/src/rekonqwindow.hpp
+++ b/src/rekonqwindow.hpp
@@ -13,7 +13,7 @@
#include "rekonq.hpp"
#include <QMainWindow>
-#include <QSplitter>
+#include <rsettings.hpp>
// Forward Declarations
class RekonqView;
@@ -29,12 +29,13 @@ public:
explicit RekonqWindow(QWidget *parent = nullptr);
~RekonqWindow() override;
- [[nodiscard]] RekonqView *currentView();
+ void setupShortcuts(const RekonqSettings *settings);
+ [[nodiscard]] REKONQ_TEST_VIRTUAL RekonqView *currentView() REKONQ_TEST_PURE;
public slots:
- int addView(RekonqView *view);
- void loadUrl(rekonq::DefaultUrl url, rekonq::OpenType type = rekonq::CurrentTab);
- void loadUrl(const QUrl &url, rekonq::OpenType type = rekonq::CurrentTab);
+ REKONQ_TEST_VIRTUAL int addView(RekonqView *view) REKONQ_TEST_PURE;
+ REKONQ_TEST_VIRTUAL void loadUrl(rekonq::DefaultUrl url, rekonq::OpenType type = rekonq::CurrentTab) REKONQ_TEST_PURE;
+ REKONQ_TEST_VIRTUAL void loadUrl(const QUrl &url, rekonq::OpenType type = rekonq::CurrentTab) REKONQ_TEST_PURE;
// void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0);
private slots:
@@ -44,7 +45,6 @@ private slots:
private:
Ui::RekonqWindow *ui;
- QSplitter *_splitter = nullptr;
// QWeakPointer<HistoryPanel> _historyPanel;
// QWeakPointer<BookmarksPanel> _bookmarksPanel;
};
diff --git a/src/rekonqwindow.ui b/src/rekonqwindow.ui
index bd14852a..b16fe187 100644
--- a/src/rekonqwindow.ui
+++ b/src/rekonqwindow.ui
@@ -120,7 +120,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
- <height>22</height>
+ <height>30</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -180,9 +180,6 @@
<property name="text">
<string>Task Manager</string>
</property>
- <property name="shortcut">
- <string>F12</string>
- </property>
</action>
<action name="actionCloseWindow">
<property name="text">
@@ -198,9 +195,6 @@
<property name="text">
<string>&amp;Quit</string>
</property>
- <property name="shortcut">
- <string>Ctrl+Q</string>
- </property>
</action>
<action name="actionAboutQt">
<property name="text">
@@ -211,17 +205,11 @@
<property name="text">
<string>New Tab</string>
</property>
- <property name="shortcut">
- <string>Ctrl+T</string>
- </property>
</action>
<action name="actionCloseTab">
<property name="text">
<string>Close Tab</string>
</property>
- <property name="shortcut">
- <string>Ctrl+W</string>
- </property>
</action>
</widget>
<customwidgets>
diff --git a/src/rekonqwindow_class.cpp b/src/rekonqwindow_class.cpp
new file mode 100644
index 00000000..d0645cb6
--- /dev/null
+++ b/src/rekonqwindow_class.cpp
@@ -0,0 +1,91 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (C) 2013 by Andrea Diamantini <adjam7 at gmail dot com>
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "rekonqwindow.hpp"
+#include "ui_rekonqwindow.h"
+#include <QRegularExpression>
+#include <rview.hpp>
+
+#ifndef REKONQ_TEST
+#include "application.hpp"
+#include "settings/settingsdialog.h"
+#include "taskmanager.h"
+#endif
+
+#if defined(QT_DEBUG) && !defined(REKONQ_TEST)
+#include "test/rview_fake.h"
+#endif
+
+RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::RekonqWindow)
+{
+ ui->setupUi(this);
+
+ connect(ui->tabs, &TabBar::currentChanged, this, [this](RekonqView *view) {
+ if (view == nullptr) { // last tab has been closed
+ close();
+ return;
+ }
+
+ ui->views->setCurrentWidget(view);
+ ui->urlBar->setCurrentView(view);
+ });
+ connect(ui->tabs, &TabBar::removeView, this, [this](RekonqView *view) { ui->views->removeWidget(view); });
+
+ connect(ui->back, &QToolButton::clicked, this, [this]() { currentView()->back(); });
+ connect(ui->forward, &QToolButton::clicked, this, [this]() { currentView()->forward(); });
+ connect(ui->refresh, &QToolButton::clicked, this, [this]() { currentView()->refresh(); });
+ connect(ui->home, &QToolButton::clicked, this, [this]() { loadUrl(rekonq::HomePage, rekonq::CurrentTab); });
+
+ auto *actionFocusUrlBar = new QAction(this);
+ actionFocusUrlBar->setShortcut({"F6"});
+ connect(actionFocusUrlBar, &QAction::triggered, this, [this]() {
+ ui->urlBar->setFocus();
+ ui->urlBar->selectAll();
+ });
+ addAction(actionFocusUrlBar);
+
+ // connect menu actions
+ // file menu
+#if defined(QT_DEBUG) && !defined(REKONQ_TEST)
+ {
+ auto *actionNewDebugTab = new QAction(tr("New Debug Tab"), ui->menuFile);
+ connect(actionNewDebugTab, &QAction::triggered, this, [this]() { addView(new RekonqView_fake(this)); });
+ ui->menuFile->insertAction(ui->actionNewTab, actionNewDebugTab);
+ }
+#endif
+ connect(ui->actionNewTab, &QAction::triggered, this,
+ [this]() { loadUrl(rekonq::NewTabPage, rekonq::NewFocusedTab); });
+ connect(ui->actionCloseTab, &QAction::triggered, this,
+ [this]() { emit ui->tabs->tabCloseRequested(ui->tabs->currentIndex()); });
+ connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit);
+ // edit menu
+ // view menu
+ // history menu
+ // bookmarks menu
+ // settings menu
+#ifndef REKONQ_TEST
+ connect(ui->actionSettings, &QAction::triggered, this,
+ [this]() { (new SettingsDialog(Application::instance()->settings(), this))->show(); });
+ connect(ui->actionTaskManager, &QAction::triggered, this, [this]() { (new TaskManager(this))->show(); });
+#endif
+ // help menu
+ connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
+
+ connect(ui->newTab, &QToolButton::clicked, ui->actionNewTab, &QAction::trigger);
+}
+
+RekonqWindow::~RekonqWindow() { delete ui; }
+
+void RekonqWindow::setupShortcuts(const RekonqSettings *settings)
+{
+ for (auto *action : findChildren<QAction *>(QRegularExpression("^action.*"))) {
+ const auto shortcut = settings->value(action->objectName());
+ if (shortcut.isValid()) action->setShortcut(shortcut.toString());
+ }
+}
diff --git a/src/test/rekonqwindow_mock.hpp b/src/test/rekonqwindow_mock.hpp
new file mode 100644
index 00000000..403237d4
--- /dev/null
+++ b/src/test/rekonqwindow_mock.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "../rekonqwindow.hpp"
+#include <gmock/gmock.h>
+
+class FakeWindow : public RekonqWindow {
+ Q_OBJECT
+
+public:
+ explicit FakeWindow(QWidget *parent = nullptr) : RekonqWindow(parent) {}
+ ~FakeWindow() override = default;
+
+ MOCK_METHOD(RekonqView *, currentView, (), (override));
+ MOCK_METHOD(int, addView, (RekonqView *), (override));
+ MOCK_METHOD(void, loadUrl, (rekonq::DefaultUrl, rekonq::OpenType), (override));
+ MOCK_METHOD(void, loadUrl, (const QUrl &, rekonq::OpenType), (override));
+};
diff --git a/src/test/settings_mock.hpp b/src/test/settings_mock.hpp
new file mode 120000
index 00000000..369a0abe
--- /dev/null
+++ b/src/test/settings_mock.hpp
@@ -0,0 +1 @@
+../settings/test/settings_mock.hpp \ No newline at end of file
diff --git a/src/test/test_rekonqwindow.cpp b/src/test/test_rekonqwindow.cpp
new file mode 100644
index 00000000..9e90cd94
--- /dev/null
+++ b/src/test/test_rekonqwindow.cpp
@@ -0,0 +1,38 @@
+#include "rekonqwindow_mock.hpp"
+#include "settings_mock.hpp"
+#include <QApplication>
+#include <QRegularExpression>
+#include <gtest/gtest.h>
+
+using ::testing::_; // NOLINT(bugprone-reserved-identifier)
+using ::testing::Matcher;
+using ::testing::ReturnArg;
+
+TEST(RekonqWindow, mock_shortcuts)
+{
+ FakeWindow window;
+ EXPECT_CALL(window, currentView).Times(0);
+ EXPECT_CALL(window, addView).Times(0);
+ EXPECT_CALL(window, loadUrl(Matcher<rekonq::DefaultUrl>(_), _)).Times(0);
+ EXPECT_CALL(window, loadUrl(Matcher<const QUrl &>(_), _)).Times(0);
+
+ for (auto *action : window.findChildren<QAction *>(QRegularExpression("^action.*"))) {
+ EXPECT_TRUE(action->shortcut().isEmpty()) << qUtf8Printable(action->objectName());
+ }
+
+ MockSettings settings;
+ EXPECT_CALL(settings, value).WillRepeatedly(ReturnArg<0>());
+
+ window.setupShortcuts(&settings);
+ for (auto *action : window.findChildren<QAction *>(QRegularExpression("^action.*"))) {
+ EXPECT_FALSE(action->shortcut().isEmpty()) << qUtf8Printable(action->objectName());
+ }
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ QApplication app(argc, argv);
+
+ return RUN_ALL_TESTS();
+}