#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; }