summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-05-07 15:43:34 -0400
committerJackLivio <jack@livio.io>2019-05-07 15:43:34 -0400
commit403eeff556eb70762451496716bd1b5b15752df4 (patch)
tree84e6d9af537de84a6eb431d3d81c26702e1ec310
parent94a46dd9cdbb7b8a281c067f81c188f66cfc6a5d (diff)
downloadsdl_core-403eeff556eb70762451496716bd1b5b15752df4.tar.gz
ADd unit tests for icon_url
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc31
-rw-r--r--src/components/application_manager/test/application_manager_impl_test.cc55
-rw-r--r--src/components/application_manager/test/mobile_event_engine_test.cc10
-rw-r--r--src/components/policy/policy_regular/test/sql_pt_representation_test.cc7
4 files changed, 96 insertions, 7 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc
index 14441d450e..7351cd67d3 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc
@@ -229,6 +229,37 @@ TEST_F(SystemRequestTest, Run_RequestTypeDisallowed_SendDisallowedResponse) {
command->Run();
}
+TEST_F(SystemRequestTest, Run_RequestType_IconURL_Success) {
+ PreConditions();
+ MessageSharedPtr msg = CreateIVSUMessage();
+ (*msg)[am::strings::msg_params][am::strings::request_type] =
+ mobile_apis::RequestType::ICON_URL;
+
+ const std::string url = "https://www.appsfakeiconurlendpoint.com/icon.png";
+
+ (*msg)[am::strings::msg_params][am::strings::file_name] = url;
+ const std::vector<uint8_t> binary_data = {1u, 2u};
+ (*msg)[am::strings::params][am::strings::binary_data] = binary_data;
+
+ EXPECT_CALL(
+ mock_policy_handler_,
+ IsRequestTypeAllowed(kAppPolicyId, mobile_apis::RequestType::ICON_URL))
+ .WillOnce(Return(true));
+ EXPECT_CALL(app_mngr_settings_, app_icons_folder())
+ .WillOnce(ReturnRef(kAppStorageFolder));
+ EXPECT_CALL(app_mngr_, PolicyIDByIconUrl(url)).WillOnce(Return(kAppPolicyId));
+
+ EXPECT_CALL(app_mngr_,
+ SaveBinary(binary_data, kAppStorageFolder, kAppPolicyId, 0u))
+ .WillOnce(Return(mobile_apis::Result::SUCCESS));
+
+ EXPECT_CALL(app_mngr_, SetIconFileFromSystemRequest(kAppPolicyId)).Times(1);
+
+ std::shared_ptr<SystemRequest> command(CreateCommand<SystemRequest>(msg));
+ ASSERT_TRUE(command->Init());
+ command->Run();
+}
+
} // namespace system_request
} // namespace mobile_commands_test
} // namespace commands_test
diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc
index 3405006859..2f69170522 100644
--- a/src/components/application_manager/test/application_manager_impl_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_test.cc
@@ -229,6 +229,7 @@ class ApplicationManagerImplTest : public ::testing::Test {
#if defined(CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT)
void AddCloudAppToPendingDeviceMap();
+ void CreatePendingApplication();
#endif
uint32_t app_id_;
NiceMock<policy_test::MockPolicySettings> mock_policy_settings_;
@@ -1476,8 +1477,7 @@ void ApplicationManagerImplTest::AddCloudAppToPendingDeviceMap() {
app_manager_impl_->RefreshCloudAppInformation();
}
-TEST_F(ApplicationManagerImplTest, CreatePendingApplication) {
- // Add to pending device map. Calls refresh cloud app
+void ApplicationManagerImplTest::CreatePendingApplication() {
AddCloudAppToPendingDeviceMap();
// CreatePendingApplication
@@ -1507,6 +1507,10 @@ TEST_F(ApplicationManagerImplTest, CreatePendingApplication) {
EXPECT_EQ(1u, app_list.size());
}
+TEST_F(ApplicationManagerImplTest, CreatePendingApplication) {
+ CreatePendingApplication();
+}
+
TEST_F(ApplicationManagerImplTest, SetPendingState) {
AddCloudAppToPendingDeviceMap();
AddMockApplication();
@@ -1666,6 +1670,53 @@ TEST_F(ApplicationManagerImplTest,
app_manager_impl_->RegisterApplication(request_for_registration_ptr);
EXPECT_EQ(0, application.use_count());
}
+
+TEST_F(ApplicationManagerImplTest, PolicyIDByIconUrl_Success) {
+ app_manager_impl_->SetMockPolicyHandler(mock_policy_handler_);
+ std::vector<std::string> enabled_apps{"1234"};
+ EXPECT_CALL(*mock_policy_handler_, GetEnabledCloudApps(_))
+ .WillOnce(SetArgReferee<0>(enabled_apps));
+ EXPECT_CALL(*mock_policy_handler_, GetCloudAppParameters(_, _, _, _, _, _, _))
+ .WillOnce(DoAll(SetArgReferee<1>(kEnabled),
+ SetArgReferee<2>(kEndpoint2),
+ SetArgReferee<3>(kCertificate),
+ SetArgReferee<4>(kAuthToken),
+ SetArgReferee<5>(kTransportType),
+ SetArgReferee<6>(kHybridAppPreferenceStr),
+ Return(true)));
+
+ std::vector<std::string> nicknames{"CloudApp"};
+ EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(_, _, _))
+ .WillOnce(DoAll(SetArgPointee<1>(nicknames), Return(true)));
+
+ const std::string url = "https://www.fakeiconurl.com/icon.png";
+ EXPECT_CALL(*mock_policy_handler_, GetIconUrl("1234"))
+ .WillRepeatedly(Return(url));
+
+ app_manager_impl_->RefreshCloudAppInformation();
+
+ std::string result = app_manager_impl_->PolicyIDByIconUrl(url);
+ EXPECT_EQ(result, "1234");
+}
+
+TEST_F(ApplicationManagerImplTest, SetIconFileFromSystemRequest_Success) {
+ CreatePendingApplication();
+ Mock::VerifyAndClearExpectations(mock_message_helper_);
+
+ file_system::CreateDirectory(kDirectoryName);
+ const std::string full_icon_path = kDirectoryName + "/1234";
+ ASSERT_TRUE(file_system::CreateFile(full_icon_path));
+
+ const std::string url = "https://www.fakeiconurl.com/icon.png";
+ EXPECT_CALL(*mock_policy_handler_, GetIconUrl("1234"))
+ .WillRepeatedly(Return(url));
+ EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(1);
+ EXPECT_CALL(mock_application_manager_settings_, app_icons_folder())
+ .WillOnce(ReturnRef(kDirectoryName));
+ app_manager_impl_->SetIconFileFromSystemRequest("1234");
+ EXPECT_TRUE(file_system::RemoveDirectory(kDirectoryName, true));
+}
+
#endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT
} // namespace application_manager_test
} // namespace components
diff --git a/src/components/application_manager/test/mobile_event_engine_test.cc b/src/components/application_manager/test/mobile_event_engine_test.cc
index 7e8583d3fd..cad1ff14ff 100644
--- a/src/components/application_manager/test/mobile_event_engine_test.cc
+++ b/src/components/application_manager/test/mobile_event_engine_test.cc
@@ -32,13 +32,13 @@
#include "gtest/gtest.h"
-#include "application_manager/event_engine/event_observer.h"
#include "application_manager/event_engine/event.h"
#include "application_manager/event_engine/event_dispatcher_impl.h"
-#include "application_manager/mock_event_observer.h"
+#include "application_manager/event_engine/event_observer.h"
+#include "application_manager/message.h"
#include "application_manager/mock_event_dispatcher.h"
+#include "application_manager/mock_event_observer.h"
#include "smart_objects/smart_object.h"
-#include "application_manager/message.h"
#include "interfaces/MOBILE_API.h"
@@ -46,10 +46,10 @@ namespace test {
namespace components {
namespace event_engine_test {
-using application_manager::event_engine::EventDispatcherImpl;
using application_manager::event_engine::Event;
-using application_manager::event_engine::MobileEvent;
+using application_manager::event_engine::EventDispatcherImpl;
using application_manager::event_engine::EventObserver;
+using application_manager::event_engine::MobileEvent;
using testing::_;
using ::testing::An;
using ::testing::Matcher;
diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
index dc11e11f12..d456aa26e4 100644
--- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
+++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
@@ -322,6 +322,8 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
app_policies["1234"]["steal_focus"] = Json::Value(false);
app_policies["1234"]["RequestType"] = Json::Value(Json::arrayValue);
app_policies["1234"]["app_services"] = Json::Value(Json::objectValue);
+ app_policies["1234"]["icon_url"] =
+ Json::Value("http:://www.sdl.com/image.png");
app_policies["1234"]["app_services"]["MEDIA"] =
Json::Value(Json::objectValue);
app_policies["1234"]["app_services"]["MEDIA"]["service_names"] =
@@ -1745,6 +1747,11 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) {
EXPECT_TRUE(handled_rpcs.is_initialized());
EXPECT_EQ(handled_rpcs[0].function_id, 41);
+
+ policy_table::ApplicationPolicies& apps = policies.apps;
+ auto icon_url = *(apps[kAppId].icon_url);
+
+ EXPECT_EQ(std::string(icon_url), "http:://www.sdl.com/image.png");
}
} // namespace policy_test