From e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 29 Apr 2020 18:49:07 +0300 Subject: 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 --- src/webengine/test/profilemanager.cpp | 120 ++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/webengine/test/profilemanager.cpp (limited to 'src/webengine/test/profilemanager.cpp') 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 +#include + +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 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 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 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 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; +} -- cgit v1.2.1