File indexing completed on 2025-01-26 04:57:20
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "checkphishingurlutiltest.h" 0008 #include "../checkphishingurlutil.h" 0009 0010 #include <QTest> 0011 0012 CheckPhishingUrlUtilTest::CheckPhishingUrlUtilTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 CheckPhishingUrlUtilTest::~CheckPhishingUrlUtilTest() = default; 0018 0019 void CheckPhishingUrlUtilTest::shouldConvertToSecond_data() 0020 { 0021 QTest::addColumn<QString>("value"); 0022 QTest::addColumn<double>("result"); 0023 QTest::newRow("empty") << QString() << (double)-1; 0024 QTest::newRow("test1") << QStringLiteral("459.123s") << 459.123; 0025 QTest::newRow("test2") << QStringLiteral("459s") << 459.; 0026 } 0027 0028 void CheckPhishingUrlUtilTest::shouldConvertToSecond() 0029 { 0030 QFETCH(QString, value); 0031 QFETCH(double, result); 0032 QCOMPARE(WebEngineViewer::CheckPhishingUrlUtil::convertToSecond(value), result); 0033 } 0034 0035 void CheckPhishingUrlUtilTest::shouldCacheIsStillValid_data() 0036 { 0037 QTest::addColumn<double>("second"); 0038 QTest::addColumn<bool>("valid"); 0039 uint currentTime = QDateTime::currentDateTimeUtc().toSecsSinceEpoch(); 0040 QTest::newRow("valid") << (currentTime + 2000.) << true; 0041 QTest::newRow("invalid") << (currentTime - 2000.) << false; 0042 } 0043 0044 void CheckPhishingUrlUtilTest::shouldCacheIsStillValid() 0045 { 0046 QFETCH(double, second); 0047 QFETCH(bool, valid); 0048 QCOMPARE(WebEngineViewer::CheckPhishingUrlUtil::cachedValueStillValid(second), valid); 0049 } 0050 0051 void CheckPhishingUrlUtilTest::shouldGenerateBackModeDelay_data() 0052 { 0053 QTest::addColumn<int>("numberFailed"); 0054 QTest::addColumn<int>("minuteMin"); 0055 QTest::addColumn<int>("minuteMax"); 0056 QTest::newRow("onefailed") << 1 << 15 << 30; 0057 QTest::newRow("twofailed") << 2 << 30 << 60; 0058 QTest::newRow("3failed") << 3 << 60 << 120; 0059 QTest::newRow("4failed") << 4 << 120 << 240; 0060 QTest::newRow("5failed") << 5 << 240 << 480; 0061 QTest::newRow("6failed") << 6 << 480 << 960; 0062 QTest::newRow("7failed") << 7 << 960 << 1440; 0063 QTest::newRow("8failed") << 8 << 1440 << 1440; 0064 QTest::newRow("9failed") << 9 << 1440 << 1440; 0065 QTest::newRow("10failed") << 10 << 1440 << 1440; 0066 } 0067 0068 void CheckPhishingUrlUtilTest::shouldGenerateBackModeDelay() 0069 { 0070 QFETCH(int, numberFailed); 0071 QFETCH(int, minuteMin); 0072 QFETCH(int, minuteMax); 0073 0074 int result = WebEngineViewer::CheckPhishingUrlUtil::generateRandomSecondValue(numberFailed); 0075 result /= 60; // minutes 0076 QVERIFY(result >= minuteMin); 0077 QVERIFY(result <= minuteMax); 0078 } 0079 0080 QTEST_GUILESS_MAIN(CheckPhishingUrlUtilTest) 0081 0082 #include "moc_checkphishingurlutiltest.cpp"