aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/test/view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/test/view.cpp')
-rw-r--r--src/webengine/test/view.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/webengine/test/view.cpp b/src/webengine/test/view.cpp
new file mode 100644
index 0000000..8aa639a
--- /dev/null
+++ b/src/webengine/test/view.cpp
@@ -0,0 +1,92 @@
+#define CATCH_CONFIG_RUNNER
+
+// clazy:excludeall=non-pod-global-static
+
+#include "webprofile.h"
+#include "webview.h"
+#include <QApplication>
+#include <QMainWindow>
+#include <QTimer>
+#include <QtWebEngine>
+#include <catch2/catch.hpp>
+
+SCENARIO("WebView")
+{
+ const QString profile_id{ "default" };
+ auto *settings = WebProfile::load(qgetenv("PROFILE"), "about:blank", QUrl{ "about:blank" }, QUrl{ "about:blank" });
+ auto *profile = WebProfile::load(profile_id, settings, true);
+
+ QMainWindow window;
+ auto *view = new WebView(profile, nullptr);
+ window.setCentralWidget(view);
+ window.show();
+ window.resize(800, 600);
+
+ WHEN("created")
+ {
+ THEN("using the default profile")
+ {
+ REQUIRE(view->profile() == profile);
+ }
+ THEN("serialized using default profile")
+ {
+ const auto data = view->serialize();
+ REQUIRE(data.profile == profile_id);
+ REQUIRE(data.url.isEmpty());
+ REQUIRE(!data.history.isEmpty());
+ }
+ THEN("loading a url")
+ {
+ // block until a loadFinished signal
+ QEventLoop pause;
+ QObject::connect(view, &WebView::loadFinished, &pause, &QEventLoop::quit);
+ view->load(QUrl{ qgetenv("URL") });
+ pause.exec();
+
+ REQUIRE(view->isLoaded());
+ }
+ }
+
+ WHEN("changing profiles")
+ {
+ const QString swap_profile_id{ "swap_profile" };
+ auto *swap_settings = WebProfile::load(QString(), "about:blank", QUrl{ "about:blank" }, QUrl{ "about:blank" });
+ auto *swap_profile = WebProfile::load(swap_profile_id, swap_settings, true);
+
+ view->setProfile(swap_profile);
+ THEN("using the swap profile")
+ {
+ REQUIRE(view->profile() == swap_profile);
+ }
+ THEN("serialized using swap profile")
+ {
+ const auto data = view->serialize();
+ REQUIRE(data.profile == swap_profile_id);
+ REQUIRE(data.url.isEmpty());
+ REQUIRE(!data.history.isEmpty());
+ }
+
+ view->setProfile(profile);
+ delete swap_settings;
+ delete swap_profile;
+ }
+
+ // cleanup
+ window.close();
+ delete view;
+ delete settings;
+ delete profile;
+}
+
+int main(int argc, char **argv)
+{
+ QtWebEngine::initialize();
+ QApplication app(argc, argv);
+
+ QTimer::singleShot(0, &app, [argc, argv, &app]() {
+ const auto n_failed = Catch::Session().run(argc, argv);
+ app.exit(n_failed);
+ });
+
+ return app.exec();
+}