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/profile.cpp | 124 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/webengine/test/profile.cpp (limited to 'src/webengine/test/profile.cpp') 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 +#include + +TEST_CASE("loading profile settings") +{ + const QString search = GENERATE(as{}, "https://search.url/t=%1", "https://duckduckgo.com/?q=%1&ia=web", "aaabbbccc"); + const QUrl homepage = GENERATE(as{}, "https://homepage.net", "about:blank", "aaabbbccc"); + const QUrl newtab = GENERATE(as{}, "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{}, "https://search.url/t=%1", "https://duckduckgo.com/?q=%1&ia=web", "aaabbbccc"); + const QUrl homepage = GENERATE(as{}, "https://homepage.net", "about:blank", "aaabbbccc"); + const QUrl newtab = GENERATE(as{}, "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{}, "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{}, "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{}, "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{}, "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; +} -- cgit v1.2.1