summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorigapchuck <igapchuck@luxoft.com>2019-06-28 15:35:08 +0300
committerigapchuck <igapchuck@luxoft.com>2019-07-24 10:26:36 +0300
commitf0928e7c0023ca77011c9906edb0accc1962480a (patch)
tree5d88d58867e4acc11acabec031602d8c5fa45c8c
parent6b7ecc6160f3511beea866b32fd6a083528f9919 (diff)
downloadsdl_core-f0928e7c0023ca77011c9906edb0accc1962480a.tar.gz
Unit tests LockScreenDismissalWarning
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc32
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc174
2 files changed, 203 insertions, 3 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
index 88be43b4b3..2f8f5c2849 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
@@ -192,6 +192,14 @@ const int32_t kMobileProtocolType_ = 0;
const int32_t kProtocolVersion_ = 3;
const uint32_t kCorrelationId_ = 1939u;
const uint32_t kAppId_ = 2014u;
+const std::string kDefaultLanguage = "en-us";
+const mobile_apis::Language::eType kMobileLanguage =
+ mobile_apis::Language::EN_US;
+
+// LSDW - lock screen dismissal warning
+const std::string kLockScreenDismissalWarningMessage_en =
+ "Swipe down to dismiss, acknowledging that you are not the driver";
+const uint32_t kConnectionKey = 2u;
} // namespace
class HMICommandsNotificationsTest
@@ -240,6 +248,9 @@ class HMICommandsNotificationsTest
.WillByDefault(ReturnRef(mock_event_dispatcher_));
ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_));
ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_));
+ ON_CALL(app_mngr_, application(kConnectionKey)).WillByDefault(Return(app_));
+ ON_CALL(mock_message_helper_, MobileLanguageToString(kMobileLanguage))
+ .WillByDefault(Return(kDefaultLanguage));
}
am::ApplicationSharedPtr ConfigureApp(NiceMock<MockApplication>** app_mock,
@@ -259,6 +270,8 @@ class HMICommandsNotificationsTest
.WillByDefault(Return(vc));
ON_CALL(**app_mock, IsAudioApplication())
.WillByDefault(Return(media || navi || vc));
+ ON_CALL(**app_mock, ui_language())
+ .WillByDefault(ReturnRef(kMobileLanguage));
return app;
}
#if defined(OS_POSIX)
@@ -1793,6 +1806,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) {
hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
(*message)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey;
std::shared_ptr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
@@ -1804,6 +1818,12 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) {
ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState())
.WillByDefault(Return(OptionalBool(true)));
+ std::string required_language = "en-us";
+ ON_CALL(mock_policy_handler_,
+ LockScreenDismissalWarningMessage(required_language))
+ .WillByDefault(Return(
+ boost::optional<std::string>(kLockScreenDismissalWarningMessage_en)));
+
ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_));
EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0);
@@ -1816,6 +1836,7 @@ TEST_F(HMICommandsNotificationsTest,
const auto state = hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
(*message)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey;
std::shared_ptr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
@@ -1827,6 +1848,11 @@ TEST_F(HMICommandsNotificationsTest,
typedef boost::optional<bool> OptionalBool;
ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState())
.WillByDefault(Return(OptionalBool(true)));
+ std::string required_language = "en-us";
+ ON_CALL(mock_policy_handler_,
+ LockScreenDismissalWarningMessage(required_language))
+ .WillByDefault(Return(
+ boost::optional<std::string>(kLockScreenDismissalWarningMessage_en)));
ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_));
EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0);
@@ -1839,6 +1865,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) {
hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
(*message)[am::strings::msg_params][am::mobile_notification::state] = state;
+ (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey;
std::shared_ptr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
@@ -1849,6 +1876,11 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) {
typedef boost::optional<bool> OptionalBool;
ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState())
.WillByDefault(Return(OptionalBool(true)));
+ std::string required_language = "en-us";
+ ON_CALL(mock_policy_handler_,
+ LockScreenDismissalWarningMessage(required_language))
+ .WillByDefault(Return(
+ boost::optional<std::string>(kLockScreenDismissalWarningMessage_en)));
ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_));
policy::CheckPermissionResult result;
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc
index 38c21cfbc4..5e0083d395 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc
@@ -52,10 +52,12 @@ namespace hmi_commands_test {
namespace on_driver_distraction_notification {
using ::testing::_;
+using ::testing::DoAll;
using ::testing::Eq;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SaveArg;
+using ::testing::SetArgumentPointee;
namespace am = ::application_manager;
using am::commands::MessageSharedPtr;
@@ -63,6 +65,17 @@ using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification;
using namespace am::commands;
using test::components::commands_test::MobileResultCodeIs;
+namespace {
+const std::string kDefaultLanguage = "en-us";
+const mobile_apis::Language::eType kMobileLanguage =
+ mobile_apis::Language::EN_US;
+
+// LSDW - lock screen dismissal warning
+const std::string kLockScreenDismissalWarningMessage_en =
+ "Swipe down to dismiss, acknowledging that you are not the driver";
+const uint32_t kConnectionKey = 2u;
+} // namespace
+
class HMIOnDriverDistractionNotificationTest
: public CommandsTest<CommandsTestMocks::kIsNice> {
public:
@@ -77,6 +90,15 @@ class HMIOnDriverDistractionNotificationTest
typedef std::shared_ptr<OnDriverDistractionNotification> NotificationPtr;
typedef boost::optional<bool> OptionalBool;
+ void SetUp() OVERRIDE {
+ ON_CALL(*mock_app_, ui_language())
+ .WillByDefault(ReturnRef(kMobileLanguage));
+ ON_CALL(app_mngr_, application(kConnectionKey))
+ .WillByDefault(Return(mock_app_));
+ ON_CALL(mock_message_helper_, MobileLanguageToString(kMobileLanguage))
+ .WillByDefault(Return(kDefaultLanguage));
+ }
+
MockAppPtr mock_app_;
std::shared_ptr<sync_primitives::Lock> app_set_lock_;
am::ApplicationSet app_set_;
@@ -108,11 +130,21 @@ ACTION_P(GetArg3, result) {
arg3 = *result;
}
+ACTION_P(SetMessage, lockScreenDismissalWarning) {
+ smart_objects::SmartObject& notification = arg0;
+
+ notification[application_manager::strings::msg_params]
+ [application_manager::mobile_notification::
+ lock_screen_dismissal_warning] = lockScreenDismissalWarning;
+}
+
TEST_F(HMIOnDriverDistractionNotificationTest,
Run_SendNotificationToMobile_SUCCESS) {
const auto state = hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map));
(*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*commands_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
NotificationPtr command(
CreateCommand<OnDriverDistractionNotification>(commands_msg));
@@ -122,17 +154,34 @@ TEST_F(HMIOnDriverDistractionNotificationTest,
ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState())
.WillByDefault(Return(OptionalBool(true)));
+ ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_))
+ .WillByDefault(Return(kLockScreenDismissalWarningMessage_en));
+
policy::CheckPermissionResult result;
result.hmi_level_permitted = policy::kRpcAllowed;
EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _))
.WillOnce(GetArg3(&result));
+ MessageSharedPtr message_to_mobile(
+ CreateMessage(smart_objects::SmartType_Map));
EXPECT_CALL(mock_rpc_service_,
ManageMobileCommand(
CheckNotificationParams(
am::mobile_api::FunctionID::OnDriverDistractionID, state),
- Command::CommandSource::SOURCE_SDL));
+ Command::CommandSource::SOURCE_SDL))
+ .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true)));
command->Run();
+
+ ASSERT_TRUE((*message_to_mobile)[am::strings::msg_params].keyExists(
+ am::mobile_notification::lock_screen_dismissal_warning));
+
+ auto LSDW_message =
+ (*message_to_mobile)
+ [am::strings::msg_params]
+ [am::mobile_notification::lock_screen_dismissal_warning]
+ .asString();
+
+ EXPECT_EQ(kLockScreenDismissalWarningMessage_en, LSDW_message);
}
TEST_F(HMIOnDriverDistractionNotificationTest,
@@ -140,22 +189,41 @@ TEST_F(HMIOnDriverDistractionNotificationTest,
const auto state = hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map));
(*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*commands_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
NotificationPtr command(
CreateCommand<OnDriverDistractionNotification>(commands_msg));
ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState())
- .WillByDefault(Return(OptionalBool(true)));
+ .WillByDefault(Return(boost::optional<bool>(true)));
+
+ ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_))
+ .WillByDefault(Return(kLockScreenDismissalWarningMessage_en));
policy::CheckPermissionResult result;
result.hmi_level_permitted = policy::kRpcDisallowed;
EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _))
.WillOnce(GetArg3(&result));
+
+ MessageSharedPtr pushed_message(CreateMessage(smart_objects::SmartType_Map));
EXPECT_CALL(*mock_app_,
PushMobileMessage(CheckNotificationParams(
- am::mobile_api::FunctionID::OnDriverDistractionID, state)));
+ am::mobile_api::FunctionID::OnDriverDistractionID, state)))
+ .WillOnce(SaveArg<0>(&pushed_message));
EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state)));
command->Run();
+
+ ASSERT_TRUE((*pushed_message)[am::strings::msg_params].keyExists(
+ am::mobile_notification::lock_screen_dismissal_warning));
+
+ auto lock_screen_dismissal_warning_message =
+ (*pushed_message)[am::strings::msg_params]
+ [am::mobile_notification::lock_screen_dismissal_warning]
+ .asString();
+
+ EXPECT_EQ(kLockScreenDismissalWarningMessage_en,
+ lock_screen_dismissal_warning_message);
}
TEST_F(HMIOnDriverDistractionNotificationTest,
@@ -186,8 +254,108 @@ TEST_F(HMIOnDriverDistractionNotificationTest,
(*command_result)[application_manager::strings::msg_params];
EXPECT_FALSE(msg_params.keyExists(
application_manager::mobile_notification::lock_screen_dismissal_enabled));
+ EXPECT_FALSE(msg_params.keyExists(
+ application_manager::mobile_notification::lock_screen_dismissal_warning));
}
+// LSDW - lock screen dimissal
+TEST_F(HMIOnDriverDistractionNotificationTest,
+ Run_SendNotificationToMobile_LSDWMessageIsAbsent_SUCCESS) {
+ const auto state = hmi_apis::Common_DriverDistractionState::DD_ON;
+ MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*commands_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ NotificationPtr command(
+ CreateCommand<OnDriverDistractionNotification>(commands_msg));
+
+ EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state)));
+
+ ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState())
+ .WillByDefault(Return(OptionalBool(false)));
+
+ // LockScreenDismissalWarning won't be added to message if value of
+ // LockScreenDismissalEnabledState is false
+ std::string required_language = "en-us";
+ EXPECT_CALL(mock_policy_handler_interface_,
+ LockScreenDismissalWarningMessage(required_language))
+ .Times(0);
+
+ policy::CheckPermissionResult result;
+ result.hmi_level_permitted = policy::kRpcAllowed;
+ EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _))
+ .WillOnce(GetArg3(&result));
+
+ MessageSharedPtr message_to_mobile(
+ CreateMessage(smart_objects::SmartType_Map));
+ EXPECT_CALL(mock_rpc_service_,
+ ManageMobileCommand(
+ CheckNotificationParams(
+ am::mobile_api::FunctionID::OnDriverDistractionID, state),
+ Command::CommandSource::SOURCE_SDL))
+ .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true)));
+ command->Run();
+
+ EXPECT_FALSE((*message_to_mobile)[am::strings::msg_params].keyExists(
+ am::mobile_notification::lock_screen_dismissal_warning));
+}
+
+TEST_F(HMIOnDriverDistractionNotificationTest,
+ Run_SendNotificationToMobile_SpecifiedLanguageIsAbsent_SUCCESS) {
+ const auto state = hmi_apis::Common_DriverDistractionState::DD_ON;
+ MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state;
+ (*commands_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ NotificationPtr command(
+ CreateCommand<OnDriverDistractionNotification>(commands_msg));
+
+ EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state)));
+
+ ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState())
+ .WillByDefault(Return(OptionalBool(true)));
+
+ ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_))
+ .WillByDefault(Return(kLockScreenDismissalWarningMessage_en));
+
+ // In case when specified language is absent in policy table, will added
+ // message on default language (en-us)
+ const mobile_apis::Language::eType mobile_language =
+ mobile_apis::Language::FR_FR;
+ std::string required_language = "FR-FR";
+ ON_CALL(*mock_app_, ui_language()).WillByDefault(ReturnRef(mobile_language));
+ ON_CALL(mock_message_helper_, MobileLanguageToString(mobile_language))
+ .WillByDefault(Return(required_language));
+
+ policy::CheckPermissionResult result;
+ result.hmi_level_permitted = policy::kRpcAllowed;
+ EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _))
+ .WillOnce(GetArg3(&result));
+
+ MessageSharedPtr message_to_mobile(
+ CreateMessage(smart_objects::SmartType_Map));
+ EXPECT_CALL(mock_rpc_service_,
+ ManageMobileCommand(
+ CheckNotificationParams(
+ am::mobile_api::FunctionID::OnDriverDistractionID, state),
+ Command::CommandSource::SOURCE_SDL))
+ .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true)));
+ command->Run();
+
+ ASSERT_TRUE((*message_to_mobile)[am::strings::msg_params].keyExists(
+ am::mobile_notification::lock_screen_dismissal_warning));
+
+ auto lock_screen_dismissal_warning_message =
+ (*message_to_mobile)
+ [am::strings::msg_params]
+ [am::mobile_notification::lock_screen_dismissal_warning]
+ .asString();
+
+ EXPECT_EQ(kLockScreenDismissalWarningMessage_en,
+ lock_screen_dismissal_warning_message);
+}
} // namespace on_driver_distraction_notification
} // namespace hmi_commands_test
} // namespace commands_test