From f96761db725d4b2651b77109b8b454a409f5c1c4 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Fri, 25 Nov 2022 16:50:45 +0100 Subject: [PATCH] Modernize the property setters/getters via inspector --- src/addons/addoni18n.cpp | 6 +- src/commands/commandui.cpp | 23 +- src/inspector/inspectorhandler.cpp | 277 +---- src/localizer.cpp | 31 +- src/localizer.h | 13 +- src/ui/screens/settings/ViewLanguage.qml | 10 +- tests/functional/actions.js | 31 +- tests/functional/helper.js | 8 +- tests/functional/setupVpn.js | 4 +- tests/functional/setupWasm.js | 2 +- tests/functional/testCaptivePortal.js | 12 +- tests/functional/testConnection.js | 4 +- tests/functional/testMultihop.js | 1106 +++++++++-------- tests/functional/testServers.js | 10 +- tests/functional/testSettings.js | 14 +- tests/functional/testTelemetryView.js | 16 +- .../functional/testTipsAndTricksIntroModal.js | 3 +- tests/functional/testTutorials.js | 8 +- tests/functional/testUnsecuredNetworkAlert.js | 8 +- tests/unit/testaddon.cpp | 2 +- tests/unit/testlocalizer.cpp | 18 +- wasm/main.js | 2 +- 22 files changed, 754 insertions(+), 854 deletions(-) diff --git a/src/addons/addoni18n.cpp b/src/addons/addoni18n.cpp index d8ad4c81976..510a8a393fd 100644 --- a/src/addons/addoni18n.cpp +++ b/src/addons/addoni18n.cpp @@ -4,7 +4,7 @@ #include "addoni18n.h" #include "leakdetector.h" -#include "localizer.h" +#include "settingsholder.h" AddonI18n::AddonI18n(QObject* parent, const QString& manifestFileName, const QString& id, const QString& name) @@ -15,11 +15,11 @@ AddonI18n::AddonI18n(QObject* parent, const QString& manifestFileName, AddonI18n::~AddonI18n() { MVPN_COUNT_DTOR(AddonI18n); } void AddonI18n::enable() { - emit Localizer::instance()->codeChanged(); + emit SettingsHolder::instance()->languageCodeChanged(); Addon::enable(); } void AddonI18n::disable() { - emit Localizer::instance()->codeChanged(); + emit SettingsHolder::instance()->languageCodeChanged(); Addon::disable(); } diff --git a/src/commands/commandui.cpp b/src/commands/commandui.cpp index 008a7e3b6ad..7be6759efa7 100644 --- a/src/commands/commandui.cpp +++ b/src/commands/commandui.cpp @@ -586,24 +586,25 @@ int CommandUI::run(QStringList& tokens) { #endif - QObject::connect(Localizer::instance(), &Localizer::codeChanged, []() { - logger.debug() << "Retranslating"; - QmlEngineHolder::instance()->engine()->retranslate(); - NotificationHandler::instance()->retranslate(); - L18nStrings::instance()->retranslate(); - AddonManager::instance()->retranslate(); + QObject::connect( + SettingsHolder::instance(), &SettingsHolder::languageCodeChanged, []() { + logger.debug() << "Retranslating"; + QmlEngineHolder::instance()->engine()->retranslate(); + NotificationHandler::instance()->retranslate(); + L18nStrings::instance()->retranslate(); + AddonManager::instance()->retranslate(); #ifdef MVPN_MACOS - MacOSMenuBar::instance()->retranslate(); + MacOSMenuBar::instance()->retranslate(); #endif #ifdef MVPN_WASM - WasmWindowController::instance()->retranslate(); + WasmWindowController::instance()->retranslate(); #endif - MozillaVPN::instance()->serverCountryModel()->retranslate(); - MozillaVPN::instance()->currentServer()->retranslate(); - }); + MozillaVPN::instance()->serverCountryModel()->retranslate(); + MozillaVPN::instance()->currentServer()->retranslate(); + }); InspectorHandler::initialize(); diff --git a/src/inspector/inspectorhandler.cpp b/src/inspector/inspectorhandler.cpp index 24e6bb971bc..c2b0370cd67 100644 --- a/src/inspector/inspectorhandler.cpp +++ b/src/inspector/inspectorhandler.cpp @@ -82,163 +82,6 @@ struct InspectorSettingCommand { std::function m_get; }; -// The list of settings exposed to the inspector. -static QList s_settingCommands{ - // Unsecured-network-alert - InspectorSettingCommand{ - "unsecured-network-alert", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setUnsecuredNetworkAlert(value == "true"); - }, - []() { - return SettingsHolder::instance()->unsecuredNetworkAlert() ? "true" - : "false"; - }}, - - // Captive portal - InspectorSettingCommand{ - "captive-portal-alert", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setCaptivePortalAlert(value == "true"); - }, - []() { - return SettingsHolder::instance()->captivePortalAlert() ? "true" - : "false"; - }}, - - // start at boot - InspectorSettingCommand{ - "start-at-boot", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setStartAtBoot(value == "true"); - }, - []() { - return SettingsHolder::instance()->startAtBoot() ? "true" : "false"; - }}, - - // local area network access - InspectorSettingCommand{ - "local-network-access", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setLocalNetworkAccess(value == "true"); - }, - []() { - return SettingsHolder::instance()->localNetworkAccess() ? "true" - : "false"; - }}, - // server-switch-notification - InspectorSettingCommand{ - "server-switch-notification", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setServerSwitchNotification(value == - "true"); - }, - []() { - return SettingsHolder::instance()->serverSwitchNotification() - ? "true" - : "false"; - }}, - // connection-change-notification - InspectorSettingCommand{ - "connection-change-notification", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setConnectionChangeNotification(value == - "true"); - }, - []() { - return SettingsHolder::instance()->connectionChangeNotification() - ? "true" - : "false"; - }}, - // server-unavailable-notification - InspectorSettingCommand{ - "server-unavailable-notification", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setServerUnavailableNotification(value == - "true"); - }, - []() { - return SettingsHolder::instance()->serverUnavailableNotification() - ? "true" - : "false"; - }}, - - // language - InspectorSettingCommand{ - "language-code", InspectorSettingCommand::String, - [](const QByteArray& value) { - Localizer::instance()->setCode(QString(value)); - }, - []() { return SettingsHolder::instance()->languageCode(); }}, - - // server country - InspectorSettingCommand{ - "current-server-country-code", InspectorSettingCommand::String, nullptr, - []() { - return MozillaVPN::instance()->currentServer()->exitCountryCode(); - }}, - - // server city - InspectorSettingCommand{ - "current-server-city", InspectorSettingCommand::String, nullptr, - []() { - return MozillaVPN::instance()->currentServer()->exitCityName(); - }}, - - // glean-enabled - InspectorSettingCommand{ - "glean-enabled", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setGleanEnabled(value == "true"); - }, - []() { - return SettingsHolder::instance()->gleanEnabled() ? "true" : "false"; - }}, - - // telemetry-policy-shown - InspectorSettingCommand{ - "telemetry-policy-shown", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setTelemetryPolicyShown(value == "true"); - }, - []() { - return SettingsHolder::instance()->telemetryPolicyShown() ? "true" - : "false"; - }}, - - // tips-and-tricks-intro-shown - InspectorSettingCommand{ - "tips-and-tricks-intro-shown", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setTipsAndTricksIntroShown(value == - "true"); - }, - []() { - return SettingsHolder::instance()->tipsAndTricksIntroShown() - ? "true" - : "false"; - }}, - - InspectorSettingCommand{ - "addon/customServer", InspectorSettingCommand::Boolean, - [](const QByteArray& value) { - SettingsHolder::instance()->setAddonCustomServer(value == "true"); - }, - []() { - return SettingsHolder::instance()->addonCustomServer() ? "true" - : "false"; - }}, - - InspectorSettingCommand{ - "addon/customServerAddress", InspectorSettingCommand::String, - [](const QByteArray& value) { - SettingsHolder::instance()->setAddonCustomServerAddress(value); - }, - []() { - return SettingsHolder::instance()->addonCustomServerAddress(); - }}, -}; - struct InspectorCommand { QString m_commandName; QString m_commandDescription; @@ -455,31 +298,6 @@ static QList s_commands{ Qt::NoModifier, point); return obj; }}, - InspectorCommand{ - "pushViewTo", "Push a QML View to a StackView", 2, - [](InspectorHandler*, const QList& arguments) { - QJsonObject obj; - QString stackViewName(arguments[1]); - QUrl qrcPath(arguments[2]); - if (!qrcPath.isValid()) { - obj["error"] = " Not a valid URL!"; - logger.error() << "Not a valid URL!"; - } - - QObject* qmlobj = InspectorUtils::findObject(stackViewName); - if (qmlobj == nullptr) { - obj["error"] = "Cant find, stackview :" + stackViewName; - } - - QVariant arg = QVariant::fromValue(qrcPath.toString()); - - bool ok = QMetaObject::invokeMethod(qmlobj, "debugPush", - QGenericReturnArgument(), - Q_ARG(QVariant, arg)); - logger.info() << "WAS OK ->" << ok; - return obj; - }}, - InspectorCommand{"click_notification", "Click on a notification", 0, [](InspectorHandler*, const QList&) { NotificationHandler::instance()->messageClickHandle(); @@ -610,49 +428,32 @@ static QList s_commands{ }}, InspectorCommand{ - "set_setting", "Set a setting", 2, + "set_setting", "Set a setting (setting, value)", 2, [](InspectorHandler*, const QList& arguments) { QJsonObject obj; - for (const InspectorSettingCommand& setting : s_settingCommands) { - if (arguments[1] == setting.m_settingName) { - switch (setting.m_type) { - case InspectorSettingCommand::Boolean: - if (arguments[2] != "true" && arguments[2] != "false") { - obj["error"] = - QString("Expected boolean (true/false) for settings %1") - .arg(QString(arguments[1])); - return obj; - } - - break; - - case InspectorSettingCommand::String: - // Nothing to do for strings. - break; - - default: - Q_ASSERT(false); - } - - if (!setting.m_set) { - obj["error"] = - QString("Read-only settings %1").arg(QString(arguments[1])); - return obj; - } - - setting.m_set(arguments[2]); - return obj; - } + SettingsHolder* settingsHolder = SettingsHolder::instance(); + const QMetaObject* metaObject = settingsHolder->metaObject(); + int propertyId = metaObject->indexOfProperty(arguments[1]); + + if (propertyId < 0) { + obj["error"] = + QString("Property %1 is not exposed by SettingsHolder") + .arg(QString(arguments[1])); + return obj; } - QStringList settings; - for (const InspectorSettingCommand& setting : s_settingCommands) { - settings.append(setting.m_settingName); + QMetaProperty property = metaObject->property(propertyId); + Q_ASSERT(property.isValid()); + + QVariant value = QVariant::fromValue(arguments[2]); + if (value.canConvert(property.type())) { + property.write(settingsHolder, value); + return obj; } - obj["error"] = QString("Invalid settings. The options are: %1") - .arg(settings.join(", ")); + obj["error"] = QString("Property %1 has a non-supported type: %2") + .arg(arguments[1], property.type()); return obj; }}, @@ -661,20 +462,38 @@ static QList s_commands{ [](InspectorHandler*, const QList& arguments) { QJsonObject obj; - for (const InspectorSettingCommand& setting : s_settingCommands) { - if (arguments[1] == setting.m_settingName) { - obj["value"] = setting.m_get(); - return obj; - } + SettingsHolder* settingsHolder = SettingsHolder::instance(); + const QMetaObject* metaObject = settingsHolder->metaObject(); + int propertyId = metaObject->indexOfProperty(arguments[1]); + + if (propertyId < 0) { + obj["error"] = + QString("Property %1 is not exposed by SettingsHolder") + .arg(QString(arguments[1])); + return obj; + } + + QMetaProperty property = metaObject->property(propertyId); + Q_ASSERT(property.isValid()); + + QVariant prop_value = property.read(settingsHolder); + if (prop_value.canConvert()) { + obj["value"] = prop_value.toJsonValue(); + return obj; + } + + if (prop_value.canConvert()) { + obj["value"] = prop_value.toDateTime().toString(); + return obj; } - QStringList settings; - for (const InspectorSettingCommand& setting : s_settingCommands) { - settings.append(setting.m_settingName); + if (prop_value.canConvert()) { + obj["value"] = prop_value.toByteArray().data(); + return obj; } - obj["error"] = QString("Invalid settings. The options are: %1") - .arg(settings.join(", ")); + obj["error"] = QString("Property %1 has a non-supported type: %2") + .arg(arguments[1], property.type()); return obj; }}, @@ -965,7 +784,7 @@ static QList s_commands{ InspectorCommand{"force_rtl", "Force RTL layout", 0, [](InspectorHandler*, const QList&) { s_forceRTL = true; - emit Localizer::instance()->codeChanged(); + emit SettingsHolder::instance()->languageCodeChanged(); return QJsonObject(); }}, diff --git a/src/localizer.cpp b/src/localizer.cpp index 2416a2720dd..f612a76bf32 100644 --- a/src/localizer.cpp +++ b/src/localizer.cpp @@ -64,9 +64,6 @@ Localizer::Localizer() { Q_ASSERT(!s_instance); s_instance = this; - SettingsHolder* settingsHolder = SettingsHolder::instance(); - m_code = settingsHolder->languageCode(); - initialize(); } @@ -101,7 +98,9 @@ void Localizer::initialize() { settingsHolder->setPreviousLanguageCode(systemCode); } - loadLanguage(m_code); + connect(settingsHolder, &SettingsHolder::languageCodeChanged, this, + &Localizer::settingsChanged); + settingsChanged(); QCoreApplication::installTranslator(&m_translator); QDir dir(":/i18n"); @@ -128,25 +127,25 @@ void Localizer::initialize() { } void Localizer::loadLanguage(const QString& code) { + SettingsHolder::instance()->setLanguageCode(code); +} + +void Localizer::settingsChanged() { + SettingsHolder* settingsHolder = SettingsHolder::instance(); + + QString code = settingsHolder->languageCode(); logger.debug() << "Loading language:" << code; + if (!loadLanguageInternal(code)) { logger.debug() << "Loading default language (fallback)"; loadLanguageInternal("en"); } - SettingsHolder* settingsHolder = SettingsHolder::instance(); - if (code.isEmpty() && settingsHolder->hasLanguageCode()) { - QString previousCode = settingsHolder->languageCode(); - if (!previousCode.isEmpty()) { - settingsHolder->setPreviousLanguageCode(previousCode); - emit previousCodeChanged(); - } + if (!m_code.isEmpty()) { + settingsHolder->setPreviousLanguageCode(m_code); } - SettingsHolder::instance()->setLanguageCode(code); - m_code = code; - emit codeChanged(); } bool Localizer::loadLanguageInternal(const QString& code) { @@ -268,10 +267,6 @@ bool Localizer::languageSort(const Localizer::Language& a, return collator->compare(a.m_localizedName, b.m_localizedName) < 0; } -QString Localizer::previousCode() const { - return SettingsHolder::instance()->previousLanguageCode(); -} - QString Localizer::localizedCityName(const QString& code, const QString& city) { return ServerI18N::translateCityName(code, city); } diff --git a/src/localizer.h b/src/localizer.h index 483f59835dd..06c41f3b452 100644 --- a/src/localizer.h +++ b/src/localizer.h @@ -16,11 +16,9 @@ class Localizer final : public QAbstractListModel { Q_OBJECT Q_DISABLE_COPY_MOVE(Localizer) - Q_PROPERTY(QString code READ code WRITE setCode NOTIFY codeChanged) - Q_PROPERTY(QString previousCode READ previousCode NOTIFY previousCodeChanged) Q_PROPERTY(bool hasLanguages READ hasLanguages CONSTANT) Q_PROPERTY(QLocale locale READ locale NOTIFY localeChanged) - Q_PROPERTY(bool isRightToLeft READ isRightToLeft NOTIFY codeChanged) + Q_PROPERTY(bool isRightToLeft READ isRightToLeft NOTIFY localeChanged) struct Language { QString m_code; @@ -48,11 +46,6 @@ class Localizer final : public QAbstractListModel { bool hasLanguages() const { return m_languages.length() > 1; } - const QString& code() const { return m_code; } - void setCode(const QString& code) { loadLanguage(code); } - - QString previousCode() const; - QStringList languages() const; // QAbstractListModel methods @@ -78,8 +71,6 @@ class Localizer final : public QAbstractListModel { bool isRightToLeft() const; signals: - void codeChanged(); - void previousCodeChanged(); void localeChanged(); private: @@ -97,6 +88,8 @@ class Localizer final : public QAbstractListModel { static QString retrieveCurrencySymbolFallback(const QString& currencyIso4217, const QLocale& currentLocale); + void settingsChanged(); + private: QTranslator m_translator; diff --git a/src/ui/screens/settings/ViewLanguage.qml b/src/ui/screens/settings/ViewLanguage.qml index b869a99be6a..c51c8cdcacd 100644 --- a/src/ui/screens/settings/ViewLanguage.qml +++ b/src/ui/screens/settings/ViewLanguage.qml @@ -49,13 +49,13 @@ VPNViewBase { return qsTrId("vpn.settings.systemLanguageTitle"); } - toggleChecked: VPNLocalizer.code === "" + toggleChecked: VPNSettings.languageCode === "" function handleClick() { toggleChecked = !toggleChecked if (toggleChecked) { - VPNLocalizer.code = ""; + VPNSettings.languageCode = ""; } else { - VPNLocalizer.code = VPNLocalizer.previousCode; + VPNSettings.languageCode = VPNSettings.previousLanguageCode; } } } @@ -122,9 +122,9 @@ VPNViewBase { objectName: "language-" + code enabled: !useSystemLanguageEnabled radioButtonLabelText: localizedLanguage - checked: VPNLocalizer.code === code && !useSystemLanguageEnabled + checked: VPNSettings.languageCode === code && !useSystemLanguageEnabled onClicked: { - VPNLocalizer.code = code; + VPNSettings.languageCode = code; } Layout.alignment: Qt.AlignLeft diff --git a/tests/functional/actions.js b/tests/functional/actions.js index 1adf724d4b3..fdcb15864ee 100644 --- a/tests/functional/actions.js +++ b/tests/functional/actions.js @@ -5,29 +5,20 @@ const { elementState } = require('./elements.js'); const vpn = require('./helper.js'); -const settings = { - setServerSwitchNotification: async (status) => { - return await vpn.setSetting('server-switch-notification', status ? "true" : "false"); - }, - - setConnectionChangeNotification: async (status) => { - return await vpn.setSetting('connection-change-notification', status ? "true" : "false"); - } -} - const serverList = { - selectCityFromList: async (cityId, countryId) => { - await vpn.setElementProperty(elementState.COUNTRY_VIEW, 'contentY', 'i', parseInt(await vpn.getElementProperty(cityId, 'y')) + parseInt(await vpn.getElementProperty(countryId, 'y'))); - }, + selectCityFromList: async (cityId, countryId) => { + await vpn.setElementProperty( + elementState.COUNTRY_VIEW, 'contentY', 'i', + parseInt(await vpn.getElementProperty(cityId, 'y')) + + parseInt(await vpn.getElementProperty(countryId, 'y'))); + }, - selectCountryFromList: async (countryId) => { + selectCountryFromList: + async (countryId) => { await vpn.setElementProperty(elementState.COUNTRY_VIEW, 'contentY', 'i', parseInt(await vpn.getElementProperty(countryId, 'y'))); } -} +}; module.exports = { - actions: { - settings, - serverList - } -} \ No newline at end of file + actions : {settings, serverList} +}; diff --git a/tests/functional/helper.js b/tests/functional/helper.js index 52e49440242..4b58e13a9f9 100644 --- a/tests/functional/helper.js +++ b/tests/functional/helper.js @@ -499,8 +499,8 @@ module.exports = { _lastAddonLoadingCompleted = false; await this.setSetting( - 'addon/customServerAddress', `${constants.ADDON_URL}/${addonPath}/`); - await this.setSetting('addon/customServer', 'true'); + 'addonCustomServerAddress', `${constants.ADDON_URL}/${addonPath}/`); + await this.setSetting('addonCustomServer', 'true'); const json = await this._writeCommand('reset_addons'); assert( @@ -517,8 +517,8 @@ module.exports = { _lastAddonLoadingCompleted = false; await this.setSetting( - 'addon/customServerAddress', `${constants.ADDON_URL}/${addonPath}/`); - await this.setSetting('addon/customServer', 'true'); + 'addonCustomServerAddress', `${constants.ADDON_URL}/${addonPath}/`); + await this.setSetting('addonCustomServer', 'true'); const json = await this._writeCommand('fetch_addons'); assert( diff --git a/tests/functional/setupVpn.js b/tests/functional/setupVpn.js index b729b9d6aed..7cb6163eb90 100644 --- a/tests/functional/setupVpn.js +++ b/tests/functional/setupVpn.js @@ -80,7 +80,7 @@ exports.mochaHooks = { await startAndConnect(); await vpn.reset(); - await vpn.setSetting('tips-and-tricks-intro-shown', 'true'); + await vpn.setSetting('tipsAndTricksIntroShown', 'true'); await vpn.flipFeatureOn('websocket'); await vpn.authenticateInApp(true, true); @@ -112,7 +112,7 @@ exports.mochaHooks = { await startAndConnect(); await vpn.reset(); - await vpn.setSetting('tips-and-tricks-intro-shown', 'true') + await vpn.setSetting('tipsAndTricksIntroShown', 'true') } await vpn.setGleanAutomationHeader(); diff --git a/tests/functional/setupWasm.js b/tests/functional/setupWasm.js index e584f92cca3..e20cc6b941f 100644 --- a/tests/functional/setupWasm.js +++ b/tests/functional/setupWasm.js @@ -67,7 +67,7 @@ exports.mochaHooks = { await startAndConnect(); await vpn.setGleanAutomationHeader(); - await vpn.setSetting('tips-and-tricks-intro-shown', 'true') + await vpn.setSetting('tipsAndTricksIntroShown', 'true') if (this.currentTest.ctx.authenticationNeeded) { await vpn.authenticateInApp(true, true); diff --git a/tests/functional/testCaptivePortal.js b/tests/functional/testCaptivePortal.js index 17e25db2674..8426c8d03e1 100644 --- a/tests/functional/testCaptivePortal.js +++ b/tests/functional/testCaptivePortal.js @@ -12,11 +12,11 @@ describe('Captive portal', function() { vpn.resetLastNotification(); //Enable captive-portal-alert feature - await vpn.setSetting('captive-portal-alert', 'false'); - assert(await vpn.getSetting('captive-portal-alert') === 'false'); + await vpn.setSetting('captivePortalAlert', 'false'); + assert(await vpn.getSetting('captivePortalAlert') === false); - await vpn.setSetting('captive-portal-alert', 'true'); - assert(await vpn.getSetting('captive-portal-alert') === 'true'); + await vpn.setSetting('captivePortalAlert', 'true'); + assert(await vpn.getSetting('captivePortalAlert') === true); }); it('Captive portal during the main view', async () => { @@ -177,7 +177,7 @@ describe('Captive portal', function() { it('Shows the prompt Before activation when a portal is detected before the activation', async () => { - await vpn.setSetting('captive-portal-alert', 'true'); + await vpn.setSetting('captivePortalAlert', 'true'); await vpn.forceCaptivePortalDetection(); await vpn.activate(); @@ -187,7 +187,7 @@ describe('Captive portal', function() { it('Shows the Captive Portal Info prompt when a portal is detected and the client is connected', async () => { - await vpn.setSetting('captive-portal-alert', 'true'); + await vpn.setSetting('captivePortalAlert', 'true'); await vpn.activate(); await vpn.waitForCondition(() => { diff --git a/tests/functional/testConnection.js b/tests/functional/testConnection.js index 75f374546e5..41c3fa541d8 100644 --- a/tests/functional/testConnection.js +++ b/tests/functional/testConnection.js @@ -27,7 +27,7 @@ describe('Connectivity', function() { it('Connect to VPN', async () => { await vpn.waitForElement(generalElements.CONTROLLER_TITLE); - await vpn.setSetting('connection-change-notification', 'true'); + await vpn.setSetting('connectionChangeNotification', 'true'); // TODO: investigate why the click doesn't work on github. // await vpn.clickOnElement('controllerToggle'); await vpn.activate(); @@ -61,7 +61,7 @@ describe('Connectivity', function() { it('Disconnecting and disconnected', async () => { await vpn.waitForElement(generalElements.CONTROLLER_TITLE); - await vpn.setSetting('connection-change-notification', 'true'); + await vpn.setSetting('connectionChangeNotification', 'true'); await vpn.activate(); await vpn.waitForCondition(async () => { return await vpn.getElementProperty(generalElements.CONTROLLER_TITLE, 'text') == diff --git a/tests/functional/testMultihop.js b/tests/functional/testMultihop.js index 9944e5a9a04..01af254aaef 100644 --- a/tests/functional/testMultihop.js +++ b/tests/functional/testMultihop.js @@ -7,21 +7,23 @@ const { elementState, generalElements, homeScreen } = require('./elements.js'); const vpn = require('./helper.js'); -describe('Server list', function() { + describe('Server list', function() { let servers; let currentCountryCode; let currentCity; this.timeout(240000); this.ctx.authenticationNeeded = true; - - beforeEach(async () => { + + beforeEach(async () => { await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); servers = await vpn.servers(); - currentCountryCode = await vpn.getSetting('current-server-country-code'); - currentCity = await vpn.getSetting('current-server-city'); - + currentCountryCode = + await vpn.getElementProperty('VPNCurrentServer', 'exitCountryCode'); + currentCity = + await vpn.getElementProperty('VPNCurrentServer', 'exitCityName'); + for (let server of servers) { if (currentCountryCode === server.code) { for (let city of server.cities) { @@ -35,498 +37,600 @@ describe('Server list', function() { console.log( 'Current city (localized):', currentCity, '| Current country code:', currentCountryCode); - }); - - it('opening the entry and exit server list', async () => { - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - assert(await vpn.getElementProperty(homeScreen.selectMultiHopServerView.VPN_COLLAPSIBLE_CARD, 'expanded') === 'false') - - await vpn.waitForElement(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - await vpn.waitForElementProperty(homeScreen.selectMultiHopServerView.ENTRY_BUTTON, 'visible', 'true'); - - await vpn.waitForElement(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - await vpn.waitForElementProperty(homeScreen.selectMultiHopServerView.EXIT_BUTTON, 'visible', 'true'); - - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.VPN_MULTHOP_CHEVRON) - assert(await vpn.getElementProperty(homeScreen.selectMultiHopServerView.VPN_COLLAPSIBLE_CARD, 'expanded')) - }); - - it.only('check the countries and cities for multihop entries', async () => { - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - for (let server of servers) { - const countryId = homeScreen.serverListView.generateCountryId(server.code); - await vpn.waitForElement(countryId); - await vpn.waitForElementProperty(countryId, 'visible', 'true'); - - await actions.serverList.selectCountryFromList(countryId) - await vpn.wait(); - - if (currentCountryCode === server.code) { - assert(await vpn.getElementProperty(countryId, 'cityListVisible') === 'true'); - } - - if (await vpn.getElementProperty(countryId, 'cityListVisible') === - 'false') { - await vpn.clickOnElement(countryId); - } - - for (let city of server.cities) { - const cityId = homeScreen.serverListView.generateCityId(countryId, city.name); - console.log(' Waiting for cityId:', cityId); - await vpn.waitForElement(cityId); - await vpn.waitForElementProperty(cityId, 'visible', 'true'); - await vpn.waitForElementProperty( - cityId, 'checked', - currentCountryCode === server.code && - currentCity === city.localizedName ? - 'true' : - 'false'); - } - } - }) - - it('check the countries and cities for multihop exits', async () => { - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - for (let server of servers) { - const countryId = homeScreen.serverListView.generateCountryId(server.code); - - await vpn.waitForElement(countryId); - await vpn.waitForElementProperty(countryId, 'visible', 'true'); - - await actions.serverList.selectCountryFromList(countryId); - await vpn.wait(); - - if (currentCountryCode === server.code) { - assert( - await vpn.getElementProperty(countryId, elementState.CITYLIST_VISIBLE) === - 'true'); - } - - if (await vpn.getElementProperty(countryId, elementState.CITYLIST_VISIBLE) === - 'false') { - await vpn.clickOnElement(countryId); - } - - for (let city of server.cities) { - const cityId = countryId + '/serverCityList/serverCity-' + - city.name.replace(/ /g, '_'); - - await vpn.waitForElement(cityId); - await vpn.waitForElementProperty(cityId, 'visible', 'true'); - await vpn.waitForElementProperty( - cityId, 'checked', - currentCountryCode === server.code && - currentCity === city.localizedName ? - 'true' : - 'false'); - } - } - }) - - it('Pick cities for entries', async () => { - let countryId; - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - for (let server of servers) { - countryId = homeScreen.serverListView.generateCountryId(server.code); - await vpn.waitForElement(countryId); - - await actions.serverList.selectCountryFromList(countryId); - await vpn.wait(); - - if (await vpn.getElementProperty(countryId, elementState.CITYLIST_VISIBLE) === 'false') { - await vpn.clickOnElement(countryId); - } - - await vpn.waitForElementProperty(countryId, elementState.CITYLIST_VISIBLE, 'true'); - - for (let city of server.cities) { - const cityId = countryId + '/serverCityList/serverCity-' + city.name.replace(/ /g, '_'); - await vpn.waitForElement(cityId); - - await actions.serverList.selectCityFromList(cityId, countryId); - await vpn.waitForElementProperty(cityId, 'visible', 'true'); - const cityName = await vpn.getElementProperty(cityId, 'radioButtonLabelText'.split(" ")); - - await vpn.wait(); - await vpn.clickOnElement(cityId); - await vpn.wait(); - - // Back to the main view. - await vpn.waitForElement(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - await vpn.waitForElementProperty(homeScreen.selectMultiHopServerView.ENTRY_BUTTON, 'visible', 'true'); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - // One selected - await vpn.waitForElement(cityId); - await vpn.waitForElementProperty(cityId, 'checked', 'true'); - assert(cityName.includes(city.name)) - } - } - }); - - it('Pick cities for exits', async () => { - let countryId; - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - for (let server of servers) { - countryId = homeScreen.serverListView.generateCountryId(server.code); - await vpn.waitForElement(countryId); - - await actions.serverList.selectCountryFromList(countryId) - await vpn.wait(); - - if (await vpn.getElementProperty(countryId, elementState.CITYLIST_VISIBLE) === 'false') { - await vpn.clickOnElement(countryId); - } - - await vpn.waitForElementProperty(countryId, elementState.CITYLIST_VISIBLE, 'true'); - - for (let city of server.cities) { - const cityId = countryId + '/serverCityList/serverCity-' + city.name.replace(/ /g, '_'); - await vpn.waitForElement(cityId); - - await actions.serverList.selectCityFromList(cityId, countryId) - await vpn.waitForElementProperty(cityId, 'visible', 'true'); - const cityName = await vpn.getElementProperty(cityId, 'radioButtonLabelText'.split(" ")); - - await vpn.wait(); - await vpn.clickOnElement(cityId); - await vpn.wait(); - - // Back to the main view. - await vpn.waitForElement(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - await vpn.waitForElementProperty(homeScreen.selectMultiHopServerView.EXIT_BUTTON, 'visible', 'true'); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // One selected - await vpn.waitForElement(cityId); - await vpn.waitForElementProperty(cityId, 'checked', 'true'); - assert(cityName.includes(city.name)) - } - } - }); - - it('Server switching -- same country different cities', async () => { - await actions.settings.setServerSwitchNotification(true) - await actions.settings.setConnectionChangeNotification(true) - - let newCurrentCountry; - let newCurrentCity; - let currentCountry; - let currentCity; - - // wait for select entry and select entry - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - // exit server details - const firstServer = servers[0] - const cityTwo = firstServer.cities[0] - const cityThree = firstServer.cities[1] - const exitFirstCountryId = homeScreen.serverListView.generateCountryId(firstServer.code); - - // entry server details - const secondServer = servers[1] - const cityOne = secondServer.cities[0] - const entryCountryId = homeScreen.serverListView.generateCountryId(secondServer.code); - - // select the first country - await actions.serverList.selectCountryFromList(entryCountryId); - await vpn.wait() - if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(entryCountryId); - } - await vpn.waitForElementProperty(entryCountryId, 'cityListVisible', 'true'); - - // select first city - const cityOneId = homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); - - await vpn.setElementProperty( - elementState.COUNTRY_VIEW, 'contentY', 'i', - parseInt(await vpn.getElementProperty(cityOneId, 'y')) + - parseInt(await vpn.getElementProperty(entryCountryId, 'y'))); - await vpn.wait() - await vpn.waitForElementAndClick(cityOneId) - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // select first country again - await actions.serverList.selectCountryFromList(exitFirstCountryId) - await vpn.wait(); - if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(exitFirstCountryId); - } - await vpn.waitForElementProperty(exitFirstCountryId, 'cityListVisible', 'true'); - - // select first city in exit country - const cityTwoId = homeScreen.serverListView.generateCityId(exitFirstCountryId, cityTwo.name); - - await vpn.setElementProperty( - elementState.COUNTRY_VIEW, 'contentY', 'i', - parseInt(await vpn.getElementProperty(cityTwoId, 'y')) + - parseInt(await vpn.getElementProperty(exitFirstCountryId, 'y'))); - await vpn.wait() - await vpn.waitForElementAndClick(cityTwoId); - - // navigate back to connection view - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON); - - // define connected server - currentCountry = firstServer.localizedName; - currentCity = cityTwo.localizedName; - - // connect vpn - await vpn.activate(); - - // wait and assert vpn connection - await vpn.waitForCondition(async () => { - return await vpn.getElementProperty(generalElements.CONTROLLER_TITLE, 'text') == - 'VPN is on'; - }); - assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); - assert.strictEqual(vpn.lastNotification().message, `Connected to ${currentCountry}, ${currentCity}`); - - // back to main view - await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // select first country again - await actions.serverList.selectCountryFromList(exitFirstCountryId) - await vpn.wait(); - if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(exitFirstCountryId); - } - await vpn.waitForElementProperty(exitFirstCountryId, 'cityListVisible', 'true'); - - // select first city in exit country - const cityThreeId = homeScreen.serverListView.generateCityId(exitFirstCountryId, cityThree.name); - - await vpn.setElementProperty( - elementState.COUNTRY_VIEW, 'contentY', 'i', - parseInt(await vpn.getElementProperty(cityThreeId, 'y')) + - parseInt(await vpn.getElementProperty(exitFirstCountryId, 'y'))); - await vpn.waitForElementAndClick(cityThreeId); - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON); - - // define new connected server - newCurrentCountry = firstServer.localizedName; - newCurrentCity = cityThree.localizedName; - - // wait and assert server switching for multihop - await vpn.waitForCondition(async () => { - return vpn.lastNotification().title == "VPN Switched Servers" - }, 20) - assert.strictEqual( - vpn.lastNotification().message, - `Switched from ${currentCountry}, ${currentCity} to ${ - newCurrentCountry}, ${newCurrentCity}`); - }); - - it('Server switching -- different country different cities', async () => { - await actions.settings.setServerSwitchNotification(true) - await actions.settings.setConnectionChangeNotification(true) - - let newCurrentCountry; - let newCurrentCity; - let currentCountry; - let currentCity; - - // wait for select entry and select entry - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - // exit server details - const firstServer = servers[0] - const cityTwo = firstServer.cities[0] - const exitFirstCountryId = homeScreen.serverListView.generateCountryId(firstServer.code); - - // second exit server details - const thirdServer = servers[2] - const cityThree = thirdServer.cities[0] - const exitThirdCountryId = homeScreen.serverListView.generateCountryId(thirdServer.code); - - // entry server details - const secondServer = servers[1] - const cityOne = secondServer.cities[0] - const entryCountryId = homeScreen.serverListView.generateCountryId(secondServer.code); - - // select the first country - await actions.serverList.selectCountryFromList(entryCountryId); - await vpn.wait() - if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(entryCountryId); - } - await vpn.waitForElementProperty(entryCountryId, 'cityListVisible', 'true'); - - // select first city - const cityOneId = homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); - await actions.serverList.selectCityFromList(cityOneId, entryCountryId) - await vpn.waitForElementAndClick(cityOneId) - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // select first country again - await actions.serverList.selectCountryFromList(exitFirstCountryId) - await vpn.wait(); - if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(exitFirstCountryId); - } - await vpn.waitForElementProperty(exitFirstCountryId, 'cityListVisible', 'true'); - - // select first city in exit country - const cityTwoId = homeScreen.serverListView.generateCityId(exitFirstCountryId, cityTwo.name); - await actions.serverList.selectCityFromList(cityTwoId, exitFirstCountryId) - await vpn.waitForElementAndClick(cityTwoId); - - // navigate back to connection view - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON); - - // define connected server - currentCountry = firstServer.localizedName; - currentCity = cityTwo.localizedName; - - // connect vpn - await vpn.activate(); - - // wait and assert vpn connection - await vpn.waitForCondition(async () => { - return await vpn.getElementProperty(generalElements.CONTROLLER_TITLE, 'text') == - 'VPN is on'; - }); - assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); - assert.strictEqual(vpn.lastNotification().message, `Connected to ${currentCountry}, ${currentCity}`); - - // back to main view - await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // select first country again - await actions.serverList.selectCountryFromList(exitThirdCountryId) - await vpn.wait(); - if (await vpn.getElementProperty(exitThirdCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(exitThirdCountryId); - } - await vpn.waitForElementProperty(exitThirdCountryId, 'cityListVisible', 'true'); - - // select first city in exit country - const cityThreeId = homeScreen.serverListView.generateCityId(exitThirdCountryId, cityThree.name); - await actions.serverList.selectCityFromList(cityThreeId, exitThirdCountryId) - await vpn.waitForElementAndClick(cityThreeId); - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON); - - // define new connected server - newCurrentCountry = thirdServer.localizedName; - newCurrentCity = cityThree.localizedName; - - // wait and assert server switching for multihop - await vpn.waitForCondition(async () => { - return vpn.lastNotification().title == "VPN Switched Servers" - }, 20) - assert.strictEqual( - vpn.lastNotification().message, - `Switched from ${currentCountry}, ${currentCity} to ${ - newCurrentCountry}, ${newCurrentCity}`); - }); - - it('Single and multihop switching', async () => { - await actions.settings.setServerSwitchNotification(true) - await actions.settings.setConnectionChangeNotification(true) - - let currentCountry; - let currentCity; - - // wait for select entry and select entry - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); - - // exit server details - const firstServer = servers[0] - const cityTwo = firstServer.cities[0] - const exitFirstCountryId = homeScreen.serverListView.generateCountryId(firstServer.code); - - // entry server details - const secondServer = servers[1] - const cityOne = secondServer.cities[0] - const entryCountryId = homeScreen.serverListView.generateCountryId(secondServer.code); - - // select the first country - await actions.serverList.selectCountryFromList(entryCountryId); - await vpn.wait() - if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(entryCountryId); - } - await vpn.waitForElementProperty(entryCountryId, 'cityListVisible', 'true'); - - // select first city - const cityOneId = homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); - await actions.serverList.selectCityFromList(cityOneId, entryCountryId) - await vpn.waitForElementAndClick(cityOneId) - - // Back at the main view. select the exit entries - await vpn.waitForElementAndClick(homeScreen.selectMultiHopServerView.EXIT_BUTTON); - - // select first country again - await actions.serverList.selectCountryFromList(exitFirstCountryId) - await vpn.wait(); - if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === 'false') { - await vpn.clickOnElement(exitFirstCountryId); - } - await vpn.waitForElementProperty(exitFirstCountryId, 'cityListVisible', 'true'); - - // select first city in exit country - const cityTwoId = homeScreen.serverListView.generateCityId(exitFirstCountryId, cityTwo.name); - await actions.serverList.selectCityFromList(cityTwoId, exitFirstCountryId) - await vpn.waitForElementAndClick(cityTwoId); - - // navigate back to connection view - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON); - - // define connected server - currentCountry = firstServer.localizedName; - currentCity = cityTwo.localizedName; - - // connect vpn - await vpn.activate(); - - // wait and assert vpn connection - await vpn.waitForCondition(async () => { - return await vpn.getElementProperty(generalElements.CONTROLLER_TITLE, 'text') == - 'VPN is on'; - }); - assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); - assert.strictEqual(vpn.lastNotification().message, `Connected to ${currentCountry}, ${currentCity}`); - - // back to main view - await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); - - - // switch from multihop to singlehop - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.SINGLEHOP_SELECTOR_TAB) - await vpn.waitForElementAndClick(homeScreen.selectSingleHopServerView.BACK_BUTTON) - - // wait and assert vpn connection - await vpn.waitForCondition(async () => { - return await vpn.getElementProperty(generalElements.CONTROLLER_TITLE, 'text') == - 'VPN is on'; - }); - assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); - assert.strictEqual(vpn.lastNotification().message, `Connected to ${currentCountry}, ${currentCity}`); - }); -}); \ No newline at end of file + }); + + it('opening the entry and exit server list', async () => { + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + assert( + await vpn.getElementProperty( + homeScreen.selectMultiHopServerView.VPN_COLLAPSIBLE_CARD, + 'expanded') === 'false'); + + await vpn.waitForElement(homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + await vpn.waitForElementProperty( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON, 'visible', 'true'); + + await vpn.waitForElement(homeScreen.selectMultiHopServerView.EXIT_BUTTON); + await vpn.waitForElementProperty( + homeScreen.selectMultiHopServerView.EXIT_BUTTON, 'visible', 'true'); + + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.VPN_MULTHOP_CHEVRON) + assert(await vpn.getElementProperty( + homeScreen.selectMultiHopServerView.VPN_COLLAPSIBLE_CARD, 'expanded')) + }); + + it.only('check the countries and cities for multihop entries', async () => { + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + for (let server of servers) { + const countryId = + homeScreen.serverListView.generateCountryId(server.code); + await vpn.waitForElement(countryId); + await vpn.waitForElementProperty(countryId, 'visible', 'true'); + + await actions.serverList.selectCountryFromList(countryId); + await vpn.wait(); + + if (currentCountryCode === server.code) { + assert( + await vpn.getElementProperty(countryId, 'cityListVisible') === + 'true'); + } + + if (await vpn.getElementProperty(countryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(countryId); + } + + for (let city of server.cities) { + const cityId = + homeScreen.serverListView.generateCityId(countryId, city.name); + console.log(' Waiting for cityId:', cityId); + await vpn.waitForElement(cityId); + await vpn.waitForElementProperty(cityId, 'visible', 'true'); + await vpn.waitForElementProperty( + cityId, 'checked', + currentCountryCode === server.code && + currentCity === city.localizedName ? + 'true' : + 'false'); + } + } + }) + + it('check the countries and cities for multihop exits', async () => { + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + for (let server of servers) { + const countryId = + homeScreen.serverListView.generateCountryId(server.code); + + await vpn.waitForElement(countryId); + await vpn.waitForElementProperty(countryId, 'visible', 'true'); + + await actions.serverList.selectCountryFromList(countryId); + await vpn.wait(); + + if (currentCountryCode === server.code) { + assert( + await vpn.getElementProperty( + countryId, elementState.CITYLIST_VISIBLE) === 'true'); + } + + if (await vpn.getElementProperty( + countryId, elementState.CITYLIST_VISIBLE) === 'false') { + await vpn.clickOnElement(countryId); + } + + for (let city of server.cities) { + const cityId = countryId + '/serverCityList/serverCity-' + + city.name.replace(/ /g, '_'); + + await vpn.waitForElement(cityId); + await vpn.waitForElementProperty(cityId, 'visible', 'true'); + await vpn.waitForElementProperty( + cityId, 'checked', + currentCountryCode === server.code && + currentCity === city.localizedName ? + 'true' : + 'false'); + } + } + }) + + it('Pick cities for entries', async () => { + let countryId; + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + for (let server of servers) { + countryId = homeScreen.serverListView.generateCountryId(server.code); + await vpn.waitForElement(countryId); + + await actions.serverList.selectCountryFromList(countryId); + await vpn.wait(); + + if (await vpn.getElementProperty( + countryId, elementState.CITYLIST_VISIBLE) === 'false') { + await vpn.clickOnElement(countryId); + } + + await vpn.waitForElementProperty( + countryId, elementState.CITYLIST_VISIBLE, 'true'); + + for (let city of server.cities) { + const cityId = countryId + '/serverCityList/serverCity-' + + city.name.replace(/ /g, '_'); + await vpn.waitForElement(cityId); + + await actions.serverList.selectCityFromList(cityId, countryId); + await vpn.waitForElementProperty(cityId, 'visible', 'true'); + const cityName = await vpn.getElementProperty( + cityId, 'radioButtonLabelText'.split(' ')); + + await vpn.wait(); + await vpn.clickOnElement(cityId); + await vpn.wait(); + + // Back to the main view. + await vpn.waitForElement( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + await vpn.waitForElementProperty( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON, 'visible', + 'true'); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + // One selected + await vpn.waitForElement(cityId); + await vpn.waitForElementProperty(cityId, 'checked', 'true'); + assert(cityName.includes(city.name)) + } + } + }); + + it('Pick cities for exits', async () => { + let countryId; + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + for (let server of servers) { + countryId = homeScreen.serverListView.generateCountryId(server.code); + await vpn.waitForElement(countryId); + + await actions.serverList.selectCountryFromList(countryId) + await vpn.wait(); + + if (await vpn.getElementProperty( + countryId, elementState.CITYLIST_VISIBLE) === 'false') { + await vpn.clickOnElement(countryId); + } + + await vpn.waitForElementProperty( + countryId, elementState.CITYLIST_VISIBLE, 'true'); + + for (let city of server.cities) { + const cityId = countryId + '/serverCityList/serverCity-' + + city.name.replace(/ /g, '_'); + await vpn.waitForElement(cityId); + + await actions.serverList + .selectCityFromList(cityId, countryId) + await vpn.waitForElementProperty(cityId, 'visible', 'true'); + const cityName = await vpn.getElementProperty( + cityId, 'radioButtonLabelText'.split(' ')); + + await vpn.wait(); + await vpn.clickOnElement(cityId); + await vpn.wait(); + + // Back to the main view. + await vpn.waitForElement( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + await vpn.waitForElementProperty( + homeScreen.selectMultiHopServerView.EXIT_BUTTON, 'visible', + 'true'); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // One selected + await vpn.waitForElement(cityId); + await vpn.waitForElementProperty(cityId, 'checked', 'true'); + assert(cityName.includes(city.name)) + } + } + }); + + it('Server switching -- same country different cities', async () => { + await vpn.setSetting('serverSwitchNotification', true); + await vpn.setSetting('connectionChangeNotification', true); + + let newCurrentCountry; + let newCurrentCity; + let currentCountry; + let currentCity; + + // wait for select entry and select entry + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + // exit server details + const firstServer = servers[0]; + const cityTwo = firstServer.cities[0]; + const cityThree = firstServer.cities[1]; + const exitFirstCountryId = + homeScreen.serverListView.generateCountryId(firstServer.code); + + // entry server details + const secondServer = servers[1]; + const cityOne = secondServer.cities[0]; + const entryCountryId = + homeScreen.serverListView.generateCountryId(secondServer.code); + + // select the first country + await actions.serverList.selectCountryFromList(entryCountryId); + await vpn.wait() + if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(entryCountryId); + } + await vpn.waitForElementProperty( + entryCountryId, 'cityListVisible', 'true'); + + // select first city + const cityOneId = + homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); + + await vpn.setElementProperty( + elementState.COUNTRY_VIEW, 'contentY', 'i', + parseInt(await vpn.getElementProperty(cityOneId, 'y')) + + parseInt(await vpn.getElementProperty(entryCountryId, 'y'))); + await vpn.wait(); + await vpn.waitForElementAndClick(cityOneId); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // select first country again + await actions.serverList.selectCountryFromList(exitFirstCountryId); + await vpn.wait(); + if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(exitFirstCountryId); + } + await vpn.waitForElementProperty( + exitFirstCountryId, 'cityListVisible', 'true'); + + // select first city in exit country + const cityTwoId = homeScreen.serverListView.generateCityId( + exitFirstCountryId, cityTwo.name); + + await vpn.setElementProperty( + elementState.COUNTRY_VIEW, 'contentY', 'i', + parseInt(await vpn.getElementProperty(cityTwoId, 'y')) + + parseInt(await vpn.getElementProperty(exitFirstCountryId, 'y'))); + await vpn.wait(); + await vpn.waitForElementAndClick(cityTwoId); + + // navigate back to connection view + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON); + + // define connected server + currentCountry = firstServer.localizedName; + currentCity = cityTwo.localizedName; + + // connect vpn + await vpn.activate(); + + // wait and assert vpn connection + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + generalElements.CONTROLLER_TITLE, 'text') == 'VPN is on'; + }); + assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); + assert.strictEqual( + vpn.lastNotification().message, + `Connected to ${currentCountry}, ${currentCity}`); + + // back to main view + await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // select first country again + await actions.serverList.selectCountryFromList(exitFirstCountryId); + await vpn.wait(); + if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(exitFirstCountryId); + } + await vpn.waitForElementProperty( + exitFirstCountryId, 'cityListVisible', 'true'); + + // select first city in exit country + const cityThreeId = homeScreen.serverListView.generateCityId( + exitFirstCountryId, cityThree.name); + + await vpn.setElementProperty( + elementState.COUNTRY_VIEW, 'contentY', 'i', + parseInt(await vpn.getElementProperty(cityThreeId, 'y')) + + parseInt(await vpn.getElementProperty(exitFirstCountryId, 'y'))); + await vpn.waitForElementAndClick(cityThreeId); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON); + + // define new connected server + newCurrentCountry = firstServer.localizedName; + newCurrentCity = cityThree.localizedName; + + // wait and assert server switching for multihop + await vpn.waitForCondition( + async () => {return vpn.lastNotification().title == + 'VPN Switched Servers'}, + 20) + assert.strictEqual( + vpn.lastNotification().message, + `Switched from ${currentCountry}, ${currentCity} to ${ + newCurrentCountry}, ${newCurrentCity}`); + }); + + it('Server switching -- different country different cities', async () => { + await vpn.setSetting('serverSwitchNotification', true); + await vpn.setSetting('connectionChangeNotification', true); + + let newCurrentCountry; + let newCurrentCity; + let currentCountry; + let currentCity; + + // wait for select entry and select entry + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + // exit server details + const firstServer = servers[0]; + const cityTwo = firstServer.cities[0]; + const exitFirstCountryId = + homeScreen.serverListView.generateCountryId(firstServer.code); + + // second exit server details + const thirdServer = servers[2]; + const cityThree = thirdServer.cities[0]; + const exitThirdCountryId = + homeScreen.serverListView.generateCountryId(thirdServer.code); + + // entry server details + const secondServer = servers[1]; + const cityOne = secondServer.cities[0]; + const entryCountryId = + homeScreen.serverListView.generateCountryId(secondServer.code); + + // select the first country + await actions.serverList.selectCountryFromList(entryCountryId); + await vpn.wait(); + + if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(entryCountryId); + } + await vpn.waitForElementProperty( + entryCountryId, 'cityListVisible', 'true'); + + // select first city + const cityOneId = + homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); + await actions.serverList.selectCityFromList(cityOneId, entryCountryId); + await vpn.waitForElementAndClick(cityOneId); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // select first country again + await actions.serverList.selectCountryFromList(exitFirstCountryId); + await vpn.wait(); + if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(exitFirstCountryId); + } + await vpn.waitForElementProperty( + exitFirstCountryId, 'cityListVisible', 'true'); + + // select first city in exit country + const cityTwoId = homeScreen.serverListView.generateCityId( + exitFirstCountryId, cityTwo.name); + await actions.serverList.selectCityFromList(cityTwoId, exitFirstCountryId); + await vpn.waitForElementAndClick(cityTwoId); + + // navigate back to connection view + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON); + + // define connected server + currentCountry = firstServer.localizedName; + currentCity = cityTwo.localizedName; + + // connect vpn + await vpn.activate(); + + // wait and assert vpn connection + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + generalElements.CONTROLLER_TITLE, 'text') == 'VPN is on'; + }); + assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); + assert.strictEqual( + vpn.lastNotification().message, + `Connected to ${currentCountry}, ${currentCity}`); + + // back to main view + await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // select first country again + await actions.serverList.selectCountryFromList(exitThirdCountryId); + await vpn.wait(); + if (await vpn.getElementProperty(exitThirdCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(exitThirdCountryId); + } + await vpn.waitForElementProperty( + exitThirdCountryId, 'cityListVisible', 'true'); + + // select first city in exit country + const cityThreeId = homeScreen.serverListView.generateCityId( + exitThirdCountryId, cityThree.name); + await actions.serverList + .selectCityFromList(cityThreeId, exitThirdCountryId) + await vpn.waitForElementAndClick(cityThreeId); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON); + + // define new connected server + newCurrentCountry = thirdServer.localizedName; + newCurrentCity = cityThree.localizedName; + + // wait and assert server switching for multihop + await vpn.waitForCondition( + async () => {return vpn.lastNotification().title == + 'VPN Switched Servers'}, + 20) + assert.strictEqual( + vpn.lastNotification().message, + `Switched from ${currentCountry}, ${currentCity} to ${ + newCurrentCountry}, ${newCurrentCity}`); + }); + + it('Single and multihop switching', async () => { + await vpn.setSetting('serverSwitchNotification', true); + await vpn.setSetting('connectionChangeNotification', true); + + let currentCountry; + let currentCity; + + // wait for select entry and select entry + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.MULTIHOP_SELECTOR_TAB); + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.ENTRY_BUTTON); + + // exit server details + const firstServer = servers[0]; + const cityTwo = firstServer.cities[0]; + const exitFirstCountryId = + homeScreen.serverListView.generateCountryId(firstServer.code); + + // entry server details + const secondServer = servers[1]; + const cityOne = secondServer.cities[0]; + const entryCountryId = + homeScreen.serverListView.generateCountryId(secondServer.code); + + // select the first country + await actions.serverList.selectCountryFromList(entryCountryId); + await vpn.wait() + if (await vpn.getElementProperty(entryCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(entryCountryId); + } + await vpn.waitForElementProperty( + entryCountryId, 'cityListVisible', 'true'); + + // select first city + const cityOneId = + homeScreen.serverListView.generateCityId(entryCountryId, cityOne.name); + await actions.serverList.selectCityFromList(cityOneId, entryCountryId); + await vpn.waitForElementAndClick(cityOneId); + + // Back at the main view. select the exit entries + await vpn.waitForElementAndClick( + homeScreen.selectMultiHopServerView.EXIT_BUTTON); + + // select first country again + await actions.serverList.selectCountryFromList(exitFirstCountryId); + await vpn.wait(); + if (await vpn.getElementProperty(exitFirstCountryId, 'cityListVisible') === + 'false') { + await vpn.clickOnElement(exitFirstCountryId); + } + await vpn.waitForElementProperty( + exitFirstCountryId, 'cityListVisible', 'true'); + + // select first city in exit country + const cityTwoId = homeScreen.serverListView.generateCityId( + exitFirstCountryId, cityTwo.name); + await actions.serverList + .selectCityFromList(cityTwoId, exitFirstCountryId) + await vpn.waitForElementAndClick(cityTwoId); + + // navigate back to connection view + await vpn.waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON); + + // define connected server + currentCountry = firstServer.localizedName; + currentCity = cityTwo.localizedName; + + // connect vpn + await vpn.activate(); + + // wait and assert vpn connection + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + generalElements.CONTROLLER_TITLE, 'text') == 'VPN is on'; + }); + assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); + assert.strictEqual( + vpn.lastNotification().message, + `Connected to ${currentCountry}, ${currentCity}`); + + // back to main view + await vpn.waitForElementAndClick(homeScreen.SERVER_LIST_BUTTON); + + + // switch from multihop to singlehop + await vpn + .waitForElementAndClick( + homeScreen.selectSingleHopServerView.SINGLEHOP_SELECTOR_TAB) + await vpn + .waitForElementAndClick( + homeScreen.selectSingleHopServerView.BACK_BUTTON) + + // wait and assert vpn connection + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + generalElements.CONTROLLER_TITLE, 'text') == 'VPN is on'; + }); + assert.strictEqual(vpn.lastNotification().title, 'VPN Connected'); + assert.strictEqual( + vpn.lastNotification().message, + `Connected to ${currentCountry}, ${currentCity}`); + }); + }); diff --git a/tests/functional/testServers.js b/tests/functional/testServers.js index adbd1627dd9..b9ebcbf083c 100644 --- a/tests/functional/testServers.js +++ b/tests/functional/testServers.js @@ -20,8 +20,10 @@ describe('Server list', function() { await vpn.wait(); servers = await vpn.servers(); - currentCountryCode = await vpn.getSetting('current-server-country-code'); - currentCity = await vpn.getSetting('current-server-city'); + currentCountryCode = + await vpn.getElementProperty('VPNCurrentServer', 'exitCountryCode'); + currentCity = + await vpn.getElementProperty('VPNCurrentServer', 'exitCityName'); for (let server of servers) { if (currentCountryCode === server.code) { @@ -143,8 +145,8 @@ describe('Server list', function() { }); it('Server switching', async () => { - await vpn.setSetting('server-switch-notification', 'true'); - await vpn.setSetting('connection-change-notification', 'true'); + await vpn.setSetting('serverSwitchNotification', 'true'); + await vpn.setSetting('connectionChangeNotification', 'true'); await vpn.waitForElement(homeScreen.selectSingleHopServerView.BACK_BUTTON); await vpn.waitForElementProperty(homeScreen.selectSingleHopServerView.BACK_BUTTON, 'visible', 'true'); await vpn.clickOnElement(homeScreen.selectSingleHopServerView.BACK_BUTTON); diff --git a/tests/functional/testSettings.js b/tests/functional/testSettings.js index 7bc252f9077..f5cfa838dba 100644 --- a/tests/functional/testSettings.js +++ b/tests/functional/testSettings.js @@ -28,12 +28,12 @@ describe('Settings', function () { await vpn.getSetting(settingKey)); await vpn.setSetting(settingKey, true); - assert((await vpn.getSetting(settingKey)) === 'true'); + assert((await vpn.getSetting(settingKey)) === true); assert((await vpn.getElementProperty(objectName, 'isChecked')) === 'true'); await vpn.wait(); await vpn.setSetting(settingKey, false); - assert((await vpn.getSetting(settingKey)) === 'false'); + assert((await vpn.getSetting(settingKey)) === false); assert((await vpn.getElementProperty(objectName, 'isChecked')) === 'false'); await vpn.wait(); } @@ -138,7 +138,7 @@ describe('Settings', function () { await vpn.clickOnElement(settingsScreen.NETWORK_SETTINGS); await vpn.wait(); - await checkSetting('settingLocalNetworkAccess', 'local-network-access'); + await checkSetting('settingLocalNetworkAccess', 'localNetworkAccess'); await vpn.waitForElement(settingsScreen.BACK); await vpn.waitForElementProperty(settingsScreen.BACK, 'visible', 'true'); @@ -150,7 +150,7 @@ describe('Settings', function () { }); it('Checking the languages settings', async () => { - await vpn.setSetting('language-code', ''); + await vpn.setSetting('languageCode', ''); await vpn.waitForElement(settingsScreen.SYSTEM_PREFERENCE); await vpn.waitForElementProperty(settingsScreen.SYSTEM_PREFERENCE, 'visible', 'true'); @@ -444,7 +444,7 @@ describe('Settings', function () { await vpn.clickOnElement(settingsScreen.SYSTEM_PREFERENCE); await vpn.wait(); - await checkSetting('dataCollection', 'glean-enabled'); + await checkSetting('dataCollection', 'gleanEnabled'); await vpn.clickOnElement(settingsScreen.BACK); await vpn.wait(); @@ -475,8 +475,8 @@ describe('Settings', function () { await checkSetting( 'settingUnsecuredNetworkAlert', 'unsecured-network-alert'); */ - await checkSetting('switchServersAlert', 'server-switch-notification'); - await checkSetting('connectionChangeAlert', 'connection-change-notification'); + await checkSetting('switchServersAlert', 'serverSwitchNotification'); + await checkSetting('connectionChangeAlert', 'connectionChangeNotification'); await vpn.clickOnElement(settingsScreen.BACK); await vpn.wait(); diff --git a/tests/functional/testTelemetryView.js b/tests/functional/testTelemetryView.js index 2edda602b49..3e2a6d8a5a1 100644 --- a/tests/functional/testTelemetryView.js +++ b/tests/functional/testTelemetryView.js @@ -21,23 +21,23 @@ describe('Telemetry view', function() { } it('Accept telemetry', async () => { - assert(await vpn.getSetting('telemetry-policy-shown') === 'false'); - assert(await vpn.getSetting('glean-enabled') === 'true'); + assert(await vpn.getSetting('telemetryPolicyShown') === false); + assert(await vpn.getSetting('gleanEnabled') === true); await _getToTelemetryPage(); await vpn.clickOnElement(telemetryScreen.TELEMETRY_POLICY_BUTTON); await vpn.wait(); - assert(await vpn.getSetting('telemetry-policy-shown') === 'true'); - assert(await vpn.getSetting('glean-enabled') === 'true'); + assert(await vpn.getSetting('telemetryPolicyShown') === true); + assert(await vpn.getSetting('gleanEnabled') === true); }); it('Deny telemetry', async () => { - assert(await vpn.getSetting('telemetry-policy-shown') === 'false'); - assert(await vpn.getSetting('glean-enabled') === 'true'); + assert(await vpn.getSetting('telemetryPolicyShown') === false); + assert(await vpn.getSetting('gleanEnabled') === true); await _getToTelemetryPage(); await vpn.clickOnElement(telemetryScreen.DECLINE_TELEMETRY); await vpn.wait(); - assert(await vpn.getSetting('telemetry-policy-shown') === 'true'); - assert(await vpn.getSetting('glean-enabled') === 'false'); + assert(await vpn.getSetting('telemetryPolicyShown') === true); + assert(await vpn.getSetting('gleanEnabled') === false); }); }); diff --git a/tests/functional/testTipsAndTricksIntroModal.js b/tests/functional/testTipsAndTricksIntroModal.js index 04ec5664be5..d897a308c93 100644 --- a/tests/functional/testTipsAndTricksIntroModal.js +++ b/tests/functional/testTipsAndTricksIntroModal.js @@ -11,8 +11,7 @@ describe('Tips and tricks intro modal', function () { beforeEach(async () => { await vpn.resetAddons('04_tutorials_basic'); - - await vpn.setSetting('tips-and-tricks-intro-shown', 'false'); + await vpn.setSetting('tipsAndTricksIntroShown', 'false'); await vpn.authenticateInApp(true, true); }); diff --git a/tests/functional/testTutorials.js b/tests/functional/testTutorials.js index 368dfad3dd0..63f29686164 100644 --- a/tests/functional/testTutorials.js +++ b/tests/functional/testTutorials.js @@ -28,13 +28,9 @@ describe('Tutorials', function () { await vpn.clickOnElement(homeScreen.TUTORIAL_LEAVE); } - async function loadAddons() { - await vpn.resetAddons('04_tutorials_basic'); - } - describe('Tutorial tooltip', function() { beforeEach(async () => { - await loadAddons(); + await vpn.resetAddons('04_tutorials_basic'); await openHighlightedTutorial(); }); @@ -57,7 +53,7 @@ describe('Tutorials', function () { describe('"Leave tutorial?" popup', function() { beforeEach(async () => { - await loadAddons(); + await vpn.resetAddons('04_tutorials_basic'); await openHighlightedTutorial(); await vpn.wait(); await clickTooltipCloseButton(); diff --git a/tests/functional/testUnsecuredNetworkAlert.js b/tests/functional/testUnsecuredNetworkAlert.js index 33c982cce0f..f25dd605df3 100644 --- a/tests/functional/testUnsecuredNetworkAlert.js +++ b/tests/functional/testUnsecuredNetworkAlert.js @@ -11,11 +11,11 @@ describe('Unsecured network alert', function() { it('Enable unsecured-network-alert feature', async () => { vpn.resetLastNotification(); - await vpn.setSetting('unsecured-network-alert', 'false'); - assert(await vpn.getSetting('unsecured-network-alert') === 'false'); + await vpn.setSetting('unsecuredNetworkAlert', 'false'); + assert(await vpn.getSetting('unsecuredNetworkAlert') === false); - await vpn.setSetting('unsecured-network-alert', 'true'); - assert(await vpn.getSetting('unsecured-network-alert') === 'true'); + await vpn.setSetting('unsecuredNetworkAlert', 'true'); + assert(await vpn.getSetting('unsecuredNetworkAlert') === true); }); it('Unsecured network alert during the main view', async () => { diff --git a/tests/unit/testaddon.cpp b/tests/unit/testaddon.cpp index 6eaf801dd6e..991fd76886b 100644 --- a/tests/unit/testaddon.cpp +++ b/tests/unit/testaddon.cpp @@ -1055,7 +1055,7 @@ void TestAddon::message_date() { Localizer localizer; QFETCH(QString, languageCode); - localizer.setCode(languageCode); + settingsHolder.setLanguageCode(languageCode); QFETCH(QDateTime, now); QVERIFY(now.isValid()); diff --git a/tests/unit/testlocalizer.cpp b/tests/unit/testlocalizer.cpp index 2887018af42..1e3eace7584 100644 --- a/tests/unit/testlocalizer.cpp +++ b/tests/unit/testlocalizer.cpp @@ -28,16 +28,16 @@ void TestLocalizer::systemLanguage() { Localizer l; - l.setCode(""); - QCOMPARE(l.code(), ""); + settings.setLanguageCode(""); + QCOMPARE(settings.languageCode(), ""); - l.setCode("en"); - QCOMPARE(l.code(), "en"); - QVERIFY(!l.previousCode().isEmpty()); + settings.setLanguageCode("en"); + QCOMPARE(settings.languageCode(), "en"); + QVERIFY(!settings.previousLanguageCode().isEmpty()); - l.setCode(""); - QCOMPARE(l.code(), ""); - QCOMPARE(l.previousCode(), "en"); + settings.setLanguageCode(""); + QCOMPARE(settings.languageCode(), ""); + QCOMPARE(settings.previousLanguageCode(), "en"); QVERIFY(!Localizer::systemLanguageCode().isEmpty()); } @@ -45,7 +45,7 @@ void TestLocalizer::systemLanguage() { void TestLocalizer::localizeCurrency() { SettingsHolder settings; Localizer l; - l.setCode("en_GB"); + settings.setLanguageCode("en_GB"); // Invalid iso4217 values QCOMPARE(l.localizeCurrency(123.123, "FOOBAR"), "FOOBAR123.12"); diff --git a/wasm/main.js b/wasm/main.js index a7c9c77bdc8..6ea228a1d8b 100644 --- a/wasm/main.js +++ b/wasm/main.js @@ -205,7 +205,7 @@ class MVPNWasm { } _loadLanguage(lang) { - controller.setSetting('language-code', lang); + controller.setSetting('languageCode', lang); } _backButtonClicked() {