From 0492a063806b6d63e4f378908b809de104a24820 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 25 Apr 2020 22:09:13 +0300 Subject: Update ProfileEditor plugin ProfileEditor: - add tests - disable read-only settings on otr profiles Add WebProfile::setHeaders and WebProfile::setCookies --- src/webengine/test/profile.cpp | 145 +++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 72 deletions(-) (limited to 'src/webengine/test/profile.cpp') diff --git a/src/webengine/test/profile.cpp b/src/webengine/test/profile.cpp index 7351f66..ae3a4e3 100644 --- a/src/webengine/test/profile.cpp +++ b/src/webengine/test/profile.cpp @@ -22,98 +22,99 @@ TEST_CASE("loading profile settings") delete settings; } -SCENARIO("loading individual profiles") +SCENARIO("profile properties") { - 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 search{ "about:blank" }; + const QUrl homepage{ "about:blank" }; + const QUrl newtab{ "about:blank" }; + const QString id{ "id" }; + + REQUIRE(qEnvironmentVariableIsSet("PROFILE")); - const QString id{ "id" }; - auto *settings = WebProfile::load(QString(), search, homepage, newtab); - auto *profile = WebProfile::load(id, settings, true); + // create an empty settings object + const QString settings_path = GENERATE(as{}, 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 != nullptr); + REQUIRE(profile->isOffTheRecord()); + + WHEN("id constant") + { 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") + WHEN("changing profile name") { - 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") + const QString name = GENERATE(as{}, "a", "bb", "ccc"); + profile->setName(name); + THEN("the name changes") { - 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")); - } + REQUIRE(profile->name() == name); + REQUIRE(settings->value("name").toString() == name); } - - WHEN("changing profile name") + } + WHEN("changing search") + { + const QString search = GENERATE(as{}, "a", "bb", "ccc"); + profile->setSearch(search); + THEN("the search url changes") { - 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); - } + REQUIRE(profile->search() == search); + REQUIRE(settings->value("search").toString() == search); } - WHEN("changing search url") + } + WHEN("changing homepage url") + { + const QUrl url = GENERATE(as{}, "a", "bb", "ccc"); + profile->setHomepage(url); + THEN("homepage changes") { - 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); - } + REQUIRE(profile->homepage() == url); + REQUIRE(settings->value("homepage").toUrl() == url); } - WHEN("changing homepage") + } + WHEN("changing newtab url") + { + const QUrl url = GENERATE(as{}, "a", "bb", "ccc"); + profile->setNewtab(url); + THEN("newtab changes") { - const QUrl url = GENERATE(as{}, "a", "bb", "ccc"); - profile->setHomepage(url); - THEN("homepage changes") - { - REQUIRE(profile->homepage() == url); - REQUIRE(settings->value("homepage").toUrl() == url); - } + REQUIRE(profile->newtab() == url); + REQUIRE(settings->value("newtab").toUrl() == url); } - WHEN("changing newtab") + } + + 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") { - const QUrl url = GENERATE(as{}, "a", "bb", "ccc"); - profile->setNewtab(url); - THEN("newtab changes") - { - REQUIRE(profile->newtab() == url); - REQUIRE(settings->value("newtab").toUrl() == url); - } + // There is no event loop, so the signals cannot fire and update the cookie list + //REQUIRE(list == profile->cookies()); } + } - delete settings; - delete profile; + WHEN("changing headers") + { + QMap 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) -- cgit v1.2.1