aboutsummaryrefslogtreecommitdiff
path: root/lib/webengine/test/profile.cpp
blob: ae3a4e30c1bab59b638a686f24942a5aa4699190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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;
}