aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/test')
-rw-r--r--src/webengine/test/form.html10
-rw-r--r--src/webengine/test/icon.svg7
-rw-r--r--src/webengine/test/profile.cpp124
-rw-r--r--src/webengine/test/profilemanager.cpp120
-rw-r--r--src/webengine/test/sample.html7
-rw-r--r--src/webengine/test/testing.profile8
-rw-r--r--src/webengine/test/view.cpp92
7 files changed, 368 insertions, 0 deletions
diff --git a/src/webengine/test/form.html b/src/webengine/test/form.html
new file mode 100644
index 0000000..9d8b19e
--- /dev/null
+++ b/src/webengine/test/form.html
@@ -0,0 +1,10 @@
+<html>
+
+<head>
+ <title>Form completion test</title>
+</head>
+
+<body>
+<h2>Form completion test</h2>
+</body>
+</html>
diff --git a/src/webengine/test/icon.svg b/src/webengine/test/icon.svg
new file mode 100644
index 0000000..a348cab
--- /dev/null
+++ b/src/webengine/test/icon.svg
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" version="1.1">
+ <circle cx="150" cy="150" r="100" stroke="#000000" stroke-width="6" fill="#e60026"></circle>
+ <circle cx="150" cy="150" r="87" stroke="#000000" stroke-width="4" fill="#e5e4e2"></circle>
+ <path d="M230,150 A80,80 0 0 0 150,70 L150,150 Z" />
+ <path d="M70,150 A80,80 0 0 0 150,230 L150,150 Z" />
+</svg>
+
diff --git a/src/webengine/test/profile.cpp b/src/webengine/test/profile.cpp
new file mode 100644
index 0000000..7351f66
--- /dev/null
+++ b/src/webengine/test/profile.cpp
@@ -0,0 +1,124 @@
+#define CATCH_CONFIG_RUNNER
+
+// clazy:excludeall=non-pod-global-static
+
+#include "webprofilemanager.h"
+#include <QApplication>
+#include <catch2/catch.hpp>
+
+TEST_CASE("loading profile settings")
+{
+ const QString search = GENERATE(as<QString>{}, "https://search.url/t=%1", "https://duckduckgo.com/?q=%1&ia=web", "aaabbbccc");
+ const QUrl homepage = GENERATE(as<QUrl>{}, "https://homepage.net", "about:blank", "aaabbbccc");
+ const QUrl newtab = GENERATE(as<QUrl>{}, "https://newtab.net", "about:blank", "aaabbbccc");
+
+ auto *settings = WebProfile::load(QString(), search, homepage, newtab);
+
+ REQUIRE(settings != nullptr);
+ REQUIRE(settings->value("search").toString() == search);
+ REQUIRE(settings->value("homepage").toUrl() == homepage);
+ REQUIRE(settings->value("newtab").toUrl() == newtab);
+
+ delete settings;
+}
+
+SCENARIO("loading individual profiles")
+{
+ GIVEN("no profile preset")
+ {
+ const QString search = GENERATE(as<QString>{}, "https://search.url/t=%1", "https://duckduckgo.com/?q=%1&ia=web", "aaabbbccc");
+ const QUrl homepage = GENERATE(as<QUrl>{}, "https://homepage.net", "about:blank", "aaabbbccc");
+ const QUrl newtab = GENERATE(as<QUrl>{}, "https://newtab.net", "about:blank", "aaabbbccc");
+
+ const QString id{ "id" };
+ auto *settings = WebProfile::load(QString(), search, homepage, newtab);
+ auto *profile = WebProfile::load(id, settings, true);
+
+ REQUIRE(profile != nullptr);
+ REQUIRE(profile->getId() == id);
+ REQUIRE(profile->property("id").toString() == id);
+ REQUIRE(profile->name() == id);
+ REQUIRE(profile->search() == search);
+ REQUIRE(profile->homepage() == homepage);
+ REQUIRE(profile->newtab() == newtab);
+
+ REQUIRE(profile->isOffTheRecord());
+ delete settings;
+ delete profile;
+ }
+
+ GIVEN("an off-the-record profile preset")
+ {
+ REQUIRE(qEnvironmentVariableIsSet("PROFILE"));
+
+ const QString id{ "id" };
+ auto *settings = WebProfile::load(qgetenv("PROFILE"), QString(), QUrl(), QUrl());
+ auto *profile = WebProfile::load(id, settings, true);
+
+ REQUIRE(profile != nullptr);
+ REQUIRE(profile->getId() == id);
+ REQUIRE(profile->isOffTheRecord());
+
+ WHEN("created")
+ {
+ THEN("uses default values")
+ {
+ REQUIRE(profile->name() == "Test Profile");
+ REQUIRE(profile->search() == "https://duckduckgo.com/?q=%1&ia=web");
+ REQUIRE(profile->homepage() == QUrl("about:blank"));
+ REQUIRE(profile->newtab() == QUrl("about:blank"));
+ }
+ }
+
+ WHEN("changing profile name")
+ {
+ const QString name = GENERATE(as<QString>{}, "a", "bb", "ccc");
+ profile->setName(name);
+ THEN("the name changes")
+ {
+ REQUIRE(profile->name() == name);
+ REQUIRE(settings->value("name").toString() == name);
+ }
+ }
+ WHEN("changing search url")
+ {
+ const QString search = GENERATE(as<QString>{}, "a", "bb", "ccc");
+ profile->setSearch(search);
+ THEN("the search url changes")
+ {
+ REQUIRE(profile->search() == search);
+ REQUIRE(settings->value("search").toString() == search);
+ }
+ }
+ WHEN("changing homepage")
+ {
+ const QUrl url = GENERATE(as<QUrl>{}, "a", "bb", "ccc");
+ profile->setHomepage(url);
+ THEN("homepage changes")
+ {
+ REQUIRE(profile->homepage() == url);
+ REQUIRE(settings->value("homepage").toUrl() == url);
+ }
+ }
+ WHEN("changing newtab")
+ {
+ const QUrl url = GENERATE(as<QUrl>{}, "a", "bb", "ccc");
+ profile->setNewtab(url);
+ THEN("newtab changes")
+ {
+ REQUIRE(profile->newtab() == url);
+ REQUIRE(settings->value("newtab").toUrl() == url);
+ }
+ }
+
+ delete settings;
+ delete profile;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ const auto r = Catch::Session().run(argc, argv);
+ return r;
+}
diff --git a/src/webengine/test/profilemanager.cpp b/src/webengine/test/profilemanager.cpp
new file mode 100644
index 0000000..dc7c903
--- /dev/null
+++ b/src/webengine/test/profilemanager.cpp
@@ -0,0 +1,120 @@
+#define CATCH_CONFIG_RUNNER
+
+// clazy:excludeall=non-pod-global-static
+
+#include "webprofilemanager.h"
+#include <QApplication>
+#include <catch2/catch.hpp>
+
+SCENARIO("WebProfileManager")
+{
+ const QString search{ "https://search.url/t=%1" };
+ const QUrl homepage{ "https://homepage.net" };
+ const QUrl newtab{ "https://newtab.net" };
+ const QString default_id{ "default" };
+
+ GIVEN("an empty profile list")
+ {
+ WebProfileManager<false> profiles({}, default_id, search, homepage, newtab);
+
+ REQUIRE(profiles.idList().count() == 1);
+ REQUIRE(profiles.profile(default_id) == WebProfile::defaultProfile());
+ REQUIRE(profiles.profile("not-in-list") == nullptr);
+
+ WHEN("adding a new profile")
+ {
+ const QString id{ "id" };
+ auto *settings = WebProfile::load(QString(), search, homepage, newtab);
+ auto *profile = WebProfile::load(id, settings, true);
+
+ THEN("doesn't add profile without settings")
+ {
+ profiles.add(id, profile, nullptr);
+ REQUIRE(profiles.idList().count() == 1);
+ }
+
+ THEN("doesn't add settings without profile")
+ {
+ profiles.add(id, nullptr, settings);
+ REQUIRE(profiles.idList().count() == 1);
+ }
+
+ THEN("adds new profile with settings")
+ {
+ profiles.add(id, profile, settings);
+ REQUIRE(profiles.idList().count() == 2);
+ }
+ }
+
+ WHEN("moving")
+ {
+ WebProfileManager<false> other(std::move(profiles));
+ THEN("moved has the same number of profiles")
+ {
+ REQUIRE(other.idList().count() == 1);
+ REQUIRE(other.profile(default_id) == WebProfile::defaultProfile());
+ REQUIRE(other.profile("not-in-list") == nullptr);
+ }
+ }
+ }
+
+ GIVEN("a number of profiles, default undefined")
+ {
+ REQUIRE(qEnvironmentVariableIsSet("PROFILES"));
+
+ WebProfileManager<false> profiles(QString::fromLatin1(qgetenv("PROFILES")).split(';'), default_id, search, homepage, newtab);
+
+ REQUIRE(profiles.idList().count() == 2);
+ REQUIRE(profiles.profile(default_id) == WebProfile::defaultProfile());
+ REQUIRE(profiles.profile("testing") != nullptr);
+ REQUIRE(profiles.profile("not-in-list") == nullptr);
+
+ WHEN("making global")
+ {
+ profiles.make_global();
+ WebProfileManager other;
+
+ THEN("global has the same number of profiles")
+ {
+ REQUIRE(other.idList().count() == 2);
+ REQUIRE(other.profile(default_id) == WebProfile::defaultProfile());
+ REQUIRE(other.profile("testing") != nullptr);
+ REQUIRE(other.profile("not-in-list") == nullptr);
+ }
+
+ THEN("walking has no nullptrs")
+ {
+ other.walk([](const QString &, WebProfile *profile, const QSettings *settings) {
+ REQUIRE(profile != nullptr);
+ REQUIRE(settings != nullptr);
+ });
+ }
+ }
+ }
+
+ GIVEN("a number of profiles, default defined")
+ {
+ REQUIRE(qEnvironmentVariableIsSet("PROFILES"));
+
+ WebProfileManager<false> profiles(QString::fromLatin1(qgetenv("PROFILES")).split(';'), "testing", search, homepage, newtab);
+
+ REQUIRE(profiles.idList().count() == 1);
+ REQUIRE(profiles.profile("testing") == WebProfile::defaultProfile());
+ REQUIRE(profiles.profile("not-in-list") == nullptr);
+
+ WHEN("walking")
+ {
+ profiles.walk([](const QString &, WebProfile *profile, const QSettings *settings) {
+ REQUIRE(profile != nullptr);
+ REQUIRE(settings != nullptr);
+ });
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ const auto r = Catch::Session().run(argc, argv);
+ return r;
+}
diff --git a/src/webengine/test/sample.html b/src/webengine/test/sample.html
new file mode 100644
index 0000000..54746d5
--- /dev/null
+++ b/src/webengine/test/sample.html
@@ -0,0 +1,7 @@
+<html>
+<head><title>sample page</title></head>
+<body>
+ <h2><img src="icon.svg" />This is a sample page</h2>
+ <iframe width="100%" height="80%" src="form.html"></iframe>
+</body>
+</html>
diff --git a/src/webengine/test/testing.profile b/src/webengine/test/testing.profile
new file mode 100644
index 0000000..e345a3e
--- /dev/null
+++ b/src/webengine/test/testing.profile
@@ -0,0 +1,8 @@
+name=Test Profile
+otr=true
+search=https://duckduckgo.com/?q=%1&ia=web
+homepage=about:blank
+newtab=about:blank
+
+[headers]
+Dnt=1
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();
+}