TestIconDownloader.cpp 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "TestIconDownloader.h"
  2. #include <QTest>
  3. #include <gui/IconDownloader.h>
  4. QTEST_GUILESS_MAIN(TestIconDownloader)
  5. void TestIconDownloader::testIconDownloader()
  6. {
  7. QFETCH(QString, url);
  8. QFETCH(QStringList, expectation);
  9. IconDownloader downloader;
  10. downloader.setUrl(url);
  11. QStringList resolved_urls;
  12. for (const auto& resolved_url : downloader.m_urlsToTry) {
  13. resolved_urls.push_back(resolved_url.toString());
  14. }
  15. QCOMPARE(resolved_urls, expectation);
  16. }
  17. void TestIconDownloader::testIconDownloader_data()
  18. {
  19. QTest::addColumn<QString>("url");
  20. QTest::addColumn<QStringList>("expectation");
  21. const QString keepassxc_favicon("https://keepassxc.org/favicon.ico");
  22. QTest::newRow("Invalid URL") << "http:sk/s.com" << QStringList{};
  23. QTest::newRow("Unsupported schema") << "ftp://google.com" << QStringList{};
  24. QTest::newRow("Missing schema") << "keepassxc.org" << QStringList{"https://keepassxc.org/favicon.ico"};
  25. QTest::newRow("Missing host") << "https:///register" << QStringList{};
  26. QTest::newRow("URL with path") << "https://keepassxc.org/register/here/"
  27. << QStringList{"https://keepassxc.org/register/here/favicon.ico", keepassxc_favicon};
  28. QTest::newRow("URL with path and query")
  29. << "https://keepassxc.org/register/here?login=me"
  30. << QStringList{"https://keepassxc.org/register/favicon.ico", keepassxc_favicon};
  31. QTest::newRow("URL with port") << "https://keepassxc.org:8080"
  32. << QStringList{"https://keepassxc.org:8080/favicon.ico"};
  33. QTest::newRow("2nd level domain") << "https://login.keepassxc.org"
  34. << QStringList{"https://login.keepassxc.org/favicon.ico", keepassxc_favicon};
  35. QTest::newRow("2nd level domain with additional fields")
  36. << "https://user:password@login.keepassxc.org:2021?test#1"
  37. << QStringList{"https://user:password@login.keepassxc.org:2021/favicon.ico",
  38. "https://user:password@keepassxc.org:2021/favicon.ico",
  39. keepassxc_favicon};
  40. QTest::newRow("2nd level domain (.co.uk special case), with subdomain")
  41. << "https://login.keepassxc.co.uk"
  42. << QStringList{"https://login.keepassxc.co.uk/favicon.ico", "https://keepassxc.co.uk/favicon.ico"};
  43. QTest::newRow("2nd level domain .co.uk special case")
  44. << "https://keepassxc.co.uk" << QStringList{"https://keepassxc.co.uk/favicon.ico"};
  45. QTest::newRow("2nd level domain with several subdomains")
  46. << "https://de.login.keepassxc.org"
  47. << QStringList{"https://de.login.keepassxc.org/favicon.ico", keepassxc_favicon};
  48. QTest::newRow("Raw IP with schema") << "https://134.130.155.184"
  49. << QStringList{"https://134.130.155.184/favicon.ico"};
  50. QTest::newRow("Raw IP") << "134.130.155.184" << QStringList{"https://134.130.155.184/favicon.ico"};
  51. QTest::newRow("Raw IP with schema and path")
  52. << "https://134.130.155.184/with/path/"
  53. << QStringList{"https://134.130.155.184/with/path/favicon.ico", "https://134.130.155.184/favicon.ico"};
  54. QTest::newRow("Raw IP with schema (https), path, and port")
  55. << "https://134.130.155.184:8080/test/"
  56. << QStringList{"https://134.130.155.184:8080/test/favicon.ico", "https://134.130.155.184:8080/favicon.ico"};
  57. QTest::newRow("Raw IP with schema (http), path, and port")
  58. << "134.130.155.184:8080/test/"
  59. << QStringList{"https://134.130.155.184:8080/test/favicon.ico", "https://134.130.155.184:8080/favicon.ico"};
  60. QTest::newRow("URL with username and password")
  61. << "https://user:password@keepassxc.org" << QStringList{"https://user:password@keepassxc.org/favicon.ico"};
  62. QTest::newRow("URL with username and password, several subdomains")
  63. << "https://user:password@de.login.keepassxc.org"
  64. << QStringList{"https://user:password@de.login.keepassxc.org/favicon.ico",
  65. "https://user:password@keepassxc.org/favicon.ico",
  66. "https://keepassxc.org/favicon.ico"};
  67. QTest::newRow("Raw IP with username and password")
  68. << "https://user:password@134.130.155.184" << QStringList{"https://user:password@134.130.155.184/favicon.ico"};
  69. QTest::newRow("Relative path should be preserved")
  70. << "https://test.com/rel-path/"
  71. << QStringList{"https://test.com/rel-path/favicon.ico", "https://test.com/favicon.ico"};
  72. }