diff --git a/src/lib/app/datapaths.cpp b/src/lib/app/datapaths.cpp index 79b914307..0a4121230 100644 --- a/src/lib/app/datapaths.cpp +++ b/src/lib/app/datapaths.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2014-2017 David Rosca +* Copyright (C) 2014-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #include "datapaths.h" #include "qztools.h" #include "../config.h" +#include "mainapplication.h" #include #include @@ -92,7 +93,12 @@ void DataPaths::init() initAssetsIn(location); } - m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + if (MainApplication::isTestModeEnabled()) { + m_paths[Config].append(QDir::tempPath() + QL1S("/QupZilla-test")); + } else { + m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + } + m_paths[Profiles].append(m_paths[Config].at(0) + QLatin1String("/profiles")); // We also allow to load data from Config path initAssetsIn(m_paths[Config].at(0)); diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 2d978250f..78f80c5eb 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -78,6 +78,8 @@ #include "registerqappassociation.h" #endif +static bool s_testMode = false; + MainApplication::MainApplication(int &argc, char** argv) : QtSingleApplication(argc, argv) , m_isPrivate(false) @@ -217,6 +219,10 @@ MainApplication::MainApplication(int &argc, char** argv) appId.append(QLatin1String("Portable")); } + if (isTestModeEnabled()) { + appId.append(QSL("TestMode")); + } + if (newInstance) { if (startProfile.isEmpty() || startProfile == QLatin1String("default")) { std::cout << "New instance cannot be started with default profile!" << std::endl; @@ -272,7 +278,7 @@ MainApplication::MainApplication(int &argc, char** argv) setupUserScripts(); - if (!isPrivate()) { + if (!isPrivate() && !isTestModeEnabled()) { m_sessionManager = new SessionManager(this); m_autoSaver = new AutoSaver(this); connect(m_autoSaver, SIGNAL(save()), m_sessionManager, SLOT(autoSaveLastSession())); @@ -313,7 +319,7 @@ MainApplication::MainApplication(int &argc, char** argv) connect(this, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(onFocusChanged())); - if (!isPrivate()) { + if (!isPrivate() && !isTestModeEnabled()) { #ifndef DISABLE_CHECK_UPDATES Settings settings; bool checkUpdates = settings.value("Web-Browser-Settings/CheckUpdates", true).toBool(); @@ -619,6 +625,18 @@ MainApplication* MainApplication::instance() return static_cast(QCoreApplication::instance()); } +// static +bool MainApplication::isTestModeEnabled() +{ + return s_testMode; +} + +// static +void MainApplication::setTestModeEnabled(bool enabled) +{ + s_testMode = enabled; +} + void MainApplication::addNewTab(const QUrl &url) { BrowserWindow* window = getWindow(); diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 188f40557..41e67a818 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -118,6 +118,9 @@ public: static MainApplication* instance(); + static bool isTestModeEnabled(); + static void setTestModeEnabled(bool enabled); + public slots: void addNewTab(const QUrl &url = QUrl()); void startPrivateBrowsing(const QUrl &startUrl = QUrl());