diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-12-15 11:51:08 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-12-15 15:23:12 +0200 |
commit | e9c6cdefff00daffb8b07e72c47f8e8f845ba436 (patch) | |
tree | feb3ec54de25fd2c41ccc6dc1d586642a84babf9 /lib/webengine/test/profile.cpp | |
parent | Code cleanup (diff) | |
download | smolbote-e9c6cdefff00daffb8b07e72c47f8e8f845ba436.tar.xz |
Move src/webengine to lib/webengine
Diffstat (limited to 'lib/webengine/test/profile.cpp')
-rw-r--r-- | lib/webengine/test/profile.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/lib/webengine/test/profile.cpp b/lib/webengine/test/profile.cpp new file mode 100644 index 0000000..ae3a4e3 --- /dev/null +++ b/lib/webengine/test/profile.cpp @@ -0,0 +1,125 @@ +#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("profile properties") +{ + const QString search{ "about:blank" }; + const QUrl homepage{ "about:blank" }; + const QUrl newtab{ "about:blank" }; + const QString id{ "id" }; + + REQUIRE(qEnvironmentVariableIsSet("PROFILE")); + + // create an empty settings object + const QString settings_path = GENERATE(as<QString>{}, QString(), qgetenv("PROFILE")); + auto *settings = WebProfile::load(settings_path, search, homepage, newtab); + // create the actual profile + auto *profile = WebProfile::load(id, settings, true); + + REQUIRE(profile != nullptr); + REQUIRE(profile->isOffTheRecord()); + + WHEN("id constant") + { + REQUIRE(profile->getId() == id); + REQUIRE(profile->property("id").toString() == id); + } + + 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") + { + 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 url") + { + 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 url") + { + 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); + } + } + + WHEN("changing cookies") + { + auto list = profile->cookies(); + REQUIRE(list.isEmpty()); + list.append(QNetworkCookie("name", "value").toRawForm()); + profile->setCookies(list); + THEN("new cookie list gets applied") + { + // There is no event loop, so the signals cannot fire and update the cookie list + //REQUIRE(list == profile->cookies()); + } + } + + WHEN("changing headers") + { + QMap<QString, QVariant> headers; + headers.insert("Dnt", "1"); + headers.insert("unknown", "pair"); + + profile->setHeaders(headers); + THEN("headers change") + { + REQUIRE(profile->headers() == headers); + } + } + + delete settings; + delete profile; +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + const auto r = Catch::Session().run(argc, argv); + return r; +} |