aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/test/profile.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-29 18:49:07 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-05-08 13:40:29 +0300
commite87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 (patch)
tree54194ca979ac7e646ff3f10ed6d7f7753273f0be /src/webengine/test/profile.cpp
parentExpand pluginloader test coverage (diff)
downloadsmolbote-e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1.tar.xz
libwebengine
Make src/webengine into a static library - Add some tests - Updated manpage - Remove WebProfileManager::id and WebProfileManager::instance - Add consumable semantics checks to WebProfileManager - Add WebProfileManager::walk Add ApplicationMenu class
Diffstat (limited to 'src/webengine/test/profile.cpp')
-rw-r--r--src/webengine/test/profile.cpp124
1 files changed, 124 insertions, 0 deletions
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;
+}