diff options
16 files changed, 202 insertions, 12 deletions
diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp index 8c0fb1ee7..dc4569fbd 100644 --- a/src/libs/installer/commandlineparser.cpp +++ b/src/libs/installer/commandlineparser.cpp @@ -146,6 +146,12 @@ CommandLineParser::CommandLineParser() QLatin1String("Create a local repository inside the installation directory. This option " "has no effect on online installers."))); + // Message query options + m_parser.addOption(QCommandLineOption(QStringList() << CommandLineOptions::scAcceptMessageQuery, + QLatin1String("Accepts all message queries without user input."))); + m_parser.addOption(QCommandLineOption(QStringList() << CommandLineOptions::scRejectMessageQuery, + QLatin1String("Rejects all message queries without user input."))); + // Developer options m_parser.addOption(QCommandLineOption(QStringList() << CommandLineOptions::scScriptShort << CommandLineOptions::scScriptLong, diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index 3759e6157..1d9be8525 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -151,6 +151,10 @@ static const QLatin1String scStartPackageManagerLong("start-package-manager"); static const QLatin1String scStartUninstallerShort("sr"); static const QLatin1String scStartUninstallerLong("start-uninstaller"); +// Message acceptance options +static const QLatin1String scAcceptMessageQuery("accept-messages"); +static const QLatin1String scRejectMessageQuery("reject-messages"); + // Misc installation options static const QLatin1String scRootShort("t"); static const QLatin1String scRootLong("root"); diff --git a/src/libs/installer/downloadarchivesjob.cpp b/src/libs/installer/downloadarchivesjob.cpp index 102783133..4d9d6b325 100644 --- a/src/libs/installer/downloadarchivesjob.cpp +++ b/src/libs/installer/downloadarchivesjob.cpp @@ -215,7 +215,10 @@ void DownloadArchivesJob::registerFile() "downloading failed. This is a temporary error, please retry."), QMessageBox::Retry | QMessageBox::Cancel, QMessageBox::Cancel); - if (res == QMessageBox::Cancel) { + // If run from command line instance, do not continue if hash verification failed. + // Same download is tried again and again causing infinite loop if hash not + // fixed to repositories. + if (res == QMessageBox::Cancel || m_core->isCommandLineInstance()) { finishWithError(tr("Cannot verify Hash")); return; } @@ -249,7 +252,9 @@ void DownloadArchivesJob::downloadFailed(const QString &error) QLatin1String("archiveDownloadError"), tr("Download Error"), tr("Cannot download archive %1: %2") .arg(m_archivesToDownload.first().second, error), QMessageBox::Retry | QMessageBox::Cancel); - if (b == QMessageBox::Retry) + // Do not call fetchNextArchiveHash when using command line instance, + // installer tries to download the same archive causing infinite loop + if (b == QMessageBox::Retry && !m_core->isCommandLineInstance()) QMetaObject::invokeMethod(this, "fetchNextArchiveHash", Qt::QueuedConnection); else downloadCanceled(); diff --git a/src/libs/installer/messageboxhandler.cpp b/src/libs/installer/messageboxhandler.cpp index cb37254eb..4562f0f3c 100644 --- a/src/libs/installer/messageboxhandler.cpp +++ b/src/libs/installer/messageboxhandler.cpp @@ -406,8 +406,12 @@ QMessageBox::StandardButton MessageBoxHandler::showMessageBox(MessageType messag qCDebug(QInstaller::lcInstallerInstallLog).nospace() << "Created " << messageTypeHash.value(messageType).toUtf8().constData() << " message box " << identifier << ": " << title << ", " << text; - if (qobject_cast<QApplication*> (qApp) == nullptr) - return defaultButton; + if (qobject_cast<QApplication*> (qApp) == nullptr) { + if (m_defaultAction != AskUser) + return autoReply(buttons); + else + return defaultButton; + } if (m_automaticAnswers.contains(identifier)) return m_automaticAnswers.value(identifier); diff --git a/src/libs/kdtools/filedownloader.cpp b/src/libs/kdtools/filedownloader.cpp index b816b5fd5..276d5bbef 100644 --- a/src/libs/kdtools/filedownloader.cpp +++ b/src/libs/kdtools/filedownloader.cpp @@ -814,7 +814,7 @@ void KDUpdater::LocalFileDownloader::doDownload() if (!d->source->open(QFile::ReadOnly)) { onError(); setDownloadAborted(tr("Cannot open file \"%1\" for reading: %2").arg(QFileInfo(localFile) - .fileName(), d->source->errorString())); + .fileName(), d->source ? d->source->errorString() : tr("File not found"))); return; } diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index ab0b9eb2f..3c0dd0da8 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -274,6 +274,11 @@ public: .isSet(CommandLineOptions::scCreateLocalRepositoryLong) || m_core->settings().createLocalRepository()); + if (m_parser.isSet(CommandLineOptions::scAcceptMessageQuery)) + m_core->autoAcceptMessageBoxes(); + if (m_parser.isSet(CommandLineOptions::scRejectMessageQuery)) + m_core->autoRejectMessageBoxes(); + return true; } diff --git a/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z b/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z Binary files differnew file mode 100644 index 000000000..4663e2b7c --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z diff --git a/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z.sha1 b/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z.sha1 new file mode 100644 index 000000000..281381b97 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/invalidhash/B/1.0.0-1content.7z.sha1 @@ -0,0 +1 @@ +1c99fe9980cb71dde6a8468c9aa09b4153bc3bff
\ No newline at end of file diff --git a/tests/auto/installer/messageboxhandler/data/invalidhash/Updates.xml b/tests/auto/installer/messageboxhandler/data/invalidhash/Updates.xml new file mode 100644 index 000000000..2dd2ca2d5 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/invalidhash/Updates.xml @@ -0,0 +1,15 @@ +<Updates> + <ApplicationName>{AnyApplication}</ApplicationName> + <ApplicationVersion>1.0.0</ApplicationVersion> + <Checksum>true</Checksum> + <PackageUpdate> + <Name>B</Name> + <DisplayName>B</DisplayName> + <Description>Example component B</Description> + <Version>1.0.0-1</Version> + <ReleaseDate>2015-01-01</ReleaseDate> + <Default>true</Default> + <UpdateFile UncompressedSize="74" OS="Any" CompressedSize="224"/> + <DownloadableArchives>content.7z</DownloadableArchives> + </PackageUpdate> +</Updates> diff --git a/tests/auto/installer/messageboxhandler/data/invalidoperation/A/1.0.2-1meta.7z b/tests/auto/installer/messageboxhandler/data/invalidoperation/A/1.0.2-1meta.7z Binary files differnew file mode 100644 index 000000000..3653317c6 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/invalidoperation/A/1.0.2-1meta.7z diff --git a/tests/auto/installer/messageboxhandler/data/invalidoperation/Updates.xml b/tests/auto/installer/messageboxhandler/data/invalidoperation/Updates.xml new file mode 100644 index 000000000..77b5a9956 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/invalidoperation/Updates.xml @@ -0,0 +1,13 @@ +<Updates> + <ApplicationName>{AnyApplication}</ApplicationName> + <ApplicationVersion>1.0.0</ApplicationVersion> + <PackageUpdate> + <Name>A</Name> + <DisplayName>A</DisplayName> + <Description>Example component A</Description> + <Version>1.0.2-1</Version> + <ReleaseDate>2015-01-01</ReleaseDate> + <Default>true</Default> + <Script>script.qs</Script> + </PackageUpdate> +</Updates> diff --git a/tests/auto/installer/messageboxhandler/data/missingarchive/C/1.0.0content.7z.sha1 b/tests/auto/installer/messageboxhandler/data/missingarchive/C/1.0.0content.7z.sha1 new file mode 100644 index 000000000..281381b97 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/missingarchive/C/1.0.0content.7z.sha1 @@ -0,0 +1 @@ +1c99fe9980cb71dde6a8468c9aa09b4153bc3bff
\ No newline at end of file diff --git a/tests/auto/installer/messageboxhandler/data/missingarchive/Updates.xml b/tests/auto/installer/messageboxhandler/data/missingarchive/Updates.xml new file mode 100644 index 000000000..0c5f7e211 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/data/missingarchive/Updates.xml @@ -0,0 +1,16 @@ +<Updates> + <ApplicationName>{AnyApplication}</ApplicationName> + <ApplicationVersion>1.0.0</ApplicationVersion> + <Checksum>true</Checksum> + <PackageUpdate> + <Name>C</Name> + <DisplayName>C</DisplayName> + <Description>Example component C</Description> + <Version>1.0.0</Version> + <ReleaseDate>2015-01-01</ReleaseDate> + <Default>true</Default> + <UpdateFile CompressedSize="224" OS="Any" UncompressedSize="74"/> + <DownloadableArchives>content.7z</DownloadableArchives> + <SHA1>3c940d54a1643ae8020162797860e827f8d246ca</SHA1> + </PackageUpdate> +</Updates> diff --git a/tests/auto/installer/messageboxhandler/messageboxhandler.pro b/tests/auto/installer/messageboxhandler/messageboxhandler.pro index c63b2e35b..3bb0f7b64 100644 --- a/tests/auto/installer/messageboxhandler/messageboxhandler.pro +++ b/tests/auto/installer/messageboxhandler/messageboxhandler.pro @@ -3,3 +3,7 @@ include(../../qttest.pri) QT += qml widgets SOURCES += tst_messageboxhandler.cpp + +RESOURCES += \ + settings.qrc \ + ..\shared\config.qrc diff --git a/tests/auto/installer/messageboxhandler/settings.qrc b/tests/auto/installer/messageboxhandler/settings.qrc new file mode 100644 index 000000000..51e4bba19 --- /dev/null +++ b/tests/auto/installer/messageboxhandler/settings.qrc @@ -0,0 +1,11 @@ +<RCC> + <qresource prefix="/"> + <file>data/invalidhash/Updates.xml</file> + <file>data/invalidhash/B/1.0.0-1content.7z</file> + <file>data/invalidhash/B/1.0.0-1content.7z.sha1</file> + <file>data/invalidoperation/Updates.xml</file> + <file>data/invalidoperation/A/1.0.2-1meta.7z</file> + <file>data/missingarchive/Updates.xml</file> + <file>data/missingarchive/C/1.0.0content.7z.sha1</file> + </qresource> +</RCC> diff --git a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp index dd127f626..1c819fa7c 100644 --- a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp +++ b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp @@ -1,7 +1,42 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + #include <messageboxhandler.h> #include <qinstallerglobal.h> #include <scriptengine.h> #include <packagemanagercore.h> +#include <component.h> +#include <utils.h> +#include <fileutils.h> +#include <binarycontent.h> +#include <packagemanagercore.h> +#include <settings.h> +#include <init.h> #include <QTest> #include <QMetaEnum> @@ -26,7 +61,15 @@ QT_END_NAMESPACE class tst_MessageBoxHandler : public QObject { Q_OBJECT -public: +private: + void setRepository(const QString &repository) { + core->cancelMetaInfoJob(); + QSet<Repository> repoList; + Repository repo = Repository::fromUserInput(repository); + repoList.insert(repo); + core->settings().setDefaultRepositories(repoList); + } + private slots: void initTestCase() { @@ -46,12 +89,21 @@ private slots: if (enumValue == QMessageBox::LastButton) break; } + + QInstaller::init(); //This will eat debug output + + core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList<OperationBlob> (), + QString(), Protocol::DefaultAuthorizationKey, Protocol::Mode::Production, + QHash<QString, QString>(), true); + core->setAllowedRunningProcesses(QStringList() << QCoreApplication::applicationFilePath()); + m_installDir = QInstaller::generateTemporaryFileName(); + QDir().mkpath(m_installDir); + core->setValue(scTargetDir, m_installDir); } void testScriptButtonValues() { - PackageManagerCore core; - ScriptEngine *scriptEngine = new ScriptEngine(&core); + ScriptEngine *scriptEngine = new ScriptEngine(core); QMapIterator<QMessageBox::StandardButton, QString> i(m_standardButtonValueMap); while (i.hasNext()) { i.next(); @@ -67,8 +119,6 @@ private slots: void testDefaultAction() { - const char ignoreMessage[] = "Created critical message box \"TestError\": \"A test error\", " - "\"This is a test error message.\""; srand(time(0)); /* initialize random seed: */ int standardButtons = QMessageBox::NoButton; @@ -82,8 +132,6 @@ private slots: // use only every 5th run to reduce the time which it takes to run this test if (iSecret > 2) continue; - - QTest::ignoreMessage(QtDebugMsg, ignoreMessage); int returnButton = MessageBoxHandler::instance()->critical(QLatin1String("TestError"), QLatin1String("A test error"), QLatin1String("This is a test error message."), static_cast<QMessageBox::StandardButton>(standardButtons)); @@ -101,9 +149,66 @@ private slots: } while (standardButtons < m_maxStandardButtons); } + void invalidOperationAutoReject() + { + setRepository(":///data/invalidoperation"); + core->autoRejectMessageBoxes(); + core->installDefaultComponentsSilently(); + QCOMPARE(PackageManagerCore::Canceled, core->status()); + } + + void invalidOperationAutoAccept() + { + setRepository(":///data/invalidoperation"); + core->autoAcceptMessageBoxes(); + core->installDefaultComponentsSilently(); + QCOMPARE(PackageManagerCore::Running, core->status()); + } + + void invalidHashAutoReject() + { + setRepository(":///data/invalidhash"); + core->autoRejectMessageBoxes(); + core->installSelectedComponentsSilently(QStringList () << "B"); + QCOMPARE(PackageManagerCore::Failure, core->status()); + } + + void invalidHashAutoAccept() + { + setRepository(":///data/invalidhash"); + core->autoAcceptMessageBoxes(); + core->installSelectedComponentsSilently(QStringList () << "B"); + QCOMPARE(PackageManagerCore::Failure, core->status()); + } + + void missingArchiveAutoReject() + { + setRepository(":///data/missingarchive"); + core->autoRejectMessageBoxes(); + core->installSelectedComponentsSilently(QStringList () << "C"); + QCOMPARE(PackageManagerCore::Canceled, core->status()); + } + + void missingArchiveAutoAccept() + { + setRepository(":///data/missingarchive"); + core->autoAcceptMessageBoxes(); + core->installSelectedComponentsSilently(QStringList () << "C"); + QCOMPARE(PackageManagerCore::Canceled, core->status()); + } + + void cleanupTestCase() + { + core->deleteLater(); + QDir dir(m_installDir); + QVERIFY(dir.removeRecursively()); + } + private: QMap<QMessageBox::StandardButton, QString> m_standardButtonValueMap; int m_maxStandardButtons; + PackageManagerCore *core; + QString m_installDir; }; QTEST_MAIN(tst_MessageBoxHandler) |