aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/test/profile.cpp
blob: 7351f66df3d3d0f2ea6ab9cb77e0b42a49fefc81 (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
#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("loading individual profiles")
{
    GIVEN("no profile preset")
    {
        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");

        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<QString>{}, "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<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")
        {
            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")
        {
            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);
            }
        }

        delete settings;
        delete profile;
    }
}

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    const auto r = Catch::Session().run(argc, argv);
    return r;
}