keepassxc

Форк
0
/
TestIconDownloader.cpp 
79 строк · 4.4 Кб
1
#include "TestIconDownloader.h"
2
#include <QTest>
3
#include <gui/IconDownloader.h>
4

5
QTEST_GUILESS_MAIN(TestIconDownloader)
6

7
void TestIconDownloader::testIconDownloader()
8
{
9
    QFETCH(QString, url);
10
    QFETCH(QStringList, expectation);
11

12
    IconDownloader downloader;
13
    downloader.setUrl(url);
14
    QStringList resolved_urls;
15
    for (const auto& resolved_url : downloader.m_urlsToTry) {
16
        resolved_urls.push_back(resolved_url.toString());
17
    }
18

19
    QCOMPARE(resolved_urls, expectation);
20
}
21

22
void TestIconDownloader::testIconDownloader_data()
23
{
24
    QTest::addColumn<QString>("url");
25
    QTest::addColumn<QStringList>("expectation");
26

27
    const QString keepassxc_favicon("https://keepassxc.org/favicon.ico");
28

29
    QTest::newRow("Invalid URL") << "http:sk/s.com" << QStringList{};
30
    QTest::newRow("Unsupported schema") << "ftp://google.com" << QStringList{};
31
    QTest::newRow("Missing schema") << "keepassxc.org" << QStringList{"https://keepassxc.org/favicon.ico"};
32
    QTest::newRow("Missing host") << "https:///register" << QStringList{};
33
    QTest::newRow("URL with path") << "https://keepassxc.org/register/here/"
34
                                   << QStringList{"https://keepassxc.org/register/here/favicon.ico", keepassxc_favicon};
35
    QTest::newRow("URL with path and query")
36
        << "https://keepassxc.org/register/here?login=me"
37
        << QStringList{"https://keepassxc.org/register/favicon.ico", keepassxc_favicon};
38
    QTest::newRow("URL with port") << "https://keepassxc.org:8080"
39
                                   << QStringList{"https://keepassxc.org:8080/favicon.ico"};
40
    QTest::newRow("2nd level domain") << "https://login.keepassxc.org"
41
                                      << QStringList{"https://login.keepassxc.org/favicon.ico", keepassxc_favicon};
42
    QTest::newRow("2nd level domain with additional fields")
43
        << "https://user:password@login.keepassxc.org:2021?test#1"
44
        << QStringList{"https://user:password@login.keepassxc.org:2021/favicon.ico",
45
                       "https://user:password@keepassxc.org:2021/favicon.ico",
46
                       keepassxc_favicon};
47
    QTest::newRow("2nd level domain (.co.uk special case), with subdomain")
48
        << "https://login.keepassxc.co.uk"
49
        << QStringList{"https://login.keepassxc.co.uk/favicon.ico", "https://keepassxc.co.uk/favicon.ico"};
50
    QTest::newRow("2nd level domain .co.uk special case")
51
        << "https://keepassxc.co.uk" << QStringList{"https://keepassxc.co.uk/favicon.ico"};
52
    QTest::newRow("2nd level domain with several subdomains")
53
        << "https://de.login.keepassxc.org"
54
        << QStringList{"https://de.login.keepassxc.org/favicon.ico", keepassxc_favicon};
55
    QTest::newRow("Raw IP with schema") << "https://134.130.155.184"
56
                                        << QStringList{"https://134.130.155.184/favicon.ico"};
57
    QTest::newRow("Raw IP") << "134.130.155.184" << QStringList{"https://134.130.155.184/favicon.ico"};
58
    QTest::newRow("Raw IP with schema and path")
59
        << "https://134.130.155.184/with/path/"
60
        << QStringList{"https://134.130.155.184/with/path/favicon.ico", "https://134.130.155.184/favicon.ico"};
61
    QTest::newRow("Raw IP with schema (https), path, and port")
62
        << "https://134.130.155.184:8080/test/"
63
        << QStringList{"https://134.130.155.184:8080/test/favicon.ico", "https://134.130.155.184:8080/favicon.ico"};
64
    QTest::newRow("Raw IP with schema (http), path, and port")
65
        << "134.130.155.184:8080/test/"
66
        << QStringList{"https://134.130.155.184:8080/test/favicon.ico", "https://134.130.155.184:8080/favicon.ico"};
67
    QTest::newRow("URL with username and password")
68
        << "https://user:password@keepassxc.org" << QStringList{"https://user:password@keepassxc.org/favicon.ico"};
69
    QTest::newRow("URL with username and password, several subdomains")
70
        << "https://user:password@de.login.keepassxc.org"
71
        << QStringList{"https://user:password@de.login.keepassxc.org/favicon.ico",
72
                       "https://user:password@keepassxc.org/favicon.ico",
73
                       "https://keepassxc.org/favicon.ico"};
74
    QTest::newRow("Raw IP with username and password")
75
        << "https://user:password@134.130.155.184" << QStringList{"https://user:password@134.130.155.184/favicon.ico"};
76
    QTest::newRow("Relative path should be preserved")
77
        << "https://test.com/rel-path/"
78
        << QStringList{"https://test.com/rel-path/favicon.ico", "https://test.com/favicon.ico"};
79
}
80

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.